gongchunyi
10 小时以前 cd079ba388c160caa8c9836b9bf16fd25a589909
src/main/java/com/ruoyi/productionPlan/service/impl/ProductionPlanServiceImpl.java
@@ -17,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;
@@ -76,6 +77,9 @@
    @Autowired
    private ProductMaterialService productMaterialService;
    @Autowired
    private IProductionOrderAppendixService productionOrderAppendixService;
    /**
     * 同步锁,确保手动和定时任务不同时执行
@@ -143,7 +147,19 @@
        productOrder.setQuantity(productionPlanDto.getTotalAssignedQuantity());
        productOrder.setPlanCompleteTime(productionPlanDto.getPlanCompleteTime());
        productOrder.setStatus(ProductOrderStatusEnum.WAIT.getCode());
        productOrderService.addProductOrder(productOrder);
        productOrder.setStrength(productionPlanDto.getStrength());
        Long orderId = productOrderService.insertProductOrder(productOrder);
        //  当下发的产品为砌块或板材,就拉取BOM子集与工艺路线子集数据存入到附表中
        if ("砌块".equals(productionPlanDto.getProductName())) {
            productOrder.setRouteId(productionOrderAppendixService.populateBlocks(orderId, productionPlanDto));
        }
        if ("板材".equals(productionPlanDto.getProductName())) {
            productOrder.setRouteId(productionOrderAppendixService.populatePlates(orderId, productionPlanDto));
        }
        //  更新绑定的工艺路线
        productOrderService.updateById(productOrder);
        // 根据下发数量,从第一个生产计划开始分配方数
        BigDecimal assignedVolume = BigDecimal.ZERO;
@@ -165,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);
@@ -177,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);
@@ -189,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;
    }