Commit b15edb4a26998581a4d709ff88a892be67c6096b
1 parent
9c94c1f5
✨ feat(mes): 新增供应商和物料存在性校验功能
Showing
5 changed files
with
36 additions
and
8 deletions
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/qc/iqc/vo/MesQcIqcSaveReqVO.java
| 1 | 1 | package cn.iocoder.yudao.module.mes.controller.admin.qc.iqc.vo; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.util.ObjUtil; |
| 4 | +import com.fasterxml.jackson.annotation.JsonIgnore; | |
| 4 | 5 | import io.swagger.v3.oas.annotations.media.Schema; |
| 5 | 6 | import jakarta.validation.constraints.AssertTrue; |
| 6 | 7 | import jakarta.validation.constraints.DecimalMin; |
| ... | ... | @@ -85,7 +86,7 @@ public class MesQcIqcSaveReqVO { |
| 85 | 86 | private String remark; |
| 86 | 87 | |
| 87 | 88 | @AssertTrue(message = "合格品数量与不合格品数量之和必须等于本次接收数量") |
| 88 | - @Schema(hidden = true) | |
| 89 | + @JsonIgnore | |
| 89 | 90 | public boolean isQuantityValid() { |
| 90 | 91 | if (ObjUtil.hasNull(qualifiedQuantity, unqualifiedQuantity, receivedQuantity)) { |
| 91 | 92 | return true; // @NotNull 会处理 null | ... | ... |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/md/vendor/MesMdVendorService.java
| ... | ... | @@ -52,6 +52,14 @@ public interface MesMdVendorService { |
| 52 | 52 | MesMdVendorDO getVendor(Long id); |
| 53 | 53 | |
| 54 | 54 | /** |
| 55 | + * 校验供应商存在 | |
| 56 | + * | |
| 57 | + * @param id 供应商 ID | |
| 58 | + * @return 供应商 | |
| 59 | + */ | |
| 60 | + MesMdVendorDO validateVendorExists(Long id); | |
| 61 | + | |
| 62 | + /** | |
| 55 | 63 | * 获得供应商分页 |
| 56 | 64 | * |
| 57 | 65 | * @param pageReqVO 分页查询 | ... | ... |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/md/vendor/MesMdVendorServiceImpl.java
| ... | ... | @@ -78,10 +78,13 @@ public class MesMdVendorServiceImpl implements MesMdVendorService { |
| 78 | 78 | vendorMapper.deleteById(id); |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | - private void validateVendorExists(Long id) { | |
| 82 | - if (vendorMapper.selectById(id) == null) { | |
| 81 | + @Override | |
| 82 | + public MesMdVendorDO validateVendorExists(Long id) { | |
| 83 | + MesMdVendorDO vendor = vendorMapper.selectById(id); | |
| 84 | + if (vendor == null) { | |
| 83 | 85 | throw exception(MD_VENDOR_NOT_EXISTS); |
| 84 | 86 | } |
| 87 | + return vendor; | |
| 85 | 88 | } |
| 86 | 89 | |
| 87 | 90 | private void validateVendorCodeUnique(Long id, String code) { | ... | ... |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/qc/iqc/MesQcIqcLineServiceImpl.java
| ... | ... | @@ -91,7 +91,9 @@ public class MesQcIqcLineServiceImpl implements MesQcIqcLineService { |
| 91 | 91 | } |
| 92 | 92 | List<MesQcIqcLineDO> updateLines = new ArrayList<>(lines.size()); |
| 93 | 93 | for (MesQcIqcLineDO line : lines) { |
| 94 | - int critical = 0, major = 0, minor = 0; | |
| 94 | + int critical = 0; | |
| 95 | + int major = 0; | |
| 96 | + int minor = 0; | |
| 95 | 97 | for (MesQcDefectRecordDO record : records) { |
| 96 | 98 | if (ObjUtil.notEqual(record.getLineId(), line.getId())) { |
| 97 | 99 | continue; | ... | ... |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/qc/iqc/MesQcIqcServiceImpl.java
| ... | ... | @@ -15,6 +15,8 @@ import cn.iocoder.yudao.module.mes.enums.MesBizTypeConstants; |
| 15 | 15 | import cn.iocoder.yudao.module.mes.enums.qc.MesQcDefectLevelEnum; |
| 16 | 16 | import cn.iocoder.yudao.module.mes.enums.qc.MesQcIqcStatusEnum; |
| 17 | 17 | import cn.iocoder.yudao.module.mes.enums.qc.MesQcTypeEnum; |
| 18 | +import cn.iocoder.yudao.module.mes.service.md.item.MesMdItemService; | |
| 19 | +import cn.iocoder.yudao.module.mes.service.md.vendor.MesMdVendorService; | |
| 18 | 20 | import cn.iocoder.yudao.module.mes.service.qc.defectrecord.MesQcDefectRecordService; |
| 19 | 21 | import cn.iocoder.yudao.module.mes.service.qc.template.MesQcTemplateDetailService; |
| 20 | 22 | import cn.iocoder.yudao.module.mes.service.wm.arrivalnotice.MesWmArrivalNoticeService; |
| ... | ... | @@ -52,15 +54,22 @@ public class MesQcIqcServiceImpl implements MesQcIqcService { |
| 52 | 54 | private MesQcDefectRecordService defectRecordService; |
| 53 | 55 | @Resource |
| 54 | 56 | private MesWmArrivalNoticeService arrivalNoticeService; |
| 57 | + @Resource | |
| 58 | + private MesMdVendorService vendorService; | |
| 59 | + @Resource | |
| 60 | + private MesMdItemService itemService; | |
| 55 | 61 | |
| 56 | 62 | @Override |
| 57 | 63 | @Transactional(rollbackFor = Exception.class) |
| 58 | 64 | public Long createIqc(MesQcIqcSaveReqVO createReqVO, Long inspectorUserId) { |
| 59 | 65 | // 1.1 校验编号唯一 |
| 60 | 66 | validateIqcCodeUnique(null, createReqVO.getCode()); |
| 61 | - // 1.2 校验来源单据参数,并验证数据存在 | |
| 67 | + // 1.2 校验供应商、物料存在 | |
| 68 | + vendorService.validateVendorExists(createReqVO.getVendorId()); | |
| 69 | + itemService.validateItemExists(createReqVO.getItemId()); | |
| 70 | + // 1.3 校验来源单据参数,并验证数据存在 | |
| 62 | 71 | validateSourceDoc(createReqVO.getSourceDocType(), createReqVO.getSourceDocId(), createReqVO.getSourceLineId()); |
| 63 | - // 1.3 通过 itemId + IQC 类型自动查找模板 | |
| 72 | + // 1.4 通过 itemId + IQC 类型自动查找模板 | |
| 64 | 73 | MesQcTemplateItemDO templateItem = templateDetailService.getRequiredTemplateByItemIdAndType( |
| 65 | 74 | createReqVO.getItemId(), MesQcTypeEnum.IQC.getType()); |
| 66 | 75 | Long templateId = templateItem.getTemplateId(); |
| ... | ... | @@ -84,6 +93,9 @@ public class MesQcIqcServiceImpl implements MesQcIqcService { |
| 84 | 93 | validateIqcStatusPrepare(updateReqVO.getId()); |
| 85 | 94 | // 1.2 校验编号唯一 |
| 86 | 95 | validateIqcCodeUnique(updateReqVO.getId(), updateReqVO.getCode()); |
| 96 | + // 1.3 校验供应商、物料存在 | |
| 97 | + vendorService.validateVendorExists(updateReqVO.getVendorId()); | |
| 98 | + itemService.validateItemExists(updateReqVO.getItemId()); | |
| 87 | 99 | |
| 88 | 100 | // 2. 更新主表 |
| 89 | 101 | MesQcIqcDO updateObj = BeanUtils.toBean(updateReqVO, MesQcIqcDO.class); |
| ... | ... | @@ -216,11 +228,14 @@ public class MesQcIqcServiceImpl implements MesQcIqcService { |
| 216 | 228 | |
| 217 | 229 | @Override |
| 218 | 230 | public void recalculateDefectStats(Long iqcId, List<MesQcDefectRecordDO> records) { |
| 231 | + MesQcIqcDO iqc = validateIqcExists(iqcId); | |
| 219 | 232 | // 1. 行级缺陷统计 |
| 220 | 233 | iqcLineService.recalculateLineDefectStats(iqcId, records); |
| 221 | 234 | |
| 222 | 235 | // 2.1 汇总主表的缺陷数量 |
| 223 | - int totalCritical = 0, totalMajor = 0, totalMinor = 0; | |
| 236 | + int totalCritical = 0; | |
| 237 | + int totalMajor = 0; | |
| 238 | + int totalMinor = 0; | |
| 224 | 239 | for (MesQcDefectRecordDO record : records) { |
| 225 | 240 | int quantity = ObjUtil.defaultIfNull(record.getQuantity(), 1); |
| 226 | 241 | if (Objects.equals(record.getLevel(), MesQcDefectLevelEnum.CRITICAL.getType())) { |
| ... | ... | @@ -234,7 +249,6 @@ public class MesQcIqcServiceImpl implements MesQcIqcService { |
| 234 | 249 | } |
| 235 | 250 | } |
| 236 | 251 | // 2.2 计算缺陷率 |
| 237 | - MesQcIqcDO iqc = validateIqcExists(iqcId); | |
| 238 | 252 | BigDecimal criticalRate = BigDecimal.ZERO; |
| 239 | 253 | BigDecimal majorRate = BigDecimal.ZERO; |
| 240 | 254 | BigDecimal minorRate = BigDecimal.ZERO; | ... | ... |