| | |
| | | |
| | | // 查询主生产计划 |
| | | List<ProductionPlan> plans = productionPlanMapper.selectBatchIds(productionPlanDto.getIds()); |
| | | plans.sort(Comparator.comparingLong(ProductionPlan::getId)); |
| | | |
| | | // 校验是否存在不同的产品名称 |
| | | String firstProductName = plans.get(0).getProductName(); |
| | |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | // 判断下发数量是否大于等于方数 |
| | | if (productionPlanDto.getTotalAssignedQuantity().compareTo(totalVolume) > 0) { |
| | | |
| | | log.warn("操作失败,下发数量不能大于方数"); |
| | | return false; |
| | | throw new BaseException("操作失败,下发数量不能大于方数"); |
| | | } |
| | | |
| | | // 创建生产订单 |
| | | ProductOrder productOrder = new ProductOrder(); |
| | | productOrder.setQuantity(productionPlanDto.getTotalAssignedQuantity()); |
| | | productOrder.setPlanCompleteTime(productionPlanDto.getPlanCompleteTime()); |
| | | productOrderService.addProductOrder(productOrder); |
| | | |
| | | // 根据下发数量,从第一个生产计划开始分配方数 |
| | | BigDecimal assignedVolume = BigDecimal.ZERO; |
| | |
| | | continue; |
| | | } |
| | | |
| | | ProductOrderPlan productOrderPlan = new ProductOrderPlan(); |
| | | productOrderPlan.setProductOrderId(productOrder.getId()); |
| | | productOrderPlan.setProductionPlanId(plan.getId()); |
| | | |
| | | if (assignedVolume.add(volume).compareTo(productionPlanDto.getTotalAssignedQuantity()) >= 0) { |
| | | // 最后一个计划,分配剩余方数 |
| | | plan.setAssignedQuantity(productionPlanDto.getTotalAssignedQuantity().subtract(assignedVolume)); |
| | | BigDecimal remainingVolume = productionPlanDto.getTotalAssignedQuantity().subtract(assignedVolume); |
| | | plan.setAssignedQuantity(plan.getAssignedQuantity().add(remainingVolume)); |
| | | productOrderPlan.setAssignedQuantity(remainingVolume); |
| | | productionPlanMapper.updateById(plan); |
| | | productOrderPlanMapper.insert(productOrderPlan); |
| | | break; |
| | | } |
| | | |
| | | // 分配当前计划方数 |
| | | plan.setAssignedQuantity(volume); |
| | | plan.setAssignedQuantity(plan.getAssignedQuantity().add(volume)); |
| | | productOrderPlan.setAssignedQuantity(volume); |
| | | // 更新生产计划 |
| | | productionPlanMapper.updateById(plan); |
| | | assignedVolume = assignedVolume.add(volume); |
| | | } |
| | | |
| | | // 创建生产订单 |
| | | ProductOrder productOrder = new ProductOrder(); |
| | | productOrder.setQuantity(productionPlanDto.getTotalAssignedQuantity()); |
| | | productOrder.setPlanCompleteTime(productionPlanDto.getPlanCompleteTime()); |
| | | productOrderService.addProductOrder(productOrder); |
| | | |
| | | for (Long planId : productionPlanDto.getIds()) { |
| | | ProductOrderPlan productOrderPlan = new ProductOrderPlan(); |
| | | productOrderPlan.setProductOrderId(productOrder.getId()); |
| | | productOrderPlan.setProductionPlanId(planId); |
| | | // 创建关联关系 |
| | | productOrderPlanMapper.insert(productOrderPlan); |
| | | assignedVolume = assignedVolume.add(volume); |
| | | } |
| | | return true; |
| | | } |