From 34640adf8a1d16f4202edcad644081b28bf61f1d Mon Sep 17 00:00:00 2001 From: 田源 <lastanimals@163.com> Date: 星期三, 26 六月 2024 17:57:20 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/frameworkcore/compatibility/impl/SmUserQueryServiceImpl.java | 222 +++++++++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 182 insertions(+), 40 deletions(-) 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 2f5a410..9c3d497 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,16 +1,17 @@ package com.vci.frameworkcore.compatibility.impl; import com.vci.client.common.objects.UserObject; -import com.vci.client.common.providers.ClientServiceProvider; import com.vci.common.util.ThreeDES; import com.vci.corba.common.PLException; +import com.vci.corba.common.data.UserEntityInfo; import com.vci.corba.framework.data.UserInfo; import com.vci.corba.omd.data.BusinessObject; import com.vci.frameworkcore.compatibility.OrgDeptQueryServiceI; import com.vci.frameworkcore.compatibility.SmPwdStrategyQueryServiceI; import com.vci.frameworkcore.compatibility.SmRoleQueryServiceI; import com.vci.frameworkcore.compatibility.SmUserQueryServiceI; -import com.vci.frameworkcore.dto.SmUserDTO; +import com.vci.frameworkcore.model.dto.SmUserDTO; +import com.vci.frameworkcore.model.SmUserDO; import com.vci.frameworkcore.pagemodel.OrgDepartmentVO; import com.vci.frameworkcore.pagemodel.SmPasswordStrategyVO; import com.vci.frameworkcore.pagemodel.SmRoleVO; @@ -26,11 +27,8 @@ 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.util.WebThreadLocalUtil; import com.vci.starter.web.wrapper.VciQueryWrapperForDO; import com.vci.web.enumpck.UserTypeEnum; -import com.vci.web.model.SmPasswordStrategyDO; -import com.vci.web.model.SmUserDO; import com.vci.web.service.WebBoServiceI; import com.vci.web.util.Func; import com.vci.web.util.PlatformClientUtil; @@ -38,9 +36,11 @@ 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.regex.Pattern; import java.util.stream.Collectors; import static com.vci.frameworkcore.constant.FrameWorkBusLangCodeConstant.DATA_OID_NOT_EXIST; @@ -171,7 +171,7 @@ * @throws VciBaseException 鏌ヨ鍑洪敊鐨勬椂鍊欎細鎶涘嚭寮傚父 */ private SmUserVO getUserByField(String queryField,String queryValue) throws VciBaseException{ - VciQueryWrapperForDO queryWrapper = new VciQueryWrapperForDO(null,SmUserDO.class,null,true); + VciQueryWrapperForDO queryWrapper = new VciQueryWrapperForDO(null, SmUserDO.class,null,true); queryWrapper.eq(queryWrapper.getTableNick() + "." +queryField,queryValue); queryWrapper.setDistinct(true); queryWrapper.wrapperSql(); @@ -277,7 +277,7 @@ * @param userInfoArr 涓氬姟鏁版嵁鏁扮粍 * @return 鏄剧ず瀵硅薄闆嗗悎 */ - private List<SmUserVO> userInfoArr2VO(UserInfo[] userInfoArr) { + private List<SmUserVO> userInfoArr2VO(UserInfo[] userInfoArr) throws PLException { List<SmUserVO> userVOList = new ArrayList<>(); for(UserInfo userInfo : userInfoArr){ userVOList.add(userInfo2VO(userInfo)); @@ -290,7 +290,10 @@ * @param userInfo 骞冲彴杩斿洖鐨勪笟鍔℃暟鎹� * @return 鐢ㄦ埛鏄剧ず瀵硅薄 */ - private SmUserVO userInfo2VO(UserInfo userInfo) { + private SmUserVO userInfo2VO(UserInfo userInfo) throws PLException { + if(Func.isBlank(userInfo.id)){ + return new SmUserVO(); + } SmUserVO smUserVO = new SmUserVO(); smUserVO.setOid(userInfo.id); smUserVO.setId(userInfo.userName); @@ -302,7 +305,13 @@ smUserVO.setDescription(userInfo.desc); smUserVO.setEmail(userInfo.email); //鐢ㄦ埛鎵�灞為儴闂ㄧ殑鏌ヨ璁剧疆 - List<OrgDepartmentVO> orgDepartmentVOList = orgDepartmentVOMap.get(userInfo.id); + List<OrgDepartmentVO> orgDepartmentVOList; + //鏌ョ湅鍏ㄥ眬鍙橀噺涓槸鍚﹀瓨鍦ㄩ儴闂ㄤ俊鎭紝瀛樺湪鐨勬儏鍐垫渶涓昏鏄拡瀵瑰鏉$敤鎴锋煡璇㈢殑鏃跺�欓伩鍏嶉噸澶嶆煡璇㈢殑 + if(Func.isNotEmpty(orgDepartmentVOMap)){ + orgDepartmentVOList = orgDepartmentVOMap.get(userInfo.id); + }else { + orgDepartmentVOList = orgDeptQueryService.listDeptByUserOid(userInfo.id,null); + } smUserVO.setPkDepartment( Func.isEmpty(orgDepartmentVOList) ? null:orgDepartmentVOList.stream().map(OrgDepartmentVO::getOid).collect(Collectors.joining(",")) @@ -312,11 +321,23 @@ null:orgDepartmentVOList.stream().map(OrgDepartmentVO::getName).collect(Collectors.joining(",")) ); //瀵嗙爜绛栫暐鏌ヨ璁剧疆 - SmPasswordStrategyVO smPasswordStrategyVO = smPwdStrategyVOMap.getOrDefault(userInfo.id,new SmPasswordStrategyVO()); + SmPasswordStrategyVO smPasswordStrategyVO; + if(Func.isNotEmpty(smPwdStrategyVOMap)){ + smPasswordStrategyVO = smPwdStrategyVOMap.getOrDefault(userInfo.id,new SmPasswordStrategyVO()); + }else { + smPasswordStrategyVO = smPwdStrategyQueryService.getPasswordStrategyVOByUserOid(userInfo.id); + //濡傛灉涓嶅瓨鍦ㄥ氨鑾峰彇榛樿鐨� + smPasswordStrategyVO = Func.isNotEmpty(smPasswordStrategyVO) ? smPasswordStrategyVO:smPwdStrategyQueryService.getPasswordStrategyVOByDefault(); + } smUserVO.setPkPasswordStrategy(smPasswordStrategyVO.getOid()); smUserVO.setPkPasswordStrategyName(smPasswordStrategyVO.getName()); //瑙掕壊鏌ヨ璁剧疆 - List<SmRoleVO> smRoleVOList = smRoleVOMap.get(userInfo.id); + List<SmRoleVO> smRoleVOList; + if (Func.isNotEmpty(smRoleVOMap)) { + smRoleVOList = smRoleVOMap.get(userInfo.id); + }else { + smRoleVOList = smRoleQueryService.listRoleByUserOid(userInfo.id,null); + } smUserVO.setPkPerson( Func.isEmpty(smRoleVOList) ? null:smRoleVOList.stream().map(SmRoleVO::getOid).collect(Collectors.joining(",")) @@ -495,6 +516,7 @@ pageHelper = new PageHelper(-1); } pageHelper.addDefaultAsc("PLTRUENAME"); + //TODO:涓轰簡鏂逛究璋冭瘯锛屾墍浠ヨ繖鍎垮厛娉ㄩ噴鍐欐鍚庨潰璁板緱鏇存敼 //String userName = WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserName(); //鍒嗛〉鏌ヨ UserInfo[] userInfos = platformClientUtil.getFrameworkService().fetchUserInfoByCondition( @@ -557,6 +579,7 @@ SmUserVO userVO = getUserByUserId(userId); return userVO == null?"":userVO.getName(); } + /** * 鏍规嵁鐢ㄦ埛涓婚敭鑾峰彇鐢ㄦ埛鐨勫鍚� * @param userOid 鐢ㄦ埛涓婚敭 @@ -928,7 +951,6 @@ return false; } - /** * 璁剧疆鏌愪釜鐢ㄦ埛鏄攣瀹氱姸鎬� * @param userId 鐢ㄦ埛鍚� @@ -960,6 +982,7 @@ * @param confirmPassword 纭瀵嗙爜 */ @Override + @Transactional(rollbackFor = Exception.class) public void changePassword(String userOid, String password, String confirmPassword) throws VciBaseException { WebUtil.alertNotNull(userOid,"鐢ㄦ埛涓婚敭",password,"瀵嗙爜",confirmPassword,"纭瀵嗙爜"); @@ -1017,40 +1040,38 @@ * @return */ @Override + @Transactional(rollbackFor = Exception.class) public boolean addUser(SmUserDTO smUserDTO) throws PLException { + //鍒ょ┖ VciBaseUtil.alertNotNull( smUserDTO,"娣诲姞鐨勭敤鎴峰璞�", - smUserDTO.getId(),"璐﹀彿", + smUserDTO.getId(),"鐢ㄦ埛鍚�", smUserDTO.getPassword(),"瀵嗙爜", smUserDTO.getConfirmPassword(),"纭瀵嗙爜", smUserDTO.getName(),"濮撳悕" ); - //纭瀵嗙爜 - String confirmPassword = smUserDTO.getConfirmPassword(); - //姣斿瀵嗙爜鏄槸鍚︿竴鑷� - if(!smUserDTO.getPassword().equals(confirmPassword)){ - throw new VciBaseException("涓ゆ瀵嗙爜涓嶄竴鑷达紝璇烽噸鏂板~鍐�!"); - } - //鍏堢敤鎴峰悕锛堣处鍙凤級鏌ラ噸 - SmUserVO dbSmUserVO = getUserByUserId(smUserDTO.getId()); - if(Func.isNotEmpty(dbSmUserVO) && Func.isNotBlank(dbSmUserVO.getOid())){ - throw new VciBaseException("璇ョ敤鎴峰悕鍦ㄧ郴缁熶腑宸茬粡瀛樺湪,璇蜂慨鏀�!"); - } - //瀵嗙爜鍔犲瘑 - ThreeDES des = new ThreeDES(); - des.getKey("daliantan0v0");// 鐢熸垚瀵嗗寵 - //绗簩娆D5鍔犲瘑 - String md5Password2 = des.getEncString(smUserDTO.getPassword()); + //鏍¢獙 + check(smUserDTO,true); //鐢熸垚瀛樺偍鐨凞O瀵硅薄 - smUserDTO.setOid(VciBaseUtil.getPk()); - smUserDTO.setPassword(md5Password2); - smUserDTO.setLockFlag("0"); - BusinessObject user = ClientServiceProvider.getBOFService().initBusinessObject("user"); - SmUserDO smUserDO = new SmUserDO(); - BeanUtil.convert(user,smUserDO); - UserInfo userInfo = new UserInfo(); - BeanUtil.convert(smUserDO,userInfo); - return platformClientUtil.getFrameworkService().saveOrUpdateUser(userInfo, null); + 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"); + UserInfo userInfo = changeUserObjectToUserInfo(smUserDTO); + UserEntityInfo userEntityInfo = new UserEntityInfo("developer", ""); + String oid = platformClientUtil.getFrameworkService().saveUser(userInfo, userEntityInfo); + if (Func.isEmpty(oid)) { + return false; + } + if(Func.isNotBlank(smUserDTO.getPkDepartment())){ + platformClientUtil.getFrameworkService().saveUserDept(new String[]{oid}, smUserDTO.getPkDepartment(), userEntityInfo); + } + return true; } /** @@ -1059,10 +1080,129 @@ * @return */ @Override + @Transactional(rollbackFor = Exception.class) public boolean updateUser(SmUserDTO smUserDTO) throws PLException { + //鍒ょ┖ + VciBaseUtil.alertNotNull( + smUserDTO,"淇敼鐨勭敤鎴峰璞�", + smUserDTO.getOid(),"鐢ㄦ埛涓婚敭", + smUserDTO.getId(),"鐢ㄦ埛鍚�", + smUserDTO.getPassword(),"瀵嗙爜", + smUserDTO.getConfirmPassword(),"纭瀵嗙爜", + smUserDTO.getName(),"濮撳悕" + ); + //鏍¢獙 + check(smUserDTO,false); + //鏌ヨ鏁版嵁搴撲腑鐨� + SmUserVO dbSmUserVO = getUserByUserId(smUserDTO.getId()); + //鏍规嵁鐢ㄦ埛鍚嶆煡璇㈠埌浜嗙敤鎴凤紝浣嗘槸oid涓嶆槸褰撳墠淇敼鐨勭敤鎴风殑oid锛岃鏄庝慨鏀圭殑鐢ㄦ埛鍚嶉噸澶� + if(Func.isNotEmpty(dbSmUserVO) + && !dbSmUserVO.getOid().equals(smUserDTO.getOid()) + ){ + throw new PLException("鐢ㄦ埛鍚嶅凡瀛樺湪锛屼笉鑳藉皢褰撳墠鐢ㄦ埛鐨勭敤鎴峰悕淇敼涓�" + dbSmUserVO.getId(),new String[0]); + } + smUserDTO.setLastModifyTime(new Date()); + //userObject.setUpdateUser(WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserName()); + smUserDTO.setLastModifier("developer"); + UserInfo userInfo = changeUserObjectToUserInfo(smUserDTO); + boolean updateBoolean = platformClientUtil.getFrameworkService().updateUser(userInfo, new UserEntityInfo("developer", null)); + //鐢ㄦ埛鍏宠仈閮ㄩ棬鏈夋墍鏇存敼 + if(Func.isNotEmpty(smUserDTO.getPkDepartment()) && !smUserDTO.getPkDepartment().equals(dbSmUserVO.getPkDepartment())){ + //鐣岄潰浼犻�掕繃鏉ョ殑宸插叧鑱旂殑閮ㄩ棬oid + List<String> updatePkDept = Func.toStrList(smUserDTO.getPkDepartment(), ","); + //鐢ㄦ埛宸插叧鑱旂殑閮ㄩ棬oid + List<String> associatedPkDept = Func.toStrList(dbSmUserVO.getPkDepartment(), ","); + //绉婚櫎 + updatePkDept.removeAll(associatedPkDept); + //鎵ц淇濆瓨鐢ㄦ埛閮ㄩ棬鍏宠仈鍏崇郴 + orgDeptQueryService.saveUserDepts(dbSmUserVO.getOid(),updatePkDept); + } + return updateBoolean; + } + + /** + * 妫�鏌ョ敤鎴蜂俊鎭槸鍚︾鍚堣鑼� + * @param smUserDTO + * @param isAdd + */ + private void check(SmUserDTO smUserDTO, boolean isAdd){ + if(!smUserDTO.getPassword().equals(smUserDTO.getConfirmPassword())){ + throw new VciBaseException("瀵嗙爜鍜岀‘璁ゅ瘑鐮佷笉鐩哥瓑"); + } + if(smUserDTO.getId().getBytes().length > 128){ + throw new VciBaseException("鐢ㄦ埛鍚嶉暱搴﹁秴杩囦笂闄�"); + } + if(smUserDTO.getPassword().getBytes().length > 128){ + throw new VciBaseException("瀵嗙爜闀垮害瓒呰繃涓婇檺"); + } + if(smUserDTO.getName().getBytes().length > 64){ + throw new VciBaseException("濮撳悕闀垮害瓒呰繃涓婇檺"); + } + if (Func.isNotBlank(smUserDTO.getSpecialties()) && smUserDTO.getSpecialties().getBytes().length > 255){ + throw new VciBaseException("涓撲笟闀垮害瓒呰繃涓婇檺"); + } + if (Func.isNotBlank(smUserDTO.getEmail()) && smUserDTO.getEmail().getBytes().length > 128){ + throw new VciBaseException("鐢靛瓙閭闀垮害瓒呰繃涓婇檺"); + } + if (Func.isNotBlank(smUserDTO.getDescription()) && smUserDTO.getDescription().getBytes().length > 255 ){ + throw new VciBaseException("鎻忚堪闀垮害瓒呰繃涓婇檺"); + } + if (!smUserDTO.getName().matches("^[A-Za-z0-9_]+$")) { + throw new VciBaseException("鐢ㄦ埛鍚嶅繀椤绘槸鐢盇-Z a-z 0-9 _缁勬垚"); + } + 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){ + //鏍规嵁鐢ㄦ埛鍚嶏紙璐﹀彿锛夋煡閲� + SmUserVO dbSmUserVO = getUserByUserId(smUserDTO.getId()); + if(Func.isNotEmpty(dbSmUserVO) && Func.isNotBlank(dbSmUserVO.getOid())){ + throw new VciBaseException("璇ョ敤鎴峰悕鍦ㄧ郴缁熶腑宸茬粡瀛樺湪,璇蜂慨鏀�!"); + } + } + //鏍规嵁褰撳墠鍒涘缓杩欎釜鐢ㄦ埛鐨勪汉鎵�缁戝畾瀵嗙爜绛栫暐鏉ヨ繘琛屽瘑鐮佹牎楠� + try { + //TODO:涓轰簡鏂逛究璋冭瘯锛屾墍浠ヨ繖鍎垮厛娉ㄩ噴鍐欐鍚庨潰璁板緱鏇存敼 + //String userName = WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserName(); + String userName = "developer"; + String error = platformClientUtil.getFrameworkService().checkPasswordStrategyByUserId(userName, smUserDTO.getPassword(),null); + if (!StringUtils.isBlank(error)) { + throw new VciBaseException("褰撳墠璁剧疆鐨勫瘑鐮侊紝瀵嗙爜绛栫暐鏍¢獙鏈�氳繃"); + } + } catch (PLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + throw new VciBaseException("妫�鏌ュ瘑鐮佺瓥鐣ョ鍚堟儏鍐靛け璐ワ紒2"); + } + } + + + + /*** + * 鐢ㄦ埛浠嶥TO瀵硅薄鍒癱orba瀵硅薄 + * @param user + * @return + */ + public UserInfo changeUserObjectToUserInfo(SmUserDTO user) { UserInfo userInfo = new UserInfo(); - BeanUtil.convert(smUserDTO,userInfo); - return platformClientUtil.getFrameworkService().updateUser(userInfo, null); + userInfo.id = user.getOid() == null ? "" : user.getOid(); + userInfo.userName = user.getId() == null ? "" : user.getId(); + userInfo.pwd = user.getPassword() == null ? "" : user.getPassword(); + userInfo.trueName = user.getName() == null ? "" : user.getName(); + userInfo.specialties = user.getSpecialties() == null ? "" : user.getSpecialties(); + userInfo.email = user.getEmail() == null ? "" : user.getEmail(); + userInfo.desc = user.getDescription() == null ? "" : user.getDescription(); + userInfo.userType = user.getUserType(); + userInfo.status = user.getStatus(); + userInfo.createTime = user.getCreateTime().getTime(); + userInfo.createUser = user.getCreator() == null ? "" : user.getCreator(); + userInfo.updateTime = user.getLastModifyTime().getTime(); + userInfo.updateUser = user.getLastModifier() == null ? "" : user.getLastModifier(); + userInfo.pwdUpdateTime = user.getPwdUpdateTime().getTime(); + userInfo.grantor = user.getGrantor() == null ? "" : user.getGrantor(); + userInfo.isDeptLeader = user.getIsDeptLeader() == null ? "0" : user.getIsDeptLeader(); + return userInfo; } /*** @@ -1098,6 +1238,7 @@ * @return */ @Override + @Transactional(rollbackFor = Exception.class) public boolean deleteUser(String[] ids) throws PLException { VciBaseUtil.alertNotNull(ids,"寰呭垹闄ょ殑鐢ㄦ埛id鍒楄〃涓嶈兘涓虹┖锛�"); return platformClientUtil.getFrameworkService().deleteUser(ids, null); @@ -1110,6 +1251,7 @@ * @return */ @Override + @Transactional(rollbackFor = Exception.class) public boolean disableOrEnableUsers(String[] ids, boolean flag) throws PLException { VciBaseUtil.alertNotNull(ids,"鍋滅敤/鍚敤鐨勭敤鎴穒d鍒楄〃"); return platformClientUtil.getFrameworkService().stopUsers(ids, flag,null); -- Gitblit v1.9.3