gongchunyi
17 小时以前 b572e82dcafea0fd893d908c7bb0e048483a1dd3
src/main/java/com/ruoyi/productionPlan/service/impl/ProductionPlanServiceImpl.java
@@ -120,6 +120,10 @@
        //  查询主生产计划
        List<ProductionPlanDto> plans = productionPlanMapper.selectWithMaterialByIds(productionPlanDto.getIds());
        if (plans == null || plans.isEmpty()) {
            throw new ServiceException("下发失败,生产计划不存在");
        }
        //  校验是否存在不同的产品名称
        String firstProductName = plans.get(0).getProductName();
        if (plans.stream().anyMatch(p -> p.getProductName() == null || !p.getProductName().equals(firstProductName))) {
@@ -148,6 +152,7 @@
        productOrder.setPlanCompleteTime(productionPlanDto.getPlanCompleteTime());
        productOrder.setStatus(ProductOrderStatusEnum.WAIT.getCode());
        productOrder.setStrength(productionPlanDto.getStrength());
        productOrder.setProductMaterialSkuId(plans.get(0).getProductMaterialSkuId());
        Long orderId = productOrderService.insertProductOrder(productOrder);
@@ -181,11 +186,9 @@
            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);
@@ -193,17 +196,28 @@
            }
            // 分配当前计划方数
            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;
    }
@@ -220,9 +234,17 @@
    @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);