fix: 添加无法删除admin角色
This commit is contained in:
parent
7d1b6d11ba
commit
5a7f0e482d
|
@ -4,6 +4,8 @@ target/
|
|||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
logs/
|
||||
!**/src/main/resources/application-prod.yml
|
||||
|
||||
### STS ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
|
@ -13,6 +15,7 @@ logs/
|
|||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.iws
|
||||
|
|
|
@ -64,6 +64,7 @@ public enum ResultCodeEnum {
|
|||
FETCH_USERINFO_ERROR(219, "获取用户信息失败"),
|
||||
ILLEGAL_DATA_REQUEST(219, "非法数据请求"),
|
||||
CLASS_NOT_FOUND(219, "类名不存在"),
|
||||
ADMIN_ROLE_CAN_NOT_DELETED(219, "无法删除admin角色"),
|
||||
|
||||
// 无权访问 403
|
||||
FAIL_REQUEST_NOT_AUTH(403, "用户未认证"),
|
||||
|
|
|
@ -45,4 +45,12 @@ public interface RoleMapper extends BaseMapper<Role> {
|
|||
*/
|
||||
@NotNull
|
||||
List<Role> selectListByUserId(long userId);
|
||||
|
||||
/**
|
||||
* * 根据用户Id列表查询用户角色
|
||||
*
|
||||
* @param ids 用户Id列表
|
||||
* @return 角色列表
|
||||
*/
|
||||
List<Role> selectListByUserIds(List<Long> ids);
|
||||
}
|
||||
|
|
|
@ -8,10 +8,7 @@ import cn.bunny.common.service.utils.minio.MinioUtil;
|
|||
import cn.bunny.dao.dto.system.files.FileUploadDto;
|
||||
import cn.bunny.dao.dto.system.user.*;
|
||||
import cn.bunny.dao.entity.log.UserLoginLog;
|
||||
import cn.bunny.dao.entity.system.AdminUser;
|
||||
import cn.bunny.dao.entity.system.AdminUserAndDept;
|
||||
import cn.bunny.dao.entity.system.EmailTemplate;
|
||||
import cn.bunny.dao.entity.system.UserDept;
|
||||
import cn.bunny.dao.entity.system.*;
|
||||
import cn.bunny.dao.pojo.constant.MinioConstant;
|
||||
import cn.bunny.dao.pojo.constant.RedisUserConstant;
|
||||
import cn.bunny.dao.pojo.enums.EmailTemplateEnums;
|
||||
|
@ -87,6 +84,8 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, AdminUser> implemen
|
|||
|
||||
@Autowired
|
||||
private EmailTemplateMapper emailTemplateMapper;
|
||||
@Autowired
|
||||
private RoleMapper roleMapper;
|
||||
|
||||
/**
|
||||
* 登录发送邮件验证码
|
||||
|
@ -483,6 +482,14 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, AdminUser> implemen
|
|||
// 判断数据请求是否为空
|
||||
if (ids.isEmpty()) throw new BunnyException(ResultCodeEnum.REQUEST_IS_EMPTY);
|
||||
|
||||
// 根据用户Id列表查询用户角色
|
||||
List<Role> list = roleMapper.selectListByUserIds(ids);
|
||||
List<Role> roleList = list.stream().filter(role -> !role.getRoleCode().equals("admin") || ids.contains(1L)).toList();
|
||||
if (roleList.isEmpty()) throw new BunnyException(ResultCodeEnum.ADMIN_ROLE_CAN_NOT_DELETED);
|
||||
|
||||
// 如果有管理员不删除
|
||||
ids.remove(1L);
|
||||
|
||||
// 逻辑删除
|
||||
baseMapper.deleteBatchIds(ids);
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ logging:
|
|||
pattern:
|
||||
dateformat: HH:mm:ss:SSS
|
||||
file:
|
||||
path: "logs/${spring.application.name}"
|
||||
path: "logs/${spring.application.name}" aaa
|
||||
|
||||
# 线上禁用文档
|
||||
knife4j:
|
||||
|
|
|
@ -47,20 +47,20 @@ knife4j:
|
|||
|
||||
bunny:
|
||||
master:
|
||||
host: 192.168.3.98
|
||||
port: 3304
|
||||
host: rm-bp12z6hlv46vi6g8mro.mysql.rds.aliyuncs.com
|
||||
port: 3306
|
||||
database: auth_admin
|
||||
username: root
|
||||
password: "02120212"
|
||||
username: auth_admin_prod
|
||||
password: 0212auth_admin
|
||||
|
||||
redis:
|
||||
host: 192.168.3.98
|
||||
host: 47.120.65.66
|
||||
port: 6379
|
||||
database: 0
|
||||
password: "123456"
|
||||
password: "02120212"
|
||||
|
||||
minio:
|
||||
endpointUrl: "http://192.168.3.98:9000"
|
||||
endpointUrl: "http://116.196.101.14:9000"
|
||||
accessKey: bunny
|
||||
secretKey: "02120212"
|
||||
bucket-name: auth-admin
|
||||
|
|
|
@ -55,5 +55,15 @@
|
|||
AND r.id = ur.role_id
|
||||
AND r.id = #{userId}
|
||||
</select>
|
||||
<select id="selectListByUserIds" resultType="cn.bunny.dao.entity.system.Role">
|
||||
SELECT r.*
|
||||
FROM sys_role r,
|
||||
sys_user_role ur
|
||||
WHERE r.id = ur.role_id
|
||||
AND ur.user_id in
|
||||
<foreach collection="ids" item="id" separator="," open="(" close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
|
|
@ -2,6 +2,7 @@ package cn.bunny.services.service.impl;
|
|||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
@ -18,4 +19,17 @@ class UserServiceImplTest {
|
|||
System.out.println(matcher.group(1));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteAdminUser() {
|
||||
ArrayList<Long> list = new ArrayList<>() {{
|
||||
add(100L);
|
||||
add(101L);
|
||||
add(102L);
|
||||
add(1L);
|
||||
}};
|
||||
list.remove(1L);
|
||||
|
||||
System.out.println(list);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue