| | |
| | | productOrder.setPlanCompleteTime(productionPlanDto.getPlanCompleteTime()); |
| | | productOrder.setStatus(ProductOrderStatusEnum.WAIT.getCode()); |
| | | productOrder.setStrength(productionPlanDto.getStrength()); |
| | | productOrder.setProductMaterialSkuId(productionPlanDto.getProductMaterialSkuId()); |
| | | |
| | | Long orderId = productOrderService.insertProductOrder(productOrder); |
| | | |
| | |
| | | if (assignedVolume.add(remainingVolume).compareTo(productionPlanDto.getTotalAssignedQuantity()) >= 0) { |
| | | // 最后一个计划,分配剩余方数 |
| | | BigDecimal lastRemainingVolume = productionPlanDto.getTotalAssignedQuantity().subtract(assignedVolume); |
| | | plan.setStatus(1); |
| | | plan.setAssignedQuantity(plan.getAssignedQuantity().add(lastRemainingVolume)); |
| | | if (plan.getAssignedQuantity().compareTo(plan.getVolume()) >= 0) { |
| | | plan.setStatus(2); |
| | | } |
| | | BigDecimal assignedQuantity = Optional.ofNullable(plan.getAssignedQuantity()).orElse(BigDecimal.ZERO).add(lastRemainingVolume); |
| | | plan.setAssignedQuantity(assignedQuantity); |
| | | plan.setStatus(assignedQuantity.compareTo(plan.getVolume()) >= 0 ? 2 : 1); |
| | | productOrderPlan.setAssignedQuantity(lastRemainingVolume); |
| | | productionPlanMapper.updateById(plan); |
| | | productOrderPlanMapper.insert(productOrderPlan); |
| | |
| | | } |
| | | |
| | | // 分配当前计划方数 |
| | | plan.setStatus(1); |
| | | if (remainingVolume.compareTo(BigDecimal.ZERO) <= 0) { |
| | | plan.setStatus(2); |
| | | } |
| | | plan.setAssignedQuantity(plan.getAssignedQuantity().add(remainingVolume)); |
| | | BigDecimal assignedQuantity = Optional.ofNullable(plan.getAssignedQuantity()).orElse(BigDecimal.ZERO).add(remainingVolume); |
| | | plan.setAssignedQuantity(assignedQuantity); |
| | | plan.setStatus(assignedQuantity.compareTo(plan.getVolume()) >= 0 ? 2 : 1); |
| | | productOrderPlan.setAssignedQuantity(remainingVolume); |
| | | // 更新生产计划 |
| | | productionPlanMapper.updateById(plan); |
| | | // 创建关联关系 |
| | | productOrderPlanMapper.insert(productOrderPlan); |
| | | assignedVolume = assignedVolume.add(remainingVolume); |
| | | } |
| | | |
| | | for (ProductionPlan plan : plans) { |
| | | BigDecimal assignedQuantity = Optional.ofNullable(plan.getAssignedQuantity()).orElse(BigDecimal.ZERO); |
| | | BigDecimal volume = Optional.ofNullable(plan.getVolume()).orElse(BigDecimal.ZERO); |
| | | if (assignedQuantity.compareTo(BigDecimal.ZERO) <= 0) { |
| | | plan.setStatus(0); |
| | | } else if (assignedQuantity.compareTo(volume) >= 0) { |
| | | plan.setStatus(2); |
| | | } else { |
| | | plan.setStatus(1); |
| | | } |
| | | productionPlanMapper.updateById(plan); |
| | | } |
| | | return true; |
| | | } |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean update(ProductionPlanDto productionPlanDto) { |
| | | if (productionPlanDto == null) { |
| | | throw new ServiceException("编辑失败,数据不能为空"); |
| | | } |
| | | ProductionPlan productionPlan = getById(productionPlanDto.getId()); |
| | | if (productionPlan == null) { |
| | | throw new ServiceException("编辑失败,主生产计划不存在"); |
| | | } |
| | | |
| | | // 已下发状态,不能编辑 |
| | | if (productionPlanDto.getStatus() != 0) { |
| | | throw new BaseException("已下发或部分下发状态,不能编辑"); |
| | | if (productionPlan.getStatus() != 0) { |
| | | throw new BaseException("编辑失败,该生产计划已下发或部分下发状态,禁止编辑"); |
| | | } |
| | | // 查询是否有关联订单 |
| | | boolean hasProductOrderPlan = productOrderPlanMapper.selectList(Wrappers.<ProductOrderPlan>lambdaQuery().eq(ProductOrderPlan::getProductionPlanId, productionPlanDto.getId())).stream().anyMatch(p -> p.getProductOrderId() != null); |