| | |
| | | import com.ruoyi.common.constant.StorageAttachmentConstants; |
| | | import com.ruoyi.common.exception.ServiceException; |
| | | import com.ruoyi.production.bean.dto.ProductionOrderDto; |
| | | import com.ruoyi.production.bean.vo.ProductionBomStructureVo; |
| | | import com.ruoyi.production.bean.vo.ProductionOrderPickVo; |
| | | import com.ruoyi.production.bean.vo.ProductionOrderVo; |
| | | import com.ruoyi.production.bean.vo.ProductionPlanVo; |
| | | import com.ruoyi.production.enums.ProductOrderStatusEnum; |
| | |
| | | import com.ruoyi.production.service.ProductionOrderService; |
| | | import com.ruoyi.sales.mapper.SalesLedgerMapper; |
| | | import com.ruoyi.sales.mapper.SalesLedgerProductMapper; |
| | | import com.ruoyi.stock.mapper.StockInventoryMapper; |
| | | import com.ruoyi.stock.pojo.StockInventory; |
| | | import com.ruoyi.technology.mapper.*; |
| | | import com.ruoyi.technology.pojo.*; |
| | | import lombok.RequiredArgsConstructor; |
| | |
| | | private final ProductionOrderPickMapper productionOrderPickMapper; |
| | | private final ProductionOrderPickRecordMapper productionOrderPickRecordMapper; |
| | | private final ProductionPlanMapper productionPlanMapper; |
| | | private final StockInventoryMapper stockInventoryMapper; |
| | | private final StorageAttachmentMapper storageAttachmentMapper; |
| | | private final StorageBlobMapper storageBlobMapper; |
| | | private final SalesLedgerMapper salesLedgerMapper; |
| | |
| | | || productionOrderRoutingMapper.selectCount(Wrappers.<ProductionOrderRouting>lambdaQuery() |
| | | .eq(ProductionOrderRouting::getProductionOrderId, productionOrder.getId())) == 0); |
| | | if (needSync) { |
| | | // 工艺、产品或数量变化后,订单快照必须和当前下单数据重新对齐。 |
| | | syncProductionOrderSnapshot(productionOrder.getId()); |
| | | } else { |
| | | // 未重建快照时,也要确保备料主单和订单数量保持同步。 |
| | | upsertOrderPick(productionOrder); |
| | | } |
| | | return true; |
| | | } |
| | |
| | | targetOperation.setDragSort(sourceOperation.getDragSort()); |
| | | targetOperation.setIsQuality(sourceOperation.getIsQuality()); |
| | | targetOperation.setOperationName(operationNameMap.get(sourceOperation.getTechnologyOperationId())); |
| | | targetOperation.setTechnologyOperationId(sourceOperation.getTechnologyOperationId()); |
| | | productionOrderRoutingOperationMapper.insert(targetOperation); |
| | | |
| | | ProductionOperationTask task = new ProductionOperationTask(); |
| | |
| | | // 工序执行参数同样做快照,避免工艺参数调整影响已下达订单。 |
| | | ProductionOrderRoutingOperationParam targetParam = new ProductionOrderRoutingOperationParam(); |
| | | targetParam.setProductionOrderId(productionOrder.getId()); |
| | | targetParam.setTechnologyRoutingOperationId(targetOperation.getId()); |
| | | targetParam.setProductionOrderRoutingOperationId(targetOperation.getId()); |
| | | targetParam.setTechnologyRoutingOperationParamId(sourceParam.getId()); |
| | | targetParam.setParamId(sourceParam.getParamId()); |
| | | targetParam.setTechnologyOperationId(sourceParam.getTechnologyOperationId()); |
| | |
| | | syncedParamCount++; |
| | | } |
| | | } |
| | | |
| | | upsertOrderPick(productionOrder); |
| | | return syncedParamCount; |
| | | } |
| | | |
| | |
| | | orderBom.setProductionOrderId(productionOrder.getId()); |
| | | orderBom.setBomId(Long.valueOf(technologyBom.getId())); |
| | | orderBom.setProductModelId(root != null ? root.getProductModelId() : productionOrder.getProductModelId()); |
| | | orderBom.setTechnologyOperationId(root == null ? null : root.getOperationId()); |
| | | orderBom.setUnitQuantity(root != null && root.getUnitQuantity() != null ? root.getUnitQuantity() : BigDecimal.ONE); |
| | | orderBom.setDemandedQuantity(orderQuantity); |
| | | orderBom.setUnit(root == null ? null : root.getUnit()); |
| | | orderBom.setRemark(technologyBom.getRemark()); |
| | | orderBom.setBomNo(technologyBom.getBomNo()); |
| | | orderBom.setVersion(technologyBom.getVersion()); |
| | | productionOrderBomMapper.insert(orderBom); |
| | | |
| | | Map<Long, Long> idMap = new HashMap<>(); |
| | |
| | | target.setProductModelId(source.getProductModelId()); |
| | | target.setTechnologyOperationId(source.getOperationId()); |
| | | target.setUnitQuantity(source.getUnitQuantity()); |
| | | target.setDemandedQuantity(resolveBomDemandQuantity(source, orderQuantity)); |
| | | target.setDemandedQuantity(source.getUnitQuantity().multiply(orderQuantity)); |
| | | target.setUnit(source.getUnit()); |
| | | productionBomStructureMapper.insert(target); |
| | | idMap.put(source.getId(), target.getId()); |
| | |
| | | return issuedQuantity.compareTo(requiredQuantity) < 0 ? 1 : 2; |
| | | } |
| | | |
| | | private void upsertOrderPick(ProductionOrder productionOrder) { |
| | | if (productionOrder == null || productionOrder.getId() == null) { |
| | | return; |
| | | } |
| | | // 订单下达后自动生成一张备料主单,后续领料记录都挂在这张单上。 |
| | | ProductionOrderPick orderPick = productionOrderPickMapper.selectOne( |
| | | Wrappers.<ProductionOrderPick>lambdaQuery() |
| | | .eq(ProductionOrderPick::getProductionOrderId, productionOrder.getId()) |
| | | .last("limit 1")); |
| | | if (orderPick == null) { |
| | | orderPick = new ProductionOrderPick(); |
| | | orderPick.setProductionOrderId(productionOrder.getId()); |
| | | } |
| | | orderPick.setProductModelId(productionOrder.getProductModelId() == null ? null : Math.toIntExact(productionOrder.getProductModelId())); |
| | | orderPick.setQuantity(defaultDecimal(productionOrder.getQuantity())); |
| | | orderPick.setRemark("下单自动生成"); |
| | | if (orderPick.getId() == null) { |
| | | productionOrderPickMapper.insert(orderPick); |
| | | } else { |
| | | productionOrderPickMapper.updateById(orderPick); |
| | | } |
| | | } |
| | | |
| | | private BigDecimal resolveBomDemandQuantity(TechnologyBomStructure source, BigDecimal orderQuantity) { |
| | | // 工艺 BOM 中的需求量按“单件需求 * 订单数量”展开成订单级需求。 |
| | | BigDecimal baseQuantity = source.getDemandedQuantity() != null ? source.getDemandedQuantity() : source.getUnitQuantity(); |
| | | baseQuantity = baseQuantity == null ? BigDecimal.ZERO : baseQuantity; |
| | | if (baseQuantity.compareTo(BigDecimal.ZERO) <= 0) { |
| | | return BigDecimal.ZERO; |
| | | } |
| | | return baseQuantity.multiply(orderQuantity); |
| | | } |
| | | |
| | | private List<Long> parsePlanIds(String productionPlanIds) { |
| | | if (productionPlanIds == null || productionPlanIds.trim().isEmpty()) { |
| | | return new ArrayList<>(); |
| | |
| | | vo.setDownloadURL(fileUtil.buildSignedDownloadUrl(vo)); |
| | | return vo; |
| | | } |
| | | |
| | | @Override |
| | | public List<ProductionOrderPickVo> pick(Long productionOrderId) { |
| | | if (productionOrderId == null) { |
| | | return Collections.emptyList(); |
| | | } |
| | | |
| | | ProductionOrderBom orderBom = productionOrderBomMapper.selectOne( |
| | | Wrappers.<ProductionOrderBom>lambdaQuery() |
| | | .eq(ProductionOrderBom::getProductionOrderId, productionOrderId) |
| | | .orderByDesc(ProductionOrderBom::getId) |
| | | .last("limit 1")); |
| | | if (orderBom == null || orderBom.getId() == null) { |
| | | return Collections.emptyList(); |
| | | } |
| | | |
| | | List<ProductionBomStructureVo> bomStructureList = productionBomStructureMapper.pickByBomId(orderBom.getId()); |
| | | if (bomStructureList == null || bomStructureList.isEmpty()) { |
| | | return Collections.emptyList(); |
| | | } |
| | | |
| | | List<Long> productModelIds = bomStructureList.stream() |
| | | .map(ProductionBomStructureVo::getProductModelId) |
| | | .filter(Objects::nonNull) |
| | | .distinct() |
| | | .collect(Collectors.toList()); |
| | | Map<Long, BigDecimal> stockQuantityMap = new HashMap<>(); |
| | | Map<Long, LinkedHashSet<String>> stockBatchNoMap = new HashMap<>(); |
| | | if (!productModelIds.isEmpty()) { |
| | | List<StockInventory> stockList = stockInventoryMapper.selectList( |
| | | Wrappers.<StockInventory>lambdaQuery() |
| | | .in(StockInventory::getProductModelId, productModelIds)); |
| | | for (StockInventory stockItem : stockList) { |
| | | if (stockItem == null || stockItem.getProductModelId() == null) { |
| | | continue; |
| | | } |
| | | Long productModelId = stockItem.getProductModelId(); |
| | | stockQuantityMap.merge(productModelId, defaultDecimal(stockItem.getQualitity()), BigDecimal::add); |
| | | String batchNo = stockItem.getBatchNo(); |
| | | if (batchNo != null && !batchNo.trim().isEmpty()) { |
| | | stockBatchNoMap.computeIfAbsent(productModelId, key -> new LinkedHashSet<>()).add(batchNo); |
| | | } |
| | | } |
| | | } |
| | | |
| | | List<ProductionOrderPickVo> result = new ArrayList<>(bomStructureList.size()); |
| | | for (ProductionBomStructureVo structure : bomStructureList) { |
| | | if (structure == null || structure.getProductModelId() == null) { |
| | | continue; |
| | | } |
| | | Long productModelId = structure.getProductModelId(); |
| | | ProductionOrderPickVo vo = new ProductionOrderPickVo(); |
| | | vo.setProductModelId(productModelId); |
| | | vo.setOperationName(structure.getOperationName()); |
| | | vo.setTechnologyOperationId(structure.getTechnologyOperationId()); |
| | | vo.setProductName(structure.getProductName()); |
| | | vo.setModel(structure.getModel()); |
| | | vo.setDemandedQuantity(defaultDecimal(structure.getDemandedQuantity())); |
| | | vo.setUnit(structure.getUnit()); |
| | | List<String> batchNoList = stockBatchNoMap.get(productModelId) == null |
| | | ? Collections.emptyList() |
| | | : new ArrayList<>(stockBatchNoMap.get(productModelId)); |
| | | vo.setBatchNoList(batchNoList); |
| | | vo.setStockQuantity(stockQuantityMap.getOrDefault(productModelId, BigDecimal.ZERO)); |
| | | vo.setBom(true); |
| | | result.add(vo); |
| | | } |
| | | return result; |
| | | } |
| | | } |