huminmin
3 天以前 e52dfc522497311025b277b5e0ef3590fb3de990
src/main/java/com/ruoyi/productionPlan/service/impl/ProductionPlanServiceImpl.java
@@ -107,6 +107,7 @@
        //  查询主生产计划
        List<ProductionPlan> plans = productionPlanMapper.selectBatchIds(productionPlanDto.getIds());
        plans.sort(Comparator.comparingLong(ProductionPlan::getId));
        //  校验是否存在不同的产品名称
        String firstProductName = plans.get(0).getProductName();
@@ -121,37 +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) {
            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));
                productionPlanMapper.updateById(plan);
                break;
            }
            // 分配当前计划方数
            plan.setAssignedQuantity(volume);
            productionPlanMapper.updateById(plan);
            assignedVolume = assignedVolume.add(volume);
        // 判断下发数量是否大于等于剩余方数
        if (productionPlanDto.getTotalAssignedQuantity().compareTo(totalRemainingVolume) > 0) {
            throw new BaseException("操作失败,下发数量不能大于剩余方数");
        }
        // 创建生产订单
@@ -160,11 +138,41 @@
        productOrder.setPlanCompleteTime(productionPlanDto.getPlanCompleteTime());
        productOrderService.addProductOrder(productOrder);
        for (Long planId : productionPlanDto.getIds()) {
        // 根据下发数量,从第一个生产计划开始分配方数
        BigDecimal assignedVolume = BigDecimal.ZERO;
        for (ProductionPlan plan : plans) {
            BigDecimal volume = plan.getVolume();
            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(planId);
            productOrderPlan.setProductionPlanId(plan.getId());
            if (assignedVolume.add(remainingVolume).compareTo(productionPlanDto.getTotalAssignedQuantity()) >= 0) {
                // 最后一个计划,分配剩余方数
                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(remainingVolume));
            productOrderPlan.setAssignedQuantity(remainingVolume);
            // 更新生产计划
            productionPlanMapper.updateById(plan);
            // 创建关联关系
            productOrderPlanMapper.insert(productOrderPlan);
            assignedVolume = assignedVolume.add(remainingVolume);
        }
        return true;
    }
@@ -307,8 +315,22 @@
        searchParam.put("systemToken", aliDingConfig.getSystemToken());
        searchParam.put("userId", aliDingConfig.getUserId());
        searchParam.put("formUuid", aliDingConfig.getFormUuid());
        searchParam.put("currentPage", pageNumber);
        searchParam.put("pageSize", pageSize);
        searchParam.put("pageNumber", pageNumber);
        JSONArray searchConditions = new JSONArray();
        JSONObject condition = new JSONObject();
        condition.put("key", "processApprovedResult");
        JSONArray valueArray = new JSONArray();
        valueArray.add("agree");
        condition.put("value", valueArray);
        condition.put("type", "ARRAY");
        condition.put("operator", "in");
        condition.put("componentName", "SelectField");
        searchConditions.add(condition);
        searchParam.put("searchFieldJson", searchConditions.toJSONString());
        // 默认按修改时间升序排序,确保分页拉取数据的连续性
        // "+" 表示升序,"gmt_modified" 是官方内置字段