From 5acc490fa6f77a9ed7b5976ee6a2e22b070df5bf Mon Sep 17 00:00:00 2001
From: ludc
Date: 星期二, 09 七月 2024 09:49:36 +0800
Subject: [PATCH] 角色管理联调修改、部门管理接口等代码上传

---
 Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/frameworkcore/compatibility/impl/OrgDeptQueryServiceImpl.java |  376 ++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 340 insertions(+), 36 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 22618bc..35748de 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
@@ -8,26 +8,44 @@
 import com.vci.frameworkcore.model.dto.OrgDepartmentDTO;
 import com.vci.frameworkcore.lcstatuspck.FrameworkDataLCStatus;
 import com.vci.frameworkcore.model.OrgDeptForPlatform1;
+import com.vci.frameworkcore.model.dto.SmUserDTO;
+import com.vci.frameworkcore.model.po.OrgDeptPO;
+import com.vci.frameworkcore.model.po.SmUserPO;
 import com.vci.frameworkcore.pagemodel.OrgDepartmentVO;
+import com.vci.frameworkcore.pagemodel.SmUserVO;
+import com.vci.frameworkcore.properties.ConfigReader;
 import com.vci.omd.utils.ObjectTool;
+import com.vci.starter.poi.bo.ReadExcelOption;
+import com.vci.starter.poi.bo.WriteExcelData;
+import com.vci.starter.poi.bo.WriteExcelOption;
+import com.vci.starter.poi.constant.ExcelLangCodeConstant;
+import com.vci.starter.poi.util.ExcelUtil;
 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.enumpck.UserSecretEnum;
 import com.vci.starter.web.exception.VciBaseException;
 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.util.*;
 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.apache.poi.hssf.util.HSSFColor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
+import org.springframework.web.util.WebUtils;
 
+import java.io.File;
+import java.nio.charset.StandardCharsets;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
 import java.util.*;
 import java.util.function.Function;
 import java.util.stream.Collectors;
@@ -59,6 +77,16 @@
 	private RevisionModelUtil revisionModelUtil;
 
 	/**
+	 * 蹇呭~鍒�
+	 */
+	private ArrayList<Integer> ColumnNameisRed = new ArrayList<Integer>();
+
+	/**
+	 * 鏃ュ織
+	 */
+	private Logger logger = LoggerFactory.getLogger(getClass());
+
+	/**
      * 鏍规嵁閮ㄩ棬涓婚敭鑾峰彇閮ㄩ棬鐨勪俊鎭�
      * @param deptOid 閮ㄩ棬涓婚敭
      * @return 閮ㄩ棬鐨勬樉绀哄璞★紝濡傛灉閮ㄩ棬涓嶅瓨鍦ㄥ垯杩斿洖null锛屼笉浼氭姏鍑哄紓甯�
@@ -69,8 +97,14 @@
 		if(StringUtils.isBlank(deptOid)){
 			return null;
 		}
-		OrgDeptForPlatform1 deptForPlatform1 = boService.selectByOid(deptOid, OrgDeptForPlatform1.class);
-		return deptDO2VO(deptForPlatform1);
+		Map<String, String> conditionMap = new HashMap<>();
+		conditionMap.put("pluid",deptOid);
+		VciQueryWrapperForDO queryWrapper = new VciQueryWrapperForDO(conditionMap,OrgDeptForPlatform1.class);
+		List<OrgDeptForPlatform1> deptForPlatform1s = boService.selectByQueryWrapper(queryWrapper, OrgDeptForPlatform1.class);
+		if(Func.isEmpty(deptForPlatform1s)){
+			return null;
+		}
+		return deptDO2VO(deptForPlatform1s.get(0));
 	}
 
 	/**
@@ -81,11 +115,11 @@
 	 * @throws VciBaseException 鍙傛暟涓虹┖鎴栬�呮暟鎹簱瀛樺湪闂鐨勬椂鍊欎細鎶涘嚭寮傚父
 	 */
 	@Override
