fix: 部分缺陷修复
This commit is contained in:
parent
f431aeb455
commit
cdccf0e4c5
|
@ -33,8 +33,6 @@ public class GlobalExceptionHandler {
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public Result<Object> exceptionHandler(RuntimeException exception) {
|
public Result<Object> exceptionHandler(RuntimeException exception) {
|
||||||
String message = exception.getMessage();
|
String message = exception.getMessage();
|
||||||
log.error("GlobalExceptionHandler===>运行时异常信息:{}", message);
|
|
||||||
exception.printStackTrace();
|
|
||||||
|
|
||||||
// 解析异常
|
// 解析异常
|
||||||
String jsonParseError = "JSON parse error (.*)";
|
String jsonParseError = "JSON parse error (.*)";
|
||||||
|
@ -54,9 +52,11 @@ public class GlobalExceptionHandler {
|
||||||
String primaryKeyError = "Duplicate entry '(.*?)' for key .*";
|
String primaryKeyError = "Duplicate entry '(.*?)' for key .*";
|
||||||
Matcher primaryKeyErrorMatcher = Pattern.compile(primaryKeyError).matcher(message);
|
Matcher primaryKeyErrorMatcher = Pattern.compile(primaryKeyError).matcher(message);
|
||||||
if (primaryKeyErrorMatcher.find()) {
|
if (primaryKeyErrorMatcher.find()) {
|
||||||
return Result.error(null, 500, "主键值" + primaryKeyErrorMatcher.group(1) + "已存在");
|
return Result.error(null, 500, "【" + primaryKeyErrorMatcher.group(1) + "】已存在");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.error("GlobalExceptionHandler===>运行时异常信息:{}", message);
|
||||||
|
exception.printStackTrace();
|
||||||
return Result.error(null, 500, "服务器异常");
|
return Result.error(null, 500, "服务器异常");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -79,7 +79,7 @@ public class EmailUsersController {
|
||||||
return Result.success(ResultCodeEnum.UPDATE_SUCCESS);
|
return Result.success(ResultCodeEnum.UPDATE_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "删除邮箱用户发送配置", description = "删除邮箱用户发送配置")
|
@Operation(summary = "删除邮箱用户", description = "删除邮箱用户")
|
||||||
@DeleteMapping("deleteEmailUsers")
|
@DeleteMapping("deleteEmailUsers")
|
||||||
public Mono<Result<String>> deleteEmailUsers(@RequestBody List<Long> ids) {
|
public Mono<Result<String>> deleteEmailUsers(@RequestBody List<Long> ids) {
|
||||||
emailUsersService.deleteEmailUsers(ids);
|
emailUsersService.deleteEmailUsers(ids);
|
||||||
|
|
|
@ -66,7 +66,13 @@ public class UserFactory {
|
||||||
// 获取IP地址并更新用户登录信息
|
// 获取IP地址并更新用户登录信息
|
||||||
String ipAddr = IpUtil.getCurrentUserIpAddress().getIpAddr();
|
String ipAddr = IpUtil.getCurrentUserIpAddress().getIpAddr();
|
||||||
String ipRegion = IpUtil.getCurrentUserIpAddress().getIpRegion();
|
String ipRegion = IpUtil.getCurrentUserIpAddress().getIpRegion();
|
||||||
setUpdateUser(userId, ipAddr, ipRegion);
|
|
||||||
|
// 设置用户IP地址,并更新用户信息
|
||||||
|
AdminUser updateUser = new AdminUser();
|
||||||
|
updateUser.setId(userId);
|
||||||
|
updateUser.setIpAddress(ipAddr);
|
||||||
|
updateUser.setIpRegion(ipRegion);
|
||||||
|
userMapper.updateById(updateUser);
|
||||||
|
|
||||||
// 将用户登录保存在用户登录日志表中
|
// 将用户登录保存在用户登录日志表中
|
||||||
userLoginLogMapper.insert(setUserLoginLog(user, token, ipAddr, ipRegion, "login"));
|
userLoginLogMapper.insert(setUserLoginLog(user, token, ipAddr, ipRegion, "login"));
|
||||||
|
@ -83,6 +89,12 @@ public class UserFactory {
|
||||||
return loginVo;
|
return loginVo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * 构建用户返回对象LoginVo
|
||||||
|
*
|
||||||
|
* @param user 用户对象
|
||||||
|
* @param readMeDay 记住我时间
|
||||||
|
*/
|
||||||
public void buildUserVo(AdminUser user, long readMeDay) {
|
public void buildUserVo(AdminUser user, long readMeDay) {
|
||||||
Long userId = user.getId();
|
Long userId = user.getId();
|
||||||
String username = user.getUsername();
|
String username = user.getUsername();
|
||||||
|
@ -144,21 +156,6 @@ public class UserFactory {
|
||||||
return loginVo;
|
return loginVo;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* * 设置更新用户设置内容
|
|
||||||
*
|
|
||||||
* @param userId 用户ID
|
|
||||||
*/
|
|
||||||
@Transactional
|
|
||||||
public void setUpdateUser(Long userId, String ipAddr, String ipRegion) {
|
|
||||||
// 设置用户IP地址,并更新用户信息
|
|
||||||
AdminUser updateUser = new AdminUser();
|
|
||||||
updateUser.setId(userId);
|
|
||||||
updateUser.setIpAddress(ipAddr);
|
|
||||||
updateUser.setIpRegion(ipRegion);
|
|
||||||
userMapper.updateById(updateUser);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 检查用户头像是否合规
|
* 检查用户头像是否合规
|
||||||
*
|
*
|
||||||
|
|
|
@ -112,10 +112,11 @@ public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements De
|
||||||
@Override
|
@Override
|
||||||
@CacheEvict(cacheNames = "dept", key = "'allDept'", beforeInvocation = true)
|
@CacheEvict(cacheNames = "dept", key = "'allDept'", beforeInvocation = true)
|
||||||
public void updateDept(DeptUpdateDto dto) {
|
public void updateDept(DeptUpdateDto dto) {
|
||||||
// 判断所更新的部门是否存在
|
|
||||||
String mangerList = dto.getManager().stream().map(String::trim).collect(Collectors.joining(","));
|
|
||||||
if (dto.getId().equals(dto.getParentId())) throw new BunnyException(ResultCodeEnum.ILLEGAL_DATA_REQUEST);
|
if (dto.getId().equals(dto.getParentId())) throw new BunnyException(ResultCodeEnum.ILLEGAL_DATA_REQUEST);
|
||||||
|
|
||||||
|
// 将管理员用户逗号分隔
|
||||||
|
String mangerList = dto.getManager().stream().map(String::trim).collect(Collectors.joining(","));
|
||||||
|
|
||||||
// 更新内容
|
// 更新内容
|
||||||
Dept dept = new Dept();
|
Dept dept = new Dept();
|
||||||
BeanUtils.copyProperties(dto, dept);
|
BeanUtils.copyProperties(dto, dept);
|
||||||
|
@ -141,5 +142,4 @@ public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements De
|
||||||
// 删除用户部门关联
|
// 删除用户部门关联
|
||||||
userDeptMapper.deleteBatchIdsByDeptIdWithPhysics(ids);
|
userDeptMapper.deleteBatchIdsByDeptIdWithPhysics(ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,10 +68,6 @@ public class EmailTemplateServiceImpl extends ServiceImpl<EmailTemplateMapper, E
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void addEmailTemplate(@Valid EmailTemplateAddDto dto) {
|
public void addEmailTemplate(@Valid EmailTemplateAddDto dto) {
|
||||||
// 查询是否添加过这个模板
|
|
||||||
List<EmailTemplate> emailTemplateList = list(Wrappers.<EmailTemplate>lambdaQuery().eq(EmailTemplate::getTemplateName, dto.getTemplateName()));
|
|
||||||
if (!emailTemplateList.isEmpty()) throw new BunnyException(ResultCodeEnum.DATA_EXIST);
|
|
||||||
|
|
||||||
// 保存数据
|
// 保存数据
|
||||||
EmailTemplate emailTemplate = new EmailTemplate();
|
EmailTemplate emailTemplate = new EmailTemplate();
|
||||||
BeanUtils.copyProperties(dto, emailTemplate);
|
BeanUtils.copyProperties(dto, emailTemplate);
|
||||||
|
|
|
@ -13,7 +13,6 @@ import cn.bunny.services.factory.EmailFactory;
|
||||||
import cn.bunny.services.mapper.EmailUsersMapper;
|
import cn.bunny.services.mapper.EmailUsersMapper;
|
||||||
import cn.bunny.services.service.EmailUsersService;
|
import cn.bunny.services.service.EmailUsersService;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
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.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
|
@ -74,10 +73,6 @@ public class EmailUsersServiceImpl extends ServiceImpl<EmailUsersMapper, EmailUs
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void addEmailUsers(EmailUsersAddDto dto) {
|
public void addEmailUsers(EmailUsersAddDto dto) {
|
||||||
// 判断邮箱是否添加
|
|
||||||
List<EmailUsers> emailUsersList = list(Wrappers.<EmailUsers>lambdaQuery().eq(EmailUsers::getEmail, dto.getEmail()));
|
|
||||||
if (!emailUsersList.isEmpty()) throw new BunnyException(ResultCodeEnum.EMAIL_EXIST);
|
|
||||||
|
|
||||||
// 更新邮箱默认状态
|
// 更新邮箱默认状态
|
||||||
emailFactory.updateEmailUserDefault(dto.getIsDefault());
|
emailFactory.updateEmailUserDefault(dto.getIsDefault());
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@ import jakarta.validation.Valid;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.cache.annotation.CacheEvict;
|
import org.springframework.cache.annotation.CacheEvict;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -32,6 +33,7 @@ import java.util.stream.Collectors;
|
||||||
* @since 2024-10-02 12:18:29
|
* @since 2024-10-02 12:18:29
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
|
@Transactional
|
||||||
public class MenuIconServiceImpl extends ServiceImpl<MenuIconMapper, MenuIcon> implements MenuIconService {
|
public class MenuIconServiceImpl extends ServiceImpl<MenuIconMapper, MenuIcon> implements MenuIconService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -92,7 +94,6 @@ public class MenuIconServiceImpl extends ServiceImpl<MenuIconMapper, MenuIcon> i
|
||||||
@Override
|
@Override
|
||||||
@CacheEvict(cacheNames = "menuIcon", key = "'menuIconList'", beforeInvocation = true)
|
@CacheEvict(cacheNames = "menuIcon", key = "'menuIconList'", beforeInvocation = true)
|
||||||
public void addMenuIcon(MenuIconAddDto dto) {
|
public void addMenuIcon(MenuIconAddDto dto) {
|
||||||
// 保存数据
|
|
||||||
MenuIcon menuIcon = new MenuIcon();
|
MenuIcon menuIcon = new MenuIcon();
|
||||||
BeanUtils.copyProperties(dto, menuIcon);
|
BeanUtils.copyProperties(dto, menuIcon);
|
||||||
save(menuIcon);
|
save(menuIcon);
|
||||||
|
@ -106,7 +107,6 @@ public class MenuIconServiceImpl extends ServiceImpl<MenuIconMapper, MenuIcon> i
|
||||||
@Override
|
@Override
|
||||||
@CacheEvict(cacheNames = "menuIcon", key = "'menuIconList'", beforeInvocation = true)
|
@CacheEvict(cacheNames = "menuIcon", key = "'menuIconList'", beforeInvocation = true)
|
||||||
public void updateMenuIcon(@Valid MenuIconUpdateDto dto) {
|
public void updateMenuIcon(@Valid MenuIconUpdateDto dto) {
|
||||||
// 更新内容
|
|
||||||
MenuIcon menuIcon = new MenuIcon();
|
MenuIcon menuIcon = new MenuIcon();
|
||||||
BeanUtils.copyProperties(dto, menuIcon);
|
BeanUtils.copyProperties(dto, menuIcon);
|
||||||
updateById(menuIcon);
|
updateById(menuIcon);
|
||||||
|
|
|
@ -4,14 +4,15 @@ import cn.bunny.common.service.exception.BunnyException;
|
||||||
import cn.bunny.dao.dto.system.rolePower.role.RoleAddDto;
|
import cn.bunny.dao.dto.system.rolePower.role.RoleAddDto;
|
||||||
import cn.bunny.dao.dto.system.rolePower.role.RoleDto;
|
import cn.bunny.dao.dto.system.rolePower.role.RoleDto;
|
||||||
import cn.bunny.dao.dto.system.rolePower.role.RoleUpdateDto;
|
import cn.bunny.dao.dto.system.rolePower.role.RoleUpdateDto;
|
||||||
|
import cn.bunny.dao.entity.system.AdminUser;
|
||||||
import cn.bunny.dao.entity.system.Role;
|
import cn.bunny.dao.entity.system.Role;
|
||||||
|
import cn.bunny.dao.entity.system.UserRole;
|
||||||
|
import cn.bunny.dao.pojo.constant.RedisUserConstant;
|
||||||
import cn.bunny.dao.pojo.result.PageResult;
|
import cn.bunny.dao.pojo.result.PageResult;
|
||||||
import cn.bunny.dao.pojo.result.ResultCodeEnum;
|
import cn.bunny.dao.pojo.result.ResultCodeEnum;
|
||||||
import cn.bunny.dao.vo.system.rolePower.RoleVo;
|
import cn.bunny.dao.vo.system.rolePower.RoleVo;
|
||||||
import cn.bunny.services.mapper.RoleMapper;
|
import cn.bunny.services.factory.UserFactory;
|
||||||
import cn.bunny.services.mapper.RolePowerMapper;
|
import cn.bunny.services.mapper.*;
|
||||||
import cn.bunny.services.mapper.RouterRoleMapper;
|
|
||||||
import cn.bunny.services.mapper.UserRoleMapper;
|
|
||||||
import cn.bunny.services.service.RoleService;
|
import cn.bunny.services.service.RoleService;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
|
@ -22,6 +23,7 @@ import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.cache.annotation.CacheEvict;
|
import org.springframework.cache.annotation.CacheEvict;
|
||||||
import org.springframework.cache.annotation.Cacheable;
|
import org.springframework.cache.annotation.Cacheable;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -46,6 +48,15 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
|
||||||
@Autowired
|
@Autowired
|
||||||
private RouterRoleMapper routerRoleMapper;
|
private RouterRoleMapper routerRoleMapper;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserMapper userMapper;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RedisTemplate<String, Object> redisTemplate;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserFactory userFactory;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* * 角色 服务实现类
|
* * 角色 服务实现类
|
||||||
|
@ -96,11 +107,6 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
|
||||||
@Override
|
@Override
|
||||||
@CacheEvict(cacheNames = "role", key = "'allRole'", beforeInvocation = true)
|
@CacheEvict(cacheNames = "role", key = "'allRole'", beforeInvocation = true)
|
||||||
public void addRole(@Valid RoleAddDto dto) {
|
public void addRole(@Valid RoleAddDto dto) {
|
||||||
// 判断角色码是否被添加过
|
|
||||||
List<Role> roleList = list(Wrappers.<Role>lambdaQuery().eq(Role::getRoleCode, dto.getRoleCode()));
|
|
||||||
if (!roleList.isEmpty()) throw new BunnyException(ResultCodeEnum.DATA_EXIST);
|
|
||||||
|
|
||||||
// 保存数据
|
|
||||||
Role role = new Role();
|
Role role = new Role();
|
||||||
BeanUtils.copyProperties(dto, role);
|
BeanUtils.copyProperties(dto, role);
|
||||||
save(role);
|
save(role);
|
||||||
|
@ -122,6 +128,24 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
|
||||||
Role role = new Role();
|
Role role = new Role();
|
||||||
BeanUtils.copyProperties(dto, role);
|
BeanUtils.copyProperties(dto, role);
|
||||||
updateById(role);
|
updateById(role);
|
||||||
|
|
||||||
|
// 找到所有和当前更新角色相同的用户
|
||||||
|
List<Long> userIds = userRoleMapper.selectList(Wrappers.<UserRole>lambdaQuery().eq(UserRole::getRoleId, dto.getId()))
|
||||||
|
.stream().map(UserRole::getUserId).toList();
|
||||||
|
|
||||||
|
// 根据Id查找所有用户
|
||||||
|
List<AdminUser> adminUsers = userMapper.selectList(Wrappers.<AdminUser>lambdaQuery().in(AdminUser::getId, userIds));
|
||||||
|
|
||||||
|
// 用户为空时不更新Redis的key
|
||||||
|
if (adminUsers.isEmpty()) return;
|
||||||
|
|
||||||
|
// 更新Redis中用户信息
|
||||||
|
adminUsers.stream().filter(user -> {
|
||||||
|
String adminLoginInfoPrefix = RedisUserConstant.getAdminLoginInfoPrefix(user.getUsername());
|
||||||
|
Object object = redisTemplate.opsForValue().get(adminLoginInfoPrefix);
|
||||||
|
return object != null;
|
||||||
|
}).forEach(user -> userFactory.buildUserVo(user, RedisUserConstant.REDIS_EXPIRATION_TIME));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -146,6 +170,5 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
|
||||||
|
|
||||||
// 删除角色和路由相关
|
// 删除角色和路由相关
|
||||||
routerRoleMapper.deleteBatchIdsByRoleIdsWithPhysics(ids);
|
routerRoleMapper.deleteBatchIdsByRoleIdsWithPhysics(ids);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -271,11 +271,11 @@ public class RouterServiceImpl extends ServiceImpl<RouterMapper, Router> impleme
|
||||||
List<Long> longList = list(Wrappers.<Router>lambdaQuery().in(Router::getParentId, ids)).stream().map(Router::getId).toList();
|
List<Long> longList = list(Wrappers.<Router>lambdaQuery().in(Router::getParentId, ids)).stream().map(Router::getId).toList();
|
||||||
ids.addAll(longList);
|
ids.addAll(longList);
|
||||||
|
|
||||||
// // 逻辑删除
|
// 逻辑删除
|
||||||
// removeBatchByIds(ids);
|
removeBatchByIds(ids);
|
||||||
|
|
||||||
// 物理删除
|
// // 物理删除
|
||||||
baseMapper.deleteBatchIdsWithPhysics(ids);
|
// baseMapper.deleteBatchIdsWithPhysics(ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -422,21 +422,11 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, AdminUser> implemen
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void addAdminUser(@Valid AdminUserAddDto dto) {
|
public void addAdminUser(@Valid AdminUserAddDto dto) {
|
||||||
AdminUser adminUser = getOne(Wrappers.<AdminUser>lambdaQuery()
|
|
||||||
.eq(AdminUser::getEmail, dto.getEmail())
|
|
||||||
.or()
|
|
||||||
.eq(AdminUser::getUsername, dto.getUsername()));
|
|
||||||
|
|
||||||
// 确保邮箱和用户名不能重复
|
|
||||||
if (adminUser != null) {
|
|
||||||
throw new BunnyException(ResultCodeEnum.ALREADY_USER_EXCEPTION);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 对密码加密
|
// 对密码加密
|
||||||
String md5Password = DigestUtils.md5DigestAsHex(dto.getPassword().getBytes());
|
String md5Password = DigestUtils.md5DigestAsHex(dto.getPassword().getBytes());
|
||||||
|
|
||||||
// 保存数据
|
// 保存数据
|
||||||
adminUser = new AdminUser();
|
AdminUser adminUser = new AdminUser();
|
||||||
BeanUtils.copyProperties(dto, adminUser);
|
BeanUtils.copyProperties(dto, adminUser);
|
||||||
adminUser.setPassword(md5Password);
|
adminUser.setPassword(md5Password);
|
||||||
save(adminUser);
|
save(adminUser);
|
||||||
|
|
|
@ -43,7 +43,6 @@
|
||||||
and type like CONCAT('%',#{dto.type},'%')
|
and type like CONCAT('%',#{dto.type},'%')
|
||||||
</if>
|
</if>
|
||||||
</where>
|
</where>
|
||||||
order by update_time desc
|
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<!-- 物理删除邮件模板表 -->
|
<!-- 物理删除邮件模板表 -->
|
||||||
|
|
Loading…
Reference in New Issue