| | |
| | | import com.ruoyi.procurementrecord.utils.StockUtils; |
| | | import com.ruoyi.production.dto.ProductOrderDto; |
| | | import com.ruoyi.production.dto.ProductStructureDto; |
| | | import com.ruoyi.production.dto.ProductWorkOrderDto; |
| | | import com.ruoyi.production.mapper.*; |
| | | import com.ruoyi.production.pojo.*; |
| | | import com.ruoyi.production.service.ProductOrderService; |
| | |
| | | // 附件 |
| | | productOrderDto.setSalesLedgerFiles(commonFileService.getFileListByBusinessId(productOrderDto.getId() |
| | | , FileNameType.PRODUCT_ORDER.getValue())); |
| | | // 获取对应工单记录 |
| | | ProductWorkOrderDto productWorkOrder = new ProductWorkOrderDto(); |
| | | productWorkOrder.setProductOrderId(productOrderDto.getId()); |
| | | List<ProductWorkOrderDto> productWorkOrders = productWorkOrderMapper.getProductWorkOrderList(productWorkOrder); |
| | | if(CollectionUtils.isNotEmpty(productWorkOrders)){ |
| | | productOrderDto.setProductWorkOrders(calculateColor(productWorkOrders)); |
| | | } |
| | | |
| | | }); |
| | | return productOrderDtoIPage; |
| | | } |
| | | |
| | | /** |
| | | * 自动计算颜色(核心方法) |
| | | * @param productWorkOrders |
| | | */ |
| | | public List<ProductWorkOrderDto> calculateColor(List<ProductWorkOrderDto> productWorkOrders) { |
| | | List<ProductWorkOrderDto> result = new java.util.ArrayList<>(); |
| | | for (int i = 0; i < productWorkOrders.size(); i++) { |
| | | ProductWorkOrderDto current = productWorkOrders.get(i); |
| | | // 判断是否存在下一道工单 + 下一道工单是否有完成数量 |
| | | boolean nextOrderHasComplete = false; // 黄色 |
| | | boolean nextOrderHasScrap = false; // 红色 |
| | | // 如果不是最后一条,就取下一条判断 |
| | | for (int j = i + 1; j < productWorkOrders.size(); j++) { |
| | | if (i < productWorkOrders.size() - 1) { |
| | | ProductWorkOrderDto next = productWorkOrders.get(j); |
| | | BigDecimal nextComplete = next.getCompleteQuantity() == null ? BigDecimal.ZERO : next.getCompleteQuantity(); |
| | | BigDecimal nextScrap = next.getPlanQuantity() == null ? BigDecimal.ZERO : next.getPlanQuantity(); |
| | | // 下一道工单完成数量 > 0 |
| | | nextOrderHasComplete = nextComplete.compareTo(BigDecimal.ZERO) > 0; |
| | | |
| | | nextOrderHasScrap = nextComplete.compareTo(nextScrap) == 0; |
| | | break; |
| | | } |
| | | } |
| | | // =============== 核心:计算颜色并赋值 =============== |
| | | BigDecimal planQty = current.getPlanQuantity() == null ? BigDecimal.ZERO : current.getPlanQuantity(); |
| | | BigDecimal completeQty = current.getCompleteQuantity() == null ? BigDecimal.ZERO : current.getCompleteQuantity(); |
| | | |
| | | // 1. 当前工序完成数量等于0 且 下一道工序已完成 → 红色(4) |
| | | if (completeQty.compareTo(BigDecimal.ZERO) == 0 |
| | | && nextOrderHasScrap) { |
| | | current.setColor(4); |
| | | } |
| | | // 2. 需求数量 > 完成数量(未完成) 且 下一道工序完成数量 > 0 → 黄色(2) |
| | | else if (planQty.compareTo(completeQty) > 0 |
| | | && nextOrderHasComplete) { |
| | | current.setColor(2); |
| | | } |
| | | // 3. 完成数量=0 → 灰色(1) |
| | | else if (completeQty.compareTo(BigDecimal.ZERO) == 0) { |
| | | current.setColor(1); |
| | | } |
| | | // 4. 完成数量=需求数量 → 绿色(3) |
| | | else if (completeQty.compareTo(planQty) == 0) { |
| | | current.setColor(3); |
| | | } |
| | | // 其他情况默认灰色(可选) |
| | | else { |
| | | current.setColor(1); |
| | | } |
| | | result.add(current); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | public int bindingRoute(ProductOrder productOrder) { |
| | | //新增生产订单下的工艺路线主表 |