| | |
| | | VciQueryWrapperForDO queryWrapperForDO = new VciQueryWrapperForDO(conditionMap,OrgDeptForPlatform1.class); |
| | | orgDepartmentVOList = deptDO2VOs(boService.selectByQueryWrapper(queryWrapperForDO,OrgDeptForPlatform1.class)); |
| | | } |
| | | TreeWrapperOptions treeWrapperOptions = new TreeWrapperOptions("pkFatherDepartment"); |
| | | TreeWrapperOptions treeWrapperOptions = new TreeWrapperOptions(); |
| | | BeanUtil.convert(treeQueryObject,treeWrapperOptions); |
| | | treeWrapperOptions.setParentFieldName("pkFatherDepartment"); |
| | | return revisionModelUtil.doList2Trees(orgDepartmentVOList,treeWrapperOptions,dept->{ |
| | | return dept.getId() + " " + dept.getName() + (FrameworkDataLCStatus.DISABLED.getValue().equals(dept.getLcStatus())?"【停用】":""); |
| | | }); |
| | |
| | | |
| | | /** |
| | | * 保存部门角色关联信息,带查重功能 |
| | | * @param userId 用户id |
| | | * @param deptIds 部门id |
| | | * @param userOIds 用户id |
| | | * @param deptId 部门id |
| | | * @return |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean saveUserDepts(String userId, List<String> deptIds) throws PLException { |
| | | if(Func.isBlank(userId) || Func.isEmpty(deptIds)){ |
| | | public boolean saveUsersDept(String[] userOIds, String deptId) throws PLException { |
| | | if(Func.isEmpty(userOIds) || Func.isBlank(deptId)){ |
| | | return false; |
| | | } |
| | | List<String> repeatDeptOidList = new ArrayList<>(); |
| | | //先进性查重处理 |
| | | List<String> repeatUserOidList = new ArrayList<>(); |
| | | //循环进行查重,避免in大于1000 |
| | | WebUtil.switchCollectionForOracleIn(deptIds).stream().forEach(deptoids->{ |
| | | String sql = "select pluseruid,pldeptuid from pluserdept where pluseruid = " + userId |
| | | + " and " + "pldeptuid in ("+WebUtil.toInSql(deptoids.toArray(new String[0]))+")"; |
| | | WebUtil.switchCollectionForOracleIn(Arrays.asList(userOIds)).stream().forEach(userOId->{ |
| | | String sql = "select pluseruid,pldeptuid from pluserdept where pldeptuid = '" + deptId |
| | | + "' and " + "pluseruid in ("+WebUtil.toInSql(userOId.toArray(new String[0]))+")"; |
| | | List<BusinessObject> cbos = boService.queryBySql(sql, null); |
| | | if(!CollectionUtils.isEmpty(cbos)){ |
| | | cbos.stream().forEach(cbo->{ |
| | | repeatDeptOidList.add(ObjectTool.getNewBOAttributeValue(cbo,"pldeptuid")); |
| | | repeatUserOidList.add(ObjectTool.getNewBOAttributeValue(cbo,"pluseruid")); |
| | | }); |
| | | } |
| | | |
| | | }); |
| | | //从即将要执行保存的部门oid中移除当前用户已经存在关联关系的的部门oid |
| | | deptIds.removeAll(repeatDeptOidList); |
| | | if(Func.isNotEmpty(deptIds)){ |
| | | for (String deptId : deptIds){ |
| | | platformClientUtil.getFrameworkService().saveUserDept(new String[]{userId}, deptId,null); |
| | | } |
| | | |
| | | //从即将要执行保存的用户oid中移除当前用户已经存在关联关系的oid |
| | | //移除重复的 |
| | | List<String> tempList = new ArrayList<>(Arrays.asList(userOIds)); |
| | | tempList.removeAll(repeatUserOidList); |
| | | userOIds = tempList.toArray(new String[tempList.size()]); |
| | | if(Func.isNotEmpty(userOIds)){ |
| | | platformClientUtil.getFrameworkService().saveUserDept(userOIds, deptId,null); |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * 获取所有部门的信息 |
| | | * @return key:部门由名称组成的路径(/间隔),value对应最小层级的部门信息 |
| | | */ |
| | | @Override |
| | | public Map<String, OrgDepartmentVO> getDeptAllTreeMap() { |
| | | List<OrgDepartmentVO> orgDepartmentVOList = listAllLevelChildrenDeptByParentOid(null, null); |
| | | Map<String, OrgDepartmentVO> stringOrgDepartmentVOMap = convertToMap(orgDepartmentVOList); |
| | | return stringOrgDepartmentVOMap; |
| | | } |
| | | |
| | | public Map<String, OrgDepartmentVO> convertToMap(List<OrgDepartmentVO> orgDepartmentVOList) { |
| | | Map<String, OrgDepartmentVO> map = new HashMap<>(); |
| | | for (OrgDepartmentVO orgDepartmentVO : orgDepartmentVOList) { |
| | | String key = buildKey(orgDepartmentVO, orgDepartmentVOList); |
| | | map.put(key, orgDepartmentVO); |
| | | } |
| | | return map; |
| | | } |
| | | |
| | | private String buildKey(OrgDepartmentVO orgDepartmentVO, List<OrgDepartmentVO> orgDepartmentVOList) { |
| | | StringBuilder keyBuilder = new StringBuilder(); |
| | | OrgDepartmentVO current = orgDepartmentVO; |
| | | while (current != null) { |
| | | keyBuilder.insert(0, current.getName()); |
| | | keyBuilder.insert(0, "/"); |
| | | current = getParentDepartment(current.getPkFatherDepartment(), orgDepartmentVOList); |
| | | } |
| | | keyBuilder.deleteCharAt(0); |
| | | return keyBuilder.toString(); |
| | | } |
| | | |
| | | private OrgDepartmentVO getParentDepartment(String pkFatherDepartment, List<OrgDepartmentVO> orgDepartmentVOList) { |
| | | for (OrgDepartmentVO orgDepartmentVO : orgDepartmentVOList) { |
| | | if (pkFatherDepartment != null && pkFatherDepartment.equals(orgDepartmentVO.getOid())) { |
| | | return orgDepartmentVO; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | } |