| | |
| | | import cn.iocoder.yudao.module.mes.enums.qc.MesQcDefectLevelEnum; |
| | | import cn.iocoder.yudao.module.mes.enums.qc.MesQcStatusEnum; |
| | | import cn.iocoder.yudao.module.mes.enums.qc.MesQcTypeEnum; |
| | | import cn.iocoder.yudao.module.mes.enums.pro.MesProFeedbackStatusEnum; |
| | | import cn.iocoder.yudao.module.mes.enums.MesBizTypeConstants; |
| | | import cn.iocoder.yudao.module.mes.service.md.item.MesMdItemService; |
| | | import cn.iocoder.yudao.module.mes.service.md.workstation.MesMdWorkstationService; |
| | |
| | | import cn.iocoder.yudao.module.mes.service.wm.productproduce.MesWmProductProduceLineService; |
| | | import cn.iocoder.yudao.module.system.api.user.AdminUserApi; |
| | | import jakarta.annotation.Resource; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | */ |
| | | @Service |
| | | @Validated |
| | | @Slf4j |
| | | public class MesQcIpqcServiceImpl implements MesQcIpqcService { |
| | | |
| | | /** |
| | |
| | | * @param ipqc 过程检验单 |
| | | */ |
| | | private void writeBackSourceDoc(MesQcIpqcDO ipqc) { |
| | | if (ipqc.getSourceDocType() == null) { |
| | | return; |
| | | } |
| | | if (ipqc.getSourceDocId() == null) { |
| | | throw new IllegalArgumentException( |
| | | "IPQC 单[" + ipqc.getId() + "] sourceDocType 非空但 sourceDocId 为空"); |
| | | // 1. 确定 sourceDocType/sourceDocId |
| | | Long sourceDocId = ipqc.getSourceDocId(); |
| | | Long sourceLineId = ipqc.getSourceLineId(); |
| | | |
| | | // 如果 IPQC 单没有设置来源,尝试通过 taskId 查找关联的待检验报工 |
| | | if (sourceDocId == null && ipqc.getTaskId() != null) { |
| | | MesProFeedbackDO feedback = feedbackService.getFeedbackListByTaskId(ipqc.getTaskId()).stream() |
| | | .filter(f -> MesProFeedbackStatusEnum.UNCHECK.getStatus().equals(f.getStatus())) |
| | | .findFirst().orElse(null); |
| | | if (feedback != null) { |
| | | sourceDocId = feedback.getId(); |
| | | log.info("[writeBackSourceDoc] IPQC({}) 未设置来源单据,通过 taskId({}) 找到待检验报工({})", |
| | | ipqc.getId(), ipqc.getTaskId(), feedback.getId()); |
| | | } |
| | | } |
| | | |
| | | if (Objects.equals(ipqc.getSourceDocType(), MesBizTypeConstants.PRO_FEEDBACK)) { |
| | | feedbackService.updateProFeedbackWhenIpqcFinish(ipqc.getSourceDocId(), ipqc.getSourceLineId(), |
| | | ObjectUtil.defaultIfNull(ipqc.getQualifiedQuantity(), BigDecimal.ZERO), |
| | | ObjectUtil.defaultIfNull(ipqc.getUnqualifiedQuantity(), BigDecimal.ZERO), |
| | | ObjectUtil.defaultIfNull(ipqc.getLaborScrapQuantity(), BigDecimal.ZERO), |
| | | ObjectUtil.defaultIfNull(ipqc.getMaterialScrapQuantity(), BigDecimal.ZERO), |
| | | ObjectUtil.defaultIfNull(ipqc.getOtherScrapQuantity(), BigDecimal.ZERO)); |
| | | } else { |
| | | throw new IllegalArgumentException( |
| | | "IPQC 单[" + ipqc.getId() + "] sourceDocType=" + ipqc.getSourceDocType() + " 无法识别,无法回写来源单据"); |
| | | if (sourceDocId == null) { |
| | | log.warn("[writeBackSourceDoc] IPQC({}) 无法确定来源报工,跳过回写", ipqc.getId()); |
| | | return; |
| | | } |
| | | |
| | | // 2. 回写报工 |
| | | feedbackService.updateProFeedbackWhenIpqcFinish(sourceDocId, sourceLineId, |
| | | ObjectUtil.defaultIfNull(ipqc.getQualifiedQuantity(), BigDecimal.ZERO), |
| | | ObjectUtil.defaultIfNull(ipqc.getUnqualifiedQuantity(), BigDecimal.ZERO), |
| | | ObjectUtil.defaultIfNull(ipqc.getLaborScrapQuantity(), BigDecimal.ZERO), |
| | | ObjectUtil.defaultIfNull(ipqc.getMaterialScrapQuantity(), BigDecimal.ZERO), |
| | | ObjectUtil.defaultIfNull(ipqc.getOtherScrapQuantity(), BigDecimal.ZERO)); |
| | | } |
| | | |
| | | @Override |