Merge branch 'master' of 202204140934/pigx into dev
This commit is contained in:
commit
9bc774e774
10 files changed
+49
-6
No files matched your search
@@ -8,6 +8,7 @@ SET FOREIGN_KEY_CHECKS = 0;
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `sys_dept`;
|
||||
CREATE TABLE `sys_dept` (
|
||||
`dept_id` bigint NOT NULL,
|
||||
`dept_id` bigint NOT NULL,
|
||||
`name` varchar(50) CHARACTER SET utf8mb4 DEFAULT NULL,
|
||||
`sort_order` int NOT NULL DEFAULT '0' COMMENT '排序',
|
||||
@@ -333,6 +334,7 @@ CREATE TABLE `sys_menu` (
|
||||
`icon` varchar(32) CHARACTER SET utf8mb4 DEFAULT NULL,
|
||||
`sort_order` int DEFAULT '1' COMMENT '排序值',
|
||||
`keep_alive` char(1) CHARACTER SET utf8mb4 DEFAULT '0',
|
||||
`visible` char(1) CHARACTER SET utf8mb4 DEFAULT '1',
|
||||
`menu_type` char(1) CHARACTER SET utf8mb4 DEFAULT '0',
|
||||
`create_by` varchar(64) CHARACTER SET utf8 NOT NULL DEFAULT ' ' COMMENT '创建人',
|
||||
`create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
|
||||
+5
@@ -37,6 +37,11 @@ public class DataScope extends HashMap {
|
||||
*/
|
||||
private String scopeName = "dept_id";
|
||||
|
||||
/**
|
||||
* 本人权限范围字段
|
||||
*/
|
||||
private String userId = "user_id";
|
||||
|
||||
/**
|
||||
* 具体的数据范围
|
||||
*/
|
||||
|
||||
+2
-1
@@ -30,8 +30,9 @@ public interface DataScopeHandle {
|
||||
/**
|
||||
* 计算用户数据权限
|
||||
* @param deptList 部门ID,如果为空表示没有任何数据权限。
|
||||
* @param userId userId
|
||||
* @return 返回true表示无需进行数据过滤处理,返回false表示需要进行数据过滤
|
||||
*/
|
||||
Boolean calcScope(List<Long> deptList);
|
||||
Boolean calcScope(List<Long> deptList,StringBuilder userId);
|
||||
|
||||
}
|
||||
+13
-3
@@ -35,21 +35,31 @@ public class DataScopeInnerInterceptor implements DataScopeInterceptor {
|
||||
if (dataScope == null) {
|
||||
return;
|
||||
}
|
||||
// 查询个人权限字段名称
|
||||
String scopeUserId = dataScope.getUserId();
|
||||
StringBuilder userid = new StringBuilder();
|
||||
|
||||
String scopeName = dataScope.getScopeName();
|
||||
List<Long> deptIds = dataScope.getDeptIds();
|
||||
// 优先获取赋值数据
|
||||
if (CollUtil.isEmpty(deptIds) && dataScopeHandle.calcScope(deptIds)) {
|
||||
if (CollUtil.isEmpty(deptIds) && dataScopeHandle.calcScope(deptIds,userid)) {
|
||||
originalSql = String.format("SELECT %s FROM (%s) temp_data_scope", dataScope.getFunc().getType(),
|
||||
originalSql);
|
||||
mpBs.sql(originalSql);
|
||||
return;
|
||||
}
|
||||
|
||||
if (deptIds.isEmpty()) {
|
||||
//检查是否有数据权限校验
|
||||
//1.无数据权限限制,则直接返回全部
|
||||
if (deptIds.isEmpty()&&(userid.length()==0)) {
|
||||
originalSql = String.format("SELECT %s FROM (%s) temp_data_scope WHERE 1 = 2",
|
||||
dataScope.getFunc().getType(), originalSql);
|
||||
}
|
||||
//2.如果为本人权限则走下面
|
||||
else if (userid.length() == 1) {
|
||||
originalSql = String.format("SELECT %s FROM (%s) temp_data_scope WHERE temp_data_scope.%s = %s",
|
||||
dataScope.getFunc().getType(), originalSql, scopeUserId, userid);
|
||||
}
|
||||
//3.都没有,则是其他权限,走下面
|
||||
else {
|
||||
String join = CollectionUtil.join(deptIds, ",");
|
||||
originalSql = String.format("SELECT %s FROM (%s) temp_data_scope WHERE temp_data_scope.%s IN (%s)",
|
||||
|
||||
+6
-1
@@ -48,7 +48,12 @@ public enum DataScopeTypeEnum {
|
||||
/**
|
||||
* 本级
|
||||
*/
|
||||
OWN_LEVEL(3, "本级");
|
||||
OWN_LEVEL(3, "本级"),
|
||||
|
||||
/**
|
||||
* 本人
|
||||
*/
|
||||
SELF_LEVEL(4, "本人");
|
||||
|
||||
/**
|
||||
* 类型
|
||||
|
||||
+7
-1
@@ -49,10 +49,11 @@ public class PigxDefaultDatascopeHandle implements DataScopeHandle {
|
||||
/**
|
||||
* 计算用户数据权限
|
||||
* @param deptList
|
||||
* @param userId 个人权限用户
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Boolean calcScope(List<Long> deptList) {
|
||||
public Boolean calcScope(List<Long> deptList,StringBuilder userId) {
|
||||
PigxUser user = SecurityUtils.getUser();
|
||||
List<String> roleIdList = user.getAuthorities().stream().map(GrantedAuthority::getAuthority)
|
||||
.filter(authority -> authority.startsWith(SecurityConstants.ROLE))
|
||||
@@ -98,6 +99,11 @@ public class PigxDefaultDatascopeHandle implements DataScopeHandle {
|
||||
if (DataScopeTypeEnum.OWN_LEVEL.getType() == dsType) {
|
||||
deptList.add(user.getDeptId());
|
||||
}
|
||||
|
||||
// 只查询本人
|
||||
if (DataScopeTypeEnum.SELF_LEVEL.getType() == dsType) {
|
||||
userId.append(user.getId());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -49,6 +49,11 @@ public class SysDept extends Model<SysDept> {
|
||||
@ApiModelProperty(value = "部门id")
|
||||
private Long deptId;
|
||||
|
||||
/**
|
||||
* 添加用户的用户id(防止报错)
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 部门名称
|
||||
*/
|
||||
|
||||
@@ -103,6 +103,12 @@ public class SysMenu extends Model<SysMenu> {
|
||||
@ApiModelProperty(value = "路由缓冲")
|
||||
private String keepAlive;
|
||||
|
||||
/**
|
||||
* 菜单显示隐藏控制
|
||||
*/
|
||||
@ApiModelProperty(value = "菜单是否显示")
|
||||
private String visible;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
|
||||
+1
@@ -155,6 +155,7 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
||||
extra.put("label", menu.getName());
|
||||
extra.put("sortOrder", menu.getSortOrder());
|
||||
extra.put("keepAlive", menu.getKeepAlive());
|
||||
extra.put("visible", menu.getVisible());
|
||||
node.setExtra(extra);
|
||||
return node;
|
||||
};
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
<result column="sort_order" property="sortOrder"/>
|
||||
<result column="menu_type" property="menuType"/>
|
||||
<result column="keep_alive" property="keepAlive"/>
|
||||
<result column="visible" property="visible"/>
|
||||
<result column="create_time" property="createTime"/>
|
||||
<result column="update_time" property="updateTime"/>
|
||||
<result column="del_flag" property="delFlag"/>
|
||||
@@ -47,6 +48,7 @@
|
||||
sys_menu.sort_order,
|
||||
sys_menu.keep_alive,
|
||||
sys_menu.menu_type,
|
||||
sys_menu.visible,
|
||||
sys_menu.create_time,
|
||||
sys_menu.update_time,
|
||||
sys_menu.del_flag
|
||||
|
||||
Reference in new issue
Block a user