| | |
| | | import cn.iocoder.yudao.module.mes.service.wm.itemconsume.MesWmItemConsumeService; |
| | | import cn.iocoder.yudao.module.mes.service.wm.productproduce.MesWmProductProduceLineService; |
| | | import cn.iocoder.yudao.module.mes.service.wm.productproduce.MesWmProductProduceService; |
| | | import cn.iocoder.yudao.module.mes.api.mps.MesProMpsApi; |
| | | import cn.iocoder.yudao.module.mes.api.mps.dto.MesProMpsRespDTO; |
| | | import cn.iocoder.yudao.module.mes.api.event.ProductionFinishedEvent; |
| | | import jakarta.annotation.Resource; |
| | | import org.springframework.context.ApplicationEventPublisher; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | private MesWmProductProduceService productProduceService; |
| | | @Resource |
| | | private MesWmProductProduceLineService produceLineService; |
| | | @Resource |
| | | private MesProMpsApi mpsApi; |
| | | @Resource |
| | | private ApplicationEventPublisher eventPublisher; |
| | | |
| | | @Override |
| | | public Long createFeedback(MesProFeedbackSaveReqVO createReqVO) { |
| | |
| | | // 3. 更新工单的已生产数量 |
| | | workOrderService.updateProducedQuantity(feedback.getWorkOrderId(), |
| | | feedback.getFeedbackQuantity()); |
| | | |
| | | // 4. 检查并发布生产完成事件 |
| | | checkAndPublishProductionFinished(feedback.getWorkOrderId()); |
| | | } |
| | | |
| | | /** |
| | | * 检查并发布生产完成事件 |
| | | */ |
| | | private void checkAndPublishProductionFinished(Long workOrderId) { |
| | | // 1. 获取工单关联的 MPS |
| | | MesProMpsRespDTO mps = mpsApi.getMpsByWorkOrderId(workOrderId); |
| | | if (mps == null || mps.getSaleOrderId() == null) { |
| | | return; // 非销售订单来源的工单,跳过 |
| | | } |
| | | |
| | | // 2. 检查销售订单所有生产是否完成 |
| | | if (mpsApi.checkSaleOrderProductionFinished(mps.getSaleOrderId())) { |
| | | eventPublisher.publishEvent(new ProductionFinishedEvent(mps.getSaleOrderId(), java.time.LocalDateTime.now())); |
| | | } |
| | | } |
| | | |
| | | // ==================== 校验方法 ==================== |