From 9a34f1cf8528b51112f62af5b646db717f612e45 Mon Sep 17 00:00:00 2001 From: ludc Date: 星期一, 01 七月 2024 18:12:06 +0800 Subject: [PATCH] 用户管理界面,下载导入模板,用户导入接口上传,增加corba.properties配置读取类。 --- Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/frameworkcore/compatibility/impl/OrgDeptQueryServiceImpl.java | 41 ++++ Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/frameworkcore/compatibility/SmUserQueryServiceI.java | 23 ++ Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/frameworkcore/compatibility/impl/SmUserQueryServiceImpl.java | 294 ++++++++++++++++++++++---------- Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/frameworkcore/compatibility/OrgDeptQueryServiceI.java | 13 + Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/frameworkcore/controller/SmUserQueryController.java | 47 ++++ Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/frameworkcore/model/po/SmUserPO.java | 84 +++++++++ Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/frameworkcore/properties/ConfigReader.java | 33 +++ 7 files changed, 430 insertions(+), 105 deletions(-) diff --git a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/frameworkcore/compatibility/OrgDeptQueryServiceI.java b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/frameworkcore/compatibility/OrgDeptQueryServiceI.java index 9369e79..4a69cb5 100644 --- a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/frameworkcore/compatibility/OrgDeptQueryServiceI.java +++ b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/frameworkcore/compatibility/OrgDeptQueryServiceI.java @@ -123,4 +123,17 @@ */ boolean saveUsersDept(String[] userOIds, String deptId) throws PLException; + /** + * 鏍规嵁閮ㄩ棬鍚嶇О缁勬垚鐨勬爲璺緞锛屾煡璇㈤儴闂ㄤ俊鎭� + * @param deptTreeNameList 閮ㄩ棬鍚嶇О(涓婁笅绾ч儴闂ㄤ箣闂翠互鍙嶆枩鏉犻殧寮�(/)) + * @return 杩斿洖鐨刱ey涓洪儴闂ㄥ悕绉扮粍鎴愮殑涓婁笅绾у叧绯伙紙deptTreeNameList涓殑姣忎釜鍏冪礌锛夛紝value涓哄搴旂殑閮ㄩ棬淇℃伅 + */ + //Map<String,String> getDeptByTreeName(/*璇蜂紶鍘婚噸鍚庣殑list*/List<String> deptTreeNameList); + + /** + * 鑾峰彇鎵�鏈夐儴闂ㄧ殑淇℃伅 + * @return key锛氶儴闂ㄧ敱鍚嶇О缁勬垚鐨勮矾寰勶紙/闂撮殧锛夛紝value瀵瑰簲鏈�灏忓眰绾х殑閮ㄩ棬淇℃伅 + */ + Map<String,OrgDepartmentVO> getDeptAllTreeMap(); + } diff --git a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/frameworkcore/compatibility/SmUserQueryServiceI.java b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/frameworkcore/compatibility/SmUserQueryServiceI.java index d8bb09d..eeb80ba 100644 --- a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/frameworkcore/compatibility/SmUserQueryServiceI.java +++ b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/frameworkcore/compatibility/SmUserQueryServiceI.java @@ -4,11 +4,11 @@ import com.vci.frameworkcore.model.dto.SmUserDTO; import com.vci.frameworkcore.pagemodel.SmUserVO; 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 org.springframework.web.multipart.MultipartFile; +import javax.servlet.http.HttpServletResponse; +import java.io.File; import java.util.Collection; import java.util.List; import java.util.Map; @@ -282,6 +282,19 @@ */ boolean stopUsers(String[] ids,boolean flag) throws PLException; - void downloadImportTemplate(); + /** + * 涓嬭浇瀵煎叆浜哄憳鐨別xcel妯℃澘銆� + * @param downloadFileName + * @return + */ + String downloadImportTemplate(String downloadFileName); + + /** + * 瀵煎叆鎴愬憳 + * @param file + * @return + * @throws VciBaseException + */ + BaseResult importUser(File file) throws VciBaseException; } 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 3f73e92..f9ff061 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 @@ -460,4 +460,45 @@ 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; + } + } diff --git a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/frameworkcore/compatibility/impl/SmUserQueryServiceImpl.java b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/frameworkcore/compatibility/impl/SmUserQueryServiceImpl.java index dc1e27b..3bce07c 100644 --- a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/frameworkcore/compatibility/impl/SmUserQueryServiceImpl.java +++ b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/frameworkcore/compatibility/impl/SmUserQueryServiceImpl.java @@ -1,6 +1,5 @@ package com.vci.frameworkcore.compatibility.impl; -import com.vci.client.common.objects.UserObject; import com.vci.common.util.ThreeDES; import com.vci.corba.common.PLException; import com.vci.corba.common.data.UserEntityInfo; @@ -12,21 +11,23 @@ import com.vci.frameworkcore.compatibility.SmUserQueryServiceI; import com.vci.frameworkcore.model.dto.SmUserDTO; import com.vci.frameworkcore.model.SmUserDO; +import com.vci.frameworkcore.model.po.SmUserPO; import com.vci.frameworkcore.pagemodel.OrgDepartmentVO; import com.vci.frameworkcore.pagemodel.SmPasswordStrategyVO; import com.vci.frameworkcore.pagemodel.SmRoleVO; 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.web.enumpck.BooleanEnum; import com.vci.starter.web.enumpck.UserSecretEnum; 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.util.BeanUtil; -import com.vci.starter.web.util.VciBaseUtil; -import com.vci.starter.web.util.VciDateUtil; +import com.vci.starter.web.pagemodel.*; +import com.vci.starter.web.util.*; import com.vci.starter.web.wrapper.VciQueryWrapperForDO; import com.vci.web.enumpck.UserTypeEnum; import com.vci.web.service.WebBoServiceI; @@ -34,16 +35,18 @@ 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 java.io.File; import java.util.*; -import java.util.regex.Pattern; import java.util.stream.Collectors; -import static com.vci.frameworkcore.constant.FrameWorkBusLangCodeConstant.DATA_OID_NOT_EXIST; import static com.vci.web.util.WebUtil.arryAndSqlToBusinessObject; /** @@ -112,6 +115,11 @@ public static final String QUERY_FIELD_ROLE = "roleUser.plroleuid"; /** + * 蹇呭~鍒� + */ + private ArrayList<Integer> ColumnNameisRed = new ArrayList<Integer>(); + + /** * 鐢ㄦ埛鍒嗛〉鏌ヨ鏃惰幏鍙栭儴闂ㄦ斁鍒拌繖閲岄伩鍏嶉噸澶嶆煡璇� */ private Map<String,List<OrgDepartmentVO>> orgDepartmentVOMap; @@ -125,6 +133,11 @@ * 鐢ㄦ埛鍒嗛〉鏌ヨ鏃惰幏鍙栧瘑鐮佺瓥鐣ユ斁鍒拌繖閲岄伩鍏嶅娆℃煡璇� */ private Map<String,SmPasswordStrategyVO> smPwdStrategyVOMap; + + /** + * 鏃ュ織 + */ + private Logger logger = LoggerFactory.getLogger(getClass()); /** * 妫�鏌ョ敤鎴锋槸鍚﹀瓨鍦紝鍙互鏍规嵁鐢ㄦ埛鍚嶏紝涔熷彲浠ユ牴鎹敤鎴穙id @@ -238,6 +251,7 @@ throw new VciBaseException("鑾峰彇鐢ㄦ埛澶辫触锛�"+e.getMessage()); } } + /** * 鏍规嵁鐢ㄦ埛涓婚敭鑾峰彇鐢ㄦ埛鐨勪俊鎭� * @param userOid 鐢ㄦ埛涓婚敭 @@ -299,9 +313,9 @@ smUserVO.setId(userInfo.userName); smUserVO.setName(userInfo.trueName); smUserVO.setSecretGrade(userInfo.secretGrade); - smUserVO.setSecretGradeText(UserSecretEnum.getSecretText(smUserVO.getSecretGrade())); + smUserVO.setSecretGradeText(UserSecretEnum.getSecretText(userInfo.secretGrade)); smUserVO.setUserType(String.valueOf(userInfo.userType)); - smUserVO.setUserTypeText(UserTypeEnum.getTextByValue(smUserVO.getUserType())); + smUserVO.setUserTypeText(UserTypeEnum.getTextByValue(String.valueOf(userInfo.userType))); smUserVO.setDescription(userInfo.desc); smUserVO.setEmail(userInfo.email); smUserVO.setStatus(userInfo.status); @@ -519,14 +533,14 @@ } pageHelper.addDefaultAsc("PLTRUENAME"); //TODO:涓轰簡鏂逛究璋冭瘯锛屾墍浠ヨ繖鍎垮厛娉ㄩ噴鍐欐鍚庨潰璁板緱鏇存敼 - //String userName = WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserName(); + String loginUserId = WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserId(); //鍒嗛〉鏌ヨ UserInfo[] userInfos = platformClientUtil.getFrameworkService().fetchUserInfoByCondition( conditionMap.get("name"), conditionMap.get("id"), conditionMap.get("pkDepartment"), conditionMap.get("pkPerson"), - "developer", //褰撳墠鐧诲綍鐨勭敤鎴峰悕 + loginUserId, //褰撳墠鐧诲綍鐨勭敤鎴峰悕 pageHelper.getPage(), pageHelper.getLimit() ); @@ -543,7 +557,7 @@ conditionMap.get("id"), conditionMap.get("pkDepartment"), conditionMap.get("pkPerson"), - "developer" //褰撳墠鐧诲綍鐨勭敤鎴峰悕 + loginUserId //褰撳墠鐧诲綍鐨勭敤鎴峰悕 ) ); } @@ -642,42 +656,6 @@ addRoleQuerySql(queryMap,queryWrapperForDO); queryWrapperForDO.eq("plstatus", "0"); queryWrapperForDO.eq("plusertype", "2"); - queryWrapperForDO.setDistinct(true); - return queryWrapperForDO; - } - - /** - * 鑾峰彇鏌ヨ灏佽鍣紝榛樿鍙煡plusertype!=1鐨� - * @param queryField 鏌ヨ灞炴�� - * @param queryValue 鏌ヨ鐨勫�� - * @param queryMap 鏌ヨ鏉′欢锛屽鏋滄槸瑙掕壊鐨勫睘鎬э紝闇�瑕佷娇鐢╬krole.xxx - * @param pageHelper 鍒嗛〉瀵硅薄 - * @param notIn 鏄惁涓轰笉鍖呭惈 - * @return 鏌ヨ灏佽鍣� - */ - private VciQueryWrapperForDO getQueryWrapper2(String queryField,String queryValue,Map<String,String> queryMap,PageHelper pageHelper,boolean notIn){ - if(pageHelper == null){ - pageHelper = new PageHelper(-1); - } - pageHelper.addDefaultAsc("plusername"); - VciQueryWrapperForDO queryWrapperForDO = new VciQueryWrapperForDO(queryMap,SmUserDO.class,pageHelper); - if(StringUtils.isNotBlank(queryField)) { - if (queryValue.contains(",")) { - if (notIn) { - queryWrapperForDO.notIn(queryField, VciBaseUtil.toInSql(VciBaseUtil.str2List(queryValue).toArray(new String[0]))); - } else { - queryWrapperForDO.in(queryField, VciBaseUtil.toInSql(VciBaseUtil.str2List(queryValue).toArray(new String[0]))); - } - } else { - if (notIn) { - queryWrapperForDO.neq(queryField, queryValue); - } else { - queryWrapperForDO.eq(queryField, queryValue); - } - } - } - addRoleQuerySql(queryMap,queryWrapperForDO); - queryWrapperForDO.neq("plusertype", "2"); queryWrapperForDO.setDistinct(true); return queryWrapperForDO; } @@ -1053,19 +1031,20 @@ smUserDTO.getName(),"濮撳悕" ); //鏍¢獙 - check(smUserDTO,true); + check(smUserDTO,true,false); //鐢熸垚瀛樺偍鐨凞O瀵硅薄 Date date = new Date(); smUserDTO.setPwdUpdateTime(date); smUserDTO.setStatus((short) 0); smUserDTO.setCreateTime(date); smUserDTO.setLastModifyTime(date); - //userObject.setCreateUser(WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserName()); - smUserDTO.setCreator("developer"); - //userObject.setUpdateUser(WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserName()); - smUserDTO.setLastModifier("developer"); + String loginUserName = WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserId(); + smUserDTO.setCreator(loginUserName); + //smUserDTO.setCreator("developer"); + smUserDTO.setLastModifier(loginUserName); + //smUserDTO.setLastModifier("developer"); UserInfo userInfo = changeSmUserDTOToUserInfo(smUserDTO); - UserEntityInfo userEntityInfo = new UserEntityInfo("developer", ""); + UserEntityInfo userEntityInfo = new UserEntityInfo(loginUserName, ""); String oid = platformClientUtil.getFrameworkService().saveUser(userInfo, userEntityInfo); if (Func.isEmpty(oid)) { return false; @@ -1096,7 +1075,7 @@ smUserDTO.getName(),"濮撳悕" ); //鏍¢獙 - check(smUserDTO,false); + check(smUserDTO,false,false); //鏌ヨ鏁版嵁搴撲腑鐨� SmUserVO dbSmUserVO = getUserByUserOid(smUserDTO.getOid()); //鏍规嵁涓婚敭娌℃煡璇㈠埌浜嗙敤鎴� @@ -1105,10 +1084,10 @@ } smUserDTO.setLastModifyTime(new Date()); - //userObject.setUpdateUser(WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserName()); - smUserDTO.setLastModifier("developer"); + String loginUserName = WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserId(); + smUserDTO.setLastModifier(loginUserName); UserInfo userInfo = changeSmUserDTOToUserInfo(smUserDTO); - boolean updateBoolean = platformClientUtil.getFrameworkService().updateUser(userInfo, new UserEntityInfo("developer", null)); + boolean updateBoolean = platformClientUtil.getFrameworkService().updateUser(userInfo, new UserEntityInfo(loginUserName, null)); //淇敼鎴愬姛锛屽苟涓旂敤鎴峰叧鑱旈儴闂ㄦ湁鎵�鏇存敼 if(updateBoolean && Func.isNotEmpty(smUserDTO.getPkDepartment()) && !smUserDTO.getPkDepartment().equals(dbSmUserVO.getPkDepartment())){ //鎵ц淇濆瓨鐢ㄦ埛閮ㄩ棬鍏宠仈鍏崇郴 @@ -1120,10 +1099,12 @@ /** * 妫�鏌ョ敤鎴蜂俊鎭槸鍚︾鍚堣鑼� * @param smUserDTO - * @param isAdd + * @param isAdd 鏄惁鏂板 + * @param isImport 鏄惁瀵煎叆 */ - private void check(SmUserDTO smUserDTO, boolean isAdd){ - if(!smUserDTO.getPassword().equals(smUserDTO.getConfirmPassword())){ + private void check(SmUserDTO smUserDTO, boolean isAdd,boolean isImport){ + //瀵煎叆鐨勬病鏈夌‘璁ゅ瘑鐮� + if(!isImport && !smUserDTO.getPassword().equals(smUserDTO.getConfirmPassword())){ throw new VciBaseException("瀵嗙爜鍜岀‘璁ゅ瘑鐮佷笉鐩哥瓑"); } if(smUserDTO.getId().getBytes().length > 128){ @@ -1150,8 +1131,10 @@ if (Func.isNotBlank(smUserDTO.getEmail()) && !smUserDTO.getEmail().matches("^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$")){ throw new VciBaseException("鐢靛瓙閭鏍煎紡閿欒"); } - //鏄柊澧炴墠鍋氱敤鎴峰悕鏌ラ噸澶勭悊锛屽洜涓虹敤鎴峰悕涓�缁忓垱寤猴紝涓嶅厑璁镐慨鏀� - if(isAdd){ + /*鏄柊澧炴墠鍋氱敤鎴峰悕鏌ラ噸澶勭悊锛屼慨鏀逛笉闇�瑕佹煡閲嶏紙涓�缁忓垱寤轰笉鍏佽淇敼鐢ㄦ埛鍚嶏級锛� + 瀵煎叆鐨勪篃涓嶉渶瑕佸湪杩欏効鏌ラ噸锛屽洜涓哄湪瀵煎叆閫昏緫閲岄潰闇�瑕佽繑鍥為噸澶嶇殑琛� + */ + if(isAdd && !isImport){ //鏍规嵁鐢ㄦ埛鍚嶏紙璐﹀彿锛夋煡閲� SmUserVO dbSmUserVO = getUserByUserId(smUserDTO.getId()); if(Func.isNotEmpty(dbSmUserVO) && Func.isNotBlank(dbSmUserVO.getOid())){ @@ -1161,7 +1144,7 @@ //鏍规嵁褰撳墠鍒涘缓杩欎釜鐢ㄦ埛鐨勪汉鎵�缁戝畾瀵嗙爜绛栫暐鏉ヨ繘琛屽瘑鐮佹牎楠� try { //TODO:涓轰簡鏂逛究璋冭瘯锛屾墍浠ヨ繖鍎垮厛娉ㄩ噴鍐欐鍚庨潰璁板緱鏇存敼 - //String userName = WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserName(); + //String userName = WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserId(); String userName = "developer"; String error = platformClientUtil.getFrameworkService().checkPasswordStrategyByUserId(userName, smUserDTO.getPassword(),null); if (!StringUtils.isBlank(error)) { @@ -1200,33 +1183,6 @@ return userInfo; } - /*** - * 鐢ㄦ埛浠庡鎴风瀵硅薄鍒癱orba瀵硅薄 - * - * @param user - * @return - */ - public UserInfo changeUserObjectToUserInfo(UserObject user) { - UserInfo userInfo = new UserInfo(); - userInfo.id = user.getId() == null ? "" : user.getId(); - userInfo.userName = user.getUserName() == null ? "" : user.getUserName(); - userInfo.pwd = user.getPwd() == null ? "" : user.getPwd(); - userInfo.trueName = user.getTrueName() == null ? "" : user.getTrueName(); - userInfo.specialties = user.getSpecialties() == null ? "" : user.getSpecialties(); - userInfo.email = user.getEmail() == null ? "" : user.getEmail(); - userInfo.desc = user.getDesc() == null ? "" : user.getDesc(); - userInfo.userType = user.getUserType(); - userInfo.status = user.getStatus(); - userInfo.createTime = user.getCreateTime(); - userInfo.createUser = user.getCreateUser() == null ? "" : user.getCreateUser(); - userInfo.updateTime = user.getUpdateTime(); - userInfo.updateUser = user.getUpdateUser() == null ? "" : user.getUpdateUser(); - userInfo.pwdUpdateTime = user.getPwdUpdateTime(); - userInfo.grantor = user.getGrantor() == null ? "" : user.getGrantor(); - userInfo.isDeptLeader = user.getIsDeptLeader() == null ? "0" : user.getIsDeptLeader(); - return userInfo; - } - /** * 鍒犻櫎鐢ㄦ埛 * @param ids @@ -1255,9 +1211,157 @@ return platformClientUtil.getFrameworkService().stopUsers(ids, flag,null); } + /** + * 涓嬭浇瀵煎叆浜哄憳鐨別xcel妯℃澘銆� + * @param downloadFileName 涓嬭浇鏃剁晫闈紶杩囨潵鎸囧畾鏂囦欢鍚嶇殑 + * @return 鏂囦欢鍦ㄦ湰鍦扮殑鍏ㄨ矾寰� + * @throws VciBaseException 鍙傛暟涓虹┖鎴栬�呮枃浠跺嚭閿欑殑鏃跺�欎細鎶涘嚭寮傚父 + */ @Override - public void downloadImportTemplate() { + public String downloadImportTemplate(String downloadFileName) { + // 璁剧疆琛ㄥ崟鍒楀悕 + List<String> columns = new ArrayList<>(Arrays.asList("璐﹀彿", "瀵嗙爜", "濮撳悕", "鐢靛瓙閭", "涓撲笟", "鎻忚堪", "閮ㄩ棬(涓婁笅绾ч儴闂ㄤ箣闂翠互鍙嶆枩鏉犻殧寮�(/))")); + //鑾峰彇鏄惁瀵煎嚭瀵嗙骇閰嶇疆椤� + String flag = ConfigReader.getConfigValue("exportSecretGrade"); + if (flag != null && flag.equalsIgnoreCase("true")) { + columns = new ArrayList<>(Arrays.asList("璐﹀彿", "瀵嗙爜", "濮撳悕", "鐢靛瓙閭", "涓撲笟", "鎻忚堪", "閮ㄩ棬(涓婁笅绾ч儴闂ㄤ箣闂翠互鍙嶆枩鏉犻殧寮�(/))" ,"瀵嗙骇")); + } + //璁剧疆蹇呭~鍒� + ColumnNameisRed.clear(); + ColumnNameisRed.add(0); + ColumnNameisRed.add(1); + ColumnNameisRed.add(2); + //鍐檈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 importUser(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); + //鏄惁瀵煎叆瀵嗙骇閰嶇疆 + boolean exportSecretGrade = Boolean.parseBoolean(ConfigReader.getConfigValue("exportSecretGrade")); + List<SmUserPO> poList = ExcelUtil.readDataObjectFromExcel(file, SmUserPO.class,excelOption,(value, po, fieldName)->{ + Integer secretValue = UserSecretEnum.getSecretValueByText(po.getSecretGradeText()); + //鏄惁蹇呴』瀵煎叆瀵嗙骇 + if(exportSecretGrade){ + if(secretValue == null){ + throw new VciBaseException("浼犲叆鐨勫瘑绾т笉绗﹀悎瑙勫垯!"); + } + po.setSecretGrade(secretValue); + } + }); + //鍘婚櫎閮芥槸绌虹殑鎯呭喌 + if(CollectionUtils.isEmpty(poList)){ + return BaseResult.fail(ExcelLangCodeConstant.IMPORT_CONTENT_NULL,new String[]{}); + } + //鏁版嵁搴撴煡璇㈡槸鍚︽湁宸插瓨鍦ㄧ殑鐢ㄦ埛锛屾柟渚垮悗缁仛鍒ら噸澶勭悊 + List<SmUserVO> smUserVOList = this.listUserByUserIds(poList.stream().map(SmUserPO::getId).collect(Collectors.toSet())); + List<String> repeatUserId = new ArrayList<>(); + if(Func.isNotEmpty(smUserVOList)){ + repeatUserId = smUserVOList.stream().map(SmUserVO::getId).collect(Collectors.toList()); + } + //褰撳墠excel涓槸鍚﹂噸澶嶇敤鐨勫垽閲峂ap:锛坘ey锛氳处鍙凤紝value锛氳鍙凤級 + Map<String, String> excelReapeat = new HashMap<>(); + //鍏堣幏鍙栧叏閮ㄩ儴闂ㄥ悕绉扮殑鐖跺瓙瀵瑰簲鍏崇郴锛歬ey涓洪儴闂ㄥ瓙鐖剁骇鍚嶇О璺緞锛寁alue涓洪儴闂ㄤ俊鎭� + Map<String,OrgDepartmentVO> deptVOMap = orgDeptQueryService.getDeptAllTreeMap(); + //鍒ゆ柇蹇呭~灞炴�ф槸鍚︿负绌猴紝鐢ㄦ埛鏄惁宸插瓨鍦紝浠ュ強閮ㄩ棬鏄惁濉敊绛夋牎楠岄�昏緫 + List<String> finalRepeatUserId = repeatUserId; + poList.stream().forEach(smUserPO -> { + //鍏堝蹇呭~灞炴�у垽绌哄鐞� + if(Func.isBlank(smUserPO.getId())){ + throw new VciBaseException("绗��"+smUserPO.getRowIndex()+"銆戣锛寀sernameerror"); + }else if(Func.isBlank(smUserPO.getName())){ + throw new VciBaseException("绗��"+smUserPO.getRowIndex()+"銆戣锛宯ameerror"); + }else if(Func.isBlank(smUserPO.getPassword())){ + throw new VciBaseException("绗��"+smUserPO.getRowIndex()+"銆戣锛宲assworderror"); + }else if (Func.isNotEmpty(smUserVOList) && finalRepeatUserId.contains(smUserPO.getId())){//2銆佸垽鏂敤鎴峰悕鏄惁閲嶅 + throw new VciBaseException("绗��"+smUserPO.getRowIndex()+"銆戣锛岀敤鎴峰悕鍦ㄧ郴缁熶腑宸茬粡瀛樺湪,璇蜂慨鏀�!"); + }else if(Func.isNotBlank(smUserPO.getPkDepartmentName())){//澶勭悊濉啓浜嗛儴闂ㄧ殑鏁版嵁琛� + OrgDepartmentVO orgDepartmentVO = deptVOMap.get(smUserPO.getPkDepartmentName()); + //閮ㄩ棬涓虹┖灏辫鏄庣敤鎴峰~鍐欓敊璇� + if(Func.isEmpty(orgDepartmentVO) && Func.isBlank(orgDepartmentVO.getOid())){ + throw new VciBaseException("绗��"+smUserPO.getRowIndex()+"銆戣鏁版嵁锛岄儴闂ㄨ缃敊璇紝鍘熷洜锛氭湭鏌ヨ鍒拌璺緞涓嬬殑閮ㄩ棬"); + } + }else if(excelReapeat.containsKey(smUserPO.getId())){//琛ㄦ牸涓垽閲� + throw new VciBaseException("绗��"+excelReapeat.get(smUserPO.getId())+"銆戣鍜岀銆�"+smUserPO.getRowIndex()+"銆戣鏁版嵁锛岃处鍙烽噸澶�"); + } + excelReapeat.put(smUserPO.getId(),smUserPO.getRowIndex()); + }); + //淇濆瓨閫昏緫 + poList.stream().forEach(smUserPO->{ + SmUserDTO smUserDTO = new SmUserDTO(); + BeanUtil.convert(smUserPO,smUserDTO); + //鐢ㄦ埛淇℃伅鏄惁瑙勮寖妫�鏌� + this.check(smUserDTO,true,true); + //鐢熸垚瀛樺偍鐨凞O瀵硅薄 + Date date = new Date(); + smUserDTO.setPwdUpdateTime(date); + smUserDTO.setStatus((short) 0); + smUserDTO.setCreateTime(date); + smUserDTO.setLastModifyTime(date); + smUserDTO.setCreator(loginUserId); + smUserDTO.setLastModifier(loginUserId); + //淇濆瓨鐢ㄦ埛 + String oid = null; + try { + //淇濆瓨鐢ㄦ埛鑾峰彇鍒扮敤鎴穙id + oid = platformClientUtil.getFrameworkService().saveUser(changeSmUserDTOToUserInfo(smUserDTO), userEntityInfo); + //淇濆瓨鐢ㄦ埛閮ㄩ棬鍏宠仈鍏崇郴 + if(Func.isNotBlank(oid) && Func.isNotBlank(smUserDTO.getPkDepartmentName())){ + orgDeptQueryService.saveUsersDept( + new String[]{oid}, + deptVOMap.get(smUserDTO.getPkDepartmentName()).getOid() + ); + } + } catch (PLException e) { + e.printStackTrace(); + throw new VciBaseException("鎵ц鍒扮銆�"+smUserPO.getRowIndex()+"銆戣淇濆瓨閫昏緫鏃跺嚭鐜伴敊璇紝鍘熷洜锛�" + VciBaseUtil.getExceptionMessage(e)); + } + }); + }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("鐢ㄦ埛瀵煎叆鎴愬姛锛�"); } } diff --git a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/frameworkcore/controller/SmUserQueryController.java b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/frameworkcore/controller/SmUserQueryController.java index 15de3d6..494db59 100644 --- a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/frameworkcore/controller/SmUserQueryController.java +++ b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/frameworkcore/controller/SmUserQueryController.java @@ -1,16 +1,25 @@ package com.vci.frameworkcore.controller; import com.vci.frameworkcore.compatibility.SmUserQueryServiceI; +import com.vci.frameworkcore.constant.FrameWorkLangCodeConstant; import com.vci.frameworkcore.model.dto.SmUserDTO; import com.vci.frameworkcore.pagemodel.SmUserVO; import com.vci.starter.web.annotation.controller.VciUnCheckRight; import com.vci.starter.web.exception.VciBaseException; import com.vci.starter.web.pagemodel.*; +import com.vci.starter.web.util.ControllerUtil; +import com.vci.starter.web.util.LangBaseUtil; +import com.vci.starter.web.util.LocalFileUtil; import com.vci.starter.web.util.VciBaseUtil; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; +import javax.servlet.http.HttpServletResponse; +import java.io.File; +import java.io.IOException; import java.util.List; /** @@ -205,18 +214,46 @@ /** * 涓嬭浇浜哄憳瀵煎叆妯℃澘 + * @param downloadFileName + * @param response */ - @RequestMapping(value = "/downloadImportTemplate",method = RequestMethod.POST) - public void downloadImportTemplate(){ - + @RequestMapping(value = "/downloadImportTemplate",method = RequestMethod.GET) + @VciUnCheckRight + public void downloadImportTemplate(String downloadFileName, HttpServletResponse response){ + String excelPath = userQueryService.downloadImportTemplate(downloadFileName); + try { + ControllerUtil.writeFileToResponse(response,excelPath); + } catch (IOException e) { + String msg = "涓嬭浇鐢ㄦ埛瀵煎叆妯℃澘鏃跺嚭鐜伴敊璇紝鍘熷洜锛�" + LangBaseUtil.getErrorMsg(e); + try { + e.printStackTrace(); + ControllerUtil.writeDataToResponse(response, StringUtils.isNotBlank(msg)?msg.getBytes():new byte[0],null); + } catch (IOException ioException) { + ioException.printStackTrace(); + } + } } /** * 浜哄憳瀵煎叆 */ @RequestMapping(value = "/importUser",method = RequestMethod.POST) - public void importUser(){ - + @VciUnCheckRight + public BaseResult importUser(MultipartFile file){ + String excelFileName = LocalFileUtil.getDefaultTempFolder() + File.separator + LocalFileUtil.getFileNameForIE(file.getOriginalFilename()); + File file1 = new File(excelFileName); + try { + file.transferTo(new File(excelFileName)); + if (file != null) { + return userQueryService.importUser(file1); + } else { + return BaseResult.fail(FrameWorkLangCodeConstant.IMPORT_FAIL, new String[]{"鏃犲鍏ョ殑鏂囦欢"}); + } + }catch (Throwable e) { + throw new VciBaseException(e.getMessage(),new String[0],e); + }finally { + file1.delete(); + } } } diff --git a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/frameworkcore/model/po/SmUserPO.java b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/frameworkcore/model/po/SmUserPO.java new file mode 100644 index 0000000..efaabd7 --- /dev/null +++ b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/frameworkcore/model/po/SmUserPO.java @@ -0,0 +1,84 @@ +package com.vci.frameworkcore.model.po; + +import com.vci.starter.poi.annotation.ExcelColumn; +import com.vci.starter.web.pagemodel.BaseModelVO; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.Date; + +/** + * 鐢ㄦ埛鐨勫鍏ュ鍑哄璞� + * @author ludc + * @date 2024/7/1 16:53 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class SmUserPO extends BaseModelVO { + + /** + * 绂佹淇敼杩欎釜鍊� + */ + private static final long serialVersionUID = -2239512786206928201L; + + /** + * 鎵�鍦ㄦ暟鎹 + */ + @ExcelColumn(rowIndexColumn = true,value = "") + private String rowIndex; + + /** + * 鐢ㄦ埛鍚� + */ + @ExcelColumn(value="璐﹀彿",nullable = false) + private String id; + + /** + * 鐢ㄦ埛瀵嗙爜 + */ + @ExcelColumn(value="瀵嗙爜",nullable = false) + private String password; + + /** + * 鐢ㄦ埛濮撳悕 + */ + @ExcelColumn(value="濮撳悕",nullable = false) + private String name; + + /** + * 閭欢鍦板潃 + */ + @ExcelColumn(value="鐢靛瓙閭") + private String email; + + /** + * 涓撲笟 + */ + @ExcelColumn(value="涓撲笟") + private String specialties; + + /** + * 鎵�灞為儴闂� + */ + private String pkDepartment; + + /** + * 鎵�灞為儴闂ㄥ悕绉� + */ + @ExcelColumn(value="閮ㄩ棬(涓婁笅绾ч儴闂ㄤ箣闂翠互鍙嶆枩鏉犻殧寮�(/))") + private String pkDepartmentName; + + /** + * 瀵嗙骇 + */ + private Integer secretGrade; + + /** + * 瀵嗙骇鏄剧ず鏂囨湰 + */ + @ExcelColumn(value="瀵嗙骇") + private String secretGradeText; + +} diff --git a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/frameworkcore/properties/ConfigReader.java b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/frameworkcore/properties/ConfigReader.java new file mode 100644 index 0000000..f5c2186 --- /dev/null +++ b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/frameworkcore/properties/ConfigReader.java @@ -0,0 +1,33 @@ +package com.vci.frameworkcore.properties; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + +/** + * corba閰嶇疆鏂囦欢璇诲彇 + * @author ludc + * @date 2024/6/28 23:11 + */ +public class ConfigReader { + + private static Properties properties; + + static { + properties = new Properties(); + try (InputStream input = ConfigReader.class.getClassLoader().getResourceAsStream("properties/corba.properties")) { + if (input == null) { + System.err.println("Unable to find corba.properties"); + } else { + properties.load(input); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static String getConfigValue(String key) { + return properties.getProperty(key); + } + +} -- Gitblit v1.9.3