lyh
2025-02-14 f2f8241dd52ef12ec109f6f4f0f13042055338ac
lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/ProductInfoServiceImpl.java
@@ -1,7 +1,9 @@
package org.jeecg.modules.dnc.service.impl;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.shiro.SecurityUtils;
@@ -11,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;
@@ -18,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;
@@ -66,9 +65,19 @@
    @Lazy
    private IProcessStreamService processStreamService;
    @Autowired
    private IWorkStepService workStepService;
    @Autowired
    private IDocInfoService docInfoService;
    @Autowired
    private INcLogInfoService iNcLogInfoService;
    @Autowired
    private IWorkStepDepartmentService workStepDepartmentService;
    @Autowired
    private IProcessionDepartmentService processionDepartmentService;
    @Autowired
    private IMdcProductionService mdcProductionService;
    @Autowired
    private IDocRelativeService iDocRelativeService;
    @Override
    @Transactional(rollbackFor = {Exception.class})
@@ -163,16 +172,27 @@
    @Override
    public List<CommonGenericTree> loadProductTree(String userId) {
        //产品
        List<ProductInfo> productInfoList = getByUserPerms(userId);
        if(productInfoList == null || productInfoList.isEmpty())
            return Collections.emptyList();
        //部件
        List<ComponentExt> componentInfoList = componentInfoService.getByUserPermsAs(userId);
        if(componentInfoList == null)
            componentInfoList = Collections.emptyList();
        //零件
        List<PartsInfo> partsInfos = partsInfoService.getByUserPerms(userId);
        if(partsInfos == null)
            partsInfos = Collections.emptyList();
        return ProductTreeWrapper.loadTree(productInfoList, componentInfoList, partsInfos);
        //工序
        List<ProcessStream> processStreams=processStreamService.getByuserPerms(userId);
        if(processStreams==null)
            processStreams = Collections.emptyList();
        //工步
        List<WorkStep> workStepList=workStepService.getByUserPerms(userId);
        if(workStepList==null)
            workStepList = Collections.emptyList();
        return ProductTreeWrapper.loadTree(productInfoList, componentInfoList, partsInfos,processStreams,workStepList);
    }
    @Override
@@ -218,6 +238,11 @@
        if(processStreams != null && !processStreams.isEmpty())
            ExceptionCast.cast(ProductInfoCode.PRODUCT_PROCESS_EXIST);
        boolean b = productPermissionService.deleteByProductId(id);
        //验证是否存在文档
        List<DocRelative> docRelativeList=iDocRelativeService.list(new QueryWrapper<DocRelative>().eq("attribution_type","1").eq("attribution_id",id));
        if (!docRelativeList.isEmpty()){
            ExceptionCast.cast(ProductInfoCode.PRODUCT_DOC_EXIST);
        }
        if(!b)
            ExceptionCast.cast(CommonCode.FAIL);
        b = productDepartmentService.deleteByProductId(id);
@@ -229,18 +254,6 @@
        b = permissionStreamService.deleteDepartPermsByProductId(id);
        if(!b)
            ExceptionCast.cast(CommonCode.FAIL);
        b = docInfoService.deleteByProductId(id);
        if(!b)
            ExceptionCast.cast(CommonCode.FAIL);
        //添加日志
        NcLogInfo ncLogInfo = new NcLogInfo();
        //模块
        ncLogInfo.setModuleInfo("产品结构树");
        //类型
        ncLogInfo.setOperateType(4);
        //日志内容
        ncLogInfo.setLogContent("产品名称:"+productInfo.getProductName());
        iNcLogInfoService.saveLogNcInfos(ncLogInfo);
        return super.removeById(id);
    }
@@ -257,25 +270,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.getProductId(),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.getProductId(),workStep.getComponentId()
                    ,workStep.getPartsId(),workStep.getProcessId(),workStep.getId(),userId);
            return permission != null;
        }
        return false;
    }
@@ -311,7 +332,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) {
@@ -320,13 +341,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) {
@@ -335,7 +362,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;
        }
    }