-	public OrgDepartmentVO getDeptByDeptPOidAndCondition(String parentDeptOid,Map<String,String> conditionMap) throws VciBaseException {
+	public List<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);
+		VciQueryWrapperForDO queryWrapper = new VciQueryWrapperForDO(conditionMap,OrgDeptForPlatform1.class);
 		//鐖朵富閿负绌烘煡椤跺眰
 		if(Func.isBlank(parentDeptOid)){
 			queryWrapper.isNull("plparentuid");
@@ -96,7 +130,7 @@
 		if(Func.isEmpty(roleForPlatform1s)){
 			return null;
 		}
-		return deptDO2VO(roleForPlatform1s.get(0));
+		return deptDO2VOs(roleForPlatform1s);
 	}
 
 	/**
@@ -121,18 +155,23 @@
 		OrgDepartmentVO departmentVO = new OrgDepartmentVO();
 		if(deptForPlatform1!=null){
 			departmentVO.setOid(deptForPlatform1.getPluid());
+			// 闄ら儴闂ㄤ富閿鐨勫敮涓�鏍囪瘑锛岄暱搴︿负Dept:+8浣嶅彲閫氳繃璇ュ弬鏁板弽鎺ㄥ洖閮ㄩ棬涓婚敭鐨刪ash缂栫爜
+			departmentVO.setUniqueId("Dept:"+Func.oidEnHash(deptForPlatform1.getPluid()));
 			departmentVO.setId(deptForPlatform1.getPlnum());
 			departmentVO.setName(deptForPlatform1.getPlname());
+			departmentVO.setStatus(deptForPlatform1.getPlstatus());
 			if(0 == deptForPlatform1.getPlstatus()){
-				departmentVO.setLcStatus(FrameworkDataLCStatus.ENABLED.getValue());
+				departmentVO.setStatusText(FrameworkDataLCStatus.ENABLED.getValue());
 			}else{
-				departmentVO.setLcStatus(FrameworkDataLCStatus.DISABLED.getValue());
+				departmentVO.setStatusText(FrameworkDataLCStatus.DISABLED.getValue());
 			}
+			departmentVO.setSpecialties(deptForPlatform1.getPlspecialties());
+			departmentVO.setCode(deptForPlatform1.getPlcode());
 			departmentVO.setPkFatherDepartment(deptForPlatform1.getPlparentuid());
 			departmentVO.setDescription(deptForPlatform1.getPldesc());
-			departmentVO.setCheckInTime(deptForPlatform1.getPlcreatetime());
+			departmentVO.setCreateTime(new Date(deptForPlatform1.getPlcreatetime()));
 			departmentVO.setCreator(deptForPlatform1.getPlcreateuser());
-			departmentVO.setLastModifyTime(deptForPlatform1.getPlupdatetime());
+			departmentVO.setLastModifyTime(new Date(deptForPlatform1.getPlupdatetime()));
 			departmentVO.setLastModifier(deptForPlatform1.getPlupdateuser());
 		}
 		return departmentVO;
@@ -312,7 +351,7 @@
      * 鎵归噺鏍规嵁鐢ㄦ埛鐨勪富閿潵鑾峰彇閮ㄩ棬
      * @param userOidCollection 鐢ㄦ埛涓婚敭闆嗗悎
      * @param queryMap 鏌ヨ鏉′欢锛屽鏋滈渶瑕佷娇鐢ㄧ敤鎴风殑灞炴�ф潵鏌ヨ鍙互浣跨敤pkUser.xxxx
-     * @return 閮ㄩ棬鐨勬樉绀哄璞★紝key鏄敤鎴蜂富閿�,value鏄繖涓敤鎴峰叧鑱旂殑閮ㄩ棬
+     * @return 閮ㄩ棬鐨勬樉绀哄璞★紝key鏄敤鎴蜂富閿�,value鏄叧鑱旂殑閮ㄩ棬
      */
 	@Override
 	public Map<String, List<OrgDepartmentVO>> batchListDeptByUserOids(
@@ -342,7 +381,6 @@
 			//杩欏効搴旇瀵筪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<>();
@@ -358,7 +396,63 @@
 		return new HashMap<>();
 	}
 
