刘小明
2024-07-17 bea49667b0a34a17490c4b47f6a14857a737f647
pms-parent/pms-web-product/src/main/java/com/dy/pmsProduct/process/ProcessSv.java
@@ -29,6 +29,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
@Slf4j
@@ -105,11 +106,11 @@
        List<PrAssemblyPlan> onlinePlanList = planList.stream().filter(plan -> plan.getStatus() == PlanStatusEnum.NORMAL.getCode()).collect(Collectors.toList());
        if (CollectionUtils.isNotEmpty(planList)) {
            if (planList.stream().anyMatch(plan -> plan.getInputNumber() > 0)) { //存在任务已经投入生产
                if (!originProductionProcess.getProName().equals(process.getProName())) {
                if (!originProductionProcess.getProId().equals(process.getProId())) {
                    throw new RuntimeException("存在已经投入生产绑定的任务,产品不能修改");
                }
                //节点id不能删除
                if (!originProductionProcess.getNodes().stream().allMatch(node -> process.getNodes().stream().anyMatch(node::equals))) {
                if (!originProductionProcess.getNodes().stream().allMatch(node -> process.getNodes().stream().anyMatch(newNode ->  node.getId().equals(newNode.getId())))) {
                    throw new RuntimeException("存在已经投入生产绑定的任务,节点不能删除");
                }
            } else if (CollectionUtils.isNotEmpty(onlinePlanList)) {
@@ -130,7 +131,13 @@
                .collect(Collectors.toList());
        if (CollectionUtils.isNotEmpty(nodeIdsToDelete)) {
            nodeDao.deleteByNodeId(nodeIdsToDelete);
            workDao.deleteByNodeId(nodeIdsToDelete);
        }
        //原来节点的SOP全部删除
        List<Long> originNodeIds = originProductionProcess.getNodes().stream()
                .map(PrProductionNode::getId) // 映射节点到其ID
                .collect(Collectors.toList());
        if (CollectionUtils.isNotEmpty(originNodeIds)) {
            workDao.deleteByNodeId(originNodeIds);
        }
        saveNodesAndInstructions(process);
        return count;
@@ -144,10 +151,21 @@
        if (loginUser != null) {
            process.creator = loginUser.id;
        }
        AtomicInteger startCount = new AtomicInteger();
        AtomicInteger endCount = new AtomicInteger();
        process.nodes.forEach(node -> {
            node.processId = process.id;
            node.deleted = false;
            if(node.isStart){
                startCount.getAndIncrement();
            }
            if(node.isEnd){
                endCount.getAndIncrement();
            }
        });
        if (startCount.get() != 1 || endCount.get() != 1) {
            throw new RuntimeException("节点开始和结束节点有且只能有一个");
        }
    }
    // 将节点和工作指示的保存逻辑封装到一个方法中