@@ -759,7 +792,7 @@
    /**
     * 待优化 TODO
     * @param nodeType 1 产品 2 部件 3 零件
     * @param nodeType 1 产品 2 部件 3 零件 5 工序 6 工步
     * @param paramId 产品树节点id
     * @param relativeFlag 1 是 2 否
     * @param departmentIds 添加部门ids
@@ -775,10 +808,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)
@@ -787,7 +840,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);
@@ -796,7 +849,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) {
@@ -805,9 +858,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<>();
@@ -820,9 +878,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);
                    }
                }
@@ -853,15 +911,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);
                        }
                    }
@@ -891,11 +949,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);
@@ -909,7 +1061,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) {
@@ -919,10 +1071,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<>();
@@ -930,35 +1087,37 @@
                String key;
                ComponentDepartment cp;
                ComponentInfo cpInfo;
                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());
                        componentPermissionMap.put(key, cp);
                    }
                }
                //查询已存在的权限数据
                List<ComponentDepartment> existList = componentDepartmentService.getByComponentIdsAndDepartIds(componentIdList, ids);
                if(existList != null && !existList.isEmpty()){
                    //踢出权限数据
                    for(ComponentDepartment permission : existList){
                        key = permission.getComponentId() + "," + permission.getDepartId();
                        if(componentPermissionMap.containsKey(key)){
                            componentPermissionMap.remove(key);
                if(childrenList != null && !childrenList.isEmpty()) {
                    for (ComponentInfo c : childrenList) {
                        componentIdList.add(c.getComponentId());
                        componentInfoMap.put(c.getComponentId(), c);
                        for (MdcProduction mdcProduction : mdcProductionList) {
                            key = c.getComponentId() + "," + mdcProduction.getId();
                            cp = new ComponentDepartment(c.getComponentId(), mdcProduction.getId());
                            componentPermissionMap.put(key, cp);
                        }
                    }
                }
                for(Map.Entry<String, ComponentDepartment> entry : componentPermissionMap.entrySet()){
                    cp = entry.getValue();
                    componentPermissionList.add(cp);
                    cpInfo = componentInfoMap.get(cp.getComponentId());
                    s = new PermissionStream();
                    s.setProductId(cpInfo.getProductId());
                    s.setComponentId(cpInfo.getComponentId());
                    s.setDepartId(cp.getDepartId());
                    permissionStreamList.add(s);
                    //查询已存在的权限数据
                    List<ComponentDepartment> existList = componentDepartmentService.getByComponentIdsAndDepartIds(componentIdList, ids);
                    if (existList != null && !existList.isEmpty()) {
                        //踢出权限数据
                        for (ComponentDepartment permission : existList) {
                            key = permission.getComponentId() + "," + permission.getDepartId();
                            if (componentPermissionMap.containsKey(key)) {
                                componentPermissionMap.remove(key);
                            }
                        }
                    }
                    for (Map.Entry<String, ComponentDepartment> entry : componentPermissionMap.entrySet()) {
                        cp = entry.getValue();
                        componentPermissionList.add(cp);
                        cpInfo = componentInfoMap.get(cp.getComponentId());
                        s = new PermissionStream();
                        s.setProductId(cpInfo.getProductId());
                        s.setComponentId(cpInfo.getComponentId());
                        s.setDepartId(cp.getDepartId());
                        permissionStreamList.add(s);
                    }
                }
                //处理子零件
@@ -967,15 +1126,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);
                        }
                    }
@@ -1005,11 +1164,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);
@@ -1022,7 +1275,7 @@
    /**
     * 待优化 TODO
     * @param nodeType 1 产品 2 部件 3 零件
     * @param nodeType 1 产品 2 部件 3 零件 5 工序 6 工步
     * @param paramId 产品树节点id
     * @param relativeFlag 1 是 2 否
     * @param departmentIds 移除部门ids
@@ -1038,10 +1291,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)
@@ -1050,7 +1323,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);
@@ -1059,7 +1332,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) {
@@ -1068,8 +1341,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());
@@ -1083,7 +1361,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());
@@ -1095,11 +1373,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);
@@ -1113,7 +1425,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) {
@@ -1121,8 +1433,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){
@@ -1138,7 +1454,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());
@@ -1150,11 +1466,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);
@@ -1241,23 +1591,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);
            }
@@ -1279,17 +1629,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);
            }
@@ -1312,21 +1662,32 @@
    @Override
    public List<String> getDepartIdsByParams(Integer nodeType, String paramId) {
        List<String> departIds = new ArrayList<>();
        if(nodeType == 2) {
            ComponentInfo en = componentInfoService.getById(paramId);
            if(en == null)
        //5-工序
        if(nodeType == 5) {
            ProcessStream processStream= processStreamService.getById(paramId);
            if(processStream == null)
                return null;
            List<PermissionStream> permissionStreamList = permissionStreamService.getByComponentId(en.getProductId(), en.getComponentId());
            List<PermissionStream> permissionStreamList = permissionStreamService.list(new QueryWrapper<PermissionStream>()
                    .eq(StrUtil.isNotEmpty(processStream.getProductId()),"product_id", processStream.getProductId())
                    .eq(StrUtil.isNotEmpty(processStream.getComponentId()),"component_id",processStream.getComponentId())
                    .eq(StrUtil.isNotEmpty(processStream.getPartsId()),"parts_id", processStream.getPartsId())
                    .eq(StrUtil.isNotEmpty(processStream.getProcessId()),"process_id",processStream.getProcessId()));
            if(permissionStreamList == null || permissionStreamList.isEmpty())
                return null;
            permissionStreamList.forEach(item -> {
                departIds.add(item.getDepartId());
            });
        }else if(nodeType == 3) {
            PartsInfo en = partsInfoService.getById(paramId);
            if(en == null)
            //6-工步
        }else if(nodeType == 6) {
            WorkStep workStep = workStepService.getById(paramId);
            if(workStep == null)
                return null;
            List<PermissionStream> permissionStreamList = permissionStreamService.getByPartsId(en.getProductId(), en.getComponentId(), en.getPartsId());
            List<PermissionStream> permissionStreamList = permissionStreamService.list(new QueryWrapper<PermissionStream>()
                    .eq(StrUtil.isNotEmpty(workStep.getProductId()),"product_id", workStep.getProductId())
                    .eq(StrUtil.isNotEmpty(workStep.getComponentId()),"component_id",workStep.getComponentId())
                    .eq(StrUtil.isNotEmpty(workStep.getPartsId()),"parts_id", workStep.getPartsId())
                    .eq(StrUtil.isNotEmpty(workStep.getProcessId()),"process_id",workStep.getProcessId())
                    .eq(StrUtil.isNotEmpty(workStep.getId()),"step_id", workStep.getId()));
            if(permissionStreamList == null || permissionStreamList.isEmpty())
                return null;
            permissionStreamList.forEach(item -> {
@@ -1335,6 +1696,10 @@
        }else {
            return null;
        }
        //去重
        Set<String> set = new HashSet<>(departIds);
        departIds.clear();
        departIds.addAll(set);
        return departIds;
    }
@@ -1427,7 +1792,8 @@
        List<ProductInfo> productInfos = this.getByUserPerms(userId, queryParam);
        List<ComponentInfo> componentInfos = componentInfoService.getByUserPerms(userId, queryParam);
        List<PartsInfo> partsInfos = partsInfoService.getByUserPerms(userId, null, queryParam);
        List<ProcessStream> processStreams=processStreamService.getByuserPerms(userId, queryParam);
        List<WorkStep> workSteps=workStepService.getByUserPerms(userId, queryParam);
        List<ComponentInfo> componentInfoList = new ArrayList<>();
        List<ProductInfo> productInfoList = new ArrayList<>();
@@ -1462,6 +1828,44 @@
            if(!componentInfoMap.containsKey(p.getComponentId())) {
                component = componentInfoService.getById(p.getComponentId());
                if(component != null) {
                    componentInfoMap.put(component.getComponentId(), component);
                    componentInfoList.add(component);
                }
            }
        }
        for (ProcessStream processStream : processStreams) {
            if (!productInfoMap.containsKey(processStream.getProductId())) {
                product  = super.getById(processStream.getProductId());
                if(product != null) {
                    productInfoMap.put(product.getProductId(), product);
                    productInfoList.add(product);
                }
            }
            if(!componentInfoMap.containsKey(processStream.getComponentId())) {
                component = componentInfoService.getById(processStream.getComponentId());
                if(component != null) {
                    componentInfoMap.put(component.getComponentId(), component);
                    componentInfoList.add(component);
                }
            }
        }
        for (WorkStep workStep :workSteps){
            if (!productInfoMap.containsKey(workStep.getProductId())) {
                product  = super.getById(workStep.getProductId());
                if(product != null) {
                    productInfoMap.put(product.getProductId(), product);
                    productInfoList.add(product);
                }
            }
            if(!componentInfoMap.containsKey(workStep.getComponentId())) {
                component = componentInfoService.getById(workStep.getComponentId());
                if(component != null) {
                    componentInfoMap.put(component.getComponentId(), component);
                    componentInfoList.add(component);
@@ -1515,6 +1919,29 @@
        //转换数据
        List<ComponentExt> componentExtList = ComponentExt.convertToExtList(componentInfoList);
        return ProductTreeWrapper.loadTree(productInfoList, componentExtList, partsInfos);
        return ProductTreeWrapper.loadTree(productInfoList, componentExtList, partsInfos,processStreams,workSteps);
    }
    @Override
    public boolean deleteProductTree(String id, Integer type){
        switch (type) {
            //产品
            case 1:
                return deleteProductInfo(id);
            //部门
            case 2:
                return componentInfoService.deleteComponentInfo(id);
            //零件
            case 3:
                return partsInfoService.deletePartsInfo(id);
            //工序
            case 5:
                return processStreamService.deleteProcessStream(id);
            //工步
            case 6:
                return workStepService.deleteWorkStep(id);
            default:
        }
        return false;
    }
}