Commit 9f3538f4ccc6b3e4c714cb323412e697f0f8e2fe

Authored by YunaiV
1 parent 702d212f

✨ feat(mes): 重构过程检验行服务,优化方法命名与逻辑

- 重命名 selectListByIpqcId 为 getIpqcLineListByIpqcId,提升可读性
- 添加 validateIpqcLineExists 方法,增强行存在性校验
- 移除不再使用的字段和方法,简化代码结构
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/qc/indicatorresult/MesQcIndicatorResultController.java
... ... @@ -137,7 +137,7 @@ public class MesQcIndicatorResultController {
137 137 indicatorIds = CollUtil.isEmpty(lines) ? Collections.emptyList()
138 138 : new ArrayList<>(convertSet(lines, MesQcIqcLineDO::getIndicatorId));
139 139 } else if (Objects.equals(qcType, MesQcTypeEnum.IPQC.getType())) {
140   - List<MesQcIpqcLineDO> lines = ipqcLineService.selectListByIpqcId(qcId);
  140 + List<MesQcIpqcLineDO> lines = ipqcLineService.getIpqcLineListByIpqcId(qcId);
141 141 indicatorIds = CollUtil.isEmpty(lines) ? Collections.emptyList()
142 142 : new ArrayList<>(convertSet(lines, MesQcIpqcLineDO::getIndicatorId));
143 143 } else if (Objects.equals(qcType, MesQcTypeEnum.OQC.getType())) {
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/qc/ipqc/MesQcIpqcController.java
... ... @@ -35,7 +35,6 @@ import org.springframework.validation.annotation.Validated;
35 35 import org.springframework.web.bind.annotation.*;
36 36  
37 37 import java.io.IOException;
38   -import java.util.ArrayList;
39 38 import java.util.Collections;
40 39 import java.util.List;
41 40 import java.util.Map;
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/qc/ipqc/MesQcIpqcLineController.java
... ... @@ -9,11 +9,9 @@ import cn.iocoder.yudao.module.mes.controller.admin.qc.ipqc.vo.line.MesQcIpqcLin
9 9 import cn.iocoder.yudao.module.mes.dal.dataobject.md.unitmeasure.MesMdUnitMeasureDO;
10 10 import cn.iocoder.yudao.module.mes.dal.dataobject.qc.indicator.MesQcIndicatorDO;
11 11 import cn.iocoder.yudao.module.mes.dal.dataobject.qc.ipqc.MesQcIpqcLineDO;
12   -import cn.iocoder.yudao.module.mes.dal.dataobject.tm.tool.MesTmToolDO;
13 12 import cn.iocoder.yudao.module.mes.service.md.unitmeasure.MesMdUnitMeasureService;
14 13 import cn.iocoder.yudao.module.mes.service.qc.indicator.MesQcIndicatorService;
15 14 import cn.iocoder.yudao.module.mes.service.qc.ipqc.MesQcIpqcLineService;
16   -import cn.iocoder.yudao.module.mes.service.tm.tool.MesTmToolService;
17 15 import io.swagger.v3.oas.annotations.Operation;
18 16 import io.swagger.v3.oas.annotations.Parameter;
19 17 import io.swagger.v3.oas.annotations.tags.Tag;
... ... @@ -46,8 +44,6 @@ public class MesQcIpqcLineController {
46 44 private MesQcIndicatorService indicatorService;
47 45 @Resource
48 46 private MesMdUnitMeasureService unitMeasureService;
49   - @Resource
50   - private MesTmToolService toolService;
51 47  
52 48 @GetMapping("/get")
53 49 @Operation(summary = "获得过程检验单行")
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/qc/ipqc/vo/MesQcIpqcSaveReqVO.java
... ... @@ -31,9 +31,6 @@ public class MesQcIpqcSaveReqVO {
31 31 @NotNull(message = "检验类型不能为空")
32 32 private Integer type;
33 33  
34   - @Schema(description = "检验模板 ID", example = "100")
35   - private Long templateId;
36   -
37 34 // ========== 来源单据 ==========
38 35  
39 36 @Schema(description = "来源单据类型", example = "FEEDBACK")
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/qc/ipqc/MesQcIpqcLineService.java
... ... @@ -15,6 +15,14 @@ import java.util.List;
15 15 public interface MesQcIpqcLineService {
16 16  
17 17 /**
  18 + * 校验过程检验行存在
  19 + *
  20 + * @param id 编号
  21 + * @return 过程检验行
  22 + */
  23 + MesQcIpqcLineDO validateIpqcLineExists(Long id);
  24 +
  25 + /**
18 26 * 获得过程检验行
19 27 *
20 28 * @param id 编号
... ... @@ -31,14 +39,6 @@ public interface MesQcIpqcLineService {
31 39 PageResult<MesQcIpqcLineDO> getIpqcLinePage(MesQcIpqcLinePageReqVO pageReqVO);
32 40  
33 41 /**
34   - * 根据过程检验单 ID 查询所有行
35   - *
36   - * @param ipqcId 过程检验单 ID
37   - * @return 行列表
38   - */
39   - List<MesQcIpqcLineDO> selectListByIpqcId(Long ipqcId);
40   -
41   - /**
42 42 * 从模板指标自动生成检验行
43 43 *
44 44 * @param ipqcId 过程检验单 ID
... ... @@ -47,26 +47,26 @@ public interface MesQcIpqcLineService {
47 47 void createLinesFromTemplate(Long ipqcId, Long templateId);
48 48  
49 49 /**
50   - * 根据过程检验单 ID 级联删除所有行
  50 + * 根据缺陷记录重新计算行级缺陷统计
51 51 *
52   - * @param ipqcId 过程检验单 ID
  52 + * @param ipqcId 过程检验单 ID
  53 + * @param records 缺陷记录列表
53 54 */
54   - void deleteByIpqcId(Long ipqcId);
  55 + void recalculateLineDefectStats(Long ipqcId, List<MesQcDefectRecordDO> records);
55 56  
56 57 /**
57   - * 校验过程检验行存在
  58 + * 根据过程检验单 ID 获取所有行
58 59 *
59   - * @param id 编号
60   - * @return 过程检验行
  60 + * @param ipqcId 过程检验单 ID
  61 + * @return 行列表
61 62 */
62   - MesQcIpqcLineDO validateIpqcLineExists(Long id);
  63 + List<MesQcIpqcLineDO> getIpqcLineListByIpqcId(Long ipqcId);
63 64  
64 65 /**
65   - * 根据缺陷记录重新计算行级缺陷统计
  66 + * 根据过程检验单 ID 级联删除所有行
66 67 *
67   - * @param ipqcId 过程检验单 ID
68   - * @param records 缺陷记录列表
  68 + * @param ipqcId 过程检验单 ID
69 69 */
70   - void recalculateLineDefectStats(Long ipqcId, List<MesQcDefectRecordDO> records);
  70 + void deleteListByIpqcId(Long ipqcId);
71 71  
72 72 }
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/qc/ipqc/MesQcIpqcLineServiceImpl.java
... ... @@ -44,6 +44,15 @@ public class MesQcIpqcLineServiceImpl implements MesQcIpqcLineService {
44 44 private MesQcIndicatorService indicatorService;
45 45  
46 46 @Override
  47 + public MesQcIpqcLineDO validateIpqcLineExists(Long id) {
  48 + MesQcIpqcLineDO line = ipqcLineMapper.selectById(id);
  49 + if (line == null) {
  50 + throw exception(QC_IPQC_LINE_NOT_EXISTS);
  51 + }
  52 + return line;
  53 + }
  54 +
  55 + @Override
47 56 public MesQcIpqcLineDO getIpqcLine(Long id) {
48 57 return ipqcLineMapper.selectById(id);
49 58 }
... ... @@ -54,11 +63,6 @@ public class MesQcIpqcLineServiceImpl implements MesQcIpqcLineService {
54 63 }
55 64  
56 65 @Override
57   - public List<MesQcIpqcLineDO> selectListByIpqcId(Long ipqcId) {
58   - return ipqcLineMapper.selectListByIpqcId(ipqcId);
59   - }
60   -
61   - @Override
62 66 public void createLinesFromTemplate(Long ipqcId, Long templateId) {
63 67 List<MesQcTemplateIndicatorDO> templateIndicators = templateIndicatorMapper.selectListByTemplateId(templateId);
64 68 if (CollUtil.isEmpty(templateIndicators)) {
... ... @@ -80,20 +84,6 @@ public class MesQcIpqcLineServiceImpl implements MesQcIpqcLineService {
80 84 }
81 85  
82 86 @Override
83   - public void deleteByIpqcId(Long ipqcId) {
84   - ipqcLineMapper.deleteByIpqcId(ipqcId);
85   - }
86   -
87   - @Override
88   - public MesQcIpqcLineDO validateIpqcLineExists(Long id) {
89   - MesQcIpqcLineDO line = ipqcLineMapper.selectById(id);
90   - if (line == null) {
91   - throw exception(QC_IPQC_LINE_NOT_EXISTS);
92   - }
93   - return line;
94   - }
95   -
96   - @Override
97 87 public void recalculateLineDefectStats(Long ipqcId, List<MesQcDefectRecordDO> records) {
98 88 List<MesQcIpqcLineDO> lines = ipqcLineMapper.selectListByIpqcId(ipqcId);
99 89 if (CollUtil.isEmpty(lines)) {
... ... @@ -101,7 +91,9 @@ public class MesQcIpqcLineServiceImpl implements MesQcIpqcLineService {
101 91 }
102 92 List<MesQcIpqcLineDO> updateLines = new ArrayList<>(lines.size());
103 93 for (MesQcIpqcLineDO line : lines) {
104   - int critical = 0, major = 0, minor = 0;
  94 + int critical = 0;
  95 + int major = 0;
  96 + int minor = 0;
105 97 for (MesQcDefectRecordDO record : records) {
106 98 if (ObjUtil.notEqual(record.getLineId(), line.getId())) {
107 99 continue;
... ... @@ -125,4 +117,14 @@ public class MesQcIpqcLineServiceImpl implements MesQcIpqcLineService {
125 117 }
126 118 }
127 119  
  120 + @Override
  121 + public List<MesQcIpqcLineDO> getIpqcLineListByIpqcId(Long ipqcId) {
  122 + return ipqcLineMapper.selectListByIpqcId(ipqcId);
  123 + }
  124 +
  125 + @Override
  126 + public void deleteListByIpqcId(Long ipqcId) {
  127 + ipqcLineMapper.deleteByIpqcId(ipqcId);
  128 + }
  129 +
128 130 }
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/qc/ipqc/MesQcIpqcServiceImpl.java
... ... @@ -104,8 +104,12 @@ public class MesQcIpqcServiceImpl implements MesQcIpqcService {
104 104 adminUserApi.validateUser(updateReqVO.getInspectorUserId());
105 105 itemService.validateItemExists(updateReqVO.getItemId());
106 106  
107   - // 2. 更新
  107 + // 2. 更新主表
108 108 MesQcIpqcDO updateObj = BeanUtils.toBean(updateReqVO, MesQcIpqcDO.class);
  109 + updateObj.setSourceDocType(null).setSourceDocId(null).setSourceLineId(null); // 不允许修改来源单据
  110 + updateObj.setTemplateId(null); // 不允许修改模板
  111 + updateObj.setItemId(null); // 不允许修改物料
  112 + updateObj.setWorkOrderId(null); // 不允许修改工单
109 113 ipqcMapper.updateById(updateObj);
110 114 }
111 115  
... ... @@ -119,9 +123,8 @@ public class MesQcIpqcServiceImpl implements MesQcIpqcService {
119 123 }
120 124  
121 125 // 2. 更新状态为已完成
122   - MesQcIpqcDO updateObj = new MesQcIpqcDO();
123   - updateObj.setId(id);
124   - updateObj.setStatus(MesQcStatusEnum.FINISHED.getStatus());
  126 + MesQcIpqcDO updateObj = new MesQcIpqcDO()
  127 + .setId(id).setStatus(MesQcStatusEnum.FINISHED.getStatus());
125 128 ipqcMapper.updateById(updateObj);
126 129  
127 130 // TODO @AI(from codex):如果检验来源是报工,需要对待检产出按检验结果拆分合格/不合格行、生成产出明细、完成产品产出入库、
... ... @@ -137,7 +140,7 @@ public class MesQcIpqcServiceImpl implements MesQcIpqcService {
137 140 // 2.1 删除主表
138 141 ipqcMapper.deleteById(id);
139 142 // 2.2 级联删除行
140   - ipqcLineService.deleteByIpqcId(id);
  143 + ipqcLineService.deleteListByIpqcId(id);
141 144 // 2.3 级联删除缺陷记录
142 145 defectRecordService.deleteListByQcTypeAndQcId(MesQcTypeEnum.IPQC.getType(), id);
143 146 }
... ...