| | |
| | | .map(ProductionPlan::getVolume) |
| | | .filter(v -> v != null) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | // 判断下发数量是否大于等于方数 |
| | | if (productionPlanDto.getTotalAssignedQuantity().compareTo(totalVolume) > 0) { |
| | | log.warn("合并失败,下发数量不能大于方数"); |
| | | return false; |
| | | } |
| | | |
| | | // 根据下发数量,从第一个生产计划开始分配方数 |
| | | BigDecimal assignedVolume = BigDecimal.ZERO; |
| | | for (ProductionPlan plan : plans) { |
| | | BigDecimal volume = plan.getVolume(); |
| | | if (volume == null) { |
| | | continue; |
| | | } |
| | | |
| | | if (assignedVolume.add(volume).compareTo(productionPlanDto.getTotalAssignedQuantity()) >= 0) { |
| | | // 最后一个计划,分配剩余方数 |
| | | plan.setAssignedQuantity(productionPlanDto.getTotalAssignedQuantity().subtract(assignedVolume)); |
| | | break; |
| | | } |
| | | |
| | | // 分配当前计划方数 |
| | | plan.setAssignedQuantity(volume); |
| | | productionPlanMapper.updateById(plan); |
| | | assignedVolume = assignedVolume.add(volume); |
| | | } |
| | | |
| | | // 创建生产订单 |
| | | ProductOrder productOrder = new ProductOrder(); |
| | | // 合并生产计划ids |
| | | String combineIds = StringUtils.join(productionPlanDto.getIds(), ","); |
| | | productOrder.setCombineProductionPlanIds(combineIds); |
| | | // 下发数量 |
| | | productOrder.setQuantity(productionPlanDto.getTotalAssignedQuantity()); |
| | | productOrder.setPlanCompleteTime(productionPlanDto.getPlanCompleteTime()); |
| | | productOrderService.addProductOrder(productOrder); |
| | | |
| | | return true; |
| | | } |
| | | |