Commit fd3a556d2dd97593ebce56981cef475075dc58e5

Authored by YunaiV
1 parent bd61514a

✨ feat(mes): 新增维修工单编码唯一性校验及设备编号字段

新增维修工单编码的唯一性校验逻辑,确保在创建和更新维修工单时编码不重复。同时,新增设备编号字段以便于关联设备信息,提升维修工单管理的准确性和完整性。
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/dv/repair/vo/MesDvRepairPageReqVO.java
... ... @@ -23,6 +23,9 @@ public class MesDvRepairPageReqVO extends PageParam {
23 23 @Schema(description = "维修工单名称", example = "注塑机维修")
24 24 private String name;
25 25  
  26 + @Schema(description = "设备编号", example = "1")
  27 + private Long machineryId;
  28 +
26 29 @Schema(description = "维修结果", example = "1")
27 30 private Integer result;
28 31  
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/dv/repair/MesDvRepairMapper.java
... ... @@ -19,12 +19,17 @@ public interface MesDvRepairMapper extends BaseMapperX<MesDvRepairDO> {
19 19 return selectPage(reqVO, new LambdaQueryWrapperX<MesDvRepairDO>()
20 20 .likeIfPresent(MesDvRepairDO::getCode, reqVO.getCode())
21 21 .likeIfPresent(MesDvRepairDO::getName, reqVO.getName())
  22 + .eqIfPresent(MesDvRepairDO::getMachineryId, reqVO.getMachineryId())
22 23 .eqIfPresent(MesDvRepairDO::getResult, reqVO.getResult())
23 24 .eqIfPresent(MesDvRepairDO::getStatus, reqVO.getStatus())
24 25 .betweenIfPresent(MesDvRepairDO::getRequireDate, reqVO.getRequireDate())
25 26 .orderByDesc(MesDvRepairDO::getId));
26 27 }
27 28  
  29 + default MesDvRepairDO selectByCode(String code) {
  30 + return selectOne(MesDvRepairDO::getCode, code);
  31 + }
  32 +
28 33 default Long selectCountByMachineryId(Long machineryId) {
29 34 return selectCount(MesDvRepairDO::getMachineryId, machineryId);
30 35 }
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/ErrorCodeConstants.java
... ... @@ -178,6 +178,7 @@ public interface ErrorCodeConstants {
178 178 // ========== MES 设备管理-维修工单(1-040-303-000) ==========
179 179 ErrorCode DV_REPAIR_NOT_EXISTS = new ErrorCode(1_040_303_000, "维修工单不存在");
180 180 ErrorCode DV_REPAIR_NOT_DRAFT = new ErrorCode(1_040_303_001, "维修工单已确认,不允许修改或删除");
  181 + ErrorCode DV_REPAIR_CODE_DUPLICATE = new ErrorCode(1_040_303_002, "维修工单编码已存在");
181 182 // ========== MES 设备管理-维修工单行(1-040-303-100) ==========
182 183 ErrorCode DV_REPAIR_LINE_NOT_EXISTS = new ErrorCode(1_040_303_100, "维修工单行不存在");
183 184  
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/repair/MesDvRepairLineService.java
... ... @@ -52,4 +52,11 @@ public interface MesDvRepairLineService {
52 52 */
53 53 PageResult<MesDvRepairLineDO> getRepairLinePage(MesDvRepairLinePageReqVO pageReqVO);
54 54  
  55 + /**
  56 + * 根据维修工单编号删除所有行
  57 + *
  58 + * @param repairId 维修工单编号
  59 + */
  60 + void deleteByRepairId(Long repairId);
  61 +
55 62 }
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/repair/MesDvRepairLineServiceImpl.java
... ... @@ -99,4 +99,9 @@ public class MesDvRepairLineServiceImpl implements MesDvRepairLineService {
99 99 return repairLineMapper.selectPage(pageReqVO);
100 100 }
101 101  
  102 + @Override
  103 + public void deleteByRepairId(Long repairId) {
  104 + repairLineMapper.deleteByRepairId(repairId);
  105 + }
  106 +
102 107 }
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/repair/MesDvRepairServiceImpl.java
... ... @@ -6,7 +6,6 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
6 6 import cn.iocoder.yudao.module.mes.controller.admin.dv.repair.vo.MesDvRepairPageReqVO;
7 7 import cn.iocoder.yudao.module.mes.controller.admin.dv.repair.vo.MesDvRepairSaveReqVO;
8 8 import cn.iocoder.yudao.module.mes.dal.dataobject.dv.repair.MesDvRepairDO;
9   -import cn.iocoder.yudao.module.mes.dal.mysql.dv.repair.MesDvRepairLineMapper;
10 9 import cn.iocoder.yudao.module.mes.dal.mysql.dv.repair.MesDvRepairMapper;
11 10 import cn.iocoder.yudao.module.mes.enums.dv.MesDvRepairResultEnum;
12 11 import cn.iocoder.yudao.module.mes.enums.dv.MesDvRepairStatusEnum;
... ... @@ -16,6 +15,8 @@ import org.springframework.stereotype.Service;
16 15 import org.springframework.transaction.annotation.Transactional;
17 16 import org.springframework.validation.annotation.Validated;
18 17  
  18 +import java.time.LocalDateTime;
  19 +
19 20 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
20 21 import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.*;
21 22  
... ... @@ -30,15 +31,19 @@ public class MesDvRepairServiceImpl implements MesDvRepairService {
30 31  
31 32 @Resource
32 33 private MesDvRepairMapper repairMapper;
  34 +
33 35 @Resource
34   - private MesDvRepairLineMapper repairLineMapper;
  36 + private MesDvRepairLineService repairLineService;
35 37 @Resource
36 38 private MesDvMachineryService machineryService;
37 39  
38 40 @Override
39 41 public Long createRepair(MesDvRepairSaveReqVO createReqVO) {
40   - // 1. 校验关联数据
  42 + // TODO @AI:抽成 validateXXSaveData(vo);
  43 + // 1.1 校验关联数据
41 44 validateRepairRelation(createReqVO);
  45 + // 1.2 校验编码唯一
  46 + validateCodeUnique(null, createReqVO.getCode());
42 47  
43 48 // 2. 插入
44 49 MesDvRepairDO repair = BeanUtils.toBean(createReqVO, MesDvRepairDO.class);
... ... @@ -51,8 +56,11 @@ public class MesDvRepairServiceImpl implements MesDvRepairService {
51 56 public void updateRepair(MesDvRepairSaveReqVO updateReqVO) {
52 57 // 1.1 校验存在,且状态为草稿
53 58 validateRepairDraft(updateReqVO.getId());
  59 + // TODO @AI:抽成 validateXXSaveData(vo);
54 60 // 1.2 校验关联数据
55 61 validateRepairRelation(updateReqVO);
  62 + // 1.3 校验编码唯一
  63 + validateCodeUnique(updateReqVO.getId(), updateReqVO.getCode());
56 64  
57 65 // 2. 更新
58 66 MesDvRepairDO updateObj = BeanUtils.toBean(updateReqVO, MesDvRepairDO.class);
... ... @@ -68,7 +76,7 @@ public class MesDvRepairServiceImpl implements MesDvRepairService {
68 76 // 删除
69 77 repairMapper.deleteById(id);
70 78 // 级联删除子表
71   - repairLineMapper.deleteByRepairId(id);
  79 + repairLineService.deleteByRepairId(id);
72 80 }
73 81  
74 82 private void validateRepairRelation(MesDvRepairSaveReqVO reqVO) {
... ... @@ -76,6 +84,20 @@ public class MesDvRepairServiceImpl implements MesDvRepairService {
76 84 machineryService.validateMachineryExists(reqVO.getMachineryId());
77 85 }
78 86  
  87 + private void validateCodeUnique(Long id, String code) {
  88 + if (code == null) {
  89 + return;
  90 + }
  91 + MesDvRepairDO repair = repairMapper.selectByCode(code);
  92 + // TODO @AI:参考别的模块,notEquals
  93 + if (repair == null) {
  94 + return;
  95 + }
  96 + if (id == null || !id.equals(repair.getId())) {
  97 + throw exception(DV_REPAIR_CODE_DUPLICATE);
  98 + }
  99 + }
  100 +
79 101 @Override
80 102 public void validateRepairExists(Long id) {
81 103 if (repairMapper.selectById(id) == null) {
... ... @@ -95,6 +117,7 @@ public class MesDvRepairServiceImpl implements MesDvRepairService {
95 117 * @return 维修工单
96 118 */
97 119 public MesDvRepairDO validateRepairDraft(Long id) {
  120 + // TODO @AI:复用 validateRepairExists 方法
98 121 MesDvRepairDO repair = repairMapper.selectById(id);
99 122 if (repair == null) {
100 123 throw exception(DV_REPAIR_NOT_EXISTS);
... ... @@ -120,10 +143,11 @@ public class MesDvRepairServiceImpl implements MesDvRepairService {
120 143 // 1. 校验存在,且状态为草稿
121 144 validateRepairDraft(id);
122 145  
123   - // 2. 更新状态为已确认,结果为通过
  146 + // 2. 更新状态为已确认,结果为通过,自动设置验收日期
124 147 repairMapper.updateById(new MesDvRepairDO().setId(id)
125 148 .setStatus(MesDvRepairStatusEnum.CONFIRMED.getStatus())
126   - .setResult(MesDvRepairResultEnum.PASS.getResult()));
  149 + .setResult(MesDvRepairResultEnum.PASS.getResult())
  150 + .setConfirmDate(LocalDateTime.now()));
127 151 }
128 152  
129 153 @Override
... ... @@ -131,10 +155,11 @@ public class MesDvRepairServiceImpl implements MesDvRepairService {
131 155 // 1. 校验存在,且状态为草稿
132 156 validateRepairDraft(id);
133 157  
134   - // 2. 更新状态为已确认,结果为不通过
  158 + // 2. 更新状态为已确认,结果为不通过,自动设置验收日期
135 159 repairMapper.updateById(new MesDvRepairDO().setId(id)
136 160 .setStatus(MesDvRepairStatusEnum.CONFIRMED.getStatus())
137   - .setResult(MesDvRepairResultEnum.FAIL.getResult()));
  161 + .setResult(MesDvRepairResultEnum.FAIL.getResult())
  162 + .setConfirmDate(LocalDateTime.now()));
138 163 }
139 164  
140 165 }
... ...