|
|
@ -35,7 +35,10 @@ import lombok.RequiredArgsConstructor;
|
|
|
|
import lombok.SneakyThrows;
|
|
|
|
import lombok.SneakyThrows;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.cache.Cache;
|
|
|
|
|
|
|
|
import org.springframework.cache.CacheManager;
|
|
|
|
import org.springframework.cache.annotation.CacheConfig;
|
|
|
|
import org.springframework.cache.annotation.CacheConfig;
|
|
|
|
|
|
|
|
import org.springframework.cache.annotation.CacheEvict;
|
|
|
|
import org.springframework.cache.annotation.Cacheable;
|
|
|
|
import org.springframework.cache.annotation.Cacheable;
|
|
|
|
import org.springframework.data.domain.Pageable;
|
|
|
|
import org.springframework.data.domain.Pageable;
|
|
|
|
import org.springframework.security.authentication.BadCredentialsException;
|
|
|
|
import org.springframework.security.authentication.BadCredentialsException;
|
|
|
@ -54,9 +57,8 @@ import java.util.*;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
|
|
|
|
* @description 用户业务实现类
|
|
|
|
|
|
|
|
* @author Enzo
|
|
|
|
* @author Enzo
|
|
|
|
|
|
|
|
* @description 用户业务实现类
|
|
|
|
* @create: 2020-08-11 16:17
|
|
|
|
* @create: 2020-08-11 16:17
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Service
|
|
|
|
@Service
|
|
|
@ -67,6 +69,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
|
|
|
|
|
|
|
|
|
|
|
private final UserMapper userMapper;
|
|
|
|
private final UserMapper userMapper;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final CacheManager cacheManager;
|
|
|
|
private final FileProperties properties;
|
|
|
|
private final FileProperties properties;
|
|
|
|
private final UserMapStruct userMapStruct;
|
|
|
|
private final UserMapStruct userMapStruct;
|
|
|
|
|
|
|
|
|
|
|
@ -155,21 +158,21 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
|
|
|
this.verifyUser(resources);
|
|
|
|
this.verifyUser(resources);
|
|
|
|
resources.setDeptId(resources.getDept().getId());
|
|
|
|
resources.setDeptId(resources.getDept().getId());
|
|
|
|
if (this.save(resources)) {
|
|
|
|
if (this.save(resources)) {
|
|
|
|
if (CollUtil.isNotEmpty(resources.getJobs())){
|
|
|
|
if (CollUtil.isNotEmpty(resources.getJobs())) {
|
|
|
|
// 插入职位信息
|
|
|
|
// 插入职位信息
|
|
|
|
// TODO: 2020/8/24 后续使用批量插入优化
|
|
|
|
// TODO: 2020/8/24 后续使用批量插入优化
|
|
|
|
resources.getJobs().forEach(job -> {
|
|
|
|
resources.getJobs().forEach(job -> {
|
|
|
|
UserJobRelation ujr = new UserJobRelation(resources.getId(),job.getId());
|
|
|
|
UserJobRelation ujr = new UserJobRelation(resources.getId(), job.getId());
|
|
|
|
this.userJobMapper.insert(ujr);
|
|
|
|
this.userJobMapper.insert(ujr);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (CollUtil.isNotEmpty(resources.getRoles())){
|
|
|
|
if (CollUtil.isNotEmpty(resources.getRoles())) {
|
|
|
|
resources.getRoles().forEach(role -> {
|
|
|
|
resources.getRoles().forEach(role -> {
|
|
|
|
UserRoleRelation urr = new UserRoleRelation(resources.getId(),role.getId());
|
|
|
|
UserRoleRelation urr = new UserRoleRelation(resources.getId(), role.getId());
|
|
|
|
this.userRoleMapper.insert(urr);
|
|
|
|
this.userRoleMapper.insert(urr);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}else {
|
|
|
|
} else {
|
|
|
|
log.error("插入数据失败:{}", resources);
|
|
|
|
log.error("插入数据失败:{}", resources);
|
|
|
|
throw new CreateFailException("插入数据失败,请联系管理员");
|
|
|
|
throw new CreateFailException("插入数据失败,请联系管理员");
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -190,7 +193,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
|
|
|
// 验证通过后查看修改后的数据与原来的数据的用户名是否发生改变
|
|
|
|
// 验证通过后查看修改后的数据与原来的数据的用户名是否发生改变
|
|
|
|
if (!oldUser.getUsername().equals(resources.getUsername())) {
|
|
|
|
if (!oldUser.getUsername().equals(resources.getUsername())) {
|
|
|
|
// 删除缓存数据
|
|
|
|
// 删除缓存数据
|
|
|
|
this.redisUtils.del( CacheKey.USER_NAME+ oldUser.getUsername());
|
|
|
|
this.redisUtils.del(CacheKey.USER_NAME + oldUser.getUsername());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 如果用户被禁用,则清除用户登陆的信息
|
|
|
|
// 如果用户被禁用,则清除用户登陆的信息
|
|
|
|
if (!resources.getEnabled()) {
|
|
|
|
if (!resources.getEnabled()) {
|
|
|
@ -345,11 +348,11 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (this.removeByIds(ids)) {
|
|
|
|
if (this.removeByIds(ids)) {
|
|
|
|
// 删除关联的角色和职位信息
|
|
|
|
// 删除关联的角色和职位信息
|
|
|
|
ids.forEach(id->{
|
|
|
|
ids.forEach(id -> {
|
|
|
|
this.userJobMapper.delete(Wrappers.<UserJobRelation>lambdaUpdate().eq(UserJobRelation::getUserId,id));
|
|
|
|
this.userJobMapper.delete(Wrappers.<UserJobRelation>lambdaUpdate().eq(UserJobRelation::getUserId, id));
|
|
|
|
this.userRoleMapper.delete(Wrappers.<UserRoleRelation>lambdaUpdate().eq(UserRoleRelation::getUserId,id));
|
|
|
|
this.userRoleMapper.delete(Wrappers.<UserRoleRelation>lambdaUpdate().eq(UserRoleRelation::getUserId, id));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}else {
|
|
|
|
} else {
|
|
|
|
log.error("删除失败:{}", ids);
|
|
|
|
log.error("删除失败:{}", ids);
|
|
|
|
throw new DeleteFailException("删除失败,请联系管理员");
|
|
|
|
throw new DeleteFailException("删除失败,请联系管理员");
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -358,11 +361,13 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 修改用户账号密码
|
|
|
|
* 修改用户账号密码
|
|
|
|
|
|
|
|
*
|
|
|
|
* @param userDto
|
|
|
|
* @param userDto
|
|
|
|
* @param encode
|
|
|
|
* @param encode
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
|
|
|
@CacheEvict(key = "'username:' + #userDto.username")
|
|
|
|
public void updatePassword(UserDto userDto, String encode) {
|
|
|
|
public void updatePassword(UserDto userDto, String encode) {
|
|
|
|
boolean update = this.update(Wrappers.<User>lambdaUpdate().set(User::getPassword, encode)
|
|
|
|
boolean update = this.update(Wrappers.<User>lambdaUpdate().set(User::getPassword, encode)
|
|
|
|
.set(User::getPwdResetTime, LocalDateTime.now(ZoneId.systemDefault()))
|
|
|
|
.set(User::getPwdResetTime, LocalDateTime.now(ZoneId.systemDefault()))
|
|
|
@ -374,7 +379,11 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
this.remoteAuthService.delete(Collections.singleton(userDto.getId()));
|
|
|
|
this.remoteAuthService.delete(Collections.singleton(userDto.getId()));
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
throw new BadRequestException(ResultCode.ERROR.getMsg());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Cache cache = this.cacheManager.getCache(CacheKey.USER_DETAILS);
|
|
|
|
|
|
|
|
if (cache != null) {
|
|
|
|
|
|
|
|
cache.evict(userDto.getUsername());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|