| | |
| | | import cn.iocoder.yudao.module.mes.service.qc.template.MesQcTemplateItemService; |
| | | import cn.iocoder.yudao.module.mes.service.wm.arrivalnotice.MesWmArrivalNoticeService; |
| | | import cn.iocoder.yudao.module.mes.service.wm.outsourcereceipt.MesWmOutsourceReceiptService; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.qc.ncr.vo.MesQcNcrSaveReqVO; |
| | | import cn.iocoder.yudao.module.mes.service.qc.ncr.MesQcNcrService; |
| | | import cn.iocoder.yudao.module.mes.enums.qc.MesQcCheckResultEnum; |
| | | import cn.iocoder.yudao.module.srm.api.supplier.SrmSupplierApi; |
| | | import cn.iocoder.yudao.module.mdm.api.item.MdmItemApi; |
| | | import cn.iocoder.yudao.module.mdm.api.item.dto.MdmItemRespDTO; |
| | | import cn.iocoder.yudao.module.system.api.user.AdminUserApi; |
| | | import jakarta.annotation.Resource; |
| | | import org.springframework.context.annotation.Lazy; |
| | |
| | | |
| | | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| | | import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.*; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.qc.iqc.vo.MesQcIqcImportExcelVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.qc.iqc.vo.MesQcIqcImportRespVO; |
| | | import cn.iocoder.yudao.framework.common.exception.ServiceException; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import java.time.LocalDateTime; |
| | | import java.util.ArrayList; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | |
| | | /** |
| | | * MES 来料检验单(IQC) Service 实现类 |
| | | * |
| | | * @author 芋道源码 |
| | | * @author 超级管理员 |
| | | */ |
| | | @Service |
| | | @Validated |
| | |
| | | |
| | | @Resource |
| | | private MdmItemApi mdmItemApi; |
| | | |
| | | @Resource |
| | | @Lazy |
| | | private MesQcNcrService ncrService; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | |
| | | .setId(id).setStatus(MesQcStatusEnum.FINISHED.getStatus()); |
| | | iqcMapper.updateById(updateObj); |
| | | |
| | | // 3. 回写来源单据 |
| | | // 3. 不合格时自动创建 NCR |
| | | generateNcrIfNeeded(iqc); |
| | | |
| | | // 4. 回写来源单据 |
| | | writeBackSourceDoc(iqc); |
| | | } |
| | | |
| | | /** |
| | | * 不合格时自动创建 NCR(不合格品处理单) |
| | | * |
| | | * @param iqc 来料检验单 |
| | | */ |
| | | private void generateNcrIfNeeded(MesQcIqcDO iqc) { |
| | | BigDecimal unqualifiedQty = iqc.getUnqualifiedQuantity(); |
| | | if (unqualifiedQty == null || unqualifiedQty.compareTo(BigDecimal.ZERO) <= 0) { |
| | | return; |
| | | } |
| | | MesQcNcrSaveReqVO saveReqVO = new MesQcNcrSaveReqVO(); |
| | | saveReqVO.setName("不合格品处理单"); |
| | | saveReqVO.setQcType(MesQcTypeEnum.IQC.getType()); |
| | | saveReqVO.setQcId(iqc.getId()); |
| | | saveReqVO.setItemId(iqc.getItemId()); |
| | | saveReqVO.setUnqualifiedQuantity(unqualifiedQty); |
| | | saveReqVO.setDefectDescription("由来料检验(" + iqc.getCode() + ")自动生成"); |
| | | ncrService.createNcr(saveReqVO); |
| | | } |
| | | |
| | | /** |
| | |
| | | return "物料ID:" + itemId; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public MesQcIqcImportRespVO importIqcList(List<MesQcIqcImportExcelVO> importList, boolean updateSupport) { |
| | | if (CollUtil.isEmpty(importList)) { |
| | | throw exception(QC_IQC_IMPORT_LIST_IS_EMPTY); |
| | | } |
| | | MesQcIqcImportRespVO respVO = MesQcIqcImportRespVO.builder() |
| | | .createCodes(new ArrayList<>()).updateCodes(new ArrayList<>()) |
| | | .failureCodes(new LinkedHashMap<>()).build(); |
| | | AtomicInteger index = new AtomicInteger(1); |
| | | importList.forEach(importItem -> { |
| | | int currentIndex = index.getAndIncrement(); |
| | | String key = "第 " + currentIndex + " 行"; |
| | | if (StrUtil.isBlank(importItem.getItemCode())) { |
| | | respVO.getFailureCodes().put(key, "产品物料编码不能为空"); |
| | | return; |
| | | } |
| | | if (importItem.getInspectorUserId() == null) { |
| | | respVO.getFailureCodes().put(key, "检测人员不能为空"); |
| | | return; |
| | | } |
| | | if (importItem.getInspectDate() == null) { |
| | | respVO.getFailureCodes().put(key, "检测日期不能为空"); |
| | | return; |
| | | } |
| | | if (importItem.getReceiveDate() == null) { |
| | | respVO.getFailureCodes().put(key, "来料日期不能为空"); |
| | | return; |
| | | } |
| | | if (importItem.getReceivedQuantity() == null || importItem.getQualifiedQuantity() == null || importItem.getUnqualifiedQuantity() == null) { |
| | | respVO.getFailureCodes().put(key, "本次接收数量、合格品数量、不合格品数量均不能为空"); |
| | | return; |
| | | } |
| | | if (importItem.getQualifiedQuantity().add(importItem.getUnqualifiedQuantity()).compareTo(importItem.getReceivedQuantity()) != 0) { |
| | | respVO.getFailureCodes().put(key, "合格品数量与不合格品数量之和必须等于本次接收数量"); |
| | | return; |
| | | } |
| | | // 来料检验单的物料以 MDM 为准,导入按 MDM 物料编码解析 |
| | | MdmItemRespDTO item = mdmItemApi.getItemByCode(importItem.getItemCode()).getCheckedData(); |
| | | if (item == null) { |
| | | respVO.getFailureCodes().put(key, "物料不存在:" + importItem.getItemCode()); |
| | | return; |
| | | } |
| | | try { |
| | | MesQcIqcSaveReqVO createReqVO = BeanUtils.toBean(importItem, MesQcIqcSaveReqVO.class); |
| | | createReqVO.setCode(generateImportCode("IQC", index)); |
| | | createReqVO.setName(StrUtil.blankToDefault(importItem.getName(), "来料检验单")); |
| | | createReqVO.setItemId(item.getId()); |
| | | Long id = createIqc(createReqVO); |
| | | MesQcIqcDO created = iqcMapper.selectById(id); |
| | | respVO.getCreateCodes().add(created != null && StrUtil.isNotBlank(created.getCode()) ? created.getCode() : key); |
| | | } catch (ServiceException e) { |
| | | respVO.getFailureCodes().put(key, e.getMessage()); |
| | | } |
| | | }); |
| | | return respVO; |
| | | } |
| | | |
| | | private String generateImportCode(String prefix, AtomicInteger seq) { |
| | | return prefix + DateUtil.format(LocalDateTime.now(), "yyyyMMddHHmmss") |
| | | + String.format("%03d", seq.incrementAndGet()); |
| | | } |
| | | |
| | | } |