Commit d21ddb539405f7a517de278bf4869e9f2d37d6a4
1 parent
34061f90
feat(mes): add validation for inspection result detail list and update related comments
Showing
3 changed files
with
14 additions
and
55 deletions
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/qc/indicatorresult/vo/MesQcIndicatorResultSaveReqVO.java
| ... | ... | @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.mes.controller.admin.qc.indicatorresult.vo; |
| 3 | 3 | import cn.iocoder.yudao.framework.common.validation.InEnum; |
| 4 | 4 | import cn.iocoder.yudao.module.mes.enums.qc.MesQcTypeEnum; |
| 5 | 5 | import io.swagger.v3.oas.annotations.media.Schema; |
| 6 | +import jakarta.validation.constraints.NotEmpty; | |
| 6 | 7 | import jakarta.validation.constraints.NotNull; |
| 7 | 8 | import lombok.Data; |
| 8 | 9 | |
| ... | ... | @@ -33,7 +34,8 @@ public class MesQcIndicatorResultSaveReqVO { |
| 33 | 34 | @Schema(description = "备注", example = "无") |
| 34 | 35 | private String remark; |
| 35 | 36 | |
| 36 | - @Schema(description = "检验结果明细列表") | |
| 37 | + @Schema(description = "检验结果明细列表", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 38 | + @NotEmpty(message = "检验结果明细列表不能为空") | |
| 37 | 39 | private List<Item> items; |
| 38 | 40 | |
| 39 | 41 | @Schema(description = "检验结果明细项") | ... | ... |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/DictTypeConstants.java
| ... | ... | @@ -27,6 +27,7 @@ public interface DictTypeConstants { |
| 27 | 27 | String MES_QC_TYPE = "mes_qc_type"; // MES 检测种类(IQC/IPQC/OQC/RQC) |
| 28 | 28 | String MES_PRO_LINK_TYPE = "mes_pro_link_type"; // MES 工序关系类型 |
| 29 | 29 | String MES_TIME_UNIT_TYPE = "mes_time_unit_type"; // MES 时间单位 |
| 30 | + String MES_IPQC_TYPE = "mes_ipqc_type"; // MES IPQC 检验类型 | |
| 30 | 31 | String MES_QC_IQC_STATUS = "mes_qc_iqc_status"; // MES 检验单状态 |
| 31 | 32 | String MES_QC_CHECK_RESULT = "mes_qc_check_result"; // MES 检测结果 |
| 32 | 33 | String MES_QC_SOURCE_DOC_TYPE = "mes_qc_source_doc_type"; // MES 来源单据类型 | ... | ... |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/qc/indicatorresult/MesQcIndicatorResultServiceImpl.java
| 1 | 1 | package cn.iocoder.yudao.module.mes.service.qc.indicatorresult; |
| 2 | 2 | |
| 3 | -import cn.hutool.core.collection.CollUtil; | |
| 4 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | 4 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 6 | 5 | import cn.iocoder.yudao.module.mes.controller.admin.qc.indicatorresult.vo.MesQcIndicatorResultPageReqVO; |
| ... | ... | @@ -44,22 +43,16 @@ public class MesQcIndicatorResultServiceImpl implements MesQcIndicatorResultServ |
| 44 | 43 | @Override |
| 45 | 44 | @Transactional(rollbackFor = Exception.class) |
| 46 | 45 | public Long createIndicatorResult(MesQcIndicatorResultSaveReqVO createReqVO) { |
| 47 | - // 1. 校验明细不为空 | |
| 48 | - // TODO @AI:是不是 MesQcIndicatorResultSaveReqVO validator 参数校验; | |
| 49 | - List<MesQcIndicatorResultSaveReqVO.Item> items = createReqVO.getItems(); | |
| 50 | - if (CollUtil.isEmpty(items)) { | |
| 51 | - throw exception(QC_RESULT_ITEMS_EMPTY); | |
| 52 | - } | |
| 53 | - | |
| 54 | - // 2. 根据 qcType 查询源质检单,获取 itemId | |
| 46 | + // 1. 根据 qcType 查询源质检单,获取 itemId | |
| 55 | 47 | Long itemId = getItemIdFromQcDoc(createReqVO.getQcId(), createReqVO.getQcType()); |
| 56 | 48 | |
| 57 | - // 3.1 插入主表 | |
| 49 | + // 2.1 插入主表 | |
| 58 | 50 | MesQcIndicatorResultDO result = BeanUtils.toBean(createReqVO, MesQcIndicatorResultDO.class); |
| 59 | 51 | result.setItemId(itemId); |
| 60 | 52 | resultMapper.insert(result); |
| 61 | - // 3.2 批量插入明细 | |
| 62 | - List<MesQcIndicatorResultDetailDO> details = BeanUtils.toBean(items, MesQcIndicatorResultDetailDO.class); | |
| 53 | + // 2.2 批量插入明细 | |
| 54 | + List<MesQcIndicatorResultDetailDO> details = BeanUtils.toBean(createReqVO.getItems(), | |
| 55 | + MesQcIndicatorResultDetailDO.class); | |
| 63 | 56 | details.forEach(detail -> detail.setResultId(result.getId())); |
| 64 | 57 | resultDetailMapper.insertBatch(details); |
| 65 | 58 | return result.getId(); |
| ... | ... | @@ -71,46 +64,13 @@ public class MesQcIndicatorResultServiceImpl implements MesQcIndicatorResultServ |
| 71 | 64 | // 1. 校验存在 |
| 72 | 65 | validateIndicatorResultExists(updateReqVO.getId()); |
| 73 | 66 | |
| 74 | - // 2. 校验明细不为空 | |
| 75 | - // TODO @AI:是不是 MesQcIndicatorResultSaveReqVO validator 参数校验; | |
| 76 | - List<MesQcIndicatorResultSaveReqVO.Item> items = updateReqVO.getItems(); | |
| 77 | - if (CollUtil.isEmpty(items)) { | |
| 78 | - throw exception(QC_RESULT_ITEMS_EMPTY); | |
| 79 | - } | |
| 80 | - | |
| 81 | 67 | // 2.1 更新主表 |
| 82 | 68 | MesQcIndicatorResultDO updateObj = BeanUtils.toBean(updateReqVO, MesQcIndicatorResultDO.class); |
| 83 | 69 | resultMapper.updateById(updateObj); |
| 84 | - | |
| 85 | - // TODO @AI:直接 for 循环,resultMapper.insertOrUpdate() 简单粗暴点! | |
| 86 | - // 4. 更新明细:diff 方式(有 id → 更新,无 id → 新增,不在列表中 → 删除) | |
| 87 | - List<MesQcIndicatorResultDetailDO> existingDetails = resultDetailMapper.selectListByResultId(updateReqVO.getId()); | |
| 88 | - Map<Long, MesQcIndicatorResultDetailDO> existingMap = convertMap(existingDetails, MesQcIndicatorResultDetailDO::getId); | |
| 89 | - | |
| 90 | - // 4.1 收集前端传入的、已有 id 的集合 | |
| 91 | - Set<Long> newItemIds = convertSet(items, MesQcIndicatorResultSaveReqVO.Item::getId); | |
| 92 | - newItemIds.remove(null); | |
| 93 | - | |
| 94 | - // 4.2 遍历传入的明细:有 id 则更新,无 id 则新增 | |
| 95 | - for (MesQcIndicatorResultSaveReqVO.Item item : items) { | |
| 96 | - MesQcIndicatorResultDetailDO detail = BeanUtils.toBean(item, MesQcIndicatorResultDetailDO.class); | |
| 97 | - detail.setResultId(updateReqVO.getId()); | |
| 98 | - if (item.getId() != null && existingMap.containsKey(item.getId())) { | |
| 99 | - // 更新已有记录 | |
| 100 | - resultDetailMapper.updateById(detail); | |
| 101 | - } else { | |
| 102 | - // 新增记录 | |
| 103 | - detail.setId(null); | |
| 104 | - resultDetailMapper.insert(detail); | |
| 105 | - } | |
| 106 | - } | |
| 107 | - | |
| 108 | - // 4.3 删除不在新列表中的旧记录 | |
| 109 | - for (MesQcIndicatorResultDetailDO existing : existingDetails) { | |
| 110 | - if (!newItemIds.contains(existing.getId())) { | |
| 111 | - resultDetailMapper.deleteById(existing.getId()); | |
| 112 | - } | |
| 113 | - } | |
| 70 | + // 2.2 批量更新明细 | |
| 71 | + List<MesQcIndicatorResultDetailDO> details = BeanUtils.toBean(updateReqVO.getItems(), | |
| 72 | + MesQcIndicatorResultDetailDO.class); | |
| 73 | + resultDetailMapper.insertOrUpdate(details); | |
| 114 | 74 | } |
| 115 | 75 | |
| 116 | 76 | @Override |
| ... | ... | @@ -155,11 +115,7 @@ public class MesQcIndicatorResultServiceImpl implements MesQcIndicatorResultServ |
| 155 | 115 | */ |
| 156 | 116 | private Long getItemIdFromQcDoc(Long qcId, Integer qcType) { |
| 157 | 117 | if (Objects.equals(qcType, MesQcTypeEnum.IQC.getType())) { |
| 158 | - // TODO @AI:使用 iqcService 的 validateIqcExists 方法,这样更聚焦! | |
| 159 | - MesQcIqcDO iqc = iqcService.getIqc(qcId); | |
| 160 | - if (iqc == null) { | |
| 161 | - throw exception(QC_RESULT_SOURCE_DOC_NOT_EXISTS); | |
| 162 | - } | |
| 118 | + MesQcIqcDO iqc = iqcService.validateIqcExists(qcId); | |
| 163 | 119 | return iqc.getItemId(); |
| 164 | 120 | } |
| 165 | 121 | // TODO @芋艿:IPQC/OQC/RQC 模块迁移后实现 | ... | ... |