| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | private IDocInfoService docInfoService; |
| | | @Autowired |
| | | private INcLogInfoService iNcLogInfoService; |
| | | @Autowired |
| | | private IWorkStepDepartmentService workStepDepartmentService; |
| | | @Autowired |
| | | private IProcessionDepartmentService processionDepartmentService; |
| | | @Autowired |
| | | private IMdcProductionService mdcProductionService; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = {Exception.class}) |
| | |
| | | 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; |
| | | } |
| | |
| | | } |
| | | |
| | | @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) { |
| | |
| | | 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) { |
| | |
| | | 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; |
| | | } |
| | | } |
| | |
| | | |
| | | /** |
| | | * 待优化 TODO |
| | | * @param nodeType 1 产品 2 部件 3 零件 |
| | | * @param nodeType 1 产品 2 部件 3 零件 5 工序 6 工步 |
| | | * @param paramId 产品树节点id |
| | | * @param relativeFlag 1 是 2 否 |
| | | * @param departmentIds 添加部门ids |
| | |
| | | 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) |
| | |
| | | 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); |
| | |
| | | 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) { |
| | |
| | | //最终保存权限数据初始化 |
| | | 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<>(); |
| | |
| | | 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); |
| | | } |
| | | } |
| | |
| | | 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); |
| | | } |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | //查询工序已存在的权限数据 |
| | | 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); |
| | |
| | | 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) { |
| | |
| | | //最终保存权限数据初始化 |
| | | 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<>(); |
| | | |
| | |
| | | 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); |
| | | } |
| | | } |
| | |
| | | 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); |
| | | } |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | //查询工序已存在的权限数据 |
| | | 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); |
| | |
| | | |
| | | /** |
| | | * 待优化 TODO |
| | | * @param nodeType 1 产品 2 部件 3 零件 |
| | | * @param nodeType 1 产品 2 部件 3 零件 5 工序 6 工步 |
| | | * @param paramId 产品树节点id |
| | | * @param relativeFlag 1 是 2 否 |
| | | * @param departmentIds 移除部门ids |
| | |
| | | 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) |
| | |
| | | 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); |
| | |
| | | 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) { |
| | |
| | | //总计需要删除的数据信息 |
| | | 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()); |
| | |
| | | |
| | | //处理产品 下的零件 |
| | | 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()); |
| | |
| | | } |
| | | } |
| | | |
| | | //处理工序 |
| | | 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); |
| | |
| | | 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) { |
| | |
| | | //总计需要删除的数据信息 |
| | | 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){ |
| | |
| | | //处理产品 下的零件 |
| | | 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()); |
| | |
| | | } |
| | | } |
| | | |
| | | //处理工序 |
| | | 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); |
| | |
| | | |
| | | @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); |
| | | } |
| | |
| | | |
| | | @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); |
| | | } |
| | |
| | | @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 -> { |
| | |
| | | }else { |
| | | return null; |
| | | } |
| | | //去重 |
| | | Set<String> set = new HashSet<>(departIds); |
| | | departIds.clear(); |
| | | departIds.addAll(set); |
| | | return departIds; |
| | | } |
| | | |