gongchunyi
3 天以前 831163b8a651e5b4e752581d48762f4f7db4ed80
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;
    }
@@ -309,7 +314,7 @@
        searchParam.put("appType", aliDingConfig.getAppType());
        searchParam.put("systemToken", aliDingConfig.getSystemToken());
        searchParam.put("userId", aliDingConfig.getUserId());
        searchParam.put("formUuid", aliDingConfig.getFormUuid());
        searchParam.put("formUuid", aliDingConfig.getProducePlanFormUuid());
        searchParam.put("currentPage", pageNumber);
        searchParam.put("pageSize", pageSize);