diff --git a/src/main/java/club/joylink/xiannccda/controller/DraftingController.java b/src/main/java/club/joylink/xiannccda/controller/DraftingController.java index 88d2c07..7748454 100644 --- a/src/main/java/club/joylink/xiannccda/controller/DraftingController.java +++ b/src/main/java/club/joylink/xiannccda/controller/DraftingController.java @@ -23,9 +23,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; /** - *

* 绘图草稿 前端控制器 - *

* * @author walker-sheng * @since 2023-06-06 @@ -53,8 +51,8 @@ public class DraftingController { @SecurityRequirement(name = "jwt") @Operation(summary = "创建绘图草稿") @ApiResponse(description = "绘图草稿信息") - public Drafting create(Principal user, - @RequestBody @Validated(Creation.class) Drafting drafting) { + public Drafting create( + Principal user, @RequestBody @Validated(Creation.class) Drafting drafting) { return this.draftingRepository.create(drafting, Integer.valueOf(user.getName())); } @@ -62,7 +60,9 @@ public class DraftingController { @SecurityRequirement(name = "jwt") @Operation(summary = "另存为绘图草稿") @ApiResponse(description = "绘图草稿信息") - public Drafting saveAs(Principal user, @PathVariable Integer id, + public Drafting saveAs( + Principal user, + @PathVariable Integer id, @RequestBody @Validated(SaveAs.class) Drafting drafting) { return this.draftingRepository.saveAs(id, drafting, Integer.valueOf(user.getName())); } @@ -79,9 +79,12 @@ public class DraftingController { @SecurityRequirement(name = "jwt") @Operation(summary = "保存绘图草稿数据") @ApiResponse(description = "保存成功失败标识") - public boolean updateDrawData(@PathVariable Integer id, + public boolean updateDrawData( + Principal user, + @PathVariable Integer id, @RequestBody @Validated(SaveData.class) Drafting drafting) { - return this.draftingRepository.updateDrawData(id, drafting.getProto()); + return this.draftingRepository.updateDrawData( + id, drafting.getProto(), Integer.valueOf(user.getName())); } @DeleteMapping("/{id}") diff --git a/src/main/java/club/joylink/xiannccda/exception/BusinessExceptionAssertEnum.java b/src/main/java/club/joylink/xiannccda/exception/BusinessExceptionAssertEnum.java index a024dcf..3f2b10f 100644 --- a/src/main/java/club/joylink/xiannccda/exception/BusinessExceptionAssertEnum.java +++ b/src/main/java/club/joylink/xiannccda/exception/BusinessExceptionAssertEnum.java @@ -7,7 +7,8 @@ public enum BusinessExceptionAssertEnum implements BusinessExceptionAssert { ARGUMENT_ILLEGAL(1001, "argument illegal"), DATA_NOT_EXIST(1002, "data not exist"), UNIQUE_FIELD_REPEAT(1003, "unique field repeat"), - DATA_ALREADY_EXISTS(1004, "data already exists"); + DATA_ALREADY_EXISTS(1004, "data already exists"), + NOT_HAVE_AUTHORIZATION(1005, "Unauthorized"); int code; diff --git a/src/main/java/club/joylink/xiannccda/repository/IDraftingRepository.java b/src/main/java/club/joylink/xiannccda/repository/IDraftingRepository.java index 8ce34da..6d453df 100644 --- a/src/main/java/club/joylink/xiannccda/repository/IDraftingRepository.java +++ b/src/main/java/club/joylink/xiannccda/repository/IDraftingRepository.java @@ -6,9 +6,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.IService; /** - *

* 绘图草稿 服务类 - *

* * @author walker-sheng * @since 2023-06-06 @@ -25,7 +23,7 @@ public interface IDraftingRepository extends IService { Drafting create(Drafting drafting, Integer creatorId); - boolean updateDrawData(Integer id, byte[] proto); + boolean updateDrawData(Integer id, byte[] proto, Integer creatorId); Drafting saveAs(Integer id, Drafting drafting, Integer creatorId); } diff --git a/src/main/java/club/joylink/xiannccda/repository/impl/DraftingRepository.java b/src/main/java/club/joylink/xiannccda/repository/impl/DraftingRepository.java index 4419edd..b7b8391 100644 --- a/src/main/java/club/joylink/xiannccda/repository/impl/DraftingRepository.java +++ b/src/main/java/club/joylink/xiannccda/repository/impl/DraftingRepository.java @@ -10,22 +10,21 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import java.time.LocalDateTime; +import java.util.Objects; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.util.StringUtils; /** - *

* 绘图草稿 服务实现类 - *

* * @author walker-sheng * @since 2023-06-06 */ @Service @Slf4j -public class DraftingRepository extends ServiceImpl implements - IDraftingRepository { +public class DraftingRepository extends ServiceImpl + implements IDraftingRepository { @Override public Page pageQuery(DraftingQueryDTO query) { @@ -48,10 +47,11 @@ public class DraftingRepository extends ServiceImpl im } @Override - public boolean updateDrawData(Integer id, byte[] proto) { + public boolean updateDrawData(Integer id, byte[] proto, Integer creatorId) { Drafting d = this.getById(id); BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(d, "草稿数据不存在"); - d.setProto(proto); + BusinessExceptionAssertEnum.NOT_HAVE_AUTHORIZATION.assertTrue( + Objects.equals(creatorId, d.getCreatorId())); d.setUpdateAt(LocalDateTime.now()); return this.updateById(d); } @@ -59,8 +59,7 @@ public class DraftingRepository extends ServiceImpl im @Override public Drafting saveAs(Integer id, Drafting drafting, Integer creatorId) { BusinessExceptionAssertEnum.UNIQUE_FIELD_REPEAT.assertNotTrue( - this.isNameExist(drafting.getName()), - String.format("草稿名称已存在: %s", drafting.getName())); + this.isNameExist(drafting.getName()), String.format("草稿名称已存在: %s", drafting.getName())); Drafting old = this.getById(id); old.setId(null); old.setName(drafting.getName()); @@ -74,5 +73,4 @@ public class DraftingRepository extends ServiceImpl im public boolean isNameExist(String name) { return this.count(Wrappers.lambdaQuery().eq(Drafting::getName, name)) > 0; } - }