| | |
| | | package com.vci.frameworkcore.compatibility.impl; |
| | | |
| | | import com.vci.corba.common.PLException; |
| | | import com.vci.corba.omd.data.BusinessObject; |
| | | import com.vci.frameworkcore.compatibility.OrgDeptQueryServiceI; |
| | | import com.vci.frameworkcore.lcstatuspck.FrameworkDataLCStatus; |
| | |
| | | import com.vci.starter.web.util.VciBaseUtil; |
| | | import com.vci.starter.web.wrapper.VciQueryWrapperForDO; |
| | | import com.vci.web.service.WebBoServiceI; |
| | | import com.vci.web.util.Func; |
| | | import com.vci.web.util.PlatformClientUtil; |
| | | import com.vci.web.util.WebUtil; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.util.*; |
| | |
| | | */ |
| | | @Autowired |
| | | private WebBoServiceI boService; |
| | | |
| | | /** |
| | | * 平台调用客户端 |
| | | */ |
| | | @Autowired |
| | | private PlatformClientUtil platformClientUtil; |
| | | |
| | | /** |
| | | * 对象操作工具类 |
| | |
| | | if(queryMap == null){ |
| | | queryMap = new HashMap<>(); |
| | | } |
| | | List<OrgDeptForPlatform1> roles = new ArrayList<>(); |
| | | List<OrgDeptForPlatform1> deptForPlatform1s = new ArrayList<>(); |
| | | if(userOid.contains(",")){ |
| | | Map<String, String> finalQueryMap = queryMap; |
| | | WebUtil.switchCollectionForOracleIn(WebUtil.str2List(userOid)).stream().forEach(userOids->{ |
| | |
| | | VciQueryWrapperForDO queryWrapper = new VciQueryWrapperForDO(conditionMap,OrgDeptForPlatform1.class); |
| | | List<OrgDeptForPlatform1> roleForPlatform1s = boService.selectByQueryWrapper(queryWrapper, OrgDeptForPlatform1.class); |
| | | if(!CollectionUtils.isEmpty(roleForPlatform1s)){ |
| | | roles.addAll(roleForPlatform1s); |
| | | deptForPlatform1s.addAll(roleForPlatform1s); |
| | | } |
| | | }); |
| | | }else { |
| | |
| | | VciQueryWrapperForDO queryWrapper = new VciQueryWrapperForDO(queryMap,OrgDeptForPlatform1.class); |
| | | List<OrgDeptForPlatform1> roleForPlatform1s = boService.selectByQueryWrapper(queryWrapper, OrgDeptForPlatform1.class); |
| | | if(!CollectionUtils.isEmpty(roleForPlatform1s)){ |
| | | roles.addAll(roleForPlatform1s); |
| | | deptForPlatform1s.addAll(roleForPlatform1s); |
| | | } |
| | | return deptDO2VOs(roles); |
| | | return deptDO2VOs(deptForPlatform1s); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return 部门的显示对象 |
| | | */ |
| | | @Override |
| | | public OrgDepartmentVO listDeptByUserOid(String userOid, |
| | | public List<OrgDepartmentVO> listDeptByUserOid(String userOid, |
| | | Map<String, String> queryMap) { |
| | | List<OrgDepartmentVO> departmentVOS = listDeptByUserOid(userOid, queryMap, false); |
| | | if(CollectionUtils.isEmpty(departmentVOS)){ |
| | | return null; |
| | | return new ArrayList<>(); |
| | | } |
| | | return departmentVOS.get(0); |
| | | return departmentVOS; |
| | | } |
| | | |
| | | /** |
| | |
| | | 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())?"【停用】":""); |
| | | }); |
| | |
| | | return dataGrid; |
| | | } |
| | | |
| | | /** |
| | | * 保存部门角色关联信息,带查重功能 |
| | | * @param userOIds 用户id |
| | | * @param deptId 部门id |
| | | * @return |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean saveUsersDept(String[] userOIds, String deptId) throws PLException { |
| | | if(Func.isEmpty(userOIds) || Func.isBlank(deptId)){ |
| | | return false; |
| | | } |
| | | //先进性查重处理 |
| | | List<String> repeatUserOidList = new ArrayList<>(); |
| | | //循环进行查重,避免in大于1000 |
| | | 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->{ |
| | | repeatUserOidList.add(ObjectTool.getNewBOAttributeValue(cbo,"pluseruid")); |
| | | }); |
| | | } |
| | | }); |
| | | |
| | | //从即将要执行保存的用户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; |
| | | } |
| | | |
| | | } |