gongchunyi
7 小时以前 cd079ba388c160caa8c9836b9bf16fd25a589909
src/main/java/com/ruoyi/productionPlan/service/impl/ProductionPlanServiceImpl.java
@@ -7,7 +7,6 @@
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.appendix.service.AppendixService;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.exception.base.BaseException;
import com.ruoyi.common.utils.StringUtils;
@@ -18,6 +17,7 @@
import com.ruoyi.production.enums.ProductOrderStatusEnum;
import com.ruoyi.production.pojo.ProductMaterialSku;
import com.ruoyi.production.pojo.ProductOrder;
import com.ruoyi.production.service.IProductionOrderAppendixService;
import com.ruoyi.production.service.ProductMaterialService;
import com.ruoyi.production.service.ProductMaterialSkuService;
import com.ruoyi.production.service.ProductOrderService;
@@ -79,7 +79,7 @@
    private ProductMaterialService productMaterialService;
    @Autowired
    private AppendixService appendixService;
    private IProductionOrderAppendixService productionOrderAppendixService;
    /**
     * 同步锁,确保手动和定时任务不同时执行
@@ -147,15 +147,19 @@
        productOrder.setQuantity(productionPlanDto.getTotalAssignedQuantity());
        productOrder.setPlanCompleteTime(productionPlanDto.getPlanCompleteTime());
        productOrder.setStatus(ProductOrderStatusEnum.WAIT.getCode());
        productOrder.setStrength(productionPlanDto.getStrength());
        Long orderId = productOrderService.insertProductOrder(productOrder);
        //  当下发的产品为砌块或板材,就拉取BOM子集与工艺路线子集数据存入到附表中
        if ("砌块".equals(productionPlanDto.getProductName())) {
            productOrder.setRouteId(appendixService.populateBlocks(productionPlanDto));
            productOrder.setRouteId(productionOrderAppendixService.populateBlocks(orderId, productionPlanDto));
        }
        if ("板材".equals(productionPlanDto.getProductName())) {
            productOrder.setRouteId(appendixService.populatePlates(productionPlanDto));
            productOrder.setRouteId(productionOrderAppendixService.populatePlates(orderId, productionPlanDto));
        }
        productOrderService.addProductOrder(productOrder);
        //  更新绑定的工艺路线
        productOrderService.updateById(productOrder);
        // 根据下发数量,从第一个生产计划开始分配方数
        BigDecimal assignedVolume = BigDecimal.ZERO;
@@ -177,11 +181,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);
@@ -189,11 +191,9 @@
            }
            // 分配当前计划方数
            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);
@@ -201,6 +201,19 @@
            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;
    }