From 8d63dd77b9b3cd9b6d9768f216670fc499a8cab3 Mon Sep 17 00:00:00 2001
From: lyh <925863403@qq.com>
Date: 星期四, 23 一月 2025 14:32:16 +0800
Subject: [PATCH] 整合DNC 权限分配 修改为设备车间管理权限

---
 lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/ProductInfoServiceImpl.java |  456 +++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 397 insertions(+), 59 deletions(-)

diff --git a/lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/ProductInfoServiceImpl.java b/lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/ProductInfoServiceImpl.java
index 5d03027..a61862f 100644
--- a/lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/ProductInfoServiceImpl.java
+++ b/lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/ProductInfoServiceImpl.java
@@ -13,6 +13,7 @@
 import org.jeecg.modules.dnc.exception.ExceptionCast;
 import org.jeecg.modules.dnc.mapper.ProductInfoMapper;
 
+import org.jeecg.modules.dnc.response.*;
 import org.jeecg.modules.dnc.service.*;
 import org.jeecg.modules.dnc.service.support.ProductTreeWrapper;
 import org.jeecg.modules.dnc.ucenter.Department;
@@ -20,15 +21,11 @@
 import org.jeecg.modules.dnc.utils.ValidateUtil;
 
 import org.jeecg.modules.dnc.entity.*;
+import org.jeecg.modules.system.entity.MdcProduction;
 import org.jeecg.modules.system.entity.SysUser;
+import org.jeecg.modules.system.service.IMdcProductionService;
 import org.jeecg.modules.system.service.ISysUserService;
 
-import org.jeecg.modules.dnc.response.ComponentInfoCode;
-import org.jeecg.modules.dnc.response.PartsInfoCode;
-import org.jeecg.modules.dnc.response.ProductInfoCode;
-import org.jeecg.modules.dnc.response.UcenterCode;
-import org.jeecg.modules.dnc.response.CommonCode;
-import org.jeecg.modules.dnc.response.CommonGenericTree;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Lazy;
@@ -73,6 +70,12 @@
     private IDocInfoService docInfoService;
     @Autowired
     private INcLogInfoService iNcLogInfoService;
+    @Autowired
+    private IWorkStepDepartmentService workStepDepartmentService;
+    @Autowired
+    private IProcessionDepartmentService processionDepartmentService;
+    @Autowired
+    private IMdcProductionService mdcProductionService;
 
     @Override
     @Transactional(rollbackFor = {Exception.class})
@@ -272,25 +275,33 @@
             if(productInfo == null)
                 ExceptionCast.cast(ProductInfoCode.PRODUCT_NOT_EXIST);
             PermissionStream permission = permissionStreamService.getByProductIdAndUserId(paramId, userId);
-            if(permission == null)
-                return false;
-            return true;
+            return permission != null;
         }else if(nodeType == 2) {
             ComponentInfo componentInfo = componentInfoService.getById(paramId);
             if(componentInfo == null)
                 ExceptionCast.cast(ComponentInfoCode.COMPONENT_NOT_EXIST);
             PermissionStream permission = permissionStreamService.getByComponentIdAndUserId(componentInfo.getProductId(), paramId, userId);
-            if(permission == null)
-                return false;
-            return true;
+            return permission != null;
         }else if(nodeType == 3) {
             PartsInfo partsInfo = partsInfoService.getById(paramId);
             if(partsInfo == null)
                 ExceptionCast.cast(PartsInfoCode.PARTS_NOT_EXIST);
             PermissionStream permission = permissionStreamService.getByPartsIdAndUserId(partsInfo.getProductId(), partsInfo.getComponentId(), paramId, userId);
-            if(permission == null)
-                return false;
-            return true;
+            return permission != null;
+        }else if (nodeType == 5) {
+            ProcessStream processStream=processStreamService.getById(paramId);
+            if(processStream == null)
+                ExceptionCast.cast(ProcessInfoCode.PROCESS_NOT_EXIST);
+            PermissionStream permission = permissionStreamService.getByProcessIdAndUserId(processStream.getProcessId(),processStream.getComponentId()
+                        ,processStream.getPartsId(),processStream.getProcessId(),userId);
+            return permission != null;
+        }else if (nodeType == 6){
+            WorkStep workStep=workStepService.getById(paramId);
+            if(workStep == null)
+                ExceptionCast.cast(ProcessInfoCode.WORKSTEP_NOT_EXIST);
+            PermissionStream permission = permissionStreamService.getByStepIdAndUserId(workStep.getProcessId(),workStep.getComponentId()
+                    ,workStep.getPartsId(),workStep.getProcessId(),workStep.getId(),userId);
+            return permission != null;
         }
         return false;
     }
@@ -326,7 +337,7 @@
     }
 
     @Override
