|
@@ -2,6 +2,7 @@ package com.xjrsoft.module.organization.service.impl;
|
|
|
|
|
|
import cn.dev33.satoken.secure.BCrypt;
|
|
import cn.dev33.satoken.secure.BCrypt;
|
|
import cn.dev33.satoken.secure.SaSecureUtil;
|
|
import cn.dev33.satoken.secure.SaSecureUtil;
|
|
|
|
+import cn.dev33.satoken.stp.StpUtil;
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
import cn.hutool.core.convert.Convert;
|
|
import cn.hutool.core.convert.Convert;
|
|
@@ -19,9 +20,8 @@ import com.xjrsoft.common.page.ConventPage;
|
|
import com.xjrsoft.common.page.PageOutput;
|
|
import com.xjrsoft.common.page.PageOutput;
|
|
import com.xjrsoft.common.utils.RedisUtil;
|
|
import com.xjrsoft.common.utils.RedisUtil;
|
|
import com.xjrsoft.common.utils.VoToColumnUtil;
|
|
import com.xjrsoft.common.utils.VoToColumnUtil;
|
|
-import com.xjrsoft.module.organization.dto.AddUserDto;
|
|
|
|
-import com.xjrsoft.module.organization.dto.UpdateUserDto;
|
|
|
|
-import com.xjrsoft.module.organization.dto.WeChatPageDto;
|
|
|
|
|
|
+import com.xjrsoft.config.CommonPropertiesConfig;
|
|
|
|
+import com.xjrsoft.module.organization.dto.*;
|
|
import com.xjrsoft.module.organization.entity.User;
|
|
import com.xjrsoft.module.organization.entity.User;
|
|
import com.xjrsoft.module.organization.entity.UserDeptRelation;
|
|
import com.xjrsoft.module.organization.entity.UserDeptRelation;
|
|
import com.xjrsoft.module.organization.entity.UserPostRelation;
|
|
import com.xjrsoft.module.organization.entity.UserPostRelation;
|
|
@@ -70,6 +70,8 @@ public class UserServiceImpl extends MPJBaseServiceImpl<UserMapper, User> implem
|
|
|
|
|
|
private final RedisUtil redisUtil;
|
|
private final RedisUtil redisUtil;
|
|
|
|
|
|
|
|
+ private final CommonPropertiesConfig propertiesConfig;
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
public boolean add(AddUserDto dto) {
|
|
public boolean add(AddUserDto dto) {
|
|
@@ -77,17 +79,29 @@ public class UserServiceImpl extends MPJBaseServiceImpl<UserMapper, User> implem
|
|
if (count > 0) {
|
|
if (count > 0) {
|
|
throw new MyException("用户名称或编码已存在");
|
|
throw new MyException("用户名称或编码已存在");
|
|
}
|
|
}
|
|
|
|
+ count = count(Wrappers.<User>query().lambda().eq(User::getMobile, dto.getMobile()));
|
|
|
|
+ if (count > 0) {
|
|
|
|
+ throw new MyException("手机号码已存在");
|
|
|
|
+ }
|
|
User user = BeanUtil.toBean(dto, User.class);
|
|
User user = BeanUtil.toBean(dto, User.class);
|
|
|
|
|
|
//密码加密加盐存储到数据库
|
|
//密码加密加盐存储到数据库
|
|
user.setPassword(BCrypt.hashpw(dto.getPassword(), BCrypt.gensalt()));
|
|
user.setPassword(BCrypt.hashpw(dto.getPassword(), BCrypt.gensalt()));
|
|
save(user);
|
|
save(user);
|
|
|
|
|
|
|
|
+ // 添加角色
|
|
|
|
+ if (dto.getRoleId() != null) {
|
|
|
|
+ UserRoleRelation userRoleRelation = new UserRoleRelation();
|
|
|
|
+ userRoleRelation.setUserId(user.getId());
|
|
|
|
+ userRoleRelation.setRoleId(dto.getRoleId());
|
|
|
|
+ userRoleRelationMapper.insert(userRoleRelation);
|
|
|
|
+ }
|
|
|
|
+
|
|
List<UserDeptRelation> userDeptRelationList = new ArrayList<>();
|
|
List<UserDeptRelation> userDeptRelationList = new ArrayList<>();
|
|
- if (StrUtil.isNotBlank(dto.getDepartmentIds())){
|
|
|
|
|
|
+ if (StrUtil.isNotBlank(dto.getDepartmentIds())) {
|
|
String allDeptIdStr = StrUtil.join(StringPool.COMMA, dto.getDepartmentIds());
|
|
String allDeptIdStr = StrUtil.join(StringPool.COMMA, dto.getDepartmentIds());
|
|
List<Long> departmentIds = Arrays.stream(allDeptIdStr.split(StringPool.COMMA)).map(Convert::toLong).collect(Collectors.toList());
|
|
List<Long> departmentIds = Arrays.stream(allDeptIdStr.split(StringPool.COMMA)).map(Convert::toLong).collect(Collectors.toList());
|
|
- if (CollectionUtil.isNotEmpty(departmentIds)){
|
|
|
|
|
|
+ if (CollectionUtil.isNotEmpty(departmentIds)) {
|
|
for (Long deptId : departmentIds) {
|
|
for (Long deptId : departmentIds) {
|
|
//将用户所选部门保存到关联表中
|
|
//将用户所选部门保存到关联表中
|
|
UserDeptRelation userDeptRelation = new UserDeptRelation();
|
|
UserDeptRelation userDeptRelation = new UserDeptRelation();
|
|
@@ -96,7 +110,7 @@ public class UserServiceImpl extends MPJBaseServiceImpl<UserMapper, User> implem
|
|
userDeptRelationList.add(userDeptRelation);
|
|
userDeptRelationList.add(userDeptRelation);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- userDeptRelationService.saveBatch(userDeptRelationList);
|
|
|
|
|
|
+ userDeptRelationService.saveBatch(userDeptRelationList);
|
|
}
|
|
}
|
|
|
|
|
|
CompletableFuture.runAsync(() -> {
|
|
CompletableFuture.runAsync(() -> {
|
|
@@ -126,12 +140,12 @@ public class UserServiceImpl extends MPJBaseServiceImpl<UserMapper, User> implem
|
|
updateById(user);
|
|
updateById(user);
|
|
|
|
|
|
//先删除再新增
|
|
//先删除再新增
|
|
- userDeptRelationService.remove(Wrappers.<UserDeptRelation>query().lambda().eq(UserDeptRelation::getUserId,user.getId()));
|
|
|
|
|
|
+ userDeptRelationService.remove(Wrappers.<UserDeptRelation>query().lambda().eq(UserDeptRelation::getUserId, user.getId()));
|
|
List<UserDeptRelation> userDeptRelationList = new ArrayList<>();
|
|
List<UserDeptRelation> userDeptRelationList = new ArrayList<>();
|
|
- if (StrUtil.isNotBlank(dto.getDepartmentIds())){
|
|
|
|
|
|
+ if (StrUtil.isNotBlank(dto.getDepartmentIds())) {
|
|
String allDeptIdStr = StrUtil.join(StringPool.COMMA, dto.getDepartmentIds());
|
|
String allDeptIdStr = StrUtil.join(StringPool.COMMA, dto.getDepartmentIds());
|
|
List<Long> departmentIds = Arrays.stream(allDeptIdStr.split(StringPool.COMMA)).map(Convert::toLong).collect(Collectors.toList());
|
|
List<Long> departmentIds = Arrays.stream(allDeptIdStr.split(StringPool.COMMA)).map(Convert::toLong).collect(Collectors.toList());
|
|
- if (CollectionUtil.isNotEmpty(departmentIds)){
|
|
|
|
|
|
+ if (CollectionUtil.isNotEmpty(departmentIds)) {
|
|
for (Long deptId : departmentIds) {
|
|
for (Long deptId : departmentIds) {
|
|
//将用户所选部门保存到关联表中
|
|
//将用户所选部门保存到关联表中
|
|
UserDeptRelation userDeptRelation = new UserDeptRelation();
|
|
UserDeptRelation userDeptRelation = new UserDeptRelation();
|
|
@@ -160,24 +174,21 @@ public class UserServiceImpl extends MPJBaseServiceImpl<UserMapper, User> implem
|
|
//删除时需要同时删除用户部门关联表和用户角色关联表和用户岗位关系表数据。
|
|
//删除时需要同时删除用户部门关联表和用户角色关联表和用户岗位关系表数据。
|
|
this.removeBatchByIds(ids);
|
|
this.removeBatchByIds(ids);
|
|
//根据用户ids去缓存中查询到对应的三个表的数据
|
|
//根据用户ids去缓存中查询到对应的三个表的数据
|
|
- List<UserDeptRelation> userDeptRelationList = redisUtil.get(GlobalConstant.USER_DEPT_RELATION_CACHE_KEY, new TypeReference<List<UserDeptRelation>>() {
|
|
|
|
- });
|
|
|
|
- List<UserPostRelation> userPostRelationList = redisUtil.get(GlobalConstant.USER_POST_RELATION_CACHE_KEY, new TypeReference<List<UserPostRelation>>() {
|
|
|
|
- });
|
|
|
|
- List<UserRoleRelation> userRoleRelationList = redisUtil.get(GlobalConstant.USER_ROLE_RELATION_CACHE_KEY, new TypeReference<List<UserRoleRelation>>() {
|
|
|
|
- });
|
|
|
|
|
|
+ List<UserDeptRelation> userDeptRelationList = redisUtil.get(GlobalConstant.USER_DEPT_RELATION_CACHE_KEY, new TypeReference<List<UserDeptRelation>>() {});
|
|
|
|
+ List<UserPostRelation> userPostRelationList = redisUtil.get(GlobalConstant.USER_POST_RELATION_CACHE_KEY, new TypeReference<List<UserPostRelation>>() {});
|
|
|
|
+ List<UserRoleRelation> userRoleRelationList = redisUtil.get(GlobalConstant.USER_ROLE_RELATION_CACHE_KEY, new TypeReference<List<UserRoleRelation>>() {});
|
|
//拿用户ids进行过滤,如果存在,就删除
|
|
//拿用户ids进行过滤,如果存在,就删除
|
|
List<Long> deptRelationIds = userDeptRelationList.stream().filter(u -> ids.contains(u.getUserId())).map(UserDeptRelation::getId).collect(Collectors.toList());
|
|
List<Long> deptRelationIds = userDeptRelationList.stream().filter(u -> ids.contains(u.getUserId())).map(UserDeptRelation::getId).collect(Collectors.toList());
|
|
List<Long> postRelationIds = userPostRelationList.stream().filter(u -> ids.contains(u.getUserId())).map(UserPostRelation::getId).collect(Collectors.toList());
|
|
List<Long> postRelationIds = userPostRelationList.stream().filter(u -> ids.contains(u.getUserId())).map(UserPostRelation::getId).collect(Collectors.toList());
|
|
List<Long> roleRelationIds = userRoleRelationList.stream().filter(u -> ids.contains(u.getUserId())).map(UserRoleRelation::getId).collect(Collectors.toList());
|
|
List<Long> roleRelationIds = userRoleRelationList.stream().filter(u -> ids.contains(u.getUserId())).map(UserRoleRelation::getId).collect(Collectors.toList());
|
|
//调用三个表的删除
|
|
//调用三个表的删除
|
|
- if(CollectionUtil.isNotEmpty(deptRelationIds)){
|
|
|
|
|
|
+ if (CollectionUtil.isNotEmpty(deptRelationIds)) {
|
|
userDeptRelationMapper.deleteBatchIds(deptRelationIds);
|
|
userDeptRelationMapper.deleteBatchIds(deptRelationIds);
|
|
}
|
|
}
|
|
- if(CollectionUtil.isNotEmpty(postRelationIds)) {
|
|
|
|
|
|
+ if (CollectionUtil.isNotEmpty(postRelationIds)) {
|
|
userPostRelationMapper.deleteBatchIds(postRelationIds);
|
|
userPostRelationMapper.deleteBatchIds(postRelationIds);
|
|
}
|
|
}
|
|
- if(CollectionUtil.isNotEmpty(roleRelationIds)) {
|
|
|
|
|
|
+ if (CollectionUtil.isNotEmpty(roleRelationIds)) {
|
|
userRoleRelationMapper.deleteBatchIds(roleRelationIds);
|
|
userRoleRelationMapper.deleteBatchIds(roleRelationIds);
|
|
}
|
|
}
|
|
//更新缓存
|
|
//更新缓存
|
|
@@ -197,6 +208,33 @@ public class UserServiceImpl extends MPJBaseServiceImpl<UserMapper, User> implem
|
|
return Boolean.TRUE;
|
|
return Boolean.TRUE;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public boolean updatePassword(UpdatePasswordDto dto) {
|
|
|
|
+
|
|
|
|
+ User updateUser = new User();
|
|
|
|
+ updateUser.setId(StpUtil.getLoginIdAsLong());
|
|
|
|
+ updateUser.setPassword(BCrypt.hashpw(dto.getNewPassword(), BCrypt.gensalt()));
|
|
|
|
+ updateUser.setIsChangePassword(0);
|
|
|
|
+
|
|
|
|
+ return updateById(updateUser);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public boolean resetPassword(ResetPasswordDto dto) {
|
|
|
|
+ User user = new User();
|
|
|
|
+ user.setId(dto.getId());
|
|
|
|
+ user.setPassword(BCrypt.hashpw(propertiesConfig.getDefaultPassword(), BCrypt.gensalt()));
|
|
|
|
+ user.setIsChangePassword(1);
|
|
|
|
+
|
|
|
|
+ CompletableFuture.runAsync(() -> {
|
|
|
|
+ List<User> list = list();
|
|
|
|
+ redisUtil.set(GlobalConstant.USER_CACHE_KEY, list);
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ return updateById(user);
|
|
|
|
+ }
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public List<UserInfoVo> getUsersInfo(String ids) {
|
|
public List<UserInfoVo> getUsersInfo(String ids) {
|
|
|
|
|
|
@@ -215,8 +253,8 @@ public class UserServiceImpl extends MPJBaseServiceImpl<UserMapper, User> implem
|
|
@Override
|
|
@Override
|
|
public PageOutput<WeChatPageVO> getPage(WeChatPageDto dto) {
|
|
public PageOutput<WeChatPageVO> getPage(WeChatPageDto dto) {
|
|
LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
|
|
LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
|
|
- queryWrapper.like(StrUtil.isNotBlank(dto.getKeyword()),User::getName,dto.getKeyword())
|
|
|
|
- .select(User.class,x -> VoToColumnUtil.fieldsToColumns(WeChatPageVO.class).contains(x.getProperty()));
|
|
|
|
|
|
+ queryWrapper.like(StrUtil.isNotBlank(dto.getKeyword()), User::getName, dto.getKeyword())
|
|
|
|
+ .select(User.class, x -> VoToColumnUtil.fieldsToColumns(WeChatPageVO.class).contains(x.getProperty()));
|
|
IPage<User> page = userMapper.selectPage(ConventPage.getPage(dto), queryWrapper);
|
|
IPage<User> page = userMapper.selectPage(ConventPage.getPage(dto), queryWrapper);
|
|
List<User> records = page.getRecords();
|
|
List<User> records = page.getRecords();
|
|
for (User record : records) {
|
|
for (User record : records) {
|