| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | @Override |
| | | public boolean checkUserExist(String userName, String oid) throws PLException { |
| | | if(Func.isEmpty(userName) && Func.isEmpty(oid)){ |
| | | throw new PLException("检查用户是否存在时,传递的参数用户名和用户oid都为空!",new String[0]); |
| | | throw new PLException("500", new String[] { "检查用户是否存在时,传递的参数用户名和用户oid都为空!"}); |
| | | } |
| | | UserInfo userInfo = null; |
| | | if(Func.isNotEmpty(userName)) { |
| | |
| | | * @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(); |
| | |
| | | * @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)); |
| | |
| | | * @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); |
| | |
| | | smUserVO.setUserTypeText(UserTypeEnum.getTextByValue(smUserVO.getUserType())); |
| | | smUserVO.setDescription(userInfo.desc); |
| | | smUserVO.setEmail(userInfo.email); |
| | | smUserVO.setStatus(userInfo.status); |
| | | smUserVO.setPassword(userInfo.pwd); |
| | | //用户所属部门的查询设置 |
| | | 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(",")) |
| | |
| | | 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(",")) |
| | |
| | | pageHelper = new PageHelper(-1); |
| | | } |
| | | pageHelper.addDefaultAsc("PLTRUENAME"); |
| | | //TODO:为了方便调试,所以这儿先注释写死后面记得更改 |
| | | //String userName = WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserName(); |
| | | //分页查询 |
| | | UserInfo[] userInfos = platformClientUtil.getFrameworkService().fetchUserInfoByCondition( |
| | | conditionMap.get("name"), |
| | | conditionMap.get("userName"), |
| | | conditionMap.get("deptId"), |
| | | conditionMap.get("roleId"), |
| | | conditionMap.get("id"), |
| | | conditionMap.get("pkDepartment"), |
| | | conditionMap.get("pkPerson"), |
| | | "developer", //当前登录的用户名 |
| | | pageHelper.getPage(), |
| | | pageHelper.getLimit() |
| | |
| | | dataGrid.setTotal( |
| | | platformClientUtil.getFrameworkService().getUserTotalByCondition( |
| | | conditionMap.get("name"), |
| | | conditionMap.get("userName"), |
| | | conditionMap.get("deptId"), |
| | | conditionMap.get("roleId"), |
| | | conditionMap.get("id"), |
| | | conditionMap.get("pkDepartment"), |
| | | conditionMap.get("pkPerson"), |
| | | "developer" //当前登录的用户名 |
| | | ) |
| | | ); |
| | |
| | | SmUserVO userVO = getUserByUserId(userId); |
| | | return userVO == null?"":userVO.getName(); |
| | | } |
| | | |
| | | /** |
| | | * 根据用户主键获取用户的姓名 |
| | | * @param userOid 用户主键 |
| | |
| | | return false; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 设置某个用户是锁定状态 |
| | | * @param userId 用户名 |
| | |
| | | * @param confirmPassword 确认密码 |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void changePassword(String userOid, String password, |
| | | String confirmPassword) throws VciBaseException { |
| | | WebUtil.alertNotNull(userOid,"用户主键",password,"密码",confirmPassword,"确认密码"); |
| | |
| | | * @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");// 生成密匙 |
| | | //第二次MD5加密 |
| | | String md5Password2 = des.getEncString(smUserDTO.getPassword()); |
| | | //校验 |
| | | check(smUserDTO,true); |
| | | //生成存储的DO对象 |
| | | 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 = changeSmUserDTOToUserInfo(smUserDTO); |
| | | UserEntityInfo userEntityInfo = new UserEntityInfo("developer", ""); |
| | | String oid = platformClientUtil.getFrameworkService().saveUser(userInfo, userEntityInfo); |
| | | if (Func.isEmpty(oid)) { |
| | | return false; |
| | | } |
| | | if(Func.isNotBlank(smUserDTO.getPkDepartment())){ |
| | | //执行保存用户部门关联关系 |
| | | orgDeptQueryService.saveUsersDept(new String[]{oid},smUserDTO.getPkDepartment()); |
| | | //platformClientUtil.getFrameworkService().saveUserDept(new String[]{oid}, smUserDTO.getPkDepartment(), userEntityInfo); |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | |
| | | * @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 = getUserByUserOid(smUserDTO.getOid()); |
| | | //根据主键没查询到了用户 |
| | | if(Func.isEmpty(dbSmUserVO) || Func.isBlank(dbSmUserVO.getOid())){ |
| | | throw new PLException("500", new String[] { "当前修改的用户不存在"}); |
| | | } |
| | | |
| | | smUserDTO.setLastModifyTime(new Date()); |
| | | //userObject.setUpdateUser(WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserName()); |
| | | smUserDTO.setLastModifier("developer"); |
| | | UserInfo userInfo = changeSmUserDTOToUserInfo(smUserDTO); |
| | | boolean updateBoolean = platformClientUtil.getFrameworkService().updateUser(userInfo, new UserEntityInfo("developer", null)); |
| | | //修改成功,并且用户关联部门有所更改 |
| | | if(updateBoolean && Func.isNotEmpty(smUserDTO.getPkDepartment()) && !smUserDTO.getPkDepartment().equals(dbSmUserVO.getPkDepartment())){ |
| | | //执行保存用户部门关联关系 |
| | | orgDeptQueryService.saveUsersDept(new String[]{dbSmUserVO.getOid()},smUserDTO.getPkDepartment()); |
| | | } |
| | | 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.getId().matches("^[A-Za-z0-9_]+$")) { |
| | | throw new VciBaseException("用户名必须是由A-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"); |
| | | } |
| | | } |
| | | |
| | | /*** |
| | | * 用户从DTO对象到corba对象 |
| | | * @param user |
| | | * @return |
| | | */ |
| | | public UserInfo changeSmUserDTOToUserInfo(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; |
| | | } |
| | | |
| | | /*** |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean deleteUser(String[] ids) throws PLException { |
| | | VciBaseUtil.alertNotNull(ids,"待删除的用户id列表不能为空!"); |
| | | if(Func.isEmpty(ids)){ |
| | | throw new VciBaseException("待删除的用户id列表不能为空!"); |
| | | } |
| | | //调用platformClientUtil的删除用户的方法,会一起删除掉具备关联关系的一些信息,如部门 |
| | | return platformClientUtil.getFrameworkService().deleteUser(ids, null); |
| | | } |
| | | |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | public boolean disableOrEnableUsers(String[] ids, boolean flag) throws PLException { |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean stopUsers(String[] ids, boolean flag) throws PLException { |
| | | VciBaseUtil.alertNotNull(ids,"停用/启用的用户id列表"); |
| | | return platformClientUtil.getFrameworkService().stopUsers(ids, flag,null); |
| | | } |
| | | |
| | | @Override |
| | | public void downloadImportTemplate() { |
| | | |
| | | } |
| | | |
| | | } |