huminmin
3 天以前 e52dfc522497311025b277b5e0ef3590fb3de990
主生产计划:优化合并下发,根据剩余下发数量对比需要下发的数量
已修改2个文件
46 ■■■■ 文件已修改
src/main/java/com/ruoyi/productionPlan/pojo/ProductionPlan.java 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/productionPlan/service/impl/ProductionPlanServiceImpl.java 31 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/productionPlan/pojo/ProductionPlan.java
@@ -230,4 +230,19 @@
    @ApiModelProperty(value = "下发数量")
    @Excel(name = "下发数量")
    private BigDecimal assignedQuantity;
    /**
     * 计算剩余方数
     * @return 剩余方数
     */
    @ApiModelProperty(value = "剩余方数")
    public BigDecimal getRemainingVolume() {
        if (volume == null) {
            return BigDecimal.ZERO;
        }
        if (assignedQuantity == null) {
            return volume;
        }
        return volume.subtract(assignedQuantity);
    }
}
src/main/java/com/ruoyi/productionPlan/service/impl/ProductionPlanServiceImpl.java
@@ -122,14 +122,14 @@
        }
        // 叠加方数
        BigDecimal totalVolume = plans.stream()
                .map(ProductionPlan::getVolume)
        // 叠加剩余方数
        BigDecimal totalRemainingVolume = plans.stream()
                .map(ProductionPlan::getRemainingVolume)
                .filter(v -> v != null)
                .reduce(BigDecimal.ZERO, BigDecimal::add);
        // 判断下发数量是否大于等于方数
        if (productionPlanDto.getTotalAssignedQuantity().compareTo(totalVolume) > 0) {
            throw new BaseException("操作失败,下发数量不能大于方数");
        // 判断下发数量是否大于等于剩余方数
        if (productionPlanDto.getTotalAssignedQuantity().compareTo(totalRemainingVolume) > 0) {
            throw new BaseException("操作失败,下发数量不能大于剩余方数");
        }
        // 创建生产订单
@@ -145,29 +145,34 @@
            if (volume == null) {
                continue;
            }
            // 计算剩余方数
            BigDecimal remainingVolume = plan.getRemainingVolume();
            if (remainingVolume.compareTo(BigDecimal.ZERO) <= 0) {
                continue;
            }
            ProductOrderPlan productOrderPlan = new ProductOrderPlan();
            productOrderPlan.setProductOrderId(productOrder.getId());
            productOrderPlan.setProductionPlanId(plan.getId());
            if (assignedVolume.add(volume).compareTo(productionPlanDto.getTotalAssignedQuantity()) >= 0) {
            if (assignedVolume.add(remainingVolume).compareTo(productionPlanDto.getTotalAssignedQuantity()) >= 0) {
                // 最后一个计划,分配剩余方数
                BigDecimal remainingVolume = productionPlanDto.getTotalAssignedQuantity().subtract(assignedVolume);
                plan.setAssignedQuantity(plan.getAssignedQuantity().add(remainingVolume));
                productOrderPlan.setAssignedQuantity(remainingVolume);
                BigDecimal lastRemainingVolume = productionPlanDto.getTotalAssignedQuantity().subtract(assignedVolume);
                plan.setAssignedQuantity(plan.getAssignedQuantity().add(lastRemainingVolume));
                productOrderPlan.setAssignedQuantity(lastRemainingVolume);
                productionPlanMapper.updateById(plan);
                productOrderPlanMapper.insert(productOrderPlan);
                break;
            }
            // 分配当前计划方数
            plan.setAssignedQuantity(plan.getAssignedQuantity().add(volume));
            productOrderPlan.setAssignedQuantity(volume);
            plan.setAssignedQuantity(plan.getAssignedQuantity().add(remainingVolume));
            productOrderPlan.setAssignedQuantity(remainingVolume);
            // 更新生产计划
            productionPlanMapper.updateById(plan);
            // 创建关联关系
            productOrderPlanMapper.insert(productOrderPlan);
            assignedVolume = assignedVolume.add(volume);
            assignedVolume = assignedVolume.add(remainingVolume);
        }
        return true;
    }