| | |
| | | import com.ruoyi.production.pojo.ProductionPlan; |
| | | import com.ruoyi.production.pojo.ProductionProductMain; |
| | | import com.ruoyi.production.enums.ProductOrderStatusEnum; |
| | | import com.ruoyi.sales.mapper.SalesLedgerMapper; |
| | | import com.ruoyi.sales.mapper.SalesLedgerProductMapper; |
| | | import com.ruoyi.sales.pojo.SalesLedger; |
| | | import com.ruoyi.sales.pojo.SalesLedgerProduct; |
| | | import com.ruoyi.production.service.ProductionOrderService; |
| | | import com.ruoyi.technology.mapper.TechnologyBomMapper; |
| | | import com.ruoyi.technology.mapper.TechnologyBomStructureMapper; |
| | |
| | | private final ProductionOrderPickMapper productionOrderPickMapper; |
| | | private final ProductionOrderPickRecordMapper productionOrderPickRecordMapper; |
| | | private final ProductionPlanMapper productionPlanMapper; |
| | | private final SalesLedgerMapper salesLedgerMapper; |
| | | private final SalesLedgerProductMapper salesLedgerProductMapper; |
| | | private final TechnologyRoutingMapper technologyRoutingMapper; |
| | | private final TechnologyRoutingOperationMapper technologyRoutingOperationMapper; |
| | | private final TechnologyRoutingOperationParamMapper technologyRoutingOperationParamMapper; |
| | |
| | | ProductionOrder query = dto == null ? new ProductionOrder() : dto; |
| | | return Wrappers.<ProductionOrder>lambdaQuery() |
| | | .eq(query.getId() != null, ProductionOrder::getId, query.getId()) |
| | | .eq(query.getSalesLedgerId() != null, ProductionOrder::getSalesLedgerId, query.getSalesLedgerId()) |
| | | .eq(query.getProductModelId() != null, ProductionOrder::getProductModelId, query.getProductModelId()) |
| | | .eq(query.getTechnologyRoutingId() != null, ProductionOrder::getTechnologyRoutingId, query.getTechnologyRoutingId()) |
| | | .like(query.getNpsNo() != null && !query.getNpsNo().trim().isEmpty(), ProductionOrder::getNpsNo, query.getNpsNo()) |
| | |
| | | if (productionOrder == null) { |
| | | throw new ServiceException("Production order is required"); |
| | | } |
| | | fillFromSalesLedgerProduct(productionOrder); |
| | | fillFromProductionPlans(productionOrder); |
| | | if (productionOrder.getProductModelId() == null) { |
| | | throw new ServiceException("productModelId is required"); |
| | | throw new ServiceException("productModelId is required when manually creating a production order"); |
| | | } |
| | | if (defaultDecimal(productionOrder.getQuantity()).compareTo(BigDecimal.ZERO) <= 0) { |
| | | throw new ServiceException("quantity must be greater than 0"); |
| | |
| | | || !Objects.equals(oldOrder.getTechnologyRoutingId(), productionOrder.getTechnologyRoutingId()) |
| | | || compareDecimal(oldOrder.getQuantity(), productionOrder.getQuantity()) != 0) { |
| | | throw new ServiceException("Started production orders cannot modify product, routing or quantity"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void fillFromSalesLedgerProduct(ProductionOrder productionOrder) { |
| | | if (productionOrder.getSaleLedgerProductId() == null) { |
| | | return; |
| | | } |
| | | // 销售明细是订单来源时,以销售明细为准回填销售台账、产品规格和默认数量。 |
| | | SalesLedgerProduct salesLedgerProduct = salesLedgerProductMapper.selectById(productionOrder.getSaleLedgerProductId().longValue()); |
| | | if (salesLedgerProduct == null) { |
| | | throw new ServiceException("Sales ledger product not found"); |
| | | } |
| | | if (productionOrder.getSalesLedgerId() == null) { |
| | | productionOrder.setSalesLedgerId(salesLedgerProduct.getSalesLedgerId()); |
| | | } else if (!Objects.equals(productionOrder.getSalesLedgerId(), salesLedgerProduct.getSalesLedgerId())) { |
| | | throw new ServiceException("salesLedgerId does not match the sales ledger product"); |
| | | } |
| | | if (productionOrder.getProductModelId() == null) { |
| | | productionOrder.setProductModelId(salesLedgerProduct.getProductModelId()); |
| | | } else if (!Objects.equals(productionOrder.getProductModelId(), salesLedgerProduct.getProductModelId())) { |
| | | throw new ServiceException("productModelId does not match the sales ledger product"); |
| | | } |
| | | if (productionOrder.getQuantity() == null || productionOrder.getQuantity().compareTo(BigDecimal.ZERO) <= 0) { |
| | | productionOrder.setQuantity(salesLedgerProduct.getQuantity()); |
| | | } |
| | | if (productionOrder.getPlanCompleteTime() == null && productionOrder.getSalesLedgerId() != null) { |
| | | SalesLedger salesLedger = salesLedgerMapper.selectById(productionOrder.getSalesLedgerId()); |
| | | if (salesLedger != null && salesLedger.getDeliveryDate() != null) { |
| | | productionOrder.setPlanCompleteTime(salesLedger.getDeliveryDate()); |
| | | } |
| | | } |
| | | } |