Compare commits

..

14 Commits

Author SHA1 Message Date
AprilWind
2bc7171abd fix 修复密码校验误删字段 2025-07-04 19:29:30 +08:00
AprilWind
4f99487d24 update 优化密码校验 2025-07-04 19:18:42 +08:00
AprilWind
a7cddc8d40 update 优化校验角色是否有数据权限 2025-07-04 18:52:29 +08:00
AprilWind
f3c4c02d73 update 优化校验角色是否有数据权限 2025-07-04 18:39:54 +08:00
疯狂的狮子Li
eb631360f4 update 优化 删除无用注释 2025-07-04 18:19:50 +08:00
秋辞未寒
a62bf04428 !721 update 发号器工具类便利性优化
* update 发号器工具类便利性优化
2025-07-04 09:46:23 +00:00
疯狂的狮子Li
7147f81b42 fix 修复 错误修改导致页面逻辑错误 2025-07-04 17:42:19 +08:00
疯狂的狮子Li
c9098563ca fix 修复 数据权限字段编辑错误 2025-07-04 16:55:20 +08:00
AprilWind
d4a8c25eab update 优化数据权限 2025-07-04 16:53:18 +08:00
AprilWind
0ddba506bf update 优化新增角色信息 2025-07-04 16:16:12 +08:00
AprilWind
d02bea85cb update 优化新增用户岗位信息判空逻辑 2025-07-04 15:54:39 +08:00
AprilWind
d27c58bfe8 docs 补充重构数据权限注释 2025-07-04 15:35:04 +08:00
疯狂的狮子Li
34bb51f5c0 update 优化 增加岗位修改校验 2025-07-04 15:29:51 +08:00
疯狂的狮子Li
64c37aaec6 update 重构用户 角色 部门 菜单的数据权限设计逻辑更符合实际业务场景与优化查询写法提高效率 2025-07-04 14:50:33 +08:00
38 changed files with 721 additions and 351 deletions

View File

@ -189,13 +189,6 @@ springdoc:
name: Lion Li
email: crazylionli@163.com
url: https://gitee.com/dromara/RuoYi-Vue-Plus
components:
# 鉴权方式配置
security-schemes:
apiKey:
type: APIKEY
in: HEADER
name: ${sa-token.token-name}
#这里定义了两个分组,可定义多个,也可以不定义
group-configs:
- group: 1.演示模块
@ -213,7 +206,7 @@ springdoc:
xss:
# 过滤开关
enabled: true
# 排除链接(多个用逗号分隔)
# 排除链接
excludeUrls:
- /system/notice

View File

@ -17,6 +17,7 @@ user.username.length.valid=账户长度必须在{min}到{max}个字符之间
user.password.not.blank=用户密码不能为空
user.password.length.valid=用户密码长度必须在{min}到{max}个字符之间
user.password.not.valid=* 5-50个字符
user.password.format.valid=密码必须包含大写字母、小写字母、数字和特殊字符
user.email.not.valid=邮箱格式错误
user.email.not.blank=邮箱不能为空
user.phonenumber.not.blank=用户手机号不能为空

View File

@ -17,6 +17,7 @@ user.username.length.valid=Account length must be between {min} and {max} charac
user.password.not.blank=Password cannot be empty
user.password.length.valid=Password length must be between {min} and {max} characters
user.password.not.valid=* 5-50 characters
user.password.format.valid=Password must contain uppercase, lowercase, digit, and special character
user.email.not.valid=Mailbox format error
user.email.not.blank=Mailbox cannot be blank
user.phonenumber.not.blank=Phone number cannot be blank

View File

@ -17,6 +17,7 @@ user.username.length.valid=账户长度必须在{min}到{max}个字符之间
user.password.not.blank=用户密码不能为空
user.password.length.valid=用户密码长度必须在{min}到{max}个字符之间
user.password.not.valid=* 5-50个字符
user.password.format.valid=密码必须包含大写字母、小写字母、数字和特殊字符
user.email.not.valid=邮箱格式错误
user.email.not.blank=邮箱不能为空
user.phonenumber.not.blank=用户手机号不能为空

View File

@ -26,6 +26,7 @@ public class PasswordLoginBody extends LoginBody {
*/
@NotBlank(message = "{user.password.not.blank}")
@Length(min = 5, max = 30, message = "{user.password.length.valid}")
// @Pattern(regexp = RegexConstants.PASSWORD, message = "{user.password.format.valid}")
private String password;
}

View File

@ -26,8 +26,12 @@ public class RegisterBody extends LoginBody {
*/
@NotBlank(message = "{user.password.not.blank}")
@Length(min = 5, max = 30, message = "{user.password.length.valid}")
// @Pattern(regexp = RegexConstants.PASSWORD, message = "{user.password.format.valid}")
private String password;
/**
* 用户类型
*/
private String userType;
}

View File

