fix: 添加无法删除admin角色
This commit is contained in:
parent
7d1b6d11ba
commit
5a7f0e482d
|
@ -4,6 +4,8 @@ target/
|
||||||
!**/src/main/**/target/
|
!**/src/main/**/target/
|
||||||
!**/src/test/**/target/
|
!**/src/test/**/target/
|
||||||
logs/
|
logs/
|
||||||
|
!**/src/main/resources/application-prod.yml
|
||||||
|
|
||||||
### STS ###
|
### STS ###
|
||||||
.apt_generated
|
.apt_generated
|
||||||
.classpath
|
.classpath
|
||||||
|
@ -13,6 +15,7 @@ logs/
|
||||||
.springBeans
|
.springBeans
|
||||||
.sts4-cache
|
.sts4-cache
|
||||||
|
|
||||||
|
|
||||||
### IntelliJ IDEA ###
|
### IntelliJ IDEA ###
|
||||||
.idea
|
.idea
|
||||||
*.iws
|
*.iws
|
||||||
|
|
|
@ -64,6 +64,7 @@ public enum ResultCodeEnum {
|
||||||
FETCH_USERINFO_ERROR(219, "获取用户信息失败"),
|
FETCH_USERINFO_ERROR(219, "获取用户信息失败"),
|
||||||
ILLEGAL_DATA_REQUEST(219, "非法数据请求"),
|
ILLEGAL_DATA_REQUEST(219, "非法数据请求"),
|
||||||
CLASS_NOT_FOUND(219, "类名不存在"),
|
CLASS_NOT_FOUND(219, "类名不存在"),
|
||||||
|
ADMIN_ROLE_CAN_NOT_DELETED(219, "无法删除admin角色"),
|
||||||
|
|
||||||
// 无权访问 403
|
// 无权访问 403
|
||||||
FAIL_REQUEST_NOT_AUTH(403, "用户未认证"),
|
FAIL_REQUEST_NOT_AUTH(403, "用户未认证"),
|
||||||
|
|
|
@ -45,4 +45,12 @@ public interface RoleMapper extends BaseMapper<Role> {
|
||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
List<Role> selectListByUserId(long userId);
|
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.files.FileUploadDto;
|
||||||
import cn.bunny.dao.dto.system.user.*;
|
import cn.bunny.dao.dto.system.user.*;
|
||||||
import cn.bunny.dao.entity.log.UserLoginLog;
|
import cn.bunny.dao.entity.log.UserLoginLog;
|
||||||
import cn.bunny.dao.entity.system.AdminUser;
|
import cn.bunny.dao.entity.system.*;
|
||||||
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.pojo.constant.MinioConstant;
|
import cn.bunny.dao.pojo.constant.MinioConstant;
|
||||||
import cn.bunny.dao.pojo.constant.RedisUserConstant;
|
import cn.bunny.dao.pojo.constant.RedisUserConstant;
|
||||||
import cn.bunny.dao.pojo.enums.EmailTemplateEnums;
|
import cn.bunny.dao.pojo.enums.EmailTemplateEnums;
|
||||||
|
@ -87,6 +84,8 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, AdminUser> implemen
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private EmailTemplateMapper emailTemplateMapper;
|
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);
|
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);
|
baseMapper.deleteBatchIds(ids);
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ logging:
|
||||||
pattern:
|
pattern:
|
||||||
dateformat: HH:mm:ss:SSS
|
dateformat: HH:mm:ss:SSS
|
||||||
file:
|
file:
|
||||||
path: "logs/${spring.application.name}"
|
path: "logs/${spring.application.name}" aaa
|
||||||
|
|
||||||
# 线上禁用文档
|
# 线上禁用文档
|
||||||
knife4j:
|
knife4j:
|
||||||
|
|
|
@ -47,20 +47,20 @@ knife4j:
|
||||||
|
|
||||||
bunny:
|
bunny:
|
||||||
master:
|
master:
|
||||||
host: 192.168.3.98
|
host: rm-bp12z6hlv46vi6g8mro.mysql.rds.aliyuncs.com
|
||||||
port: 3304
|
port: 3306
|
||||||
database: auth_admin
|
database: auth_admin
|
||||||
username: root
|
username: auth_admin_prod
|
||||||
password: "02120212"
|
password: 0212auth_admin
|
||||||
|
|
||||||
redis:
|
redis:
|
||||||
host: 192.168.3.98
|
host: 47.120.65.66
|
||||||
port: 6379
|
port: 6379
|
||||||
database: 0
|
database: 0
|
||||||
password: "123456"
|
password: "02120212"
|
||||||
|
|
||||||
minio:
|
minio:
|
||||||
endpointUrl: "http://192.168.3.98:9000"
|
endpointUrl: "http://116.196.101.14:9000"
|
||||||
accessKey: bunny
|
accessKey: bunny
|
||||||
secretKey: "02120212"
|
secretKey: "02120212"
|
||||||
bucket-name: auth-admin
|
bucket-name: auth-admin
|
||||||
|
|
|
@ -55,5 +55,15 @@
|
||||||
AND r.id = ur.role_id
|
AND r.id = ur.role_id
|
||||||
AND r.id = #{userId}
|
AND r.id = #{userId}
|
||||||
</select>
|
</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>
|
</mapper>
|
||||||
|
|
|
@ -2,6 +2,7 @@ package cn.bunny.services.service.impl;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
@ -18,4 +19,17 @@ class UserServiceImplTest {
|
||||||
System.out.println(matcher.group(1));
|
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