|
|
@@ -1,266 +1,331 @@
|
|
|
package cn.tr.module.sys.user.service.impl;
|
|
|
|
|
|
-import cn.hutool.core.collection.CollectionUtil;
|
|
|
-import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.dev33.satoken.exception.NotPermissionException;
|
|
|
+import cn.dev33.satoken.session.SaSession;
|
|
|
+import cn.dev33.satoken.stp.StpLogic;
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
-import cn.tr.core.annotation.TenantIgnore;
|
|
|
-import cn.tr.core.exception.ServiceException;
|
|
|
-import cn.tr.core.exception.TRExcCode;
|
|
|
-import cn.tr.core.utils.PswUtils;
|
|
|
-import cn.tr.module.sys.config.SysConfigManager;
|
|
|
-import cn.tr.module.sys.user.constant.UserType;
|
|
|
-import cn.tr.module.sys.user.dto.SysUserPortalListDTO;
|
|
|
-import cn.tr.module.sys.user.mapper.SysUserMapper;
|
|
|
-import cn.tr.module.sys.user.dto.SysUserDTO;
|
|
|
-import cn.tr.module.sys.user.dto.SysUserEditDTO;
|
|
|
-import cn.tr.module.sys.user.dto.SysUserQueryDTO;
|
|
|
+import cn.tr.module.common.menus.StatusEnum;
|
|
|
+import cn.tr.module.common.menus.YesNoEnum;
|
|
|
+import cn.tr.module.common.utils.Constants;
|
|
|
+import cn.tr.module.sys.exception.CustomException;
|
|
|
+import cn.tr.module.sys.oauth2.bean.LoginUser;
|
|
|
+import cn.tr.module.sys.oauth2.bean.SysRoleInfo;
|
|
|
+import cn.tr.module.sys.oauth2.utils.SecurityUtil;
|
|
|
+import cn.tr.module.sys.user.dto.*;
|
|
|
+import cn.tr.module.sys.user.po.*;
|
|
|
import cn.tr.module.sys.user.repository.SysUserRepository;
|
|
|
-import cn.tr.module.sys.user.service.ISysUserPortalService;
|
|
|
-import cn.tr.module.sys.user.service.ISysUserPositionService;
|
|
|
-import cn.tr.module.sys.user.service.ISysUserRoleService;
|
|
|
-import cn.tr.module.sys.user.service.ISysUserService;
|
|
|
-import cn.tr.module.sys.user.po.SysUserPO;
|
|
|
+import cn.tr.module.sys.user.service.*;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import jakarta.annotation.Resource;
|
|
|
+import lombok.SneakyThrows;
|
|
|
+import org.apache.commons.compress.utils.Lists;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
-import java.util.*;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+import jakarta.annotation.Resource;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.concurrent.CompletableFuture;
|
|
|
import java.util.stream.Collectors;
|
|
|
-import cn.hutool.core.lang.Pair;
|
|
|
+
|
|
|
/**
|
|
|
- * @ClassName : SysUserServiceImpl
|
|
|
- * @Description :
|
|
|
- * @Author : LF
|
|
|
- * @Date: 2023年03月31日
|
|
|
+ * <p>
|
|
|
+ * 用户表 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author Kevin
|
|
|
+ * @since 2021-06-10
|
|
|
*/
|
|
|
@Service
|
|
|
-public class SysUserServiceImpl extends ServiceImpl<SysUserRepository,SysUserPO> implements ISysUserService {
|
|
|
+public class SysUserServiceImpl extends ServiceImpl<SysUserRepository, SysUserPO> implements ISysUserService {
|
|
|
|
|
|
@Resource
|
|
|
- @Lazy
|
|
|
- private ISysUserService userService;
|
|
|
- @Resource
|
|
|
- @Lazy
|
|
|
- private ISysUserRoleService userRoleService;
|
|
|
- @Resource
|
|
|
- @Lazy
|
|
|
- private ISysUserPortalService userPortalService;
|
|
|
+ private ISysUserRoleService sysUserRoleService;
|
|
|
+
|
|
|
@Resource
|
|
|
- @Lazy
|
|
|
- private ISysUserPositionService userPositionService;
|
|
|
+ private ISysUserPostService sysUserPostService;
|
|
|
+
|
|
|
+ @Autowired(required = false) // 使用自动装配并允许为空,避免启动时立即创建依赖
|
|
|
+ @Lazy // 使用懒加载避免循环依赖
|
|
|
+ private ISysDeptService sysDeptService;
|
|
|
+
|
|
|
@Resource
|
|
|
- @Lazy
|
|
|
- private SysConfigManager configManager;
|
|
|
+ private ISysMenuService sysMenuService;
|
|
|
|
|
|
@Resource
|
|
|
- @Lazy
|
|
|
- private ISysUserService sysUserService;
|
|
|
+ private ISysRoleService sysRoleService;
|
|
|
|
|
|
- @Override
|
|
|
- public List<SysUserDTO> selectSysUserList(SysUserQueryDTO query) {
|
|
|
- return SysUserMapper.INSTANCE.toUserDTOList(baseMapper.selectList(
|
|
|
- new LambdaQueryWrapper<SysUserPO>()
|
|
|
- .eq(StrUtil.isNotEmpty(query.getStatus()),SysUserPO::getStatus,query.getStatus())
|
|
|
- .eq(StrUtil.isNotEmpty(query.getOrgId()),SysUserPO::getOrgId,query.getOrgId())
|
|
|
- .like(StrUtil.isNotEmpty(query.getNickname()),SysUserPO::getNickname,query.getNickname())
|
|
|
- .like(StrUtil.isNotEmpty(query.getPhone()),SysUserPO::getPhone,query.getPhone())
|
|
|
- .like(StrUtil.isNotEmpty(query.getUsername()),SysUserPO::getUsername,query.getUsername())
|
|
|
- ));
|
|
|
- }
|
|
|
|
|
|
@Override
|
|
|
- public SysUserDTO selectSysUserById(String id) {
|
|
|
- SysUserDTO result = SysUserMapper.INSTANCE.toUserDTO(baseMapper.selectById(id));
|
|
|
- if(result==null){
|
|
|
- return result;
|
|
|
+ public IPage<SysUserPO> page(Page reqPage, SysUserQueryDTO req) {
|
|
|
+ List<SysDeptPO> sysDeptList = Lists.newArrayList();
|
|
|
+ if (StrUtil.isNotBlank(req.getDeptId()) && sysDeptService != null) {
|
|
|
+ sysDeptList = sysDeptService.list(Wrappers.lambdaQuery(SysDeptPO.class).apply("find_in_set({0}, ancestors)", req.getDeptId()));
|
|
|
+ }
|
|
|
+ List<String> sysDeptIdList = sysDeptList.stream().map(item -> String.valueOf(item.getId())).collect(Collectors.toList());
|
|
|
+ LambdaQueryWrapper<SysUserPO> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.like(StrUtil.isNotBlank(req.getAccount()), SysUserPO::getAccount, req.getAccount());
|
|
|
+ queryWrapper.like(StrUtil.isNotBlank(req.getNickname()), SysUserPO::getNickname, req.getNickname());
|
|
|
+ queryWrapper.like(StrUtil.isNotBlank(req.getRealname()), SysUserPO::getRealname, req.getRealname());
|
|
|
+ queryWrapper.like(StrUtil.isNotBlank(req.getEnglishName()), SysUserPO::getEnglishName, req.getEnglishName());
|
|
|
+ queryWrapper.like(StrUtil.isNotBlank(req.getEmail()), SysUserPO::getEmail, req.getEmail());
|
|
|
+ queryWrapper.like(StrUtil.isNotBlank(req.getPhone()), SysUserPO::getPhone, req.getPhone());
|
|
|
+ queryWrapper.like(StrUtil.isNotBlank(req.getStaffNumber()), SysUserPO::getStaffNumber, req.getStaffNumber());
|
|
|
+ queryWrapper.eq(SysUserPO::getStatus, StatusEnum.YES.getValue());
|
|
|
+ queryWrapper.and(StrUtil.isNotBlank(req.getDeptId()), wrapper -> wrapper.eq(SysUserPO::getDeptId, req.getDeptId())
|
|
|
+ .or(!CollectionUtils.isEmpty(sysDeptIdList), wrapper2 -> wrapper2.in(SysUserPO::getDeptId, sysDeptIdList)));
|
|
|
+ queryWrapper.orderByAsc(SysUserPO::getCreateTime);
|
|
|
+ IPage<SysUserPO> page = this.page(reqPage, queryWrapper);
|
|
|
+ if(sysDeptService != null) {
|
|
|
+ page.getRecords().forEach(item -> {
|
|
|
+ // 设置部门名称
|
|
|
+ SysDeptPO sysDept = sysDeptService.getById(item.getDeptId());
|
|
|
+ item.setDeptName(Objects.isNull(sysDept) ? null : sysDept.getDeptName());
|
|
|
+ });
|
|
|
}
|
|
|
- result.setRoleIds(userRoleService.findRoleIdsByUserId(id));
|
|
|
- result.setPortalIds(userPortalService.findPortalsByUserId(id).stream()
|
|
|
- .map(SysUserPortalListDTO::getId).collect(Collectors.toSet()));
|
|
|
- result.setPostIds(userPositionService.findPositionIdsByUserId(id));
|
|
|
- return result;
|
|
|
+ return page;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Pair<String,String> selectNickNameAndAvatarById(String userId) {
|
|
|
- SysUserPO user = getById(userId);
|
|
|
- if(user==null){
|
|
|
- return null;
|
|
|
+ public List<SysUserPO> list(SysUserQueryDTO req) {
|
|
|
+ LambdaQueryWrapper<SysUserPO> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.like(StrUtil.isNotBlank(req.getAccount()), SysUserPO::getAccount, req.getAccount());
|
|
|
+ queryWrapper.like(StrUtil.isNotBlank(req.getNickname()), SysUserPO::getNickname, req.getNickname());
|
|
|
+ queryWrapper.like(StrUtil.isNotBlank(req.getRealname()), SysUserPO::getRealname, req.getRealname());
|
|
|
+ queryWrapper.like(StrUtil.isNotBlank(req.getEnglishName()), SysUserPO::getEnglishName, req.getEnglishName());
|
|
|
+ queryWrapper.like(StrUtil.isNotBlank(req.getEmail()), SysUserPO::getEmail, req.getEmail());
|
|
|
+ queryWrapper.like(StrUtil.isNotBlank(req.getPhone()), SysUserPO::getPhone, req.getPhone());
|
|
|
+ queryWrapper.like(StrUtil.isNotBlank(req.getStaffNumber()), SysUserPO::getStaffNumber, req.getStaffNumber());
|
|
|
+ queryWrapper.like(StrUtil.isNotBlank(req.getDeptId()), SysUserPO::getDeptId, req.getDeptId());
|
|
|
+ queryWrapper.eq(SysUserPO::getStatus, StatusEnum.YES.getValue());
|
|
|
+ queryWrapper.orderByAsc(SysUserPO::getCreateTime);
|
|
|
+ List<SysUserPO> list = this.list(queryWrapper);
|
|
|
+ if(sysDeptService != null) {
|
|
|
+ list.forEach(item -> {
|
|
|
+ SysDeptPO sysDept = sysDeptService.getById(item.getDeptId());
|
|
|
+ item.setDeptName(Objects.isNull(sysDept) ? null : sysDept.getDeptName());
|
|
|
+ });
|
|
|
}
|
|
|
- return Pair.of(user.getNickname(),user.getGender());
|
|
|
+ return list;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public boolean updateSysUserById(SysUserEditDTO source) {
|
|
|
- SysUserPO po = SysUserMapper.INSTANCE.toUserPO(source);
|
|
|
- boolean result= baseMapper.updateById(po)!=0;
|
|
|
- if(result){
|
|
|
- assignUserRole(source.getId(),source.getRoleIds());
|
|
|
- assignUserPortal(source.getId(),source.getPortalIds());
|
|
|
- assignUserPosition(source.getId(),source.getPostIds());
|
|
|
+ public void add(SysUserAddDTO req) {
|
|
|
+ if (!this.checkUniqueAccount(req.getAccount(), null)) {
|
|
|
+ throw new CustomException("账号已存在");
|
|
|
}
|
|
|
- sysUserService.delNickNameAndAvatarCache(source.getId());
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public SysUserDTO selectUserByUsername(String username) {
|
|
|
- return SysUserMapper.INSTANCE.toUserDTO(baseMapper.selectOne(new LambdaQueryWrapper<SysUserPO>()
|
|
|
- .eq(SysUserPO::getUsername,username)
|
|
|
- .last("limit 1")));
|
|
|
- }
|
|
|
+// if (!this.checkUniqueEmail(req.getEmail(), null)) {
|
|
|
+// throw new CustomException("邮箱已存在");
|
|
|
+// }
|
|
|
+// if (!this.checkUniquePhone(req.getPhone(), null)) {
|
|
|
+// throw new CustomException("手机号已存在");
|
|
|
+// }
|
|
|
+// if (!this.checkUniqueStaffNumber(req.getStaffNumber(), null)) {
|
|
|
+// throw new CustomException("工号已存在");
|
|
|
+// }
|
|
|
+ LoginUser loginUser = SecurityUtil.getLoginUser();
|
|
|
+ if(!Boolean.TRUE.equals(loginUser.isSys())&&Boolean.TRUE.equals(req.getIsSys())){
|
|
|
+ throw new NotPermissionException("无权设置系统用户");
|
|
|
+ }
|
|
|
+ SysUserPO entity = BeanUtil.copyProperties(req, SysUserPO.class);
|
|
|
+ // 密码加密
|
|
|
+ entity.setPassword(SecurityUtil.encryptPassword(entity.getPassword()));
|
|
|
+ entity.setPswModified(YesNoEnum.NO.getCode());
|
|
|
+ this.save(entity);
|
|
|
|
|
|
- @Override
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public boolean updatePsw(String userId, String oldPsw, String newPsw) {
|
|
|
- SysUserPO user = baseMapper.selectById(userId);
|
|
|
- if(user==null){
|
|
|
- return true;
|
|
|
+ // 删除用户与岗位关联
|
|
|
+ sysUserPostService.remove(Wrappers.lambdaQuery(SysUserPostPO.class).eq(SysUserPostPO::getUserId, entity.getId()));
|
|
|
+ // 新增用户与岗位关联
|
|
|
+ if (Objects.nonNull(req.getPostIds())) {
|
|
|
+ List<SysUserPostPO> sysUserPostList = req.getPostIds().stream().map(item -> {
|
|
|
+ SysUserPostPO sysUserPost = new SysUserPostPO();
|
|
|
+ sysUserPost.setUserId(entity.getId());
|
|
|
+ sysUserPost.setPostId(item);
|
|
|
+ return sysUserPost;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ sysUserPostService.saveBatch(sysUserPostList);
|
|
|
}
|
|
|
- if (StrUtil.isNotBlank(user.getPassword())&&!PswUtils.matchesPassword(oldPsw, user.getPassword())) {
|
|
|
- throw new ServiceException(TRExcCode.SYSTEM_ERROR_B0001,"旧密码错误");
|
|
|
+
|
|
|
+ // 删除用户与角色关联
|
|
|
+ sysUserRoleService.remove(Wrappers.lambdaQuery(SysUserRolePO.class).eq(SysUserRolePO::getUserId, entity.getId()));
|
|
|
+ // 新增用户与角色关联
|
|
|
+ if (Objects.nonNull(req.getRoleIds())) {
|
|
|
+ List<SysUserRolePO> sysUserRoleList = req.getRoleIds().stream().map(item -> {
|
|
|
+ SysUserRolePO sysUserRole = new SysUserRolePO();
|
|
|
+ sysUserRole.setUserId(entity.getId());
|
|
|
+ sysUserRole.setRoleId(item);
|
|
|
+ return sysUserRole;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ sysUserRoleService.saveBatch(sysUserRoleList);
|
|
|
}
|
|
|
- SysUserPO updateUser = new SysUserPO();
|
|
|
- updateUser.setId(user.getId());
|
|
|
- updateUser.setPassword(PswUtils.encryptPassword(newPsw));
|
|
|
- return baseMapper.updateById(updateUser) != 0;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public boolean insertSysUser(SysUserDTO source) {
|
|
|
- boolean result=false;
|
|
|
- SysUserPO insertUser = SysUserMapper.INSTANCE.toUserPO(source);
|
|
|
- insertUser.setType(UserType.NORMAL);
|
|
|
- insertUser.setPassword(PswUtils.encryptPassword(insertUser.getPassword()));
|
|
|
- //所有租户下的正常使用的账号
|
|
|
- List<SysUserDTO> allUsingUser = userService.selectUserByUsernameIgnoreTenant(source.getUsername());
|
|
|
- if(CollectionUtil.isNotEmpty(allUsingUser)){
|
|
|
- throw new ServiceException(TRExcCode.SYSTEM_ERROR_B0001,String.format("系统中已存在账户{%s},不可重复添加",source.getUsername()));
|
|
|
+ public void edit(SysUserEditDTO req) {
|
|
|
+ if (!this.checkUniqueAccount(req.getAccount(), req.getId())) {
|
|
|
+ throw new CustomException("账号已存在");
|
|
|
}
|
|
|
- //当前租户下的账号
|
|
|
- SysUserPO delUser = baseMapper.selectUserByUsernameIgnoreDel(source.getUsername());
|
|
|
- if(delUser==null){
|
|
|
- result= baseMapper.insert(insertUser)!=0;
|
|
|
- }else {
|
|
|
- if(Boolean.TRUE.equals(delUser.getDeleted())){
|
|
|
- baseMapper.recoverBatch(Arrays.asList(delUser));
|
|
|
- result= baseMapper.updateById(insertUser)!=0;
|
|
|
- }else {
|
|
|
- throw new ServiceException(TRExcCode.SYSTEM_ERROR_B0001,String.format("当前租户中已存在账户{%s},不可重复添加",source.getUsername()));
|
|
|
+ if(Boolean.TRUE.equals(req.getIsSys())){
|
|
|
+ try {
|
|
|
+ LoginUser loginUser =SecurityUtil.getLoginUser();
|
|
|
+ if(!Boolean.TRUE.equals(loginUser.isSys())){
|
|
|
+ throw new CustomException("当前用户没有操作系统级别用户的权限");
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ throw new CustomException("当前用户没有操作系统级别用户的权限");
|
|
|
}
|
|
|
}
|
|
|
- source.setId(insertUser.getId());
|
|
|
- if(result){
|
|
|
- assignUserRole(source.getId(),source.getRoleIds());
|
|
|
- assignUserPortal(source.getId(),source.getPortalIds());
|
|
|
- assignUserPosition(source.getId(),source.getPostIds());
|
|
|
- sysUserService.delUserIdAndNickNameCache();
|
|
|
+ // 当前用户不是超级管理员,不允许修改
|
|
|
+ if (!SecurityUtil.getId().equals(req.getId()) && SecurityUtil.isSysSuperAdmin(req.getId())) {
|
|
|
+ throw new CustomException("超管账户不允许修改");
|
|
|
+ }
|
|
|
+ SysUserPO entity = BeanUtil.copyProperties(req, SysUserPO.class);
|
|
|
+ this.updateById(entity);
|
|
|
+ // 删除用户与岗位关联
|
|
|
+ sysUserPostService.remove(Wrappers.lambdaQuery(SysUserPostPO.class).eq(SysUserPostPO::getUserId, entity.getId()));
|
|
|
+ // 新增用户与岗位关联
|
|
|
+ if (Objects.nonNull(req.getPostIds())) {
|
|
|
+ List<SysUserPostPO> sysUserPostList = req.getPostIds().stream().map(item -> {
|
|
|
+ SysUserPostPO sysUserPost = new SysUserPostPO();
|
|
|
+ sysUserPost.setUserId(entity.getId());
|
|
|
+ sysUserPost.setPostId(item);
|
|
|
+ return sysUserPost;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ sysUserPostService.saveBatch(sysUserPostList);
|
|
|
}
|
|
|
- return result;
|
|
|
- }
|
|
|
|
|
|
- @Override
|
|
|
- public String insertWxUserAndReturnId(SysUserDTO source,String appId) {
|
|
|
- SysUserPO insertUser = SysUserMapper.INSTANCE.toUserPO(source);
|
|
|
- insertUser.setType(UserType.NORMAL);
|
|
|
- //所有租户下的正常使用的账号
|
|
|
- SysUserPO user = baseMapper.selectOne(new LambdaQueryWrapper<SysUserPO>()
|
|
|
- .eq(SysUserPO::getOpenId, source.getOpenId())
|
|
|
-// .eq(SysUserPO::getAppId, appId)
|
|
|
- .last("limit 1"));
|
|
|
- if(ObjectUtil.isNotEmpty(user)){
|
|
|
- insertUser.setId(user.getId());
|
|
|
- baseMapper.updateById(user);
|
|
|
- return user.getId();
|
|
|
- }else {
|
|
|
- baseMapper.insert(insertUser);
|
|
|
- return insertUser.getId();
|
|
|
+ // 删除用户与角色关联
|
|
|
+ sysUserRoleService.remove(Wrappers.lambdaQuery(SysUserRolePO.class).eq(SysUserRolePO::getUserId, entity.getId()));
|
|
|
+ // 新增用户与角色关联
|
|
|
+ if (Objects.nonNull(req.getRoleIds())) {
|
|
|
+ List<SysUserRolePO> sysUserRoleList = req.getRoleIds().stream().map(item -> {
|
|
|
+ SysUserRolePO sysUserRole = new SysUserRolePO();
|
|
|
+ sysUserRole.setUserId(entity.getId());
|
|
|
+ sysUserRole.setRoleId(item);
|
|
|
+ return sysUserRole;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ sysUserRoleService.saveBatch(sysUserRoleList);
|
|
|
+
|
|
|
+ //更新缓存用户权限信息
|
|
|
+ Set<String> permissionsByUserId = sysMenuService.getPermissionsByUserId(req.getId());
|
|
|
+ List<String> tokens = SecurityUtil.getStpLogic().getTokenValueListByLoginId(req.getId());
|
|
|
+ List<SysRolePO> sysRoleList = sysRoleService.listSysRoleByUserId(req.getId());
|
|
|
+ StpLogic stpLogic = SecurityUtil.getStpLogic();
|
|
|
+ tokens.parallelStream()
|
|
|
+ .forEach(token->{
|
|
|
+ SaSession tokenSessionByToken = stpLogic.getTokenSessionByToken(token);
|
|
|
+ LoginUser user = (LoginUser) tokenSessionByToken.get(Constants.LOGIN_USER_KEY);
|
|
|
+ if(user!=null){
|
|
|
+ user.setPermissions(permissionsByUserId);
|
|
|
+ user.setRoles(sysRoleList.stream().map(item -> BeanUtil.copyProperties(item, SysRoleInfo.class)).collect(Collectors.toList()));
|
|
|
+ tokenSessionByToken.set(Constants.LOGIN_USER_KEY,user);
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- @TenantIgnore
|
|
|
- public List<SysUserDTO> selectUserByUsernameIgnoreTenant(String username) {
|
|
|
- return SysUserMapper.INSTANCE.toUserDTOList(baseMapper.selectList(new LambdaQueryWrapper<SysUserPO>()
|
|
|
- .eq(SysUserPO::getUsername,username)));
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void remove(Long id) {
|
|
|
+ sysUserRoleService.remove(new QueryWrapper<SysUserRolePO>()
|
|
|
+ .lambda().eq(SysUserRolePO::getUserId,id));
|
|
|
+ this.removeById(id);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public int deleteSysUserByIds(Collection<String> ids) {
|
|
|
- if(CollectionUtil.isEmpty(ids)){
|
|
|
- throw new ServiceException(TRExcCode.SYSTEM_ERROR_B0001,"请选择要删除的数据");
|
|
|
+ public SysUserPO view(String id) {
|
|
|
+ SysUserPO sysUser = this.getById(id);
|
|
|
+ if(sysUser==null){
|
|
|
+ throw new CustomException("查询用户不存在");
|
|
|
}
|
|
|
- int result = baseMapper.deleteByIds(ids);
|
|
|
- sysUserService.delUserIdAndNickNameCache();
|
|
|
- return result;
|
|
|
- }
|
|
|
+ List<SysUserRolePO> sysUserRoleList = sysUserRoleService.list(Wrappers.lambdaQuery(SysUserRolePO.class)
|
|
|
+ .eq(SysUserRolePO::getUserId, sysUser.getId()));
|
|
|
+ sysUser.setRoleIds(sysUserRoleList.stream().map(item2 -> item2.getRoleId().toString()).collect(Collectors.toList()));
|
|
|
|
|
|
- @Override
|
|
|
- @TenantIgnore
|
|
|
- public boolean isValidUsername(String userId, String username) {
|
|
|
- return baseMapper.selectCount(new LambdaQueryWrapper<SysUserPO>()
|
|
|
- .ne(StrUtil.isNotEmpty(userId),SysUserPO::getId,userId)
|
|
|
- .eq(SysUserPO::getUsername,username))==0;
|
|
|
+ List<SysUserPostPO> sysUserPostList = sysUserPostService.list(Wrappers.lambdaQuery(SysUserPostPO.class)
|
|
|
+ .eq(SysUserPostPO::getUserId, sysUser.getId()));
|
|
|
+ sysUser.setPostIds(sysUserPostList.stream().map(item2 -> item2.getPostId().toString()).collect(Collectors.toList()));
|
|
|
+ return sysUser;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public boolean resetPsw(Collection<String> userIds) {
|
|
|
- String defaultPsw = configManager.getCurrent().getDefaultPsw();
|
|
|
- String password = PswUtils.encryptPassword(defaultPsw);
|
|
|
- List<SysUserPO> users = baseMapper.selectByIds(userIds);
|
|
|
- for (SysUserPO user : users) {
|
|
|
- user.setPassword(password);
|
|
|
- }
|
|
|
- this.updateBatchById(users);
|
|
|
- return true;
|
|
|
+ public void resetPwd(SysUserResetPwdDTO<Long> req) {
|
|
|
+ SysUserPO entity = BeanUtil.copyProperties(req, SysUserPO.class);
|
|
|
+ // 密码加密
|
|
|
+ entity.setPassword(SecurityUtil.encryptPassword(entity.getPassword()));
|
|
|
+ entity.setPswModified(YesNoEnum.YES.getCode());
|
|
|
+ this.updateById(entity);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 根据用户id查询用户信息
|
|
|
+ * @param userId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@Override
|
|
|
- public void updateLastLoginInfo(String id, Date loginTime, String ip, String cityInfo) {
|
|
|
- SysUserPO user = this.getById(id);
|
|
|
- user.setLastLoginDate(loginTime);
|
|
|
- user.setLastLoginIp(ip);
|
|
|
- user.setLastLoginAddress(cityInfo);
|
|
|
- this.updateById(user);
|
|
|
- sysUserService.delUserIdAndNickNameCache();
|
|
|
+ public SysUserDTO selectSysUserById(String userId) {
|
|
|
+ SysUserPO byId = this.getById(userId);
|
|
|
+ return BeanUtil.copyProperties(byId, SysUserDTO.class);
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public List<Pair<String, String>> selectAllUserIdAndNickName() {
|
|
|
- List<SysUserPO> allUser = baseMapper.selectList(new LambdaQueryWrapper<SysUserPO>()
|
|
|
- .select(SysUserPO::getId, SysUserPO::getNickname));
|
|
|
- List<Pair<String, String>> result = new ArrayList<>();
|
|
|
- for (SysUserPO userPO : allUser) {
|
|
|
- result.add(Pair.of(userPO.getId(),userPO.getNickname()));
|
|
|
+ @SneakyThrows
|
|
|
+ private Boolean checkUniqueAccount(String value, Long id){
|
|
|
+ if (StrUtil.isBlank(value)) {
|
|
|
+ return true;
|
|
|
}
|
|
|
- return result;
|
|
|
+ id = Objects.isNull(id) ? -1L : id;
|
|
|
+ SysUserPO entity = CompletableFuture.supplyAsync(() ->
|
|
|
+ getOne(Wrappers.lambdaQuery(SysUserPO.class)
|
|
|
+ .select(SysUserPO::getId, SysUserPO::getAccount)
|
|
|
+ .eq(SysUserPO::getAccount, value)
|
|
|
+ .eq(SysUserPO::getDelFlag,"0"))
|
|
|
+ ).get();
|
|
|
+
|
|
|
+
|
|
|
+ return Objects.isNull(entity) || entity.getId().longValue() == id.longValue();
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public SysUserDTO selectUserByOpenId(String openId) {
|
|
|
- SysUserPO userPO = baseMapper.selectOne(new LambdaQueryWrapper<SysUserPO>()
|
|
|
- .eq(SysUserPO::getOpenId, openId));
|
|
|
- if (userPO == null) {
|
|
|
- return null;
|
|
|
+ private Boolean checkUniqueEmail(String value, Long id) {
|
|
|
+ if (StrUtil.isBlank(value)) {
|
|
|
+ return true;
|
|
|
}
|
|
|
- return SysUserMapper.INSTANCE.toUserDTO(userPO);
|
|
|
+ id = Objects.isNull(id) ? -1L : id;
|
|
|
+ SysUserPO entity = getOne(Wrappers.lambdaQuery(SysUserPO.class)
|
|
|
+ .select(SysUserPO::getId, SysUserPO::getEmail)
|
|
|
+ .eq(SysUserPO::getEmail, value));
|
|
|
+ return Objects.isNull(entity) || entity.getId().longValue() == id.longValue();
|
|
|
}
|
|
|
|
|
|
- private void assignUserRole(String userId, Set<String> roleIds){
|
|
|
- userRoleService.assignUserRole(userId,roleIds);
|
|
|
+ private Boolean checkUniquePhone(String value, Long id) {
|
|
|
+ if (StrUtil.isBlank(value)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ id = Objects.isNull(id) ? -1L : id;
|
|
|
+ SysUserPO entity = getOne(Wrappers.lambdaQuery(SysUserPO.class)
|
|
|
+ .select(SysUserPO::getId, SysUserPO::getPhone)
|
|
|
+ .eq(SysUserPO::getPhone, value));
|
|
|
+ return Objects.isNull(entity) || entity.getId().longValue() == id.longValue();
|
|
|
}
|
|
|
|
|
|
- private void assignUserPortal(String userId, Set<String> portalIds){
|
|
|
- userPortalService.assignUserPortal(userId,portalIds);
|
|
|
+ private Boolean checkUniqueStaffNumber(String value, Long id) {
|
|
|
+ if (StrUtil.isBlank(value)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ id = Objects.isNull(id) ? -1L : id;
|
|
|
+ SysUserPO entity = getOne(Wrappers.lambdaQuery(SysUserPO.class)
|
|
|
+ .select(SysUserPO::getId, SysUserPO::getStaffNumber)
|
|
|
+ .eq(SysUserPO::getStaffNumber, value));
|
|
|
+ return Objects.isNull(entity) || entity.getId().longValue() == id.longValue();
|
|
|
}
|
|
|
|
|
|
- private void assignUserPosition(String userId, Set<String> positionIds){
|
|
|
- userPositionService.assignUserPosition(userId,positionIds);
|
|
|
- }
|
|
|
-}
|
|
|
+}
|