From 8c4b79d994c5a95dd33d4b0313e2f2d63985e074 Mon Sep 17 00:00:00 2001 From: ludc Date: 星期四, 04 七月 2024 19:16:18 +0800 Subject: [PATCH] 角色管理、部门管理相关接口上传。 --- Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/frameworkcore/compatibility/impl/OrgDeptQueryServiceImpl.java | 269 +++++++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 248 insertions(+), 21 deletions(-) diff --git a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/frameworkcore/compatibility/impl/OrgDeptQueryServiceImpl.java b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/frameworkcore/compatibility/impl/OrgDeptQueryServiceImpl.java index d652b0e..22618bc 100644 --- a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/frameworkcore/compatibility/impl/OrgDeptQueryServiceImpl.java +++ b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/frameworkcore/compatibility/impl/OrgDeptQueryServiceImpl.java @@ -1,32 +1,35 @@ package com.vci.frameworkcore.compatibility.impl; +import com.vci.corba.common.PLException; +import com.vci.corba.common.data.UserEntityInfo; +import com.vci.corba.framework.data.DeptInfo; import com.vci.corba.omd.data.BusinessObject; import com.vci.frameworkcore.compatibility.OrgDeptQueryServiceI; +import com.vci.frameworkcore.model.dto.OrgDepartmentDTO; import com.vci.frameworkcore.lcstatuspck.FrameworkDataLCStatus; import com.vci.frameworkcore.model.OrgDeptForPlatform1; -import com.vci.frameworkcore.model.SmRoleForPlatform1; import com.vci.frameworkcore.pagemodel.OrgDepartmentVO; -import com.vci.frameworkcore.pagemodel.SmRoleVO; import com.vci.omd.utils.ObjectTool; import com.vci.starter.revision.bo.TreeWrapperOptions; import com.vci.starter.revision.service.RevisionModelUtil; import com.vci.starter.web.constant.QueryOptionConstant; import com.vci.starter.web.exception.VciBaseException; -import com.vci.starter.web.pagemodel.DataGrid; -import com.vci.starter.web.pagemodel.PageHelper; -import com.vci.starter.web.pagemodel.Tree; -import com.vci.starter.web.pagemodel.TreeQueryObject; +import com.vci.starter.web.pagemodel.*; import com.vci.starter.web.util.BeanUtil; 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.*; +import java.util.function.Function; import java.util.stream.Collectors; /** @@ -44,6 +47,12 @@ private WebBoServiceI boService; /** + * 骞冲彴璋冪敤瀹㈡埛绔� + */ + @Autowired + private PlatformClientUtil platformClientUtil; + + /** * 瀵硅薄鎿嶄綔宸ュ叿绫� */ @Autowired @@ -56,13 +65,38 @@ * @throws VciBaseException 鍙傛暟涓虹┖鎴栬�呮暟鎹簱瀛樺湪闂鐨勬椂鍊欎細鎶涘嚭寮傚父 */ @Override - public OrgDepartmentVO getDeptByDeptOid(String deptOid) - throws VciBaseException { + public OrgDepartmentVO getDeptByDeptOid(String deptOid) throws VciBaseException { if(StringUtils.isBlank(deptOid)){ return null; } OrgDeptForPlatform1 deptForPlatform1 = boService.selectByOid(deptOid, OrgDeptForPlatform1.class); return deptDO2VO(deptForPlatform1); + } + + /** + * 鏍规嵁鐖堕儴闂ㄤ富閿幏鍙栧拰閮ㄩ棬鍚嶇О閮ㄩ棬鐨勪俊鎭� + * @param parentDeptOid 鐖堕儴闂ㄤ富閿� + * @param conditionMap 閮ㄩ棬鍚嶇О + * @return 閮ㄩ棬鐨勬樉绀哄璞★紝濡傛灉閮ㄩ棬涓嶅瓨鍦ㄥ垯杩斿洖null锛屼笉浼氭姏鍑哄紓甯� + * @throws VciBaseException 鍙傛暟涓虹┖鎴栬�呮暟鎹簱瀛樺湪闂鐨勬椂鍊欎細鎶涘嚭寮傚父 + */ + @Override + public OrgDepartmentVO getDeptByDeptPOidAndCondition(String parentDeptOid,Map<String,String> conditionMap) throws VciBaseException { + if(Func.isEmpty(conditionMap)){ + conditionMap = new HashMap(); + } + VciQueryWrapperForDO queryWrapper = new VciQueryWrapperForDO(new HashMap<>(),OrgDeptForPlatform1.class); + //鐖朵富閿负绌烘煡椤跺眰 + if(Func.isBlank(parentDeptOid)){ + queryWrapper.isNull("plparentuid"); + }else{ + queryWrapper.eq("plparentuid",parentDeptOid); + } + List<OrgDeptForPlatform1> roleForPlatform1s = boService.selectByQueryWrapper(queryWrapper, OrgDeptForPlatform1.class); + if(Func.isEmpty(roleForPlatform1s)){ + return null; + } + return deptDO2VO(roleForPlatform1s.get(0)); } /** @@ -103,6 +137,7 @@ } return departmentVO; } + /** * 鎵归噺鑾峰彇閮ㄩ棬鐨勪俊鎭� 锛堟牴鎹儴闂ㄤ富閿級 * @param deptOidCollections 閮ㄩ棬涓婚敭鐨勯泦鍚堬紝鍙互瓒呰繃1000涓� @@ -125,8 +160,9 @@ depts.addAll(roleForPlatform1s); } }); - return deptDO2VOs(depts); + return deptDO2VOs(depts); } + /** * 鑾峰彇閮ㄩ棬鐨勫垪琛紝榛樿浼氫互閮ㄩ棬鍚嶇О鍗囧簭鎺掑垪锛岄儴闂ㄧ殑缂栬緫椤甸潰鍒楄〃涓嶈浣跨敤杩欎釜鎺ュ彛 * @param queryMap 鏌ヨ鏉′欢 @@ -140,6 +176,7 @@ if(pageHelper == null){ pageHelper = new PageHelper(-1); } + //鏍规嵁閮ㄩ棬缂栧彿鎺掑簭 pageHelper.addDefaultAsc("plnum"); VciQueryWrapperForDO queryWrapper = new VciQueryWrapperForDO(queryMap,OrgDeptForPlatform1.class,pageHelper); List<OrgDeptForPlatform1> deptForPlatform1s = boService.selectByQueryWrapper(queryWrapper, OrgDeptForPlatform1.class); @@ -150,6 +187,7 @@ } return dataGrid; } + /** * 鏍规嵁閮ㄩ棬涓婚敭鑾峰彇閮ㄩ棬鐨勫鍚� * @param deptOid 閮ㄩ棬涓婚敭 @@ -175,7 +213,7 @@ 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->{ @@ -187,7 +225,7 @@ 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 { @@ -196,25 +234,27 @@ 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); } - /** + + /** * 鏍规嵁鐢ㄦ埛涓婚敭鑾峰彇鍏宠仈鐨勯儴闂� * @param userOid 鐢ㄦ埛涓婚敭 * @param queryMap 鏌ヨ鏉′欢锛屽鏋滈渶瑕佷娇鐢ㄧ敤鎴风殑灞炴�ф潵鏌ヨ鍙互浣跨敤pkUser.xxxx * @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; } + /** * 鑾峰彇鏈叧鑱旀煇涓敤鎴风殑閮ㄩ棬 * @param userOid 鐢ㄦ埛涓婚敭 @@ -290,16 +330,19 @@ List<BusinessObject> cbos = boService.queryBySql(sql, null); if(!CollectionUtils.isEmpty(cbos)){ cbos.stream().forEach(cbo->{ - String userOid = ObjectTool.getBOAttributeValue(cbo,"pluseruid"); + String userOid = ObjectTool.getNewBOAttributeValue(cbo,"pluseruid"); List<String> deptOids = userDeptOidMap.getOrDefault(userOid,new ArrayList<>()); - deptOids.add(ObjectTool.getBOAttributeValue(cbo,"pldeptuid")); + deptOids.add(ObjectTool.getNewBOAttributeValue(cbo,"pldeptuid")); userDeptOidMap.put(userOid,deptOids); }); } } }); if(!CollectionUtils.isEmpty(deptVOList)){ - Map<String, OrgDepartmentVO> deptVOMap = deptVOList.stream().collect(Collectors.toMap(s -> s.getOid(), t -> t)); + //杩欏効搴旇瀵筪eptVOList鍋氫竴娆″幓閲嶅鐞嗭紝鍥犱负鑲畾浼氭湁閲嶅鐨勯儴闂ㄨ鏌ュ嚭鏉� + Map<String, OrgDepartmentVO> deptVOMap = deptVOList.stream() + .collect(Collectors.toMap(OrgDepartmentVO::getOid, Function.identity(), (existing, replacement) -> existing)); + //Map<String, OrgDepartmentVO> deptVOMap = deptVOList.stream().distinct().collect(Collectors.toMap(s -> s.getOid(), t -> t)); Map<String, List<OrgDepartmentVO>> userDeptVOMap = new HashMap<>(); userDeptOidMap.forEach((userOid,deptOids)->{ List<OrgDepartmentVO> deptVOS = new ArrayList<>(); @@ -314,6 +357,7 @@ } return new HashMap<>(); } + /** * 鑾峰彇鏌愪釜閮ㄩ棬鐨勭洿灞炰笅绾ч儴闂� * @param pkFatherDepartmment 閮ㄩ棬鐨勪富閿� @@ -332,6 +376,7 @@ List<OrgDeptForPlatform1> depts = boService.selectByQueryWrapper(queryWrapperForDO, OrgDeptForPlatform1.class); return deptDO2VOs(depts); } + /** * 鑾峰彇鏌愪釜閮ㄩ棬鐨勬墍鏈夊眰绾х殑涓嬬骇閮ㄩ棬 * @param pkFatherDepartmment 閮ㄩ棬鐨勪富閿� @@ -345,6 +390,7 @@ queryWrapperForDO.in("pluid","select pluid from pldept start with " + (StringUtils.isBlank(pkFatherDepartmment)?" (plparentuid is null or plparentuid = '') ":"plparentuid = '" + pkFatherDepartmment.trim() + "'") + "connect by PRIOR pluid=plparentuid"); return deptDO2VOs(boService.selectByQueryWrapper(queryWrapperForDO, OrgDeptForPlatform1.class)); } + /** * 鍙傜収鏍戝舰鏁版嵁鐨勯儴闂ㄤ俊鎭� * @param treeQueryObject 鏍戝舰鏌ヨ鐨勬潯浠� @@ -365,12 +411,14 @@ 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 treeQueryObject 鏍戝舰鏌ヨ鐨勬潯浠� @@ -399,4 +447,183 @@ return dataGrid; } + /** + * 淇濆瓨閮ㄩ棬瑙掕壊鍏宠仈淇℃伅锛屽甫鏌ラ噸鍔熻兘 + * @param userOIds 鐢ㄦ埛id + * @param deptId 閮ㄩ棬id + * @return + */ + @Override + @Transactional(rollbackFor = Exception.class) + public boolean saveUsersDept(String[] userOIds, String deptId) throws PLException { + //鍏堣繘鎬ф煡閲嶅鐞� + List<String> repeatUserOidList = new ArrayList<>(); + //寰幆杩涜鏌ラ噸锛岄伩鍏峣n澶т簬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")); + }); + } + }); + + //浠庡嵆灏嗚鎵ц淇濆瓨鐨勭敤鎴穙id涓Щ闄ゅ綋鍓嶇敤鎴峰凡缁忓瓨鍦ㄥ叧鑱斿叧绯荤殑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; + } + + /** + * 澧炲姞閮ㄩ棬淇℃伅 + * @param orgDepartmentDTO + * @return + */ + @Override + public boolean addDept(OrgDepartmentDTO orgDepartmentDTO) throws PLException { + //鍒ょ┖ + VciBaseUtil.alertNotNull( + orgDepartmentDTO,"娣诲姞鐨勯儴闂ㄥ璞�", + orgDepartmentDTO.getName(),"閮ㄩ棬鍚�"); + //閮ㄩ棬鍚嶅垽閲� + Map<String, String> conditionMap = new HashMap<>(); + conditionMap.put("plname",orgDepartmentDTO.getName()); + conditionMap.put("plnum",QueryOptionConstant.OR + orgDepartmentDTO.getId()); + OrgDepartmentVO departmentVO = getDeptByDeptPOidAndCondition(orgDepartmentDTO.getPkFatherDepartment(), conditionMap); + if(Func.isNotEmpty(departmentVO)){ + throw new VciBaseException("鍚屼竴鐖惰妭鐐逛笅璇ラ儴闂ㄥ悕绉版垨缂栧彿宸茬粡瀛樺湪,璇蜂慨鏀�!"); + } + //SessionInfo loginUser = WebThreadLocalUtil.getCurrentUserSessionInfoInThread(); + String userId = "developer";//loginUser.getUserId(); + + //鐢熸垚瀛樺偍鐨刢orba瀵硅薄 + orgDepartmentDTO.setCreateTime(new Date()); + orgDepartmentDTO.setCreator(userId); + orgDepartmentDTO.setLastModifier(userId); + orgDepartmentDTO.setStatus((short) 0); + DeptInfo deptInfo = changeOrgDeptDTOToDeptInfo(orgDepartmentDTO); + UserEntityInfo userEntityInfo = new UserEntityInfo(userId, ""); + String oid = platformClientUtil.getFrameworkService().saveDepartment(deptInfo, userEntityInfo); + if (Func.isEmpty(oid)) { + return false; + } + return true; + } + + /** + * 淇敼閮ㄩ棬淇℃伅 + * @param orgDepartmentDTO + * @return + */ + @Override + public boolean updateDept(OrgDepartmentDTO orgDepartmentDTO) throws PLException { + //鍒ょ┖ + VciBaseUtil.alertNotNull( + orgDepartmentDTO,"淇敼鐨勯儴闂ㄥ璞�", + orgDepartmentDTO.getOid(),"鐢ㄦ埛涓婚敭", + orgDepartmentDTO.getId(),"鐢ㄦ埛鍚�" + ); + //鎸塷id鏌ヨ鏁版嵁搴撲腑宸插瓨鍦ㄧ殑 + OrgDepartmentVO departmentVO = getDeptByDeptOid(orgDepartmentDTO.getOid()); + //鏍规嵁涓婚敭娌℃煡璇㈠埌 + OrgDepartmentDTO orgDepartmentDTO1 = new OrgDepartmentDTO(); + //榛樿灞炴�х粰璧嬪�间笂 + //BeanUtil.convert(departmentVO,orgDepartmentDTO1); + Func.copy(departmentVO,orgDepartmentDTO); + //orgDepartmentDTO1.setName(orgDepartmentDTO.getName()); + //orgDepartmentDTO1.setCode(orgDepartmentDTO.getCode()); + //orgDepartmentDTO1.setDescription(orgDepartmentDTO.getDescription()); + String loginUserId = "developer";//WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserId(); + orgDepartmentDTO1.setLastModifier(loginUserId); + DeptInfo deptInfo = changeOrgDeptDTOToDeptInfo(orgDepartmentDTO1); + boolean updateBoolean = platformClientUtil.getFrameworkService().updateDepartment(deptInfo, new UserEntityInfo(loginUserId, null)); + return updateBoolean; + } + + /** + * Dto瀵硅薄杞琧orb瀵硅薄 + * @param orgDepartmentDTO + * @return + */ + public DeptInfo changeOrgDeptDTOToDeptInfo(OrgDepartmentDTO orgDepartmentDTO) { + DeptInfo departmentInfo = new DeptInfo(); + departmentInfo.id = orgDepartmentDTO.getOid() == null ? "" : orgDepartmentDTO.getOid(); + departmentInfo.name = orgDepartmentDTO.getName() == null ? "" : orgDepartmentDTO.getName(); + departmentInfo.num = orgDepartmentDTO.getId() == null ? "" : orgDepartmentDTO.getId(); + departmentInfo.code = orgDepartmentDTO.getCode() == null ? "" : orgDepartmentDTO.getCode(); + departmentInfo.specialties = orgDepartmentDTO.getSpecialties() == null ? "" : orgDepartmentDTO.getSpecialties(); + departmentInfo.status = orgDepartmentDTO.getStatus() == 0 ? 0 : orgDepartmentDTO.getStatus(); + departmentInfo.description = orgDepartmentDTO.getDescription() == null ? "" : orgDepartmentDTO.getDescription(); + departmentInfo.parentId = orgDepartmentDTO.getPkFatherDepartment() == null ? "" : orgDepartmentDTO.getPkFatherDepartment(); + departmentInfo.createUser = orgDepartmentDTO.getCreator() == null ? "" : orgDepartmentDTO.getCreator(); + departmentInfo.createTime = orgDepartmentDTO.getCreateTime().getTime(); + departmentInfo.updateTime = System.currentTimeMillis(); + departmentInfo.updateUser = orgDepartmentDTO.getLastModifier() == null ? "" : orgDepartmentDTO.getLastModifier(); + //departmentInfo.grantor = orgDepartmentDTO.getGrantor() == null ? "" : orgDepartmentDTO.getGrantor(); + return departmentInfo; + } + + /** + * 鍒犻櫎閮ㄩ棬 + * @param ids + * @return + */ + @Override + public boolean deleteDept(String[] ids) throws PLException { + VciBaseUtil.alertNotNull(ids,"瑕佸垹闄ょ殑閮ㄩ棬涓婚敭"); + //鍏峰杩炲甫鍒犻櫎鐨勫姛鑳斤紝濡傝鑹茶彍鍗曟巿鏉冭〃閲岄潰鐨勬巿鏉冧俊鎭� + return platformClientUtil.getFrameworkService().deleteDepartment( + ids, + new UserEntityInfo("developer"/*WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserId()*/, null) + ); + } + + /** + * 鑾峰彇鎵�鏈夐儴闂ㄧ殑淇℃伅 + * @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; + } + } -- Gitblit v1.9.3