-	 /**
+	/**
+	 * 鎵归噺鏍规嵁鐢ㄦ埛鐨勪富閿潵鑾峰彇閮ㄩ棬鍚嶇О锛�/闂撮殧鏂瑰紡锛�
+	 * @param userOidCollection 鐢ㄦ埛涓婚敭闆嗗悎
+	 * @param queryMap 鏌ヨ鏉′欢锛屽鏋滈渶瑕佷娇鐢ㄧ敤鎴风殑灞炴�ф潵鏌ヨ鍙互浣跨敤pkUser.xxxx
+	 * @return 閮ㄩ棬鐨勬樉绀哄璞★紝key鏄敤鎴蜂富閿�,value鏄叧鑱旂殑閮ㄩ棬锛堝寘鍚埗鑺傜偣濡傚綋鍓嶉儴闂ㄤ负浜哄姏璧勬簮閮ㄥ垯鍊间负锛�550/浜哄姏璧勬簮閮級
+	 */
+	@Override
+	public Map<String,Map<String,String>> batchMapDeptNameByUserOids(Collection<String> userOidCollection, Map<String, String> queryMap) {
+		if(CollectionUtils.isEmpty(userOidCollection)){
+			return new HashMap<>();
+		}
+		Map<String,Map<String,String>> deptOidNameMap = new HashMap<>();
+		Map<String,Map<String,String>> userDeptOidMap = new HashMap<>();
+		WebUtil.switchCollectionForOracleIn(userOidCollection).stream().forEach(userOids->{
+			//1銆佽鍏堟牴鎹敤鎴蜂富閿幏鍙栧埌鍏宠仈鐨勯儴闂ㄤ富閿�
+			String sql = "select pluseruid,pldeptuid from pluserdept where pluseruid in (" + WebUtil.toInSql(userOids.toArray(new String[0])) + ")";
+			List<BusinessObject> cbos = boService.queryBySql(sql, null);
+			if(!CollectionUtils.isEmpty(cbos)){
+				cbos.stream().forEach(cbo->{
+					//瑙掕壊涓婚敭
+					String userOid = ObjectTool.getNewBOAttributeValue(cbo,"pluseruid");
+					//閮ㄩ棬涓婚敭
+					String deptUid = ObjectTool.getNewBOAttributeValue(cbo, "pldeptuid");
+					//2銆佺劧鍚庢牴鎹儴闂ㄤ富閿幏鍙栧埌鐢遍儴闂ㄥ悕绉�/缁勬垚鐨勫��
+					//閬垮厤澶氭鏌ヨ锛屾垨鑰呭惊鐜煡璇�
+					if(deptOidNameMap.containsKey(deptUid)){
+						userDeptOidMap.put(userOid,deptOidNameMap.get(deptUid));
+					}else {
+						if(Func.isNotEmpty(deptUid)){
+							//2.1銆佹煡璇㈤儴闂╫id锛屽綋鍓嶉儴闂ㄥ寘鍚埗閮ㄩ棬
+							String queryDeptSql = "select pluid,plname from pldept START with pluid = '" +
+									deptUid + "' connect by prior plparentuid = pluid";
+							List<BusinessObject> cboDepts = boService.queryBySql(queryDeptSql, null);
+							if(!CollectionUtils.isEmpty(cboDepts)){
+								StringBuilder sb = new StringBuilder();
+								for (int i = cboDepts.size()-1; i >=0; i--) {
+									String deptName = ObjectTool.getNewBOAttributeValue(cboDepts.get(i),"plname");
+									sb.append(deptName);
+									sb.append("/");
+								}
+								//2.2銆侀伩鍏嶅悓涓�閮ㄩ棬澶氭鏌ヨ锛岃繖閲屽瓨鍌ㄥ湪涓�涓叕鍏遍泦鍚堜腑锛屼究浜庨噸澶嶄娇鐢�
+								//鍒犻櫎鏈�鍚庝竴涓枩鏉�
+								sb.deleteCharAt(sb.length() - 1);
+								Map<String,String> tempMap = new HashMap<>();
+								tempMap.put(deptUid,sb.toString());
+								deptOidNameMap.put(deptUid,tempMap);
+								userDeptOidMap.put(userOid,tempMap);
+							}
+						}
+					}
+				});
+			}
+		});
+		return userDeptOidMap;
+	}
+
+	/**
      * 鑾峰彇鏌愪釜閮ㄩ棬鐨勭洿灞炰笅绾ч儴闂�
      * @param pkFatherDepartmment 閮ㄩ棬鐨勪富閿�
      * @param queryMap 鏌ヨ鏉′欢
@@ -400,6 +494,7 @@
 	public List<Tree> refTreeDept(TreeQueryObject treeQueryObject) {
 		String pkFatherDepartmment=treeQueryObject.getParentOid();
 		Map<String, String> conditionMap = treeQueryObject.getConditionMap();
+		Map<String, String> extandParamsMap = treeQueryObject.getExtandParamsMap();
 		if(conditionMap==null){
 			conditionMap=new HashMap<String, String>();
 		}
@@ -414,9 +509,27 @@
 		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())?"銆愬仠鐢ㄣ��":"");
+		List<Tree> trees = revisionModelUtil.doList2Trees(orgDepartmentVOList, treeWrapperOptions, dept -> {
+			return dept.getId() + " " + dept.getName() + (FrameworkDataLCStatus.DISABLED.getValue().equals(dept.getLcStatus()) ? "銆愬仠鐢ㄣ��" : "");
 		});
+		//extandParamsMap涓坊鍔�"showAllDepartmentNode"涓�"true"鏃�,骞朵笖parentOid涓虹┖锛岃繑鍥炵粨鏋滀腑浼氬寘鍚�滄墍鏈夐儴闂ㄢ�濊繖涓妭鐐�
+		if(Func.isBlank(pkFatherDepartmment) && (Func.isNotEmpty(extandParamsMap) && Boolean.parseBoolean(extandParamsMap.getOrDefault("showAllDepartmentNode","false")))){
+			List<Tree> treeList = new ArrayList<>();
+			Tree tree = new Tree();
+			tree.setLeaf(false);
+			tree.setParentId(null);
+			//娌℃湁瀹為檯浣滅敤鍙槸鐣岄潰涓婃覆鏌撲娇鐢�
+			tree.setOid(UUID.randomUUID().toString());
+			tree.setParentName(null);
+			Map<String, String> map = new HashMap<>();
+			map.put("name","鎵�鏈夐儴闂�");
+			map.put("ALLDept","ALLDept");
+			tree.setAttributes(map);
+			tree.setChildren(trees);
+			treeList.add(tree);
+			return treeList;
+		}
+		return trees;
 	}
 
 	  /**
@@ -476,7 +589,7 @@
 		tempList.removeAll(repeatUserOidList);
 		userOIds = tempList.toArray(new String[tempList.size()]);
 		if(Func.isNotEmpty(userOIds)){
-			platformClientUtil.getFrameworkService().saveUserDept(userOIds, deptId,null);
+			platformClientUtil.getFrameworkService().saveUserDept(userOIds, deptId,new UserEntityInfo(WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserId(),null));
 		}
 		return true;
 	}
@@ -492,16 +605,18 @@
 		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)){
+		conditionMap.put("plname",QueryOptionConstant.OR + orgDepartmentDTO.getName());
+		if(Func.isNotBlank(orgDepartmentDTO.getId())){
+			conditionMap.put("plnum",QueryOptionConstant.OR + orgDepartmentDTO.getId());
+		}
+		List<OrgDepartmentVO> departmentVOS = getDeptByDeptPOidAndCondition(orgDepartmentDTO.getPkFatherDepartment(), conditionMap);
+		if(Func.isNotEmpty(departmentVOS)){
 			throw new VciBaseException("鍚屼竴鐖惰妭鐐逛笅璇ラ儴闂ㄥ悕绉版垨缂栧彿宸茬粡瀛樺湪,璇蜂慨鏀�!");
 		}
-		//SessionInfo loginUser = WebThreadLocalUtil.getCurrentUserSessionInfoInThread();
-		String userId = "developer";//loginUser.getUserId();
+		SessionInfo loginUser = WebThreadLocalUtil.getCurrentUserSessionInfoInThread();
+		String userId = loginUser.getUserId();
 
 		//鐢熸垚瀛樺偍鐨刢orba瀵硅薄
 		orgDepartmentDTO.setCreateTime(new Date());
@@ -531,18 +646,37 @@
 				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);
+		OrgDepartmentVO dbDepartmentVO = getDeptByDeptOid(orgDepartmentDTO.getOid());
+		if(Func.isEmpty(dbDepartmentVO)){
+			throw new VciBaseException("淇敼鐨勯儴闂ㄤ笉瀛樺湪锛�");
+		}
+		//閮ㄩ棬鍚嶅拰缂栧彿鍒ら噸
+		Map<String, String> conditionMap = new HashMap<>();
+		conditionMap.put("plname",QueryOptionConstant.OR + orgDepartmentDTO.getName());
+		if(Func.isNotBlank(orgDepartmentDTO.getId())){
+			conditionMap.put("plnum",QueryOptionConstant.OR + orgDepartmentDTO.getId());
+		}
+		List<OrgDepartmentVO> repeatDepartmentVOS = getDeptByDeptPOidAndCondition(orgDepartmentDTO.getPkFatherDepartment(), conditionMap);
+		repeatDepartmentVOS = repeatDepartmentVOS.stream().filter(item -> {
+			if((item.getName().equals(orgDepartmentDTO.getName()) || item.getId().equals(orgDepartmentDTO.getId())) &&
+					!item.getOid().equals(orgDepartmentDTO.getOid())){
+				return true;
+			}
+			return false;
+		}).collect(Collectors.toList());
+		if(Func.isNotEmpty(repeatDepartmentVOS) ){
+			throw new VciBaseException("鍚屼竴鐖惰妭鐐逛笅璇ラ儴闂ㄥ悕绉版垨缂栧彿宸茬粡瀛樺湪,璇蜂慨鏀�!");
+		}
+		OrgDepartmentDTO departmentDTO = new OrgDepartmentDTO();
+		BeanUtil.convert(dbDepartmentVO,departmentDTO);
+		departmentDTO.setCode(orgDepartmentDTO.getCode());
+		departmentDTO.setId(orgDepartmentDTO.getId());
+		departmentDTO.setSpecialties(orgDepartmentDTO.getSpecialties());
+		departmentDTO.setDescription(orgDepartmentDTO.getDescription());
+		departmentDTO.setName(orgDepartmentDTO.getName());
+		String loginUserId = WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserId();
+		orgDepartmentDTO.setLastModifier(loginUserId);
+		DeptInfo deptInfo = changeOrgDeptDTOToDeptInfo(departmentDTO);
 		boolean updateBoolean = platformClientUtil.getFrameworkService().updateDepartment(deptInfo, new UserEntityInfo(loginUserId, null));
 		return updateBoolean;
 	}
@@ -596,6 +730,176 @@
 		return stringOrgDepartmentVOMap;
 	}
 
+	/**
+	 * 涓嬭浇瀵煎叆閮ㄩ棬鐨別xcel妯℃澘銆�
+	 * @param downloadFileName
+	 * @return
+	 */
+	@Override
+	public String downloadImportTemplate(String downloadFileName) {
+		//鐣岄潰娌′紶鍚嶇О锛屼娇鐢ㄩ粯璁ゅ悕绉�
+		downloadFileName = Func.isBlank(downloadFileName) ?  "閮ㄩ棬瀵煎叆妯℃澘_" + Func.format(new Date(),"yyyy-MM-dd HHmmss.sss"):downloadFileName;
+		// 璁剧疆琛ㄥ崟鍒楀悕
+		List<String> columns = new ArrayList<>(Arrays.asList("ID", "鍚嶇О", "缂栧彿", "浠e彿", "涓撲笟", "鐖禝D锛堥儴闂ㄥ敮涓�鏍囪瘑ID锛�", "鎻忚堪"));
+		//璁剧疆蹇呭~鍒�
+		ColumnNameisRed.clear();
+		ColumnNameisRed.add(0);
+		ColumnNameisRed.add(1);
+		//鍐檈xcel
+		String excelPath = LocalFileUtil.getDefaultTempFolder() + File.separator + downloadFileName +  ".xls";
+		try {
+			new File(excelPath).createNewFile();
+		} catch (Throwable e) {
+			throw new VciBaseException(LangBaseUtil.getErrorMsg(e), new String[]{excelPath}, e);
+		}
+		//璁剧疆鍒�
+		List<WriteExcelData> excelDataList = new ArrayList<>();
+		for (int index = 0; index < columns.size(); index++) {
+			//鍒ゆ柇鏄惁涓哄繀濉垪锛岀粰蹇呭~鍒楄缃鑹�
+			if(ColumnNameisRed.contains(index)){
+				WriteExcelData excelData = new WriteExcelData(0, index, columns.get(index));
+				excelData.setFontColor(String.valueOf(HSSFColor.HSSFColorPredefined.RED.getIndex()));
+				excelDataList.add(excelData);
+			}else{
+				excelDataList.add(new WriteExcelData(0,index, columns.get(index)));
+			}
+		}
+		WriteExcelOption excelOption = new WriteExcelOption(excelDataList);
+		ExcelUtil.writeDataToFile(excelPath, excelOption);
+		return excelPath;
+	}
+
+	/**
+	 * 瀵煎叆閮ㄩ棬
+	 * @param file
+	 * @return
+	 * @throws VciBaseException
+	 */
+	@Override
+	public BaseResult importDept(File file) throws VciBaseException {
+		VciBaseUtil.alertNotNull(file,"excel鏂囦欢");
+		if(!file.exists()){
+			throw new VciBaseException("瀵煎叆鐨別xcel鏂囦欢涓嶅瓨鍦�,{0}",new String[]{file.getPath()});
+		}
+		try{
+			//1銆佽鍙杄xcel涓殑鏁版嵁锛岀粍鎴愬璞�
+			ReadExcelOption excelOption = new ReadExcelOption();
+			//褰撳墠鐧诲綍鐨勭敤鎴疯处鍙�
+			//String loginUserId = WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserId();
+			String loginUserId = "developer";
+			UserEntityInfo userEntityInfo = new UserEntityInfo(loginUserId,null);
+			List<OrgDeptPO> poList = ExcelUtil.readDataObjectFromExcel(file, OrgDeptPO.class,excelOption,(value, po, fieldName)->{});
+			//鍘婚櫎閮芥槸绌虹殑鎯呭喌
+			if(CollectionUtils.isEmpty(poList)){
+				return BaseResult.fail(ExcelLangCodeConstant.IMPORT_CONTENT_NULL,new String[]{});
+			}
+			/*閮ㄩ棬瀵煎叆鍑犱釜姣旇緝閲嶈鐨勬儏鏅細
+				1銆佸綋鍓嶅鍏ョ殑鏁版嵁鏄竴涓儴闂ㄦ爲缁撴瀯(瑕佸垽鏂敤鎴锋墜杈撶殑ID鏄惁瀛樺湪閲嶅锛岃緭浜嗗氨瑕佸垽鏂槸鍚﹀湪褰撳墠琛ㄦ牸涓噸澶嶏紝
+					骞朵笖淇濆瓨鏃朵笉鑳戒娇鐢ㄧ敤鎴锋墜杈撶殑ID锛岃鏍规嵁鎵嬭緭ID鍜屽疄闄呭瓨鍌∣ID鍋氬搴旀槧灏勶紝
+					骞朵笖涓嶇牬鍧忚〃鏍间腑閮ㄩ棬鏍戠粨鏋勶紝濡傛灉娌℃墜杈揑D灏卞彧闇�瑕佸叧娉╬arentId杩欎釜灞炴�э紝
+					骞朵笖闇�瑕佹敞鎰忓鏋滄湁鐨処D鏈夛紝鏈夌殑娌℃湁閭e氨闇�瑕佹敞鎰忥紝鏃㈠瓨鍦ㄥ拰绯荤粺涓紝
+					鍏宠仈鐨勯儴闂ㄦ爲锛屽張瀛樺湪鍜屽綋鍓嶈〃鏍间腑鍏宠仈鐨勯儴闂ㄦ爲)銆�
+				2銆佸綋鍓嶅鍏ョ殑鏁版嵁鐖秈d鍏宠仈浜嗗凡瀛樺湪鐨勯儴闂╫id(瑕佹煡璇㈢埗id杩欎釜閮ㄩ棬鏄惁瀛樺湪锛�)
+			瑙e喅鎬濊矾锛氭渶濂芥槸灏嗚〃鏍间腑鍙兘鏄儴闂ㄦ爲鐨勭粰閬嶅巻鎴愭爲锛岀劧鍚庡啀鍋氭煡閲嶅暐鐨勫鐞�
+			*/
+			//2銆佸繀濉垽绌恒�佸垽閲嶏紙鏁版嵁搴撳垽閲嶅拰excel涓垽閲嶏級锛岀粍瑁呮垚淇濆瓨鐢ㄧ殑鏁版嵁瀵硅薄
+			List<DeptInfo> deptInfoList = new ArrayList<>();
+			//2.1銆佺敤浠ュ瓨鍌╡xcel涓噸澶嶇殑鏁版嵁锛屼笁涓笉鍙噸澶嶇殑瀛楁锛夛紙Name涓嶈兘涓虹┖锛孨ame銆丆ode鍚屼竴鐖堕儴闂ㄤ笅鍞竴锛�
+			List<String> repeatIdList = new ArrayList<>();
+			Map<String,String> repeatNameMap = new HashMap<>();
+			Map<String,String> repeatNumMap = new HashMap<>();
+			Map<String,String> indexMap = new HashMap<>();
+			//2.2銆佸瓨鍌ㄧ敤鎴锋墜杈撶殑oid鍜屽疄闄呭瓨鍌╫id鐨勬槧灏勫叧绯�
+			Map<String, String> oidMap = new HashMap<>();
+			poList.stream().forEach(po->{
+				String parentId = Func.isBlank(po.getParentId()) ? "":po.getParentId();
+				//琛ㄦ牸鍐呭垽閲�
+				//閮ㄩ棬鍚嶇О鍒ょ┖
+				if(Func.isEmpty(po.getName())){
+					throw new VciBaseException("绗��"+po.getRowIndex()+"銆戣锛宒epterror,Reason:Name cannot be empty");
+				}else if(repeatNameMap.getOrDefault(po.getName(), "").equals(parentId)/*excel涓悓涓�閮ㄩ棬涓婲ame鐩哥瓑*/){
+					//鍚屼竴閮ㄩ棬涓嬪悕绉板垽閲�
+					throw new VciBaseException("绗��"+po.getRowIndex()+"銆戣锛宒eptnameerror,Reason: Names under the same department cannot be duplicated");
+				}else if(Func.isNotEmpty(po.getId()) && repeatIdList.equals(po.getId())){
+					throw new VciBaseException("绗��"+po.getRowIndex()+"銆戣锛宒eptiderror,Reason: The primary key cannot be duplicated");
+				}else if(Func.isNotEmpty(po.getNum()) && repeatNumMap.getOrDefault(po.getNum(),"").equals(parentId)/*excel涓悓涓�閮ㄩ棬涓嬬紪鍙峰瓨鍦� */){
+					throw new VciBaseException("绗��"+po.getRowIndex()+"銆戣锛宒eptnumerror,Reason: The number cannot be duplicated");
+				}else{
+					//2.2銆佹煡璇㈡暟鎹簱涓殑鏁版嵁锛堟煡閲岻D鍜孨UM锛夛紝姣旇緝楹荤儲闇�瑕佹牴鎹甈arentID鏌ヨ锛堟墍鏈夊彧鑳藉崟鏉℃煡璇㈣繘琛屽垽閲嶏級
+					//缁勮鏌ラ噸鏉′欢:鍚屼竴閮ㄩ棬涓�(parentId鐩哥瓑)锛宯ame鎴栬�卬um鐩哥瓑
+					HashMap<String, String> conditionMap = new HashMap<>();
+					conditionMap.put("plname",po.getName());
+					conditionMap.put("plnum",QueryOptionConstant.OR + po.getNum());
+					String pId = Func.isBlank(po.getParentId()) ? null:po.getParentId();
+					List<OrgDepartmentVO> repeatOrgDept = this.getDeptByDeptPOidAndCondition(pId, conditionMap);
+					//鍙涓嶄负绌哄氨璇存槑褰撳墠琛屾暟鎹湪绯荤粺涓噸澶�
+					if(Func.isNotEmpty(repeatOrgDept)){
+						throw new VciBaseException("绗��"+po.getRowIndex()+"銆戣锛宒eptname or deptnum error,Reason: The name or number already exists in the system");
+					}
+				}
+				//瀛樺偍鏍¢獙閫氳繃鐨勬暟鎹紝浠ヤ究鍚庣画excel鏌ラ噸
+				repeatNameMap.put(po.getName(),Func.isBlank(po.getParentId()) ? "":po.getParentId());
+				repeatIdList.add(po.getId());
+				repeatNumMap.put(po.getNum(),po.getParentId());
+				indexMap.put(po.getName(),po.getRowIndex());
+				//鏍¢獙鏁版嵁灏辫缁勮鎴怐TO鏁版嵁瀵硅薄浜�
+				OrgDepartmentDTO dto = new OrgDepartmentDTO();
+				BeanUtil.convert(po,dto);
+				dto.setOid(po.getId());
+				dto.setId(po.getNum());
+				dto.setPkFatherDepartment(po.getParentId());
+				dto.setCreateTime(new Date());
+				dto.setCreator(loginUserId);
+				dto.setLastModifier(loginUserId);
+				dto.setStatus((short) 0);
+				//2.2銆佽繃绋嬩腑澶勭悊涓婚敭杞崲闂鏈�濂芥槸涓�鏉′竴鏉$殑澶勭悊ID鏄惁瀛樺湪杩樻湁ParentID鏄惁瀛樺湪鐨勯棶棰�
+				//鍏堝垽鏂槸宸插瓨鍦ㄧ殑閮ㄩ棬ID锛岃繕鏄笉瀛樺湪鐨勯儴闂↖D锛屽凡瀛樺湪绯荤粺涓殑ID灏辨槸涓篋ept:寮�澶寸殑
+				String pId = dto.getPkFatherDepartment();
+				//鏄凡瀛樺湪绯荤粺涓殑閮ㄩ棬id
+				if(pId.contains("Dept:")){
+					//瑙f瀽鍑虹湡瀹炵殑oid
+					String deParentId = Func.oidDeHash(pId.replace("Dept:", "").trim());
+					//瑙f瀽鍑烘潵鐨刣eParentId蹇呴』寰楀湪搴撲腑瀛樺湪
+					if(Func.isBlank(deParentId) || Func.isEmpty(this.getDeptByDeptOid(deParentId))){
+						throw new VciBaseException("绗��"+ po.getRowIndex() +"銆戣锛宒eptparentiderror,Reason:Parent ID resolution error or does not exist in the system");
+					}
+					//鏇挎崲鎺変复鏃朵娇鐢ㄧ殑閮ㄩ棬鍞竴鏍囪瘑
+					dto.setPkOrganizationName(deParentId);
+				}
+				//鐢ㄦ埛鎵嬭緭浜嗛儴闂╫id锛屼絾鏄伩鍏峯id涓嶈鑼冮渶瑕侊紝鐢ㄨ鑼僶id杩涜鏇挎崲锛屽鏋滄病杈撳叆淇濆瓨鏃朵細鑷姩鐢熸垚oid
+				if(Func.isNotBlank(dto.getOid())){
+					String pkOid = VciBaseUtil.getPk();
+					dto.setOid(pkOid);
+					//oid鏄犲皠鍏崇郴锛屽悗缁敤鏉ユ洿鏂皃arentId
+					oidMap.put(dto.getOid(),pkOid);
+				}
+				DeptInfo deptInfo = this.changeOrgDeptDTOToDeptInfo(dto);
+				deptInfoList.add(deptInfo);
+			});
+			//3銆佸鐞唅d鍜宲arentId鐨勬槧灏勫叧绯�:灏嗙敤鎴锋墜杈撶殑鐖禝D杞崲鎴愬疄闄呭瓨鍌ㄧ殑ID
+			List<DeptInfo> lastDeptInfoList = deptInfoList.stream().map(info -> {
+				//parentId涓嶄负绌哄苟涓旀病鏈塂ept:鐩稿叧鐨勫瓧绗︿覆,璇存槑鏄敤鎴锋墜杈撶殑ParentId(瀵煎叆鐨勬暟鎹氨鏄竴涓爲缁撴瀯)
+				if (Func.isNotBlank(info.parentId) || info.parentId.contains("Dept:")) {
+					//杞崲ParentId涓哄疄闄呰瀛樺偍鐨勯儴闂↖D
+					info.parentId = oidMap.get(info.parentId);
+				}
+				return info;
+			}).collect(Collectors.toList());
+			//4銆佸鏈�缁堝鐞嗗ソ鐨勯儴闂ㄦ暟鎹繚瀛橈紝瀹炵幇鏈�缁堢粺涓�淇濆瓨锛岄伩鍏嶄簡涓�閮ㄥ垎鏁版嵁杩涗簡涓�閮ㄥ垎鏁版嵁鍥犱负鏍¢獙娌¤繃娌¤繘搴撶殑闂
+			platformClientUtil.getFrameworkService().batchSaveDepart(
+					lastDeptInfoList.toArray(new DeptInfo[lastDeptInfoList.size()]),
+					userEntityInfo
+			);
+		}catch (Exception e){
+			if(logger.isErrorEnabled()){
+				logger.error("璇诲彇excel鍐呭鏃舵垨淇濆瓨鐢ㄦ埛淇℃伅鏃跺嚭鐜颁簡閿欒锛屽叿浣撳師鍥狅細",e.getMessage());
+			}
+			e.printStackTrace();
+			return BaseResult.fail(LangBaseUtil.getErrorMsg(e),new String[]{},e);
+		}
+		return BaseResult.success("閮ㄩ棬瀵煎叆鎴愬姛锛�");
+	}
+
 	public Map<String, OrgDepartmentVO> convertToMap(List<OrgDepartmentVO> orgDepartmentVOList) {
 		Map<String, OrgDepartmentVO> map = new HashMap<>();
 		for (OrgDepartmentVO orgDepartmentVO : orgDepartmentVOList) {

--
Gitblit v1.9.3