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