-    public List<Department> getDepartPermsList(Integer nodeType, String paramId) {
+    public List<MdcProduction> getDepartPermsList(Integer nodeType, String paramId) {
         if(!ValidateUtil.validateInteger(nodeType) || !ValidateUtil.validateString(paramId))
             return null;
         if(nodeType == 1) {
@@ -335,13 +346,19 @@
             return componentDepartmentService.getDepartPermsByComponentId(paramId);
         }else if(nodeType == 3) {
             return partsDepartmentService.getDepartPermsByPartsId(paramId);
-        }else {
+        }else if(nodeType == 5) {
+            return processionDepartmentService.getDepartPermsByProcessId(paramId);
+        }else if(nodeType == 6) {
+            return workStepDepartmentService.getDepartPermsByStepId(paramId);
+        }
+        //todo 灏佽鏍戠姸缁撴瀯
+        else {
             return null;
         }
     }
 
     @Override
-    public List<Department> getDepartNonPermsList(Integer nodeType, String paramId) {
+    public List<MdcProduction> getDepartNonPermsList(Integer nodeType, String paramId) {
         if(!ValidateUtil.validateInteger(nodeType) || !ValidateUtil.validateString(paramId))
             return null;
         if(nodeType == 1) {
@@ -350,7 +367,13 @@
             return componentDepartmentService.getDepartNonPermsByComponentId(paramId);
         }else if(nodeType == 3) {
             return partsDepartmentService.getDepartNonPermsByProductId(paramId);
-        }else {
+        }else if(nodeType == 5) {
+            return processionDepartmentService.getDepartNonPermsByProcessId(paramId);
+        }else if(nodeType == 6) {
+            return workStepDepartmentService.getDepartNonPermsByStepId(paramId);
+        }
+        //todo 灏佽鏍戠姸缁撴瀯
+        else {
             return null;
         }
     }
@@ -774,7 +797,7 @@
 
     /**
      * 寰呬紭鍖� TODO
-     * @param nodeType 1 浜у搧 2 閮ㄤ欢 3 闆朵欢
+     * @param nodeType 1 浜у搧 2 閮ㄤ欢 3 闆朵欢 5 宸ュ簭 6 宸ユ
      * @param paramId 浜у搧鏍戣妭鐐筰d
      * @param relativeFlag 1 鏄� 2 鍚�
      * @param departmentIds 娣诲姞閮ㄩ棬ids
@@ -790,10 +813,30 @@
             ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_NONE);
         List<String> ids = new ArrayList<>(departmentIds.length);
         Collections.addAll(ids, departmentIds);
-        Collection<Department> departList = departmentService.listByIds(ids);
-        if(departList == null || departList.isEmpty() || departList.size() != departmentIds.length)
+        Collection<MdcProduction> mdcProductionList=mdcProductionService.listByIds(ids);
+        if(mdcProductionList == null || mdcProductionList.isEmpty() || mdcProductionList.size() != departmentIds.length)
             ExceptionCast.cast(CommonCode.INVALID_PARAM);
-        if(nodeType == 3) {
+        if(nodeType == 6) {
+            //澶勭悊宸ユ
+            WorkStep workStep=workStepService.getById(paramId);
+            if (workStep == null)
+                ExceptionCast.cast(PartsInfoCode.PARTS_NOT_EXIST);
+            boolean b = checkProductPerm(6, workStep.getId());
+            if (!b) {
+                ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
+            }
+            return workStepService.assignAddDepart(workStep, mdcProductionList);
+        }else if(nodeType == 5) {
+            //澶勭悊宸ュ簭
+            ProcessStream processStream = processStreamService.getById(paramId);
+            if (processStream == null)
+                ExceptionCast.cast(PartsInfoCode.PARTS_NOT_EXIST);
+            boolean b = checkProductPerm(5, processStream.getProcessId());
+            if (!b) {
+                ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
+            }
+            return processStreamService.assignAddDepart(processStream, mdcProductionList);
+        }else if(nodeType == 3) {
             //澶勭悊闆朵欢
             PartsInfo partsInfo = partsInfoService.getById(paramId);
             if(partsInfo == null)
@@ -802,7 +845,7 @@
             if(!b) {
                 ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
             }
-            return partsInfoService.assignAddDepart(partsInfo, departList);
+            return partsInfoService.assignAddDepart(partsInfo, mdcProductionList);
         }else if(nodeType == 1) {
             //澶勭悊浜у搧
             ProductInfo productInfo = super.getById(paramId);
@@ -811,7 +854,7 @@
             boolean b1 = checkProductPerm(1, productInfo.getProductId());
             if(!b1)
                 ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
-            b1 = this.assignAddDepartment(productInfo, departList);
+            b1 = this.assignAddDepartment(productInfo, mdcProductionList);
             if(!b1)
                 ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
             if(relativeFlag == 1) {
@@ -820,9 +863,14 @@
                 //鏈�缁堜繚瀛樻潈闄愭暟鎹垵濮嬪寲
                 List<ComponentDepartment> componentPermissionList = new ArrayList<>();
                 List<PartsDepartment> partsPermissionList = new ArrayList<>();
+                List<ProcessionDepartment> processionPermissionList = new ArrayList<>();
+                List<WorkStepDepartment> workStepDepartmentList=new ArrayList<>();
                 List<PermissionStream> permissionStreamList = new ArrayList<>();
                 //澶勭悊瀛愰儴浠�
                 List<String> componentIds = new ArrayList<>();
+                List<String> partsIds= new ArrayList<>();
+                List<String> ProcessionIds= new ArrayList<>();
+                List<String> workStepIds= new ArrayList<>();
                 PermissionStream s;
 
                 Map<String, ComponentDepartment> componentPermissionMap = new HashMap<>();
@@ -835,9 +883,9 @@
                 for(ComponentInfo c : componentInfoList){
                     componentIds.add(c.getComponentId());
                     componentInfoMap.put(c.getComponentId(), c);
-                    for(Department u : departList){
-                        key = c.getComponentId() + "," + u.getDepartId();
-                        cp = new ComponentDepartment(c.getComponentId(), u.getDepartId());
+                    for(MdcProduction mdcProduction : mdcProductionList){
+                        key = c.getComponentId() + "," + mdcProduction.getId();
+                        cp = new ComponentDepartment(c.getComponentId(), mdcProduction.getId());
                         componentPermissionMap.put(key, cp);
                     }
                 }
@@ -868,15 +916,15 @@
                 if(partsInfoList != null && !partsInfoList.isEmpty()) {
                     Map<String, PartsDepartment> partsPermissionHashMap = new HashMap<>();
                     Map<String, PartsInfo> partsInfoMap = new HashMap<>();
-                    List<String> partsIds = new ArrayList<>();
+                    partsIds = new ArrayList<>();
                     PartsDepartment pp;
                     PartsInfo ptInfo;
                     for(PartsInfo p : partsInfoList){
                         partsIds.add(p.getPartsId());
                         partsInfoMap.put(p.getPartsId(), p);
-                        for(Department u : departList){
-                            key = p.getPartsId() + "," + u.getDepartId();
-                            pp = new PartsDepartment(p.getPartsId(), u.getDepartId());
+                        for(MdcProduction mdcProduction : mdcProductionList){
+                            key = p.getPartsId() + "," + mdcProduction.getId();
+                            pp = new PartsDepartment(p.getPartsId(), mdcProduction.getId());
                             partsPermissionHashMap.put(key, pp);
                         }
                     }
@@ -906,11 +954,105 @@
                     }
                 }
 
+                //鏌ヨ宸ュ簭宸插瓨鍦ㄧ殑鏉冮檺鏁版嵁
+                List<ProcessStream> processStreamList = processStreamService.getByComponentIdList(productInfo.getProductId(),componentIds,partsIds);
+                if(processStreamList != null && !processStreamList.isEmpty()) {
+                    Map<String, ProcessionDepartment> processionDepartmentHashMap = new HashMap<>();
+                    Map<String, ProcessStream> processStreamMap = new HashMap<>();
+                    ProcessionIds = new ArrayList<>();
+                    ProcessionDepartment pp;
+                    ProcessStream processStream;
+                    for(ProcessStream p : processStreamList){
+                        ProcessionIds.add(p.getProcessId());
+                        processStreamMap.put(p.getProcessId(), p);
+                        for(MdcProduction mdcProduction : mdcProductionList){
+                            key = p.getPartsId() + "," + mdcProduction.getId();
+                            pp = new ProcessionDepartment(p.getProcessId(), mdcProduction.getId());
+                            processionDepartmentHashMap.put(key, pp);
+                        }
+                    }
+
+                    //鏌ヨ宸插瓨鍦ㄧ殑鏉冮檺鏁版嵁
+                    List<ProcessionDepartment> processionDepartmentList = processionDepartmentService.getByPartsIdsAndDepartIds(ProcessionIds, ids);
+                    if(processionDepartmentList != null && !processionDepartmentList.isEmpty()){
+                        //韪㈠嚭鏉冮檺鏁版嵁
+                        for(ProcessionDepartment processionDepartment : processionDepartmentList){
+                            key = processionDepartment.getProcessId() + "," + processionDepartment.getDepartId();
+                            if(processionDepartmentHashMap.containsKey(key)){
+                                processionDepartmentHashMap.remove(key);
+                            }
+                        }
+                    }
+
+                    for(Map.Entry<String, ProcessionDepartment> entry : processionDepartmentHashMap.entrySet()){
+                        pp = entry.getValue();
+                        processionPermissionList.add(pp);
+                        processStream = processStreamMap.get(pp.getProcessId());
+                        s = new PermissionStream();
+                        s.setProductId(processStream.getProductId());
+                        s.setComponentId(processStream.getComponentId());
+                        s.setPartsId(processStream.getPartsId());
+                        s.setProcessId(processStream.getProcessId());
+                        s.setDepartId(pp.getDepartId());
+                        permissionStreamList.add(s);
+                    }
+                }
+                //鏌ヨ宸ユ宸插瓨鍦ㄧ殑鏉冮檺鏁版嵁
+                List<WorkStep> workStepList = workStepService.getByProcessIds(productInfo.getProductId(),ProcessionIds);
+                if(workStepList != null && !workStepList.isEmpty()) {
+                    Map<String, WorkStepDepartment> workStepDepartmentHashMap = new HashMap<>();
+                    Map<String, WorkStep> workStepHashMap = new HashMap<>();
+                    workStepIds = new ArrayList<>();
+                    WorkStepDepartment ws;
+                    WorkStep workStep;
+                    for(WorkStep w : workStepList){
+                        workStepIds.add(w.getId());
+                        workStepHashMap.put(w.getId(), w);
+                        for(MdcProduction mdcProduction : mdcProductionList){
+                            key = w.getId() + "," + mdcProduction.getId();
+                            ws = new WorkStepDepartment(w.getId(), mdcProduction.getId());
+                            workStepDepartmentHashMap.put(key, ws);
+                        }
+                    }
+
+                    //鏌ヨ宸插瓨鍦ㄧ殑鏉冮檺鏁版嵁
+                    List<WorkStepDepartment> workStepDepartments = workStepDepartmentService.getByPartsIdsAndDepartIds(workStepIds, ids);
+                    if(workStepDepartments != null && !workStepDepartments.isEmpty()){
+                        //韪㈠嚭鏉冮檺鏁版嵁
+                        for(WorkStepDepartment workStepDepartment : workStepDepartments){
+                            key = workStepDepartment.getStepId() + "," + workStepDepartment.getDepartId();
+                            if(workStepDepartmentHashMap.containsKey(key)){
+                                workStepDepartmentHashMap.remove(key);
+                            }
+                        }
+                    }
+
+                    for(Map.Entry<String, WorkStepDepartment> entry : workStepDepartmentHashMap.entrySet()){
+                        ws = entry.getValue();
+                        workStepDepartmentList.add(ws);
+                        workStep = workStepHashMap.get(ws.getStepId());
+                        s = new PermissionStream();
+                        s.setProductId(workStep.getProductId());
+                        s.setComponentId(workStep.getComponentId());
+                        s.setPartsId(workStep.getPartsId());
+                        s.setProcessId(workStep.getProcessId());
+                        s.setStepId(workStep.getId());
+                        s.setDepartId(ws.getDepartId());
+                        permissionStreamList.add(s);
+                    }
+                }
+
                 if(!componentPermissionList.isEmpty()){
                     componentDepartmentService.saveBatch(componentPermissionList);
                 }
                 if(!partsPermissionList.isEmpty()){
                     partsDepartmentService.saveBatch(partsPermissionList);
+                }
+                if(!processionPermissionList.isEmpty()){
+                    processionDepartmentService.saveBatch(processionPermissionList);
+                }
+                if (!workStepDepartmentList.isEmpty()) {
+                    workStepDepartmentService.saveBatch(workStepDepartmentList);
                 }
                 if(!permissionStreamList.isEmpty()){
                     permissionStreamService.saveBatch(permissionStreamList);
@@ -924,7 +1066,7 @@
             boolean b1 = checkProductPerm(2, componentInfo.getComponentId());
             if(!b1)
                 ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
-            b1 = componentInfoService.assignAddDepart(componentInfo, departList);
+            b1 = componentInfoService.assignAddDepart(componentInfo, mdcProductionList);
             if(!b1)
                 ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
             if(relativeFlag == 1) {
@@ -934,10 +1076,15 @@
                 //鏈�缁堜繚瀛樻潈闄愭暟鎹垵濮嬪寲
                 List<ComponentDepartment> componentPermissionList = new ArrayList<>();
                 List<PartsDepartment> partsPermissionList = new ArrayList<>();
+                List<ProcessionDepartment> processionPermissionList = new ArrayList<>();
+                List<WorkStepDepartment> workStepDepartmentList=new ArrayList<>();
                 List<PermissionStream> permissionStreamList = new ArrayList<>();
                 //澶勭悊瀛愰儴浠�
                 PermissionStream s;
-
+                List<String> componentIds = new ArrayList<>();
+                List<String> partsIds= new ArrayList<>();
+                List<String> ProcessionIds= new ArrayList<>();
+                List<String> workStepIds= new ArrayList<>();
                 Map<String, ComponentDepartment> componentPermissionMap = new HashMap<>();
                 Map<String, ComponentInfo> componentInfoMap = new HashMap<>();
 
@@ -948,9 +1095,9 @@
                 for(ComponentInfo c : childrenList){
                     componentIdList.add(c.getComponentId());
                     componentInfoMap.put(c.getComponentId(), c);
-                    for(Department u : departList){
-                        key = c.getComponentId() + "," + u.getDepartId();
-                        cp = new ComponentDepartment(c.getComponentId(), u.getDepartId());
+                    for(MdcProduction mdcProduction : mdcProductionList){
+                        key = c.getComponentId() + "," + mdcProduction.getId();
+                        cp = new ComponentDepartment(c.getComponentId(), mdcProduction.getId());
                         componentPermissionMap.put(key, cp);
                     }
                 }
@@ -982,15 +1129,15 @@
                 if(partsInfoList != null && !partsInfoList.isEmpty()) {
                     Map<String, PartsDepartment> partsPermissionHashMap = new HashMap<>();
                     Map<String, PartsInfo> partsInfoMap = new HashMap<>();
-                    List<String> partsIds = new ArrayList<>();
+                    partsIds = new ArrayList<>();
                     PartsDepartment pp;
                     PartsInfo ptInfo;
                     for(PartsInfo p : partsInfoList){
                         partsIds.add(p.getPartsId());
                         partsInfoMap.put(p.getPartsId(), p);
-                        for(Department u : departList){
-                            key = p.getPartsId() + "," + u.getDepartId();
-                            pp = new PartsDepartment(p.getPartsId(), u.getDepartId());
+                        for(MdcProduction mdcProduction : mdcProductionList){
+                            key = p.getPartsId() + "," + mdcProduction.getId();
+                            pp = new PartsDepartment(p.getPartsId(), mdcProduction.getId());
                             partsPermissionHashMap.put(key, pp);
                         }
                     }
@@ -1020,11 +1167,105 @@
                     }
                 }
 
+                //鏌ヨ宸ュ簭宸插瓨鍦ㄧ殑鏉冮檺鏁版嵁
+                List<ProcessStream> processStreamList = processStreamService.getByComponentIdList(componentInfo.getProductId(),componentIds,partsIds);
+                if(processStreamList != null && !processStreamList.isEmpty()) {
+                    Map<String, ProcessionDepartment> processionDepartmentHashMap = new HashMap<>();
+                    Map<String, ProcessStream> processStreamMap = new HashMap<>();
+                    ProcessionIds = new ArrayList<>();
+                    ProcessionDepartment pp;
+                    ProcessStream processStream;
+                    for(ProcessStream p : processStreamList){
+                        ProcessionIds.add(p.getProcessId());
+                        processStreamMap.put(p.getProcessId(), p);
+                        for(MdcProduction mdcProduction : mdcProductionList){
+                            key = p.getPartsId() + "," + mdcProduction.getId();
+                            pp = new ProcessionDepartment(p.getProcessId(), mdcProduction.getId());
+                            processionDepartmentHashMap.put(key, pp);
+                        }
+                    }
+
+                    //鏌ヨ宸插瓨鍦ㄧ殑鏉冮檺鏁版嵁
+                    List<ProcessionDepartment> processionDepartmentList = processionDepartmentService.getByPartsIdsAndDepartIds(ProcessionIds, ids);
+                    if(processionDepartmentList != null && !processionDepartmentList.isEmpty()){
+                        //韪㈠嚭鏉冮檺鏁版嵁
+                        for(ProcessionDepartment processionDepartment : processionDepartmentList){
+                            key = processionDepartment.getProcessId() + "," + processionDepartment.getDepartId();
+                            if(processionDepartmentHashMap.containsKey(key)){
+                                processionDepartmentHashMap.remove(key);
+                            }
+                        }
+                    }
+
+                    for(Map.Entry<String, ProcessionDepartment> entry : processionDepartmentHashMap.entrySet()){
+                        pp = entry.getValue();
+                        processionPermissionList.add(pp);
+                        processStream = processStreamMap.get(pp.getProcessId());
+                        s = new PermissionStream();
+                        s.setProductId(processStream.getProductId());
+                        s.setComponentId(processStream.getComponentId());
+                        s.setPartsId(processStream.getPartsId());
+                        s.setProcessId(processStream.getProcessId());
+                        s.setDepartId(pp.getDepartId());
+                        permissionStreamList.add(s);
+                    }
+                }
+                //鏌ヨ宸ユ宸插瓨鍦ㄧ殑鏉冮檺鏁版嵁
+                List<WorkStep> workStepList = workStepService.getByProcessIds(componentInfo.getProductId(),ProcessionIds);
+                if(workStepList != null && !workStepList.isEmpty()) {
+                    Map<String, WorkStepDepartment> workStepDepartmentHashMap = new HashMap<>();
+                    Map<String, WorkStep> workStepHashMap = new HashMap<>();
+                    workStepIds = new ArrayList<>();
+                    WorkStepDepartment ws;
+                    WorkStep workStep;
+                    for(WorkStep w : workStepList){
+                        workStepIds.add(w.getId());
+                        workStepHashMap.put(w.getId(), w);
+                        for(MdcProduction mdcProduction : mdcProductionList){
+                            key = w.getId() + "," + mdcProduction.getId();
+                            ws = new WorkStepDepartment(w.getId(), mdcProduction.getId());
+                            workStepDepartmentHashMap.put(key, ws);
+                        }
+                    }
+
+                    //鏌ヨ宸插瓨鍦ㄧ殑鏉冮檺鏁版嵁
+                    List<WorkStepDepartment> workStepDepartments = workStepDepartmentService.getByPartsIdsAndDepartIds(workStepIds, ids);
+                    if(workStepDepartments != null && !workStepDepartments.isEmpty()){
+                        //韪㈠嚭鏉冮檺鏁版嵁
+                        for(WorkStepDepartment workStepDepartment : workStepDepartments){
+                            key = workStepDepartment.getStepId() + "," + workStepDepartment.getDepartId();
+                            if(workStepDepartmentHashMap.containsKey(key)){
+                                workStepDepartmentHashMap.remove(key);
+                            }
+                        }
+                    }
+
+                    for(Map.Entry<String, WorkStepDepartment> entry : workStepDepartmentHashMap.entrySet()){
+                        ws = entry.getValue();
+                        workStepDepartmentList.add(ws);
+                        workStep = workStepHashMap.get(ws.getStepId());
+                        s = new PermissionStream();
+                        s.setProductId(workStep.getProductId());
+                        s.setComponentId(workStep.getComponentId());
+                        s.setPartsId(workStep.getPartsId());
+                        s.setProcessId(workStep.getProcessId());
+                        s.setStepId(workStep.getId());
+                        s.setDepartId(ws.getDepartId());
+                        permissionStreamList.add(s);
+                    }
+                }
+
                 if(!componentPermissionList.isEmpty()){
                     componentDepartmentService.saveBatch(componentPermissionList);
                 }
                 if(!partsPermissionList.isEmpty()){
                     partsDepartmentService.saveBatch(partsPermissionList);
+                }
+                if(!processionPermissionList.isEmpty()){
+                    processionDepartmentService.saveBatch(processionPermissionList);
+                }
+                if (!workStepDepartmentList.isEmpty()) {
+                    workStepDepartmentService.saveBatch(workStepDepartmentList);
                 }
                 if(!permissionStreamList.isEmpty()){
                     permissionStreamService.saveBatch(permissionStreamList);
@@ -1037,7 +1278,7 @@
 
     /**
      * 寰呬紭鍖� TODO
-     * @param nodeType 1 浜у搧 2 閮ㄤ欢 3 闆朵欢
+     * @param nodeType 1 浜у搧 2 閮ㄤ欢 3 闆朵欢 5 宸ュ簭 6 宸ユ
      * @param paramId 浜у搧鏍戣妭鐐筰d
      * @param relativeFlag 1 鏄� 2 鍚�
      * @param departmentIds 绉婚櫎閮ㄩ棬ids
@@ -1053,10 +1294,30 @@
             ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_NONE);
         List<String> ids = new ArrayList<>(departmentIds.length);
         Collections.addAll(ids, departmentIds);
-        Collection<Department> departList = departmentService.listByIds(ids);
-        if(departList == null || departList.isEmpty() || departList.size() != departmentIds.length)
+        Collection<MdcProduction> mdcProductionList=mdcProductionService.listByIds(ids);
+        if(mdcProductionList == null || mdcProductionList.isEmpty() || mdcProductionList.size() != departmentIds.length)
             ExceptionCast.cast(CommonCode.INVALID_PARAM);
-        if(nodeType == 3) {
+        if(nodeType == 6) {
+            //澶勭悊宸ユ
+            WorkStep workStep=workStepService.getById(paramId);
+            if (workStep == null)
+                ExceptionCast.cast(PartsInfoCode.PARTS_NOT_EXIST);
+            boolean b = checkProductPerm(6, workStep.getId());
+            if (!b) {
+                ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
+            }
+            return workStepService.assignRemoveDepart(workStep, mdcProductionList);
+        }else if(nodeType == 5) {
+            //澶勭悊宸ュ簭
+            ProcessStream processStream = processStreamService.getById(paramId);
+            if (processStream == null)
+                ExceptionCast.cast(PartsInfoCode.PARTS_NOT_EXIST);
+            boolean b = checkProductPerm(5, processStream.getProcessId());
+            if (!b) {
+                ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
+            }
+            return processStreamService.assignRemoveDepart(processStream, mdcProductionList);
+        }else if(nodeType == 3) {
             //澶勭悊闆朵欢
             PartsInfo partsInfo = partsInfoService.getById(paramId);
             if(partsInfo == null)
@@ -1065,7 +1326,7 @@
             if(!b) {
                 ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
             }
-            return partsInfoService.assignRemoveDepart(partsInfo, departList);
+            return partsInfoService.assignRemoveDepart(partsInfo, mdcProductionList);
         }else if(nodeType == 1) {
             //澶勭悊浜у搧
             ProductInfo productInfo = super.getById(paramId);
@@ -1074,7 +1335,7 @@
             boolean b1 = checkProductPerm(1, productInfo.getProductId());
             if(!b1)
                 ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
-            b1 = this.assignRemoveDepartment(productInfo, departList);
+            b1 = this.assignRemoveDepartment(productInfo, mdcProductionList);
             if(!b1)
                 ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
             if(relativeFlag == 1) {
@@ -1083,8 +1344,13 @@
                 //鎬昏闇�瑕佸垹闄ょ殑鏁版嵁淇℃伅
                 List<ComponentDepartment> componentPermissionList = new ArrayList<>();
                 List<PartsDepartment> partsPermissionList = new ArrayList<>();
+                List<ProcessionDepartment> processionPermissionList = new ArrayList<>();
+                List<WorkStepDepartment> workStepDepartmentList=new ArrayList<>();
                 List<PermissionStream> permissionStreamList = new ArrayList<>();
                 List<ComponentInfo> componentInfoList = componentInfoService.getByProductId(productInfo.getProductId());
+                List<String> partsIds= new ArrayList<>();
+                List<String> ProcessionIds= new ArrayList<>();
+                List<String> workStepIds= new ArrayList<>();
                 if(componentInfoList != null && !componentInfoList.isEmpty()) {
                     for(ComponentInfo componentInfo : componentInfoList){
                         componentIds.add(componentInfo.getComponentId());
@@ -1098,7 +1364,7 @@
 
                 //澶勭悊浜у搧 涓嬬殑闆朵欢
                 List<PartsInfo> partsInfoList = partsInfoService.getByComponentIdList(productInfo.getProductId(), componentIds);
-                List<String> partsIds = new ArrayList<>();
+                partsIds = new ArrayList<>();
                 if(partsInfoList != null && !partsInfoList.isEmpty()) {
                     for(PartsInfo partsInfo : partsInfoList){
                         partsIds.add(partsInfo.getPartsId());
@@ -1110,11 +1376,45 @@
                     }
                 }
 
+                //澶勭悊宸ュ簭
+                List<ProcessStream> processStreamList=processStreamService.getByComponentIdList(productInfo.getProductId(), componentIds,partsIds);
+                ProcessionIds = new ArrayList<>();
+                if(processStreamList != null && !processStreamList.isEmpty()) {
+                    for(ProcessStream processStream : processStreamList){
+                        ProcessionIds.add(processStream.getProcessId());
+                    }
+                    processionPermissionList = processionDepartmentService.getByPartsIdsAndDepartIds(ProcessionIds, ids);
+                    List<PermissionStream> existPermissionList = permissionStreamService.getByPartsIdsAndDepartIds(ProcessionIds, ids);
+                    if(existPermissionList != null && !existPermissionList.isEmpty()){
+                        permissionStreamList.addAll(existPermissionList);
+                    }
+                }
+
+                //澶勭悊宸ユ
+                List<WorkStep> workStepList=workStepService.getByProcessIds(productInfo.getProductId(), ProcessionIds);
+                workStepIds = new ArrayList<>();
+                if(workStepList != null && !workStepList.isEmpty()) {
+                    for(WorkStep workStep : workStepList){
+                        workStepIds.add(workStep.getId());
+                    }
+                    workStepDepartmentList = workStepDepartmentService.getByPartsIdsAndDepartIds(workStepIds, ids);
+                    List<PermissionStream> existPermissionList = permissionStreamService.getByPartsIdsAndDepartIds(workStepIds, ids);
+                    if(existPermissionList != null && !existPermissionList.isEmpty()){
+                        permissionStreamList.addAll(existPermissionList);
+                    }
+                }
+
                 if(componentPermissionList != null && !componentPermissionList.isEmpty()){
                     componentDepartmentService.removeByCollection(componentPermissionList);
                 }
                 if(partsPermissionList != null && !partsPermissionList.isEmpty()){
                     partsDepartmentService.removeByCollection(partsPermissionList);
+                }
+                if(processionPermissionList != null && !processionPermissionList.isEmpty()){
+                    processionDepartmentService.removeByCollection(processionPermissionList);
+                }
+                if(workStepDepartmentList != null && !workStepDepartmentList.isEmpty()){
+                    workStepDepartmentService.removeByCollection(workStepDepartmentList);
                 }
                 if(permissionStreamList != null && !permissionStreamList.isEmpty()){
                     permissionStreamService.removeByCollection(permissionStreamList);
@@ -1128,7 +1428,7 @@
             boolean b1 = checkProductPerm(2, componentInfo.getComponentId());
             if(!b1)
                 ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
-            b1 = componentInfoService.assignRemoveDepart(componentInfo, departList);
+            b1 = componentInfoService.assignRemoveDepart(componentInfo, mdcProductionList);
             if(!b1)
                 ExceptionCast.cast(ProductInfoCode.PRODUCT_USER_PERM_ERROR);
             if(relativeFlag == 1) {
@@ -1136,8 +1436,12 @@
                 //鎬昏闇�瑕佸垹闄ょ殑鏁版嵁淇℃伅
                 List<ComponentDepartment> componentPermissionList = new ArrayList<>();
                 List<PartsDepartment> partsPermissionList = new ArrayList<>();
+                List<ProcessionDepartment> processionPermissionList = new ArrayList<>();
+                List<WorkStepDepartment> workStepDepartmentList=new ArrayList<>();
                 List<PermissionStream> permissionStreamList = new ArrayList<>();
-
+                List<String> partsIds= new ArrayList<>();
+                List<String> ProcessionIds= new ArrayList<>();
+                List<String> workStepIds= new ArrayList<>();
                 List<ComponentInfo> childrenList = componentInfoService.getByParentId(componentInfo.getComponentId());
                 if(childrenList != null && !childrenList.isEmpty()) {
                     for(ComponentInfo cpn : childrenList){
@@ -1153,7 +1457,7 @@
                 //澶勭悊浜у搧 涓嬬殑闆朵欢
                 componentIdList.add(componentInfo.getComponentId());
                 List<PartsInfo> partsInfoList = partsInfoService.getByComponentIdList(componentInfo.getProductId(), componentIdList);
-                List<String> partsIds = new ArrayList<>();
+                partsIds = new ArrayList<>();
                 if(partsInfoList != null && !partsInfoList.isEmpty()) {
                     for(PartsInfo partsInfo : partsInfoList){
                         partsIds.add(partsInfo.getPartsId());
@@ -1165,11 +1469,45 @@
                     }
                 }
 
+                //澶勭悊宸ュ簭
+                List<ProcessStream> processStreamList=processStreamService.getByComponentIdList(componentInfo.getProductId(), componentIdList,partsIds);
+                ProcessionIds = new ArrayList<>();
+                if(processStreamList != null && !processStreamList.isEmpty()) {
+                    for(ProcessStream processStream : processStreamList){
+                        ProcessionIds.add(processStream.getProcessId());
+                    }
+                    processionPermissionList = processionDepartmentService.getByPartsIdsAndDepartIds(ProcessionIds, ids);
+                    List<PermissionStream> existPermissionList = permissionStreamService.getByPartsIdsAndDepartIds(ProcessionIds, ids);
+                    if(existPermissionList != null && !existPermissionList.isEmpty()){
+                        permissionStreamList.addAll(existPermissionList);
+                    }
+                }
+
+                //澶勭悊宸ユ
+                List<WorkStep> workStepList=workStepService.getByProcessIds(componentInfo.getProductId(), ProcessionIds);
+                workStepIds = new ArrayList<>();
+                if(workStepList != null && !workStepList.isEmpty()) {
+                    for(WorkStep workStep : workStepList){
+                        workStepIds.add(workStep.getId());
+                    }
+                    workStepDepartmentList = workStepDepartmentService.getByPartsIdsAndDepartIds(workStepIds, ids);
+                    List<PermissionStream> existPermissionList = permissionStreamService.getByPartsIdsAndDepartIds(workStepIds, ids);
+                    if(existPermissionList != null && !existPermissionList.isEmpty()){
+                        permissionStreamList.addAll(existPermissionList);
+                    }
+                }
+
                 if(componentPermissionList != null && !componentPermissionList.isEmpty()){
                     componentDepartmentService.removeByCollection(componentPermissionList);
                 }
                 if(partsPermissionList != null && !partsPermissionList.isEmpty()){
                     partsDepartmentService.removeByCollection(partsPermissionList);
+                }
+                if(processionPermissionList != null && !processionPermissionList.isEmpty()){
+                    processionDepartmentService.removeByCollection(processionPermissionList);
+                }
+                if(workStepDepartmentList != null && !workStepDepartmentList.isEmpty()){
+                    workStepDepartmentService.removeByCollection(workStepDepartmentList);
                 }
                 if(permissionStreamList != null && !permissionStreamList.isEmpty()){
                     permissionStreamService.removeByCollection(permissionStreamList);
@@ -1256,23 +1594,23 @@
 
     @Override
     @Transactional(rollbackFor = {Exception.class})
-    public boolean assignAddDepartment(ProductInfo productInfo, Collection<Department> departmentList) {
+    public boolean assignAddDepartment(ProductInfo productInfo, Collection<MdcProduction> departmentList) {
         if(productInfo == null || departmentList == null || departmentList.isEmpty())
             ExceptionCast.cast(CommonCode.INVALID_PARAM);
         List<ProductDepartment> productDepartmentList = new ArrayList<>();
         List<PermissionStream> permissionStreamList = new ArrayList<>();
         departmentList.forEach(item -> {
-            ProductDepartment en = productDepartmentService.getByProductIdAndDepartId(productInfo.getProductId(), item.getDepartId());
+            ProductDepartment en = productDepartmentService.getByProductIdAndDepartId(productInfo.getProductId(), item.getId());
             if(en == null) {
                 en = new ProductDepartment();
-                en.setDepartId(item.getDepartId());
+                en.setDepartId(item.getId());
                 en.setProductId(productInfo.getProductId());
                 productDepartmentList.add(en);
             }
-            PermissionStream stream = permissionStreamService.getByProductIdAndDepartId(productInfo.getProductId(), item.getDepartId());
+            PermissionStream stream = permissionStreamService.getByProductIdAndDepartId(productInfo.getProductId(), item.getId());
             if(stream == null) {
                 stream = new PermissionStream();
-                stream.setDepartId(item.getDepartId());
+                stream.setDepartId(item.getId());
                 stream.setProductId(productInfo.getProductId());
                 permissionStreamList.add(stream);
             }
@@ -1294,17 +1632,17 @@
 
     @Override
     @Transactional(rollbackFor = {Exception.class})
-    public boolean assignRemoveDepartment(ProductInfo productInfo, Collection<Department> departmentList) {
+    public boolean assignRemoveDepartment(ProductInfo productInfo, Collection<MdcProduction> departmentList) {
         if(productInfo == null || departmentList == null || departmentList.isEmpty())
             ExceptionCast.cast(CommonCode.INVALID_PARAM);
         List<ProductDepartment> productDepartmentList = new ArrayList<>();
         List<PermissionStream> permissionStreamList = new ArrayList<>();
         departmentList.forEach(item -> {
-            ProductDepartment en = productDepartmentService.getByProductIdAndDepartId(productInfo.getProductId(), item.getDepartId());
+            ProductDepartment en = productDepartmentService.getByProductIdAndDepartId(productInfo.getProductId(), item.getId());
             if(en != null) {
                 productDepartmentList.add(en);
             }
-            PermissionStream stream = permissionStreamService.getByProductIdAndDepartId(productInfo.getProductId(), item.getDepartId());
+            PermissionStream stream = permissionStreamService.getByProductIdAndDepartId(productInfo.getProductId(), item.getId());
             if(stream != null) {
                 permissionStreamList.add(stream);
             }

--
Gitblit v1.9.3