Merge remote-tracking branch 'origin/master'

This commit is contained in:
tiger_zhou 2023-06-26 14:47:44 +08:00
commit 0dae9b7021
4 changed files with 20 additions and 20 deletions

View File

@ -23,9 +23,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* <p>
* 绘图草稿 前端控制器
* </p>
*
* @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}")

View File

@ -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;

View File

@ -6,9 +6,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
/**
* <p>
* 绘图草稿 服务类
* </p>
*
* @author walker-sheng
* @since 2023-06-06
@ -25,7 +23,7 @@ public interface IDraftingRepository extends IService<Drafting> {
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);
}

View File

@ -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;
/**
* <p>
* 绘图草稿 服务实现类
* </p>
*
* @author walker-sheng
* @since 2023-06-06
*/
@Service
@Slf4j
public class DraftingRepository extends ServiceImpl<DraftingMapper, Drafting> implements
IDraftingRepository {
public class DraftingRepository extends ServiceImpl<DraftingMapper, Drafting>
implements IDraftingRepository {
@Override
public Page<Drafting> pageQuery(DraftingQueryDTO query) {
@ -48,10 +47,11 @@ public class DraftingRepository extends ServiceImpl<DraftingMapper, Drafting> 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<DraftingMapper, Drafting> 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<DraftingMapper, Drafting> im
public boolean isNameExist(String name) {
return this.count(Wrappers.<Drafting>lambdaQuery().eq(Drafting::getName, name)) > 0;
}
}