| | |
| | | |
| | | // 校验是否存在不同的产品名称 |
| | | String firstProductName = plans.get(0).getProductName(); |
| | | if (plans.stream().anyMatch(p -> !p.getProductName().equals(firstProductName))) { |
| | | if (plans.stream().anyMatch(p -> p.getProductName() == null || !p.getProductName().equals(firstProductName))) { |
| | | throw new BaseException("合并失败,存在不同的产品名称"); |
| | | } |
| | | |
| | | // 校验是否存在不同的产品规格 |
| | | String firstProductSpec = plans.get(0).getSpecification(); |
| | | if (plans.stream().anyMatch(p -> !p.getSpecification().equals(firstProductSpec))) { |
| | | if (plans.stream().anyMatch(p -> p.getSpecification() == null || !p.getSpecification().equals(firstProductSpec))) { |
| | | throw new BaseException("合并失败,存在不同的产品规格"); |
| | | } |
| | | |
| | | // 叠加剩余方数 |
| | | BigDecimal totalRemainingVolume = plans.stream() |
| | | .map(ProductionPlan::getRemainingVolume) |
| | | .filter(v -> v != null) |
| | | .filter(Objects::nonNull) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | // 判断下发数量是否大于等于剩余方数 |
| | | if (productionPlanDto.getTotalAssignedQuantity().compareTo(totalRemainingVolume) > 0) { |
| | |
| | | // 最后一个计划,分配剩余方数 |
| | | BigDecimal lastRemainingVolume = productionPlanDto.getTotalAssignedQuantity().subtract(assignedVolume); |
| | | plan.setStatus(1); |
| | | if (lastRemainingVolume.compareTo(BigDecimal.ZERO) <= 0) { |
| | | plan.setStatus(2); |
| | | } |
| | | plan.setAssignedQuantity(plan.getAssignedQuantity().add(lastRemainingVolume)); |
| | | productOrderPlan.setAssignedQuantity(lastRemainingVolume); |
| | | productionPlanMapper.updateById(plan); |
| | |
| | | |
| | | // 分配当前计划方数 |
| | | plan.setStatus(1); |
| | | if (remainingVolume.compareTo(BigDecimal.ZERO) <= 0) { |
| | | plan.setStatus(2); |
| | | } |
| | | plan.setAssignedQuantity(plan.getAssignedQuantity().add(remainingVolume)); |
| | | productOrderPlan.setAssignedQuantity(remainingVolume); |
| | | // 更新生产计划 |
| | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean add(ProductionPlanDto productionPlanDto) { |
| | | productionPlanDto.setDataSourceType(DataSourceTypeEnum.MANUAL.getCode()); |
| | | productionPlanDto.setStatus(0); |
| | | productionPlanMapper.insert(productionPlanDto); |
| | | return true; |
| | | } |
| | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean update(ProductionPlanDto productionPlanDto) { |
| | | // 已下发状态,不能编辑 |
| | | if (productionPlanDto.getStatus() == 1) { |
| | | throw new BaseException("已下发状态,不能编辑"); |
| | | if (productionPlanDto.getStatus() != 0) { |
| | | throw new BaseException("已下发或部分下发状态,不能编辑"); |
| | | } |
| | | // 查询是否有关联订单 |
| | | boolean hasProductOrderPlan = productOrderPlanMapper.selectList(Wrappers.<ProductOrderPlan>lambdaQuery().eq(ProductOrderPlan::getProductionPlanId, productionPlanDto.getId())).stream().anyMatch(p -> p.getProductOrderId() != null); |
| | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean delete(List<Long> ids) { |
| | | // 如果存在已下发的计划,则不能删除 |
| | | if (productionPlanMapper.selectList(Wrappers.<ProductionPlan>lambdaQuery().in(ProductionPlan::getId, ids).eq(ProductionPlan::getStatus, 1)).stream().anyMatch(p -> p.getStatus() == 1)) { |
| | | throw new BaseException("删除失败,存在已下发的计划"); |
| | | if (productionPlanMapper.selectList(Wrappers.<ProductionPlan>lambdaQuery().in(ProductionPlan::getId, ids)).stream().anyMatch(p -> p.getStatus() == 1 || p.getStatus() == 2)) { |
| | | throw new BaseException("删除失败,存在已下发或部分下发的计划"); |
| | | } |
| | | // 如果有关联订单,则不能删除 |
| | | if (productOrderPlanMapper.selectList(Wrappers.<ProductOrderPlan>lambdaQuery().in(ProductOrderPlan::getProductionPlanId, ids)).stream().anyMatch(p -> p.getProductOrderId() != null)) { |