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 |  248 ++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 231 insertions(+), 17 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 f2a737f..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,29 +1,31 @@
 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.*;
@@ -45,6 +47,12 @@
 	private WebBoServiceI boService;
 
 	/**
+	 * 骞冲彴璋冪敤瀹㈡埛绔�
+	 */
+	@Autowired
+	private PlatformClientUtil platformClientUtil;
+
+	/**
 	 * 瀵硅薄鎿嶄綔宸ュ叿绫�
 	 */
 	@Autowired
@@ -57,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));
 	}
 
 	/**
@@ -127,7 +160,7 @@
 				depts.addAll(roleForPlatform1s);
 			}
 		});
-		return 	deptDO2VOs(depts);
+		return deptDO2VOs(depts);
 	}
 
 	/**
@@ -143,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);
@@ -179,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->{
@@ -191,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 {
@@ -200,9 +234,9 @@
 		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);
 	}
 
 	/**
@@ -212,13 +246,13 @@
      * @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;
 	}
 
 	/**
@@ -377,8 +411,9 @@
 			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())?"銆愬仠鐢ㄣ��":"");
 		});
@@ -412,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