@ -1,7 +1,6 @@
package org.dromara.common.redis.utils;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.dromara.common.core.utils.SpringUtils;
@ -10,6 +9,10 @@ import org.redisson.api.RIdGenerator;
import org.redisson.api.RedissonClient;
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAccessor;
/**
* 发号器工具类
@ -23,12 +26,12 @@ public class SequenceUtils {
/**
* 默认初始值
*/
public static final Long DEFAULT_INIT_VALUE = 1L;
public static final long DEFAULT_INIT_VALUE = 1L;
/**
* 默认步长
*/
public static final Long DEFAULT_STEP_VALUE = 1L;
public static final long DEFAULT_STEP_VALUE = 1L;
/**
* 默认过期时间-
@ -40,6 +43,11 @@ public class SequenceUtils {
*/
public static final Duration DEFAULT_EXPIRE_TIME_MINUTE = Duration.ofMinutes(1);
/**
* 默认最小ID容量位数 - 6位数即至少可以生成的ID为999999个
*/
public static final int DEFAULT_MIN_ID_CAPACITY_BITS = 6;
/**
* 获取Redisson客户端实例
*/
@ -54,14 +62,11 @@ public class SequenceUtils {
* @param stepValue ID步长
* @return ID生成器
*/
private static RIdGenerator getIdGenerator(String key, Duration expireTime, Long initValue, Long stepValue) {
if (initValue == null || initValue <= 0) {
initValue = DEFAULT_INIT_VALUE;
}
if (stepValue == null || stepValue <= 0) {
stepValue = DEFAULT_STEP_VALUE;
}
public static RIdGenerator getIdGenerator(String key, Duration expireTime, long initValue, long stepValue) {
RIdGenerator idGenerator = REDISSON_CLIENT.getIdGenerator(key);
// 初始值和步长不能小于等于0
initValue = initValue <= 0 ? DEFAULT_INIT_VALUE : initValue;
stepValue = stepValue <= 0 ? DEFAULT_STEP_VALUE : stepValue;
// 设置初始值和步长
idGenerator.tryInit(initValue, stepValue);
// 设置过期时间
@ -69,6 +74,17 @@ public class SequenceUtils {
return idGenerator;
}
/**
* 获取ID生成器
*
* @param key 业务key
* @param expireTime 过期时间
* @return ID生成器
*/
public static RIdGenerator getIdGenerator(String key, Duration expireTime) {
return getIdGenerator(key, expireTime, DEFAULT_INIT_VALUE, DEFAULT_STEP_VALUE);
}
/**
* 获取指定业务key的唯一id
*
@ -78,10 +94,21 @@ public class SequenceUtils {
* @param stepValue ID步长
* @return 唯一id
*/
public static long nextId(String key, Duration expireTime, Long initValue, Long stepValue) {
public static long getNextId(String key, Duration expireTime, long initValue, long stepValue) {
return getIdGenerator(key, expireTime, initValue, stepValue).nextId();
}
/**
* 获取指定业务key的唯一id (ID初始值=1,ID步长=1)
*
* @param key 业务key
* @param expireTime 过期时间
* @return 唯一id
*/
public static long getNextId(String key, Duration expireTime) {
return getIdGenerator(key, expireTime).nextId();
}
/**
* 获取指定业务key的唯一id字符串
*
@ -91,19 +118,8 @@ public class SequenceUtils {
* @param stepValue ID步长
* @return 唯一id
*/
public static String nextIdStr(String key, Duration expireTime, Long initValue, Long stepValue) {
return String.valueOf(nextId(key, expireTime, initValue, stepValue));
}
/**
* 获取指定业务key的唯一id (ID初始值=1,ID步长=1)
*
* @param key 业务key
* @param expireTime 过期时间
* @return 唯一id
*/
public static long nextId(String key, Duration expireTime) {
return getIdGenerator(key, expireTime, DEFAULT_INIT_VALUE, DEFAULT_STEP_VALUE).nextId();
public static String getNextIdString(String key, Duration expireTime, long initValue, long stepValue) {
return String.valueOf(getNextId(key, expireTime, initValue, stepValue));
}
/**
@ -113,8 +129,8 @@ public class SequenceUtils {
* @param expireTime 过期时间
* @return 唯一id
*/
public static String nextIdStr(String key, Duration expireTime) {
return String.valueOf(nextId(key, expireTime));
public static String getNextIdString(String key, Duration expireTime) {
return String.valueOf(getNextId(key, expireTime));
}
/**
@ -125,56 +141,210 @@ public class SequenceUtils {
* @param width 位数不足左补0
* @return 补零后的唯一id字符串
*/
public static String nextPaddedIdStr(String key, Duration expireTime, Integer width) {
return StringUtils.leftPad(nextIdStr(key, expireTime), width, '0');
public static String getPaddedNextIdString(String key, Duration expireTime, Integer width) {
return StringUtils.leftPad(getNextIdString(key, expireTime), width, '0');
}
/**
* 获取 yyyyMMdd 开头的唯一id
* 获取 yyyyMMdd 格式的唯一id
*
* @return 唯一id
* @deprecated 请使用 {@link #getDateId(String)} {@link #getDateId(String, boolean)}{@link #getDateId(String, boolean, int)}确保不同业务的ID连续性
*/
public static String nextIdDate() {
return nextIdDate("");
@Deprecated
public static String getDateId() {
return getDateId("");
}
/**
* 获取 prefix + yyyyMMdd 开头的唯一id
* 获取 prefix + yyyyMMdd 格式的唯一id
*
* @param prefix 业务前缀
* @return 唯一id
*/
public static String nextIdDate(String prefix) {
// 前缀+日期 构建 prefixKey
String prefixKey = StringUtils.format("{}{}", StringUtils.blankToDefault(prefix, ""), DateUtil.format(DateUtil.date(), DatePattern.PURE_DATE_FORMATTER));
// 获取下一个id
long nextId = getIdGenerator(prefixKey, DEFAULT_EXPIRE_TIME_DAY, DEFAULT_INIT_VALUE, DEFAULT_STEP_VALUE).nextId();
// 返回完整id
return StringUtils.format("{}{}", prefixKey, nextId);
public static String getDateId(String prefix) {
return getDateId(prefix, true);
}
/**
* 获取 yyyyMMddHHmmss 开头的唯一id
* 获取 prefix + yyyyMMdd 格式的唯一id
*
* @param prefix 业务前缀
* @param isWithPrefix id是否携带业务前缀
* @return 唯一id
*/
public static String nextIdDateTime() {
return nextIdDateTime("");
public static String getDateId(String prefix, boolean isWithPrefix) {
return getDateId(prefix, isWithPrefix, -1);
}
/**
* 获取 prefix + yyyyMMddHHmmss 开头的唯一id
* 获取 prefix + yyyyMMdd 格式的唯一id (启用ID补位补位长度 = {@link #DEFAULT_MIN_ID_CAPACITY_BITS})}
*
* @param prefix 业务前缀
* @param isWithPrefix id是否携带业务前缀
* @return 唯一id
*/
public static String getPaddedDateId(String prefix, boolean isWithPrefix) {
return getDateId(prefix, isWithPrefix, DEFAULT_MIN_ID_CAPACITY_BITS);
}
/**
* 获取 prefix + yyyyMMdd 格式的唯一id
*
* @param prefix 业务前缀
* @param isWithPrefix id是否携带业务前缀
* @param minIdCapacityBits 最小ID容量位数小于该位数的ID左补0小于等于0表示不启用补位
* @return 唯一id
*/
public static String getDateId(String prefix, boolean isWithPrefix, int minIdCapacityBits) {
return getDateId(prefix, isWithPrefix, minIdCapacityBits, LocalDate.now());
}
/**
* 获取 prefix + yyyyMMdd 格式的唯一id
*
* @param prefix 业务前缀
* @param isWithPrefix id是否携带业务前缀
* @param minIdCapacityBits 最小ID容量位数小于该位数的ID左补0小于等于0表示不启用补位
* @param time 时间
* @return 唯一id
*/
public static String getDateId(String prefix, boolean isWithPrefix, int minIdCapacityBits, LocalDate time) {
return getDateId(prefix, isWithPrefix, minIdCapacityBits, time, DEFAULT_INIT_VALUE, DEFAULT_STEP_VALUE);
}
/**
* 获取 prefix + yyyyMMdd 格式的唯一id
*
* @param prefix 业务前缀
* @param isWithPrefix id是否携带业务前缀
* @param minIdCapacityBits 最小ID容量位数小于该位数的ID左补0小于等于0表示不启用补位
* @param time 时间
* @param initValue ID初始值
* @param stepValue ID步长
* @return 唯一id
*/
public static String getDateId(String prefix, boolean isWithPrefix, int minIdCapacityBits, LocalDate time, long initValue, long stepValue) {
return getDatePatternId(prefix, isWithPrefix, minIdCapacityBits, time, DatePattern.PURE_DATE_FORMATTER, DEFAULT_EXPIRE_TIME_DAY, initValue, stepValue);
}
/**
* 获取 yyyyMMddHHmmss 格式的唯一id
*
* @return 唯一id
* @deprecated 请使用 {@link #getDateTimeId(String)} {@link #getDateTimeId(String, boolean)}{@link #getDateTimeId(String, boolean, int)}确保不同业务的ID连续性
*/
@Deprecated
public static String getDateTimeId() {
return getDateTimeId("", false);
}
/**
* 获取 prefix + yyyyMMddHHmmss 格式的唯一id
*
* @param prefix 业务前缀
* @return 唯一id
*/
public static String nextIdDateTime(String prefix) {
// 前缀+日期时间 构建 prefixKey
String prefixKey = StringUtils.format("{}{}", StringUtils.blankToDefault(prefix, ""), DateUtil.format(DateUtil.date(), DatePattern.PURE_DATETIME_FORMATTER));
// 获取下一个id
long nextId = getIdGenerator(prefixKey, DEFAULT_EXPIRE_TIME_MINUTE, DEFAULT_INIT_VALUE, DEFAULT_STEP_VALUE).nextId();
// 返回完整id
return StringUtils.format("{}{}", prefixKey, nextId);
public static String getDateTimeId(String prefix) {
return getDateTimeId(prefix, true);
}
/**
* 获取 prefix + yyyyMMddHHmmss 格式的唯一id
*
* @param prefix 业务前缀
* @param isWithPrefix id是否携带业务前缀
* @return 唯一id
*/
public static String getDateTimeId(String prefix, boolean isWithPrefix) {
return getDateTimeId(prefix, isWithPrefix, -1);
}
/**
* 获取 prefix + yyyyMMddHHmmss 格式的唯一id (启用ID补位补位长度 = {@link #DEFAULT_MIN_ID_CAPACITY_BITS})}
*
* @param prefix 业务前缀
* @param isWithPrefix id是否携带业务前缀
* @return 唯一id
*/
public static String getPaddedDateTimeId(String prefix, boolean isWithPrefix) {
return getDateTimeId(prefix, isWithPrefix, DEFAULT_MIN_ID_CAPACITY_BITS);
}
/**
* 获取 prefix + yyyyMMddHHmmss 格式的唯一id
*
* @param prefix 业务前缀
* @param isWithPrefix id是否携带业务前缀
* @param minIdCapacityBits 最小ID容量位数小于该位数的ID左补0小于等于0表示不启用补位
* @return 唯一id
*/
public static String getDateTimeId(String prefix, boolean isWithPrefix, int minIdCapacityBits) {
return getDateTimeId(prefix, isWithPrefix, minIdCapacityBits, LocalDateTime.now());
}
/**
* 获取 prefix + yyyyMMddHHmmss 格式的唯一id
*
* @param prefix 业务前缀
* @param isWithPrefix id是否携带业务前缀
* @param minIdCapacityBits 最小ID容量位数小于该位数的ID左补0小于等于0表示不启用补位
* @param time 时间
* @return 唯一id
*/
public static String getDateTimeId(String prefix, boolean isWithPrefix, int minIdCapacityBits, LocalDateTime time) {
return getDateTimeId(prefix, isWithPrefix, minIdCapacityBits, time, DEFAULT_INIT_VALUE, DEFAULT_STEP_VALUE);
}
/**
* 获取 prefix + yyyyMMddHHmmss 格式的唯一id
*
* @param prefix 业务前缀
* @param isWithPrefix id是否携带业务前缀
* @param minIdCapacityBits 最小ID容量位数小于该位数的ID左补0小于等于0表示不启用补位
* @param initValue ID初始值
* @param stepValue ID步长
* @return 唯一id
*/
public static String getDateTimeId(String prefix, boolean isWithPrefix, int minIdCapacityBits, LocalDateTime time, long initValue, long stepValue) {
return getDatePatternId(prefix, isWithPrefix, minIdCapacityBits, time, DatePattern.PURE_DATETIME_FORMATTER, DEFAULT_EXPIRE_TIME_MINUTE, initValue, stepValue);
}
/**
* 获取指定业务key的指定时间格式的ID
*
* @param prefix 业务前缀
* @param isWithPrefix id是否携带业务前缀
* @param minIdCapacityBits 最小ID容量位数小于该位数的ID左补0小于等于0表示不启用补位
* @param temporalAccessor 时间访问器
* @param timeFormatter 时间格式
* @param expireTime 过期时间
* @param initValue ID初始值
* @param stepValue ID步长
* @return 唯一id
*/
private static String getDatePatternId(String prefix, boolean isWithPrefix, int minIdCapacityBits, TemporalAccessor temporalAccessor, DateTimeFormatter timeFormatter, Duration expireTime, long initValue, long stepValue) {
// 时间前缀
String timePrefix = timeFormatter.format(temporalAccessor);
// 业务前缀 + 时间前缀 构建 prefixKey
String prefixKey = StringUtils.format("{}{}", StringUtils.blankToDefault(prefix, ""), timePrefix);
// 获取id -> 1
String nextId = getNextIdString(prefixKey, expireTime, initValue, stepValue);
// minIdCapacityBits 大于0 nextId 的长度小于 minIdCapacityBits则左补0
if (minIdCapacityBits > 0 && nextId.length() < minIdCapacityBits) {
nextId = StringUtils.leftPad(nextId, minIdCapacityBits, '0');
}
// 是否携带业务前缀
if (isWithPrefix) {
// -> P202507031
// 其中 P 为业务前缀202507031 yyyyMMdd 格式时间, 1 为nextId
return StringUtils.format("{}{}", prefixKey, nextId);
}
// -> 202507031
// 其中 202507031 yyyyMMdd 格式时间, 1 为nextId
return StringUtils.format("{}{}", timePrefix, nextId);
}
}

View File

@ -144,7 +144,7 @@ public class SysRoleController extends BaseController {
@Log(title = "角色管理", businessType = BusinessType.DELETE)
@DeleteMapping("/{roleIds}")
public R<Void> remove(@PathVariable Long[] roleIds) {
return toAjax(roleService.deleteRoleByIds(roleIds));
return toAjax(roleService.deleteRoleByIds(List.of(roleIds)));
}
/**

View File

@ -1,17 +1,17 @@
package org.dromara.system.domain.bo;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.system.domain.SysTenant;
import io.github.linpeilie.annotations.AutoMapper;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import lombok.EqualsAndHashCode;
import jakarta.validation.constraints.*;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.mybatis.core.domain.BaseEntity;
import org.dromara.system.domain.SysTenant;
import java.util.Date;
import org.dromara.common.mybatis.core.domain.BaseEntity;
/**
* 租户业务对象 sys_tenant
*
@ -62,6 +62,7 @@ public class SysTenantBo extends BaseEntity {
* 密码创建系统用户
*/
@NotBlank(message = "密码不能为空", groups = { AddGroup.class })
// @Pattern(regexp = RegexConstants.PASSWORD, message = "{user.password.format.valid}", groups = { AddGroup.class })
private String password;
/**

View File

@ -3,7 +3,6 @@ package org.dromara.system.mapper;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.dromara.common.core.utils.StreamUtils;
import org.dromara.common.mybatis.annotation.DataColumn;
import org.dromara.common.mybatis.annotation.DataPermission;
@ -21,6 +20,38 @@ import java.util.List;
*/
public interface SysDeptMapper extends BaseMapperPlus<SysDept, SysDeptVo> {
/**
* 构建角色对应的部门 SQL 查询语句
*
* <p> SQL 用于查询某个角色关联的所有部门 ID常用于数据权限控制</p>
*
* @param roleId 角色ID
* @return 查询部门ID的 SQL 语句字符串
*/
default String buildDeptByRoleSql(Long roleId) {
return """
select dept_id from sys_role_dept where role_id = %d
""".formatted(roleId);
}
/**
* 构建 SQL 查询用于获取当前角色拥有的部门中所有的父部门ID
*
* <p>
* SQL 用于 deptCheckStrictly 场景下排除非叶子节点父节点
* </p>
*
* @param roleId 角色ID
* @return SQL 语句字符串查询角色下部门的所有父部门ID
*/
default String buildParentDeptByRoleSql(Long roleId) {
return """
select parent_id from sys_dept where dept_id in (
select dept_id from sys_role_dept where role_id = %d
)
""".formatted(roleId);
}
/**
* 查询部门管理数据
*
@ -93,6 +124,16 @@ public interface SysDeptMapper extends BaseMapperPlus<SysDept, SysDeptVo> {
* @param deptCheckStrictly 部门树选择项是否关联显示
* @return 选中部门列表
*/
List<Long> selectDeptListByRoleId(@Param("roleId") Long roleId, @Param("deptCheckStrictly") boolean deptCheckStrictly);
default List<Long> selectDeptListByRoleId(Long roleId, boolean deptCheckStrictly) {
LambdaQueryWrapper<SysDept> wrapper = new LambdaQueryWrapper<>();
wrapper.select(SysDept::getDeptId)
.inSql(SysDept::getDeptId, this.buildDeptByRoleSql(roleId))
.orderByAsc(SysDept::getParentId)
.orderByAsc(SysDept::getOrderNum);
if (deptCheckStrictly) {
wrapper.notInSql(SysDept::getDeptId, this.buildParentDeptByRoleSql(roleId));
}
return this.selectObjs(wrapper);
}
}

View File

@ -1,9 +1,6 @@
package org.dromara.system.mapper;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import org.apache.ibatis.annotations.Param;
import org.dromara.common.core.constant.SystemConstants;
import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;
import org.dromara.system.domain.SysMenu;
@ -19,12 +16,58 @@ import java.util.List;
public interface SysMenuMapper extends BaseMapperPlus<SysMenu, SysMenuVo> {
/**
* 根据用户查询系统菜单列表
* 构建用户权限菜单 SQL
*
* @param queryWrapper 查询条件
* @return 菜单列表
* <p>
* 查询用户所属角色所拥有的菜单权限用于权限判断菜单加载等场景
* </p>
*
* @param userId 用户ID
* @return SQL 字符串用于 inSql 条件
*/
List<SysMenu> selectMenuListByUserId(@Param(Constants.WRAPPER) Wrapper<SysMenu> queryWrapper);
default String buildMenuByUserSql(Long userId) {
return """
select menu_id from sys_role_menu where role_id in (
select role_id from sys_user_role where user_id = %d
)
""".formatted(userId);
}
/**
* 构建角色对应的菜单ID SQL 子查询
*
* <p>
* 用于根据角色ID查询其所拥有的菜单权限用于权限标识菜单显示等场景
* 通常配合 inSql 使用
* </p>
*
* @param roleId 角色ID
* @return 查询菜单ID的 SQL 子查询字符串
*/
default String buildMenuByRoleSql(Long roleId) {
return """
select menu_id from sys_role_menu where role_id = %d
""".formatted(roleId);
}
/**
* 构建角色所关联菜单的父菜单ID查询 SQL
*
* <p>
* 用于配合菜单勾选树结构的 {@code menuCheckStrictly} 模式过滤掉非叶子节点父菜单
* 只返回角色实际勾选的末级菜单
* </p>
*
* @param roleId 角色ID
* @return SQL 语句字符串查询菜单的父菜单ID
*/
default String buildParentMenuByRoleSql(Long roleId) {
return """
select parent_id from sys_menu where menu_id in (
select menu_id from sys_role_menu where role_id = %d
)
""".formatted(roleId);
}
/**
* 根据用户ID查询权限
@ -32,7 +75,13 @@ public interface SysMenuMapper extends BaseMapperPlus<SysMenu, SysMenuVo> {
* @param userId 用户ID
* @return 权限列表
*/
List<String> selectMenuPermsByUserId(Long userId);
default List<String> selectMenuPermsByUserId(Long userId) {
return this.selectObjs(
new LambdaQueryWrapper<SysMenu>()
.select(SysMenu::getPerms)
.inSql(SysMenu::getMenuId, this.buildMenuByUserSql(userId))
);
}
/**
* 根据角色ID查询权限
@ -40,7 +89,13 @@ public interface SysMenuMapper extends BaseMapperPlus<SysMenu, SysMenuVo> {
* @param roleId 角色ID
* @return 权限列表
*/
List<String> selectMenuPermsByRoleId(Long roleId);
default List<String> selectMenuPermsByRoleId(Long roleId) {
return this.selectObjs(
new LambdaQueryWrapper<SysMenu>()
.select(SysMenu::getPerms)
.inSql(SysMenu::getMenuId, this.buildMenuByRoleSql(roleId))
);
}
/**
* 根据用户ID查询菜单
@ -56,14 +111,6 @@ public interface SysMenuMapper extends BaseMapperPlus<SysMenu, SysMenuVo> {
return this.selectList(lqw);
}
/**
* 根据用户ID查询菜单
*
* @param userId 用户ID
* @return 菜单列表
*/
List<SysMenu> selectMenuTreeByUserId(Long userId);
/**
* 根据角色ID查询菜单树信息
*
@ -71,6 +118,16 @@ public interface SysMenuMapper extends BaseMapperPlus<SysMenu, SysMenuVo> {
* @param menuCheckStrictly 菜单树选择项是否关联显示
* @return 选中菜单列表
*/
List<Long> selectMenuListByRoleId(@Param("roleId") Long roleId, @Param("menuCheckStrictly") boolean menuCheckStrictly);
default List<Long> selectMenuListByRoleId(Long roleId, boolean menuCheckStrictly) {
LambdaQueryWrapper<SysMenu> wrapper = new LambdaQueryWrapper<>();
wrapper.select(SysMenu::getMenuId)
.inSql(SysMenu::getMenuId, buildMenuByRoleSql(roleId))
.orderByAsc(SysMenu::getParentId)
.orderByAsc(SysMenu::getOrderNum);
if (menuCheckStrictly) {
wrapper.notInSql(SysMenu::getMenuId, this.buildParentMenuByRoleSql(roleId));
}
return this.selectObjs(wrapper);
}
}

View File

@ -1,6 +1,7 @@
package org.dromara.system.mapper;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.dromara.common.mybatis.annotation.DataColumn;
import org.dromara.common.mybatis.annotation.DataPermission;
@ -33,11 +34,42 @@ public interface SysPostMapper extends BaseMapperPlus<SysPost, SysPostVo> {
}
/**
* 查询用户所属岗位组
* 查询岗位列表
*
* @param queryWrapper 查询条件
* @return 岗位信息列表
*/
@DataPermission({
@DataColumn(key = "deptName", value = "dept_id"),
@DataColumn(key = "userName", value = "create_by")
})
default List<SysPostVo> selectPostList(Wrapper<SysPost> queryWrapper) {
return this.selectVoList(queryWrapper);
}
/**
* 根据岗位ID集合查询岗位数量
*
* @param postIds 岗位ID列表
* @return 匹配的岗位数量
*/
@DataPermission({
@DataColumn(key = "deptName", value = "dept_id"),
@DataColumn(key = "userName", value = "create_by")
})
default long selectPostCount(List<Long> postIds) {
return this.selectCount(new LambdaQueryWrapper<SysPost>().in(SysPost::getPostId, postIds));
}
/**
* 根据用户ID查询其关联的岗位列表
*
* @param userId 用户ID
* @return 结果
* @return 岗位信息列表
*/
List<SysPostVo> selectPostsByUserId(Long userId);
default List<SysPostVo> selectPostsByUserId(Long userId) {
return this.selectVoList(new LambdaQueryWrapper<SysPost>()
.inSql(SysPost::getPostId, "select post_id from sys_user_post where user_id = " + userId));
}
}

View File

@ -1,6 +1,7 @@
package org.dromara.system.mapper;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
@ -19,6 +20,18 @@ import java.util.List;
*/
public interface SysRoleMapper extends BaseMapperPlus<SysRole, SysRoleVo> {
/**
* 构建根据用户ID查询角色ID的SQL子查询
*
* @param userId 用户ID
* @return 查询用户对应角色ID的SQL语句字符串
*/
default String buildRoleByUserSql(Long userId) {
return """
select role_id from sys_user_role where user_id = %d
""".formatted(userId);
}
/**
* 分页查询角色列表
*
@ -27,22 +40,40 @@ public interface SysRoleMapper extends BaseMapperPlus<SysRole, SysRoleVo> {
* @return 包含角色信息的分页结果
*/
@DataPermission({
@DataColumn(key = "deptName", value = "d.dept_id"),
@DataColumn(key = "userName", value = "r.create_by")
@DataColumn(key = "deptName", value = "create_dept"),
@DataColumn(key = "userName", value = "create_by")
})
Page<SysRoleVo> selectPageRoleList(@Param("page") Page<SysRole> page, @Param(Constants.WRAPPER) Wrapper<SysRole> queryWrapper);
default Page<SysRoleVo> selectPageRoleList(@Param("page") Page<SysRole> page, @Param(Constants.WRAPPER) Wrapper<SysRole> queryWrapper) {
return this.selectVoPage(page, queryWrapper);
}
/**
* 根据条件分页查询角色数据
* 根据条件查询角色数据
*
* @param queryWrapper 查询条件
* @return 角色数据集合信息
*/
@DataPermission({
@DataColumn(key = "deptName", value = "d.dept_id"),
@DataColumn(key = "userName", value = "r.create_by")
@DataColumn(key = "deptName", value = "create_dept"),
@DataColumn(key = "userName", value = "create_by")
})
List<SysRoleVo> selectRoleList(@Param(Constants.WRAPPER) Wrapper<SysRole> queryWrapper);
default List<SysRoleVo> selectRoleList(@Param(Constants.WRAPPER) Wrapper<SysRole> queryWrapper) {
return this.selectVoList(queryWrapper);
}
/**
* 根据角色ID集合查询角色数量
*
* @param roleIds 角色ID列表
* @return 匹配的角色数量
*/
@DataPermission({
@DataColumn(key = "deptName", value = "create_dept"),
@DataColumn(key = "userName", value = "create_by")
})
default long selectRoleCount(List<Long> roleIds) {
return this.selectCount(new LambdaQueryWrapper<SysRole>().in(SysRole::getRoleId, roleIds));
}
/**
* 根据角色ID查询角色信息
@ -51,10 +82,12 @@ public interface SysRoleMapper extends BaseMapperPlus<SysRole, SysRoleVo> {
* @return 对应的角色信息
*/
@DataPermission({
@DataColumn(key = "deptName", value = "d.dept_id"),
@DataColumn(key = "userName", value = "r.create_by")
@DataColumn(key = "deptName", value = "create_dept"),
@DataColumn(key = "userName", value = "create_by")
})
SysRoleVo selectRoleById(Long roleId);
default SysRoleVo selectRoleById(Long roleId) {
return this.selectVoById(roleId);
}
/**
* 根据用户ID查询角色
@ -62,14 +95,11 @@ public interface SysRoleMapper extends BaseMapperPlus<SysRole, SysRoleVo> {
* @param userId 用户ID
* @return 角色列表
*/
List<SysRoleVo> selectRolePermissionByUserId(Long userId);
/**
* 根据用户ID查询角色
*
* @param userId 用户ID
* @return 角色列表
*/
List<SysRoleVo> selectRolesByUserId(Long userId);
default List<SysRoleVo> selectRolesByUserId(Long userId) {
return this.selectVoList(new LambdaQueryWrapper<SysRole>()
.select(SysRole::getRoleId, SysRole::getRoleName, SysRole::getRoleKey,
SysRole::getRoleSort, SysRole::getDataScope, SysRole::getStatus)
.inSql(SysRole::getRoleId, this.buildRoleByUserSql(userId)));
}
}

View File

@ -30,7 +30,7 @@ public interface SysUserMapper extends BaseMapperPlus<SysUser, SysUserVo> {
*/
@DataPermission({
@DataColumn(key = "deptName", value = "dept_id"),
@DataColumn(key = "userName", value = "user_id")
@DataColumn(key = "userName", value = "create_by")
})
default Page<SysUserVo> selectPageUserList(Page<SysUser> page, Wrapper<SysUser> queryWrapper) {
return this.selectVoPage(page, queryWrapper);
@ -44,7 +44,7 @@ public interface SysUserMapper extends BaseMapperPlus<SysUser, SysUserVo> {
*/
@DataPermission({
@DataColumn(key = "deptName", value = "dept_id"),
@DataColumn(key = "userName", value = "user_id")
@DataColumn(key = "userName", value = "create_by")
})
default List<SysUserVo> selectUserList(Wrapper<SysUser> queryWrapper) {
return this.selectVoList(queryWrapper);
@ -58,7 +58,7 @@ public interface SysUserMapper extends BaseMapperPlus<SysUser, SysUserVo> {
*/
@DataPermission({
@DataColumn(key = "deptName", value = "d.dept_id"),
@DataColumn(key = "userName", value = "u.user_id")
@DataColumn(key = "userName", value = "u.create_by")
})
List<SysUserExportVo> selectUserExportList(@Param(Constants.WRAPPER) Wrapper<SysUser> queryWrapper);
@ -71,7 +71,7 @@ public interface SysUserMapper extends BaseMapperPlus<SysUser, SysUserVo> {
*/
@DataPermission({
@DataColumn(key = "deptName", value = "d.dept_id"),
@DataColumn(key = "userName", value = "u.user_id")
@DataColumn(key = "userName", value = "u.create_by")
})
Page<SysUserVo> selectAllocatedList(@Param("page") Page<SysUser> page, @Param(Constants.WRAPPER) Wrapper<SysUser> queryWrapper);
@ -83,7 +83,7 @@ public interface SysUserMapper extends BaseMapperPlus<SysUser, SysUserVo> {
*/
@DataPermission({
@DataColumn(key = "deptName", value = "d.dept_id"),
@DataColumn(key = "userName", value = "u.user_id")
@DataColumn(key = "userName", value = "u.create_by")
})
Page<SysUserVo> selectUnallocatedList(@Param("page") Page<SysUser> page, @Param(Constants.WRAPPER) Wrapper<SysUser> queryWrapper);
@ -95,7 +95,7 @@ public interface SysUserMapper extends BaseMapperPlus<SysUser, SysUserVo> {
*/
@DataPermission({
@DataColumn(key = "deptName", value = "dept_id"),
@DataColumn(key = "userName", value = "user_id")
@DataColumn(key = "userName", value = "create_by")
})
default long countUserById(Long userId) {
return this.selectCount(new LambdaQueryWrapper<SysUser>().eq(SysUser::getUserId, userId));
@ -111,7 +111,7 @@ public interface SysUserMapper extends BaseMapperPlus<SysUser, SysUserVo> {
@Override
@DataPermission({
@DataColumn(key = "deptName", value = "dept_id"),
@DataColumn(key = "userName", value = "user_id")
@DataColumn(key = "userName", value = "create_by")
})
int update(@Param(Constants.ENTITY) SysUser user, @Param(Constants.WRAPPER) Wrapper<SysUser> updateWrapper);
@ -124,7 +124,7 @@ public interface SysUserMapper extends BaseMapperPlus<SysUser, SysUserVo> {
@Override
@DataPermission({
@DataColumn(key = "deptName", value = "dept_id"),
@DataColumn(key = "userName", value = "user_id")
@DataColumn(key = "userName", value = "create_by")
})
int updateById(@Param(Constants.ENTITY) SysUser user);

View File

@ -1,5 +1,6 @@
package org.dromara.system.mapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;
import org.dromara.system.domain.SysUserRole;
@ -18,6 +19,10 @@ public interface SysUserRoleMapper extends BaseMapperPlus<SysUserRole, SysUserRo
* @param roleId 角色ID
* @return 关联到指定角色的用户ID列表
*/
List<Long> selectUserIdsByRoleId(Long roleId);
default List<Long> selectUserIdsByRoleId(Long roleId) {
return this.selectObjs(new LambdaQueryWrapper<SysUserRole>()
.select(SysUserRole::getUserId).eq(SysUserRole::getRoleId, roleId)
);
}
}

View File

@ -14,7 +14,13 @@ import java.util.List;
*/
public interface ISysConfigService {
/**
* 分页查询参数配置列表
*
* @param config 查询条件
* @param pageQuery 分页参数
* @return 参数配置分页列表
*/
TableDataInfo<SysConfigVo> selectPageConfigList(SysConfigBo config, PageQuery pageQuery);
/**

View File

@ -14,7 +14,13 @@ import java.util.List;
*/
public interface ISysDictDataService {
/**
* 分页查询字典数据列表
*
* @param dictData 查询条件
* @param pageQuery 分页参数
* @return 字典数据分页列表
*/
TableDataInfo<SysDictDataVo> selectPageDictDataList(SysDictDataBo dictData, PageQuery pageQuery);
/**

View File

@ -15,7 +15,13 @@ import java.util.List;
*/
public interface ISysDictTypeService {
/**
* 分页查询字典类型列表
*
* @param dictType 查询条件
* @param pageQuery 分页参数
* @return 字典类型分页列表
*/
TableDataInfo<SysDictTypeVo> selectPageDictTypeList(SysDictTypeBo dictType, PageQuery pageQuery);
/**

View File

@ -14,7 +14,13 @@ import java.util.List;
*/
public interface ISysLogininforService {
/**
* 分页查询登录日志列表
*
* @param logininfor 查询条件
* @param pageQuery 分页参数
* @return 登录日志分页列表
*/
TableDataInfo<SysLogininforVo> selectPageLogininforList(SysLogininforBo logininfor, PageQuery pageQuery);
/**

View File

@ -14,7 +14,13 @@ import java.util.List;
*/
public interface ISysNoticeService {
/**
* 分页查询通知公告列表
*
* @param notice 查询条件
* @param pageQuery 分页参数
* @return 通知公告分页列表
*/
TableDataInfo<SysNoticeVo> selectPageNoticeList(SysNoticeBo notice, PageQuery pageQuery);
/**

View File

@ -14,6 +14,13 @@ import java.util.List;
*/
public interface ISysOperLogService {
/**
* 分页查询操作日志列表
*
* @param operLog 查询条件
* @param pageQuery 分页参数
* @return 操作日志分页列表
*/
TableDataInfo<SysOperLogVo> selectPageOperLogList(SysOperLogBo operLog, PageQuery pageQuery);
/**

View File

@ -14,7 +14,13 @@ import java.util.List;
*/
public interface ISysPostService {
/**
* 分页查询岗位列表
*
* @param post 查询条件
* @param pageQuery 分页参数
* @return 岗位分页列表
*/
TableDataInfo<SysPostVo> selectPagePostList(SysPostBo post, PageQuery pageQuery);
/**

View File

@ -16,11 +16,17 @@ import java.util.Set;
*/
public interface ISysRoleService {
/**
* 分页查询角色列表
*
* @param role 查询条件
* @param pageQuery 分页参数
* @return 角色分页列表
*/
TableDataInfo<SysRoleVo> selectPageRoleList(SysRoleBo role, PageQuery pageQuery);
/**
* 根据条件分页查询角色数据
* 根据条件查询角色数据
*
* @param role 角色信息
* @return 角色数据集合信息
@ -112,6 +118,13 @@ public interface ISysRoleService {
*/
void checkRoleDataScope(Long roleId);
/**
* 校验角色是否有数据权限
*
* @param roleIds 角色ID列表支持传单个ID
*/
void checkRoleDataScope(List<Long> roleIds);
/**
* 通过角色ID查询角色使用数量
*
@ -167,7 +180,7 @@ public interface ISysRoleService {
* @param roleIds 需要删除的角色ID
* @return 结果
*/
int deleteRoleByIds(Long[] roleIds);
int deleteRoleByIds(List<Long> roleIds);
/**
* 取消授权用户角色
@ -195,8 +208,29 @@ public interface ISysRoleService {
*/
int insertAuthUsers(Long roleId, Long[] userIds);
/**
* 根据角色ID清除该角色关联的所有在线用户的登录状态踢出在线用户
*
* <p>
* 先判断角色是否绑定用户若无绑定则直接返回
* 然后遍历当前所有在线Token查找拥有该角色的用户并强制登出
* 注意在线用户量过大时操作可能导致 Redis 阻塞需谨慎调用
* </p>
*
* @param roleId 角色ID
*/
void cleanOnlineUserByRole(Long roleId);
/**
* 根据用户ID列表清除对应在线用户的登录状态踢出指定用户
*
* <p>
* 遍历当前所有在线Token匹配用户ID列表中的用户强制登出
* 注意在线用户量过大时操作可能导致 Redis 阻塞需谨慎调用
* </p>
*
* @param userIds 需要清除的用户ID列表
*/
void cleanOnlineUser(List<Long> userIds);
}

View File

@ -41,6 +41,13 @@ public class SysConfigServiceImpl implements ISysConfigService, ConfigService {
private final SysConfigMapper baseMapper;
/**
* 分页查询参数配置列表
*
* @param config 查询条件
* @param pageQuery 分页参数
* @return 参数配置分页列表
*/
@Override
public TableDataInfo<SysConfigVo> selectPageConfigList(SysConfigBo config, PageQuery pageQuery) {
LambdaQueryWrapper<SysConfig> lqw = buildQueryWrapper(config);

View File

@ -33,6 +33,13 @@ public class SysDictDataServiceImpl implements ISysDictDataService {
private final SysDictDataMapper baseMapper;
/**
* 分页查询字典数据列表
*
* @param dictData 查询条件
* @param pageQuery 分页参数
* @return 字典数据分页列表
*/
@Override
public TableDataInfo<SysDictDataVo> selectPageDictDataList(SysDictDataBo dictData, PageQuery pageQuery) {
LambdaQueryWrapper<SysDictData> lqw = buildQueryWrapper(dictData);

View File

@ -48,6 +48,13 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService
private final SysDictTypeMapper baseMapper;
private final SysDictDataMapper dictDataMapper;
/**
* 分页查询字典类型列表
*
* @param dictType 查询条件
* @param pageQuery 分页参数
* @return 字典类型分页列表
*/
@Override
public TableDataInfo<SysDictTypeVo> selectPageDictTypeList(SysDictTypeBo dictType, PageQuery pageQuery) {
LambdaQueryWrapper<SysDictType> lqw = buildQueryWrapper(dictType);

View File

@ -108,6 +108,13 @@ public class SysLogininforServiceImpl implements ISysLogininforService {
return "[" + msg.toString() + "]";
}
/**
* 分页查询登录日志列表
*
* @param logininfor 查询条件
* @param pageQuery 分页参数
* @return 登录日志分页列表
*/
@Override
public TableDataInfo<SysLogininforVo> selectPageLogininforList(SysLogininforBo logininfor, PageQuery pageQuery) {
Map<String, Object> params = logininfor.getParams();

View File

@ -5,8 +5,6 @@ import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.tree.Tree;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.constant.Constants;
import org.dromara.common.core.constant.SystemConstants;
@ -67,29 +65,20 @@ public class SysMenuServiceImpl implements ISysMenuService {
@Override
public List<SysMenuVo> selectMenuList(SysMenuBo menu, Long userId) {
List<SysMenuVo> menuList;
// 管理员显示所有菜单信息
if (LoginHelper.isSuperAdmin(userId)) {
menuList = baseMapper.selectVoList(new LambdaQueryWrapper<SysMenu>()
.like(StringUtils.isNotBlank(menu.getMenuName()), SysMenu::getMenuName, menu.getMenuName())
LambdaQueryWrapper<SysMenu> wrapper = new LambdaQueryWrapper<>();
// 管理员显示所有菜单信息 不是管理员 按用户id过滤菜单
if (!LoginHelper.isSuperAdmin(userId)) {
// 通过用户id获取角色id 通过角色id获取菜单id 然后in菜单
wrapper.inSql(SysMenu::getMenuId, baseMapper.buildMenuByUserSql(userId));
}
menuList = baseMapper.selectVoList(
wrapper.like(StringUtils.isNotBlank(menu.getMenuName()), SysMenu::getMenuName, menu.getMenuName())
.eq(StringUtils.isNotBlank(menu.getVisible()), SysMenu::getVisible, menu.getVisible())
.eq(StringUtils.isNotBlank(menu.getStatus()), SysMenu::getStatus, menu.getStatus())
.eq(StringUtils.isNotBlank(menu.getMenuType()), SysMenu::getMenuType, menu.getMenuType())
.eq(ObjectUtil.isNotNull(menu.getParentId()), SysMenu::getParentId, menu.getParentId())
.orderByAsc(SysMenu::getParentId)
.orderByAsc(SysMenu::getOrderNum));
} else {
QueryWrapper<SysMenu> wrapper = Wrappers.query();
wrapper.inSql("r.role_id", "select role_id from sys_user_role where user_id = " + userId)
.like(StringUtils.isNotBlank(menu.getMenuName()), "m.menu_name", menu.getMenuName())
.eq(StringUtils.isNotBlank(menu.getVisible()), "m.visible", menu.getVisible())
.eq(StringUtils.isNotBlank(menu.getStatus()), "m.status", menu.getStatus())
.eq(StringUtils.isNotBlank(menu.getMenuType()), "m.menu_type", menu.getMenuType())
.eq(ObjectUtil.isNotNull(menu.getParentId()), "m.parent_id", menu.getParentId())
.orderByAsc("m.parent_id")
.orderByAsc("m.order_num");
List<SysMenu> list = baseMapper.selectMenuListByUserId(wrapper);
menuList = MapstructUtils.convert(list, SysMenuVo.class);
}
return menuList;
}
@ -141,7 +130,13 @@ public class SysMenuServiceImpl implements ISysMenuService {
if (LoginHelper.isSuperAdmin(userId)) {
menus = baseMapper.selectMenuTreeAll();
} else {
menus = baseMapper.selectMenuTreeByUserId(userId);
LambdaQueryWrapper<SysMenu> wrapper = new LambdaQueryWrapper<>();
menus = baseMapper.selectList(
wrapper.in(SysMenu::getMenuType, SystemConstants.TYPE_DIR, SystemConstants.TYPE_MENU)
.eq(SysMenu::getStatus, SystemConstants.NORMAL)
.inSql(SysMenu::getMenuId, baseMapper.buildMenuByUserSql(userId))
.orderByAsc(SysMenu::getParentId)
.orderByAsc(SysMenu::getOrderNum));
}
return getChildPerms(menus, Constants.TOP_PARENT_ID);
}

View File

@ -3,6 +3,7 @@ package org.dromara.system.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.utils.MapstructUtils;
import org.dromara.common.core.utils.ObjectUtils;
import org.dromara.common.core.utils.StringUtils;
@ -16,7 +17,6 @@ import org.dromara.system.domain.vo.SysUserVo;
import org.dromara.system.mapper.SysNoticeMapper;
import org.dromara.system.mapper.SysUserMapper;
import org.dromara.system.service.ISysNoticeService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.Arrays;
@ -34,6 +34,13 @@ public class SysNoticeServiceImpl implements ISysNoticeService {
private final SysNoticeMapper baseMapper;
private final SysUserMapper userMapper;
/**
* 分页查询通知公告列表
*
* @param notice 查询条件
* @param pageQuery 分页参数
* @return 通知公告分页列表
*/
@Override
public TableDataInfo<SysNoticeVo> selectPageNoticeList(SysNoticeBo notice, PageQuery pageQuery) {
LambdaQueryWrapper<SysNotice> lqw = buildQueryWrapper(notice);

View File

@ -49,6 +49,13 @@ public class SysOperLogServiceImpl implements ISysOperLogService {
insertOperlog(operLog);
}
/**
* 分页查询操作日志列表
*
* @param operLog 查询条件
* @param pageQuery 分页参数
* @return 操作日志分页列表
*/
@Override
public TableDataInfo<SysOperLogVo> selectPageOperLogList(SysOperLogBo operLog, PageQuery pageQuery) {
LambdaQueryWrapper<SysOperLog> lqw = buildQueryWrapper(operLog);

View File

@ -41,6 +41,13 @@ public class SysPostServiceImpl implements ISysPostService, PostService {
private final SysDeptMapper deptMapper;
private final SysUserPostMapper userPostMapper;
/**
* 分页查询岗位列表
*
* @param post 查询条件
* @param pageQuery 分页参数
* @return 岗位分页列表
*/
@Override
public TableDataInfo<SysPostVo> selectPagePostList(SysPostBo post, PageQuery pageQuery) {
Page<SysPostVo> page = baseMapper.selectPagePostList(pageQuery.build(), buildQueryWrapper(post));

View File

@ -7,7 +7,6 @@ import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@ -55,6 +54,13 @@ public class SysRoleServiceImpl implements ISysRoleService, RoleService {
private final SysUserRoleMapper userRoleMapper;
private final SysRoleDeptMapper roleDeptMapper;
/**
* 分页查询角色列表
*
* @param role 查询条件
* @param pageQuery 分页参数
* @return 角色分页列表
*/
@Override
public TableDataInfo<SysRoleVo> selectPageRoleList(SysRoleBo role, PageQuery pageQuery) {
Page<SysRoleVo> page = baseMapper.selectPageRoleList(pageQuery.build(), this.buildQueryWrapper(role));
@ -62,7 +68,7 @@ public class SysRoleServiceImpl implements ISysRoleService, RoleService {
}
/**
* 根据条件分页查询角色数据
* 根据条件查询角色数据
*
* @param role 角色信息
* @return 角色数据集合信息
@ -74,15 +80,14 @@ public class SysRoleServiceImpl implements ISysRoleService, RoleService {
private Wrapper<SysRole> buildQueryWrapper(SysRoleBo bo) {
Map<String, Object> params = bo.getParams();
QueryWrapper<SysRole> wrapper = Wrappers.query();
wrapper.eq("r.del_flag", SystemConstants.NORMAL)
.eq(ObjectUtil.isNotNull(bo.getRoleId()), "r.role_id", bo.getRoleId())
.like(StringUtils.isNotBlank(bo.getRoleName()), "r.role_name", bo.getRoleName())
.eq(StringUtils.isNotBlank(bo.getStatus()), "r.status", bo.getStatus())
.like(StringUtils.isNotBlank(bo.getRoleKey()), "r.role_key", bo.getRoleKey())
LambdaQueryWrapper<SysRole> wrapper = Wrappers.lambdaQuery();
wrapper.eq(ObjectUtil.isNotNull(bo.getRoleId()), SysRole::getRoleId, bo.getRoleId())
.like(StringUtils.isNotBlank(bo.getRoleName()), SysRole::getRoleName, bo.getRoleName())
.eq(StringUtils.isNotBlank(bo.getStatus()), SysRole::getStatus, bo.getStatus())
.like(StringUtils.isNotBlank(bo.getRoleKey()), SysRole::getRoleKey, bo.getRoleKey())
.between(params.get("beginTime") != null && params.get("endTime") != null,
"r.create_time", params.get("beginTime"), params.get("endTime"))
.orderByAsc("r.role_sort").orderByAsc("r.create_time");
SysRole::getCreateTime, params.get("beginTime"), params.get("endTime"))
.orderByAsc(SysRole::getRoleSort).orderByAsc(SysRole::getCreateTime);
return wrapper;
}
@ -176,9 +181,9 @@ public class SysRoleServiceImpl implements ISysRoleService, RoleService {
*/
@Override
public List<SysRoleVo> selectRoleByIds(List<Long> roleIds) {
return baseMapper.selectRoleList(new QueryWrapper<SysRole>()
.eq("r.status", SystemConstants.NORMAL)
.in(CollUtil.isNotEmpty(roleIds), "r.role_id", roleIds));
return baseMapper.selectRoleList(new LambdaQueryWrapper<SysRole>()
.eq(SysRole::getStatus, SystemConstants.NORMAL)
.in(CollUtil.isNotEmpty(roleIds), SysRole::getRoleId, roleIds));
}
/**
@ -249,14 +254,23 @@ public class SysRoleServiceImpl implements ISysRoleService, RoleService {
if (ObjectUtil.isNull(roleId)) {
return;
}
if (LoginHelper.isSuperAdmin()) {
this.checkRoleDataScope(Collections.singletonList(roleId));
}
/**
* 校验角色是否有数据权限
*
* @param roleIds 角色ID列表支持传单个ID
*/
@Override
public void checkRoleDataScope(List<Long> roleIds) {
if (CollUtil.isEmpty(roleIds) || LoginHelper.isSuperAdmin()) {
return;
}
List<SysRoleVo> roles = this.selectRoleList(new SysRoleBo(roleId));
if (CollUtil.isEmpty(roles)) {
throw new ServiceException("没有权限访问角色数据!");
long count = baseMapper.selectRoleCount(roleIds);
if (count != roleIds.size()) {
throw new ServiceException("没有权限访问部分角色数据!");
}
}
/**
@ -359,7 +373,7 @@ public class SysRoleServiceImpl implements ISysRoleService, RoleService {
rm.setMenuId(menuId);
list.add(rm);
}
if (list.size() > 0) {
if (CollUtil.isNotEmpty(list)) {
rows = roleMenuMapper.insertBatch(list) ? list.size() : 0;
}
return rows;
@ -380,7 +394,7 @@ public class SysRoleServiceImpl implements ISysRoleService, RoleService {
rd.setDeptId(deptId);
list.add(rd);
}
if (list.size() > 0) {
if (CollUtil.isNotEmpty(list)) {
rows = roleDeptMapper.insertBatch(list) ? list.size() : 0;
}
return rows;
@ -412,21 +426,20 @@ public class SysRoleServiceImpl implements ISysRoleService, RoleService {
@CacheEvict(cacheNames = CacheNames.SYS_ROLE_CUSTOM, allEntries = true)
@Override
@Transactional(rollbackFor = Exception.class)
public int deleteRoleByIds(Long[] roleIds) {
for (Long roleId : roleIds) {
SysRole role = baseMapper.selectById(roleId);
public int deleteRoleByIds(List<Long> roleIds) {
this.checkRoleDataScope(roleIds);
List<SysRole> roles = baseMapper.selectByIds(roleIds);
for (SysRole role : roles) {
checkRoleAllowed(BeanUtil.toBean(role, SysRoleBo.class));
checkRoleDataScope(roleId);
if (countUserRoleByRoleId(roleId) > 0) {
if (countUserRoleByRoleId(role.getRoleId()) > 0) {
throw new ServiceException(String.format("%1$s已分配不能删除!", role.getRoleName()));
}
}
List<Long> ids = Arrays.asList(roleIds);
// 删除角色与菜单关联
roleMenuMapper.delete(new LambdaQueryWrapper<SysRoleMenu>().in(SysRoleMenu::getRoleId, ids));
roleMenuMapper.delete(new LambdaQueryWrapper<SysRoleMenu>().in(SysRoleMenu::getRoleId, roleIds));
// 删除角色与部门关联
roleDeptMapper.delete(new LambdaQueryWrapper<SysRoleDept>().in(SysRoleDept::getRoleId, ids));
return baseMapper.deleteByIds(ids);
roleDeptMapper.delete(new LambdaQueryWrapper<SysRoleDept>().in(SysRoleDept::getRoleId, roleIds));
return baseMapper.deleteByIds(roleIds);
}
/**
@ -437,6 +450,9 @@ public class SysRoleServiceImpl implements ISysRoleService, RoleService {
*/
@Override
public int deleteAuthUser(SysUserRole userRole) {
if (LoginHelper.getUserId().equals(userRole.getUserId())) {
throw new ServiceException("不允许修改当前用户角色!");
}
int rows = userRoleMapper.delete(new LambdaQueryWrapper<SysUserRole>()
.eq(SysUserRole::getRoleId, userRole.getRoleId())
.eq(SysUserRole::getUserId, userRole.getUserId()));
@ -456,6 +472,9 @@ public class SysRoleServiceImpl implements ISysRoleService, RoleService {
@Override
public int deleteAuthUsers(Long roleId, Long[] userIds) {
List<Long> ids = List.of(userIds);
if (ids.contains(LoginHelper.getUserId())) {
throw new ServiceException("不允许修改当前用户角色!");
}
int rows = userRoleMapper.delete(new LambdaQueryWrapper<SysUserRole>()
.eq(SysUserRole::getRoleId, roleId)
.in(SysUserRole::getUserId, ids));
@ -477,6 +496,9 @@ public class SysRoleServiceImpl implements ISysRoleService, RoleService {
// 新增用户与角色管理
int rows = 1;
List<Long> ids = List.of(userIds);
if (ids.contains(LoginHelper.getUserId())) {
throw new ServiceException("不允许修改当前用户角色!");
}
List<SysUserRole> list = StreamUtils.toList(ids, userId -> {
SysUserRole ur = new SysUserRole();
ur.setUserId(userId);
@ -492,6 +514,17 @@ public class SysRoleServiceImpl implements ISysRoleService, RoleService {
return rows;
}
/**
* 根据角色ID清除该角色关联的所有在线用户的登录状态踢出在线用户
*
* <p>
* 先判断角色是否绑定用户若无绑定则直接返回
* 然后遍历当前所有在线Token查找拥有该角色的用户并强制登出
* 注意在线用户量过大时操作可能导致 Redis 阻塞需谨慎调用
* </p>
*
* @param roleId 角色ID
*/
@Override
public void cleanOnlineUserByRole(Long roleId) {
// 如果角色未绑定用户 直接返回
@ -523,6 +556,16 @@ public class SysRoleServiceImpl implements ISysRoleService, RoleService {
});
}
/**
* 根据用户ID列表清除对应在线用户的登录状态踢出指定用户
*
* <p>
* 遍历当前所有在线Token匹配用户ID列表中的用户强制登出
* 注意在线用户量过大时操作可能导致 Redis 阻塞需谨慎调用
* </p>
*
* @param userIds 需要清除的用户ID列表
*/
@Override
public void cleanOnlineUser(List<Long> userIds) {
List<String> keys = StpUtil.searchTokenValue("", 0, -1, false);

View File

@ -22,7 +22,6 @@ import org.dromara.common.core.utils.*;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.satoken.utils.LoginHelper;
import org.dromara.system.domain.SysRole;
import org.dromara.system.domain.SysUser;
import org.dromara.system.domain.SysUserPost;
import org.dromara.system.domain.SysUserRole;
@ -452,21 +451,31 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
* @param clear 清除已存在的关联数据
*/
private void insertUserPost(SysUserBo user, boolean clear) {
Long[] posts = user.getPostIds();
if (ArrayUtil.isNotEmpty(posts)) {
if (clear) {
// 删除用户与岗位关联
userPostMapper.delete(new LambdaQueryWrapper<SysUserPost>().eq(SysUserPost::getUserId, user.getUserId()));
}
// 新增用户与岗位管理
List<SysUserPost> list = StreamUtils.toList(List.of(posts), postId -> {
Long[] postIdArr = user.getPostIds();
if (ArrayUtil.isEmpty(postIdArr)) {
return;
}
List<Long> postIds = Arrays.asList(postIdArr);
// 校验是否有权限操作这些岗位含数据权限控制
if (postMapper.selectPostCount(postIds) != postIds.size()) {
throw new ServiceException("没有权限访问岗位的数据");
}
// 是否清除旧的用户岗位绑定
if (clear) {
userPostMapper.delete(new LambdaQueryWrapper<SysUserPost>().eq(SysUserPost::getUserId, user.getUserId()));
}
// 构建用户岗位关联列表并批量插入
List<SysUserPost> list = StreamUtils.toList(postIds,
postId -> {
SysUserPost up = new SysUserPost();
up.setUserId(user.getUserId());
up.setPostId(postId);
return up;
});
userPostMapper.insertBatch(list);
}
userPostMapper.insertBatch(list);
}
/**
@ -477,30 +486,36 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
* @param clear 清除已存在的关联数据
*/
private void insertUserRole(Long userId, Long[] roleIds, boolean clear) {
if (ArrayUtil.isNotEmpty(roleIds)) {
List<Long> roleList = new ArrayList<>(List.of(roleIds));
if (!LoginHelper.isSuperAdmin(userId)) {
roleList.remove(SystemConstants.SUPER_ADMIN_ID);
}
// 判断是否具有此角色的操作权限
List<SysRoleVo> roles = roleMapper.selectRoleList(
new QueryWrapper<SysRole>().in("r.role_id", roleList));
if (CollUtil.isEmpty(roles)) {
throw new ServiceException("没有权限访问角色的数据");
}
if (clear) {
// 删除用户与角色关联
userRoleMapper.delete(new LambdaQueryWrapper<SysUserRole>().eq(SysUserRole::getUserId, userId));
}
// 新增用户与角色管理
List<SysUserRole> list = StreamUtils.toList(roleList, roleId -> {
if (ArrayUtil.isEmpty(roleIds)) {
return;
}
List<Long> roleList = new ArrayList<>(Arrays.asList(roleIds));
// 非超级管理员禁止包含超级管理员角色
if (!LoginHelper.isSuperAdmin(userId)) {
roleList.remove(SystemConstants.SUPER_ADMIN_ID);
}
// 校验是否有权限访问这些角色含数据权限控制
if (roleMapper.selectRoleCount(roleList) != roleList.size()) {
throw new ServiceException("没有权限访问角色的数据");
}
// 是否清除原有绑定
if (clear) {
userRoleMapper.delete(new LambdaQueryWrapper<SysUserRole>().eq(SysUserRole::getUserId, userId));
}
// 批量插入用户-角色关联
List<SysUserRole> list = StreamUtils.toList(roleList,
roleId -> {
SysUserRole ur = new SysUserRole();
ur.setUserId(userId);
ur.setRoleId(roleId);
return ur;
});
userRoleMapper.insertBatch(list);
}
userRoleMapper.insertBatch(list);
}
/**

View File

@ -4,18 +4,4 @@
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.dromara.system.mapper.SysDeptMapper">
<resultMap type="org.dromara.system.domain.vo.SysDeptVo" id="SysDeptResult">
</resultMap>
<select id="selectDeptListByRoleId" resultType="Long">
select d.dept_id
from sys_dept d
left join sys_role_dept rd on d.dept_id = rd.dept_id
where rd.role_id = #{roleId}
<if test="deptCheckStrictly">
and d.dept_id not in (select d.parent_id from sys_dept d inner join sys_role_dept rd on d.dept_id = rd.dept_id and rd.role_id = #{roleId})
</if>
order by d.parent_id, d.order_num
</select>
</mapper>

View File

@ -4,67 +4,4 @@
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.dromara.system.mapper.SysMenuMapper">
<resultMap type="org.dromara.system.domain.SysMenu" id="SysMenuResult">
</resultMap>
<select id="selectMenuListByUserId" resultMap="SysMenuResult">
select distinct m.menu_id, m.parent_id, m.menu_name, m.path, m.component, m.query_param, m.visible, m.status,
m.perms, m.is_frame, m.is_cache, m.menu_type, m.icon, m.order_num, m.create_time
from sys_menu m
left join sys_role_menu rm on m.menu_id = rm.menu_id
left join sys_role r on rm.role_id = r.role_id
${ew.getCustomSqlSegment}
</select>
<select id="selectMenuTreeByUserId" parameterType="Long" resultMap="SysMenuResult">
select distinct m.menu_id,
m.parent_id,
m.menu_name,
m.path,
m.component,
m.query_param,
m.visible,
m.status,
m.perms,
m.is_frame,
m.is_cache,
m.menu_type,
m.icon,
m.order_num,
m.create_time
from sys_menu m
left join sys_role_menu rm on m.menu_id = rm.menu_id and m.status = '0'
left join sys_role r on rm.role_id = r.role_id and r.status = '0'
where m.menu_type in ('M', 'C')
and r.role_id in (select role_id from sys_user_role where user_id = #{userId})
order by m.parent_id, m.order_num
</select>
<select id="selectMenuListByRoleId" resultType="Long">
select m.menu_id
from sys_menu m
left join sys_role_menu rm on m.menu_id = rm.menu_id
where rm.role_id = #{roleId}
<if test="menuCheckStrictly">
and m.menu_id not in (select m.parent_id from sys_menu m inner join sys_role_menu rm on m.menu_id =
rm.menu_id and rm.role_id = #{roleId})
</if>
order by m.parent_id, m.order_num
</select>
<select id="selectMenuPermsByUserId" parameterType="Long" resultType="String">
select distinct m.perms
from sys_menu m
left join sys_role_menu rm on m.menu_id = rm.menu_id and m.status = '0'
left join sys_role r on r.role_id = rm.role_id and r.status = '0'
where r.role_id in (select role_id from sys_user_role where user_id = #{userId})
</select>
<select id="selectMenuPermsByRoleId" parameterType="Long" resultType="String">
select distinct m.perms
from sys_menu m
left join sys_role_menu rm on m.menu_id = rm.menu_id
where m.status = '0' and rm.role_id = #{roleId}
</select>
</mapper>

View File

@ -4,15 +4,4 @@
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.dromara.system.mapper.SysPostMapper">
<resultMap type="org.dromara.system.domain.vo.SysPostVo" id="SysPostResult">
</resultMap>
<select id="selectPostsByUserId" parameterType="Long" resultMap="SysPostResult">
select p.post_id, p.dept_id, p.post_name, p.post_code, p.post_category
from sys_post p
left join sys_user_post up on up.post_id = p.post_id
left join sys_user u on u.user_id = up.user_id
where u.user_id = #{userId}
</select>
</mapper>

View File

@ -4,56 +4,4 @@
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.dromara.system.mapper.SysRoleMapper">
<resultMap type="org.dromara.system.domain.vo.SysRoleVo" id="SysRoleResult">
</resultMap>
<sql id="selectRoleVo">
select distinct r.role_id,
r.role_name,
r.role_key,
r.role_sort,
r.data_scope,
r.menu_check_strictly,
r.dept_check_strictly,
r.status,
r.del_flag,
r.create_time,
r.remark
from sys_role r
left join sys_user_role sur on sur.role_id = r.role_id
left join sys_user u on u.user_id = sur.user_id
left join sys_dept d on u.dept_id = d.dept_id
</sql>
<select id="selectPageRoleList" resultMap="SysRoleResult">
<include refid="selectRoleVo"/>
${ew.getCustomSqlSegment}
</select>
<select id="selectRoleList" resultMap="SysRoleResult">
<include refid="selectRoleVo"/>
${ew.getCustomSqlSegment}
</select>
<select id="selectRolePermissionByUserId" parameterType="Long" resultMap="SysRoleResult">
<include refid="selectRoleVo"/>
WHERE r.del_flag = '0' and sur.user_id = #{userId}
</select>
<select id="selectRolesByUserId" parameterType="Long" resultMap="SysRoleResult">
select r.role_id,
r.role_name,
r.role_key,
r.role_sort,
r.data_scope,
r.status
from sys_role r
WHERE r.del_flag = '0' and r.role_id in (select role_id from sys_user_role where user_id = #{userId})
</select>
<select id="selectRoleById" resultMap="SysRoleResult">
<include refid="selectRoleVo"/>
WHERE r.del_flag = '0' and r.role_id = #{roleId}
</select>
</mapper>

View File

@ -4,10 +4,4 @@
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.dromara.system.mapper.SysUserRoleMapper">
<select id="selectUserIdsByRoleId" resultType="Long">
select u.user_id from sys_user u
inner join sys_user_role sur
on u.user_id = sur.user_id and sur.role_id = #{roleId}
</select>
</mapper>