mirror of https://gitee.com/stylefeng/roses
parent
2bc5e18fe8
commit
4345fb0e5b
|
@ -112,4 +112,9 @@ public class ResourceDefinition implements Serializable {
|
|||
*/
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
private String createUser;
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package cn.stylefeng.roses.kernel.system;
|
||||
|
||||
import cn.stylefeng.roses.kernel.system.pojo.role.response.SysRoleMenuButtonResponse;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.role.response.SysRoleMenuResponse;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.role.response.SysRoleResourceResponse;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.role.response.SysRoleResponse;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -62,6 +65,16 @@ public interface RoleServiceApi {
|
|||
*/
|
||||
List<String> getRoleResourceCodeList(List<Long> roleIdList);
|
||||
|
||||
/**
|
||||
* 获取角色的资源code集合
|
||||
*
|
||||
* @param roleIdList 角色id集合
|
||||
* @return 资源code集合
|
||||
* @author majianguo
|
||||
* @date 2020/11/5 上午11:17
|
||||
*/
|
||||
List<SysRoleResourceResponse> getRoleResourceList(List<Long> roleIdList);
|
||||
|
||||
/**
|
||||
* 获取角色对应的按钮编码集合
|
||||
*
|
||||
|
@ -72,4 +85,22 @@ public interface RoleServiceApi {
|
|||
*/
|
||||
Set<String> getRoleButtonCodes(List<Long> roleIdList);
|
||||
|
||||
/**
|
||||
* 获取角色拥有的菜单
|
||||
*
|
||||
* @param roleIdList 角色集合
|
||||
* @author majianguo
|
||||
* @date 2021/1/9 17:33
|
||||
*/
|
||||
List<SysRoleMenuResponse> getRoleMenuList(List<Long> roleIdList);
|
||||
|
||||
/**
|
||||
* 获取角色拥有的菜单按钮
|
||||
*
|
||||
* @param roleIdList 角色集合
|
||||
* @author majianguo
|
||||
* @date 2021/1/9 17:33
|
||||
*/
|
||||
List<SysRoleMenuButtonResponse> getRoleMenuButtonList(List<Long> roleIdList);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package cn.stylefeng.roses.kernel.system;
|
||||
|
||||
import cn.stylefeng.roses.kernel.auth.api.pojo.login.LoginUser;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.user.SysUserResponse;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.user.UserLoginInfoDTO;
|
||||
|
||||
import java.util.Date;
|
||||
|
@ -76,8 +77,18 @@ public interface UserServiceApi {
|
|||
|
||||
/**
|
||||
* 获取在线用户列表
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
List<LoginUser> onlineUserList();
|
||||
|
||||
/**
|
||||
* 根据用户ID获取用户信息
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @author majianguo
|
||||
* @date 2021/1/9 19:00
|
||||
*/
|
||||
SysUserResponse getUserInfoByUserId(Long userId);
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
package cn.stylefeng.roses.kernel.system.pojo.menu.layui;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 角色分配资源和菜单的树
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/1/9 16:59
|
||||
*/
|
||||
@Data
|
||||
public class LayuiMenuAndButtonTreeResponse {
|
||||
|
||||
/**
|
||||
* 节点ID
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 节点父ID
|
||||
*/
|
||||
private Long pid;
|
||||
|
||||
/**
|
||||
* 节点名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 是否是菜单(如果是false,则pid是菜单的id)
|
||||
*/
|
||||
private Boolean menuFlag;
|
||||
|
||||
/**
|
||||
* 是否选择(已拥有的是true)
|
||||
*/
|
||||
private Boolean checked;
|
||||
|
||||
/**
|
||||
* 按钮code
|
||||
*/
|
||||
private String buttonCode;
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package cn.stylefeng.roses.kernel.system.pojo.role.request;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 角色按钮
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/1/9 17:33
|
||||
*/
|
||||
@Data
|
||||
public class SysRoleMenuButtonRequest {
|
||||
|
||||
/**
|
||||
* 按钮id
|
||||
*/
|
||||
private Long buttonId;
|
||||
|
||||
/**
|
||||
* 按钮编码
|
||||
*/
|
||||
private String buttonCode;
|
||||
|
||||
}
|
|
@ -48,7 +48,7 @@ public class SysRoleRequest extends BaseRequest {
|
|||
/**
|
||||
* 主键
|
||||
*/
|
||||
@NotNull(message = "roleId不能为空", groups = {edit.class, delete.class, detail.class, updateStatus.class, grantResource.class, grantData.class})
|
||||
@NotNull(message = "roleId不能为空", groups = {edit.class, delete.class, detail.class, updateStatus.class, grantResource.class, grantData.class, grantMenuButton.class})
|
||||
private Long roleId;
|
||||
|
||||
/**
|
||||
|
@ -61,13 +61,7 @@ public class SysRoleRequest extends BaseRequest {
|
|||
* 角色编码
|
||||
*/
|
||||
@NotBlank(message = "角色编码不能为空", groups = {add.class, edit.class})
|
||||
@TableUniqueValue(
|
||||
message = "角色编码存在重复",
|
||||
groups = {add.class, edit.class},
|
||||
tableName = "sys_role",
|
||||
columnName = "role_code",
|
||||
idFieldName = "role_id",
|
||||
excludeLogicDeleteItems = true)
|
||||
@TableUniqueValue(message = "角色编码存在重复", groups = {add.class, edit.class}, tableName = "sys_role", columnName = "role_code", idFieldName = "role_id", excludeLogicDeleteItems = true)
|
||||
private String roleCode;
|
||||
|
||||
/**
|
||||
|
@ -105,16 +99,37 @@ public class SysRoleRequest extends BaseRequest {
|
|||
@NotNull(message = "授权数据不能为空,请检查grantOrgIdList参数", groups = {grantData.class})
|
||||
private List<Long> grantOrgIdList;
|
||||
|
||||
/**
|
||||
* 授权菜单
|
||||
*/
|
||||
@NotNull(message = "授权菜单Id不能为空,请检查grantMenuIdList参数", groups = {grantMenuButton.class})
|
||||
private List<Long> grantMenuIdList;
|
||||
|
||||
/**
|
||||
* 授权菜单按钮
|
||||
*/
|
||||
@NotNull(message = "授权菜单按钮Id不能为空,请检查grantMenuButtonIdList参数", groups = {grantMenuButton.class})
|
||||
private List<SysRoleMenuButtonRequest> grantMenuButtonIdList;
|
||||
|
||||
/**
|
||||
* 参数校验分组:授权菜单和按钮
|
||||
*/
|
||||
public @interface grantMenuButton {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 参数校验分组:授权资源
|
||||
*/
|
||||
public @interface grantResource {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 参数校验分组:授权数据
|
||||
*/
|
||||
public @interface grantData {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
package cn.stylefeng.roses.kernel.system.pojo.role.response;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 角色按钮关联结果
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/1/9 17:33
|
||||
*/
|
||||
@Data
|
||||
public class SysRoleMenuButtonResponse {
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
private Long roleButtonId;
|
||||
|
||||
/**
|
||||
* 角色id
|
||||
*/
|
||||
private Long roleId;
|
||||
|
||||
/**
|
||||
* 按钮id
|
||||
*/
|
||||
private Long buttonId;
|
||||
|
||||
/**
|
||||
* 按钮编码
|
||||
*/
|
||||
private String buttonCode;
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package cn.stylefeng.roses.kernel.system.pojo.role.response;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 角色菜单关联返回数据
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/1/9 18:07
|
||||
*/
|
||||
@Data
|
||||
public class SysRoleMenuResponse {
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
private Long roleMenuId;
|
||||
|
||||
/**
|
||||
* 角色id
|
||||
*/
|
||||
private Long roleId;
|
||||
|
||||
/**
|
||||
* 菜单id
|
||||
*/
|
||||
private Long menuId;
|
||||
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
Copyright [2020] [https://www.stylefeng.cn]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
Guns采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
|
||||
|
||||
1.请不要删除和修改根目录下的LICENSE文件。
|
||||
2.请不要删除和修改Guns源码头部的版权声明。
|
||||
3.请保留源码和相关描述文件的项目出处,作者声明等。
|
||||
4.分发源码时候,请注明软件出处 https://gitee.com/stylefeng/guns-separation
|
||||
5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/stylefeng/guns-separation
|
||||
6.若您的项目无法满足以上几点,可申请商业授权,获取Guns商业授权许可,请在官网购买授权,地址为 https://www.stylefeng.cn
|
||||
*/
|
||||
package cn.stylefeng.roses.kernel.system.pojo.role.response;
|
||||
|
||||
import cn.stylefeng.roses.kernel.db.api.pojo.entity.BaseEntity;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 角色资源关联
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2020/11/5 下午4:30
|
||||
*/
|
||||
@Data
|
||||
public class SysRoleResourceResponse extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
private Long roleResourceId;
|
||||
|
||||
/**
|
||||
* 角色id
|
||||
*/
|
||||
private Long roleId;
|
||||
|
||||
/**
|
||||
* 资源编码
|
||||
*/
|
||||
private String resourceCode;
|
||||
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
package cn.stylefeng.roses.kernel.system.pojo.user;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 系统用户结果
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2020/4/2 9:19
|
||||
*/
|
||||
@Data
|
||||
public class SysUserResponse {
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 账号
|
||||
*/
|
||||
private String account;
|
||||
|
||||
/**
|
||||
* 昵称
|
||||
*/
|
||||
private String nickName;
|
||||
|
||||
/**
|
||||
* 姓名
|
||||
*/
|
||||
private String realName;
|
||||
|
||||
/**
|
||||
* 头像
|
||||
*/
|
||||
private Long avatar;
|
||||
|
||||
/**
|
||||
* 生日
|
||||
*/
|
||||
private Date birthday;
|
||||
|
||||
/**
|
||||
* 性别(M-男,F-女)
|
||||
*/
|
||||
private String sex;
|
||||
|
||||
/**
|
||||
* 邮箱
|
||||
*/
|
||||
private String email;
|
||||
|
||||
/**
|
||||
* 手机
|
||||
*/
|
||||
private String phone;
|
||||
|
||||
/**
|
||||
* 电话
|
||||
*/
|
||||
private String tel;
|
||||
|
||||
/**
|
||||
* 用户所属机构
|
||||
*/
|
||||
private Long orgId;
|
||||
|
||||
/**
|
||||
* 用户所属机构的职务
|
||||
*/
|
||||
private Long positionId;
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
private Integer statusFlag;
|
||||
|
||||
}
|
|
@ -10,6 +10,8 @@ import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
|
|||
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.menu.SysMenuRequest;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.menu.antd.AntdSysMenuResponse;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.menu.layui.LayuiMenuAndButtonTreeResponse;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.role.request.SysRoleRequest;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.ztree.ZTreeNode;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
@ -133,6 +135,17 @@ public class SysMenuController {
|
|||
return new SuccessResponseData(sysMenuService.treeForGrant(sysMenuRequest));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取系统菜单树(包含按钮),用于给角色授权时选择
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/1/9 17:10
|
||||
*/
|
||||
@GetResource(name = "获取系统菜单树(包含按钮),用于给角色授权时选择", path = "/sysMenu/menuAndButtonTree")
|
||||
public List<LayuiMenuAndButtonTreeResponse> menuAndButtonTree(SysRoleRequest sysRoleRequest) {
|
||||
return sysMenuService.getMenuAndButtonTree(sysRoleRequest);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取主页左侧菜单列表(适配Antd Vue的版本)
|
||||
*
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
package cn.stylefeng.roses.kernel.menu.modular.entity;
|
||||
|
||||
import cn.stylefeng.roses.kernel.db.api.pojo.entity.BaseEntity;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 菜单下的按钮实例类
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/01/09 14:44
|
||||
*/
|
||||
@TableName("sys_menu_button")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class SysMenuButton extends BaseEntity implements Serializable {
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId("button_id")
|
||||
private Long buttonId;
|
||||
|
||||
/**
|
||||
* 菜单id,按钮需要挂在菜单下
|
||||
*/
|
||||
@TableField("menu_id")
|
||||
private Long menuId;
|
||||
|
||||
/**
|
||||
* 按钮的名称
|
||||
*/
|
||||
@TableField("button_name")
|
||||
private String buttonName;
|
||||
|
||||
/**
|
||||
* 按钮的编码
|
||||
*/
|
||||
@TableField("button_code")
|
||||
private String buttonCode;
|
||||
|
||||
/**
|
||||
* 是否删除:Y-被删除,N-未删除
|
||||
*/
|
||||
@TableField("del_flag")
|
||||
private String delFlag;
|
||||
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package cn.stylefeng.roses.kernel.menu.modular.mapper;
|
||||
|
||||
import cn.stylefeng.roses.kernel.menu.modular.entity.SysMenuButton;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* 菜单下的按钮数据层
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/01/09 14:44
|
||||
*/
|
||||
public interface SysMenuButtonMapper extends BaseMapper<SysMenuButton> {
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="cn.stylefeng.roses.kernel.menu.modular.mapper.SysMenuButtonMapper">
|
||||
</mapper>
|
|
@ -0,0 +1,14 @@
|
|||
package cn.stylefeng.roses.kernel.menu.modular.service;
|
||||
|
||||
import cn.stylefeng.roses.kernel.menu.modular.entity.SysMenuButton;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* 菜单下的按钮业务层
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/01/09 14:44
|
||||
*/
|
||||
public interface SysMenuButtonService extends IService<SysMenuButton> {
|
||||
|
||||
}
|
|
@ -29,7 +29,9 @@ import cn.stylefeng.roses.kernel.system.pojo.menu.SysMenuRequest;
|
|||
import cn.stylefeng.roses.kernel.system.pojo.menu.antd.AntdIndexMenuTreeNode;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.menu.antd.AntdSysMenuResponse;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.menu.layui.LayuiAppIndexMenus;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.menu.layui.LayuiMenuAndButtonTreeResponse;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.menu.other.MenuSelectTreeNode;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.role.request.SysRoleRequest;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.ztree.ZTreeNode;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
|
@ -171,4 +173,11 @@ public interface SysMenuService extends IService<SysMenu> {
|
|||
*/
|
||||
List<AntdSysMenuResponse> getSystemAllMenusAntdv();
|
||||
|
||||
/**
|
||||
* 获取包含按钮的系统菜单
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/1/9 17:11
|
||||
*/
|
||||
List<LayuiMenuAndButtonTreeResponse> getMenuAndButtonTree(SysRoleRequest sysRoleRequest);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
package cn.stylefeng.roses.kernel.menu.modular.service.impl;
|
||||
|
||||
import cn.stylefeng.roses.kernel.menu.modular.entity.SysMenuButton;
|
||||
import cn.stylefeng.roses.kernel.menu.modular.mapper.SysMenuButtonMapper;
|
||||
import cn.stylefeng.roses.kernel.menu.modular.service.SysMenuButtonService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 菜单下的按钮业务实现层
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/01/09 14:44
|
||||
*/
|
||||
@Service
|
||||
public class SysMenuButtonServiceImpl extends ServiceImpl<SysMenuButtonMapper, SysMenuButton> implements SysMenuButtonService {
|
||||
|
||||
}
|
|
@ -33,10 +33,12 @@ import cn.stylefeng.roses.kernel.auth.api.pojo.login.LoginUser;
|
|||
import cn.stylefeng.roses.kernel.auth.api.pojo.login.basic.SimpleRoleInfo;
|
||||
import cn.stylefeng.roses.kernel.db.api.DbOperatorApi;
|
||||
import cn.stylefeng.roses.kernel.menu.modular.entity.SysMenu;
|
||||
import cn.stylefeng.roses.kernel.menu.modular.entity.SysMenuButton;
|
||||
import cn.stylefeng.roses.kernel.menu.modular.factory.AntdMenusFactory;
|
||||
import cn.stylefeng.roses.kernel.menu.modular.factory.LayuiMenusFactory;
|
||||
import cn.stylefeng.roses.kernel.menu.modular.factory.common.CommonMenusFactory;
|
||||
import cn.stylefeng.roses.kernel.menu.modular.mapper.SysMenuMapper;
|
||||
import cn.stylefeng.roses.kernel.menu.modular.service.SysMenuButtonService;
|
||||
import cn.stylefeng.roses.kernel.menu.modular.service.SysMenuService;
|
||||
import cn.stylefeng.roses.kernel.rule.enums.StatusEnum;
|
||||
import cn.stylefeng.roses.kernel.rule.enums.YesOrNotEnum;
|
||||
|
@ -54,7 +56,11 @@ import cn.stylefeng.roses.kernel.system.pojo.menu.SysMenuRequest;
|
|||
import cn.stylefeng.roses.kernel.system.pojo.menu.antd.AntdIndexMenuTreeNode;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.menu.antd.AntdSysMenuResponse;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.menu.layui.LayuiAppIndexMenus;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.menu.layui.LayuiMenuAndButtonTreeResponse;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.menu.other.MenuSelectTreeNode;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.role.request.SysRoleRequest;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.role.response.SysRoleMenuButtonResponse;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.role.response.SysRoleMenuResponse;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.ztree.ZTreeNode;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
|
@ -63,10 +69,7 @@ import org.springframework.stereotype.Service;
|
|||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
|
@ -87,6 +90,9 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
|||
@Resource
|
||||
private AppServiceApi appServiceApi;
|
||||
|
||||
@Resource
|
||||
private SysMenuButtonService sysMenuButtonService;
|
||||
|
||||
@Override
|
||||
public void add(SysMenuRequest sysMenuRequest) {
|
||||
|
||||
|
@ -258,8 +264,7 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
|||
// 给应用排序,激活的应用放在前边
|
||||
String activeAppCode = appServiceApi.getActiveAppCode();
|
||||
if (activeAppCode != null) {
|
||||
List<LayuiAppIndexMenus> layuiAppIndexMenusArrayList =
|
||||
layuiAppIndexMenus.stream().filter(i -> activeAppCode.equals(i.getAppCode())).collect(Collectors.toList());
|
||||
List<LayuiAppIndexMenus> layuiAppIndexMenusArrayList = layuiAppIndexMenus.stream().filter(i -> activeAppCode.equals(i.getAppCode())).collect(Collectors.toList());
|
||||
layuiAppIndexMenusArrayList.addAll(layuiAppIndexMenus.stream().filter(i -> !activeAppCode.equals(i.getAppCode())).collect(Collectors.toList()));
|
||||
return layuiAppIndexMenusArrayList;
|
||||
}
|
||||
|
@ -321,6 +326,106 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
|||
return this.baseMapper.getSystemAllMenus();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<LayuiMenuAndButtonTreeResponse> getMenuAndButtonTree(SysRoleRequest sysRoleRequest) {
|
||||
List<LayuiMenuAndButtonTreeResponse> menuTreeNodeList = CollectionUtil.newArrayList();
|
||||
|
||||
LambdaQueryWrapper<SysMenu> munuWrapper = new LambdaQueryWrapper<>();
|
||||
munuWrapper.eq(SysMenu::getStatusFlag, StatusEnum.ENABLE.getCode());
|
||||
munuWrapper.eq(SysMenu::getDelFlag, YesOrNotEnum.N.getCode());
|
||||
// 非超级管理员则获取自己拥有的菜单,分配给人员,防止越级授权
|
||||
if (!LoginContext.me().getSuperAdminFlag()) {
|
||||
List<Long> menuIdList = getCurrentUserMenuIds();
|
||||
if (!menuIdList.isEmpty()) {
|
||||
munuWrapper.in(SysMenu::getMenuId, menuIdList);
|
||||
}
|
||||
}
|
||||
|
||||
List<SysMenu> sysMenuList = this.list(munuWrapper);
|
||||
|
||||
List<Long> menuList = sysMenuList.parallelStream().map(SysMenu::getMenuId).collect(Collectors.toList());
|
||||
|
||||
// 查询所有的按钮
|
||||
LambdaQueryWrapper<SysMenuButton> buttonWrapper = new LambdaQueryWrapper<>();
|
||||
buttonWrapper.eq(SysMenuButton::getDelFlag, YesOrNotEnum.N.getCode());
|
||||
buttonWrapper.in(SysMenuButton::getMenuId, menuList);
|
||||
List<SysMenuButton> sysMenuButtons = sysMenuButtonService.list(buttonWrapper);
|
||||
|
||||
// 把按钮按照菜单id存起来,方便后续操作
|
||||
Map<Long, List<SysMenuButton>> buttons = new HashMap<>(menuList.size());
|
||||
for (SysMenuButton menuButton : sysMenuButtons) {
|
||||
List<SysMenuButton> buttonList = buttons.get(menuButton.getMenuId());
|
||||
if (ObjectUtil.isEmpty(buttonList)) {
|
||||
buttonList = new ArrayList<>();
|
||||
buttons.put(menuButton.getMenuId(), buttonList);
|
||||
}
|
||||
buttonList.add(menuButton);
|
||||
}
|
||||
|
||||
// 查询所有已有的权限
|
||||
// 所有已有的菜单权限
|
||||
List<SysRoleMenuResponse> roleMenuList = roleServiceApi.getRoleMenuList(Collections.singletonList(sysRoleRequest.getRoleId()));
|
||||
// 转换成map方便后续处理
|
||||
Map<Long, SysRoleMenuResponse> roleMenuMap = new HashMap<>();
|
||||
for (SysRoleMenuResponse sysRoleMenuResponse : roleMenuList) {
|
||||
roleMenuMap.put(sysRoleMenuResponse.getMenuId(), sysRoleMenuResponse);
|
||||
}
|
||||
|
||||
// 所有的按钮权限
|
||||
List<SysRoleMenuButtonResponse> roleMenuButtonList = roleServiceApi.getRoleMenuButtonList(Collections.singletonList(sysRoleRequest.getRoleId()));
|
||||
|
||||
// 转换成map方便后续处理
|
||||
Map<Long, SysRoleMenuButtonResponse> roleMenuButtonMap = new HashMap<>();
|
||||
for (SysRoleMenuButtonResponse buttonResponse : roleMenuButtonList) {
|
||||
roleMenuButtonMap.put(buttonResponse.getButtonId(), buttonResponse);
|
||||
}
|
||||
|
||||
// 组装树结果
|
||||
for (SysMenu sysMenu : sysMenuList) {
|
||||
LayuiMenuAndButtonTreeResponse menuTree = new LayuiMenuAndButtonTreeResponse();
|
||||
menuTree.setId(sysMenu.getMenuId());
|
||||
menuTree.setMenuFlag(true);
|
||||
menuTree.setName(sysMenu.getMenuName());
|
||||
menuTree.setPid(sysMenu.getMenuParentId());
|
||||
// 判断是否已经有了
|
||||
SysRoleMenuResponse roleMenuResponse = roleMenuMap.get(sysMenu.getMenuId());
|
||||
if (ObjectUtil.isEmpty(roleMenuResponse)) {
|
||||
menuTree.setChecked(false);
|
||||
} else {
|
||||
menuTree.setChecked(true);
|
||||
}
|
||||
|
||||
// 处理该菜单的按钮
|
||||
List<SysMenuButton> menuButtons = buttons.get(sysMenu.getMenuId());
|
||||
|
||||
// 不为空就去处理
|
||||
if (ObjectUtil.isNotEmpty(menuButtons)) {
|
||||
for (SysMenuButton menuButton : menuButtons) {
|
||||
LayuiMenuAndButtonTreeResponse buttonTree = new LayuiMenuAndButtonTreeResponse();
|
||||
buttonTree.setName(menuButton.getButtonName());
|
||||
buttonTree.setId(menuButton.getButtonId());
|
||||
buttonTree.setPid(menuButton.getMenuId());
|
||||
buttonTree.setButtonCode(menuButton.getButtonCode());
|
||||
buttonTree.setMenuFlag(false);
|
||||
// 判断是否已经拥有
|
||||
SysRoleMenuButtonResponse buttonResponse = roleMenuButtonMap.get(menuButton.getButtonId());
|
||||
if (ObjectUtil.isNotEmpty(buttonResponse)) {
|
||||
buttonTree.setChecked(true);
|
||||
menuTree.setChecked(true);
|
||||
} else {
|
||||
buttonTree.setChecked(false);
|
||||
}
|
||||
// 记录按钮节点
|
||||
menuTreeNodeList.add(buttonTree);
|
||||
}
|
||||
}
|
||||
// 记录菜单节点
|
||||
menuTreeNodeList.add(menuTree);
|
||||
}
|
||||
|
||||
return menuTreeNodeList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasMenu(String appCode) {
|
||||
SysMenuRequest sysMenuRequest = new SysMenuRequest();
|
||||
|
|
|
@ -11,6 +11,7 @@ import cn.stylefeng.roses.kernel.rule.pojo.request.BaseRequest;
|
|||
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
|
||||
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.resource.request.ResourceRequest;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.role.request.SysRoleRequest;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
|
@ -66,6 +67,17 @@ public class ResourceController {
|
|||
return new SuccessResponseData(resourceTree);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取资源平级树列表,用于分配接口权限
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/1/9 15:07
|
||||
*/
|
||||
@GetResource(name = "获取资源平级树列表,用于分配接口权限", path = "/resource/getLateralTree")
|
||||
public List<ResourceTreeNode> getLateralTree(SysRoleRequest sysRoleRequest) {
|
||||
return sysResourceService.getResourceLateralTree(sysRoleRequest.getRoleId());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取接口详情
|
||||
*
|
||||
|
|
|
@ -36,6 +36,11 @@ public class ResourceTreeNode {
|
|||
*/
|
||||
private Boolean resourceFlag;
|
||||
|
||||
/**
|
||||
* 能否选择
|
||||
*/
|
||||
private Boolean checked;
|
||||
|
||||
/**
|
||||
* 子节点集合
|
||||
*/
|
||||
|
|
|
@ -67,4 +67,11 @@ public interface SysResourceService extends IService<SysResource> {
|
|||
*/
|
||||
ResourceDefinition getResourceDetail(ResourceRequest resourceRequest);
|
||||
|
||||
/**
|
||||
* 获取平级树节点列表
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/1/9 15:08
|
||||
*/
|
||||
List<ResourceTreeNode> getResourceLateralTree(Long roleId);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
package cn.stylefeng.roses.kernel.resource.modular.service.impl;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.stylefeng.roses.kernel.auth.api.LoginUserApi;
|
||||
import cn.stylefeng.roses.kernel.auth.api.context.LoginContext;
|
||||
import cn.stylefeng.roses.kernel.auth.api.pojo.login.basic.SimpleRoleInfo;
|
||||
import cn.stylefeng.roses.kernel.db.api.factory.PageFactory;
|
||||
import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory;
|
||||
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
|
||||
|
@ -14,12 +17,19 @@ import cn.stylefeng.roses.kernel.resource.modular.factory.ResourceFactory;
|
|||
import cn.stylefeng.roses.kernel.resource.modular.mapper.SysResourceMapper;
|
||||
import cn.stylefeng.roses.kernel.resource.modular.pojo.ResourceTreeNode;
|
||||
import cn.stylefeng.roses.kernel.resource.modular.service.SysResourceService;
|
||||
import cn.stylefeng.roses.kernel.rule.constants.RuleConstants;
|
||||
import cn.stylefeng.roses.kernel.rule.enums.YesOrNotEnum;
|
||||
import cn.stylefeng.roses.kernel.system.ResourceServiceApi;
|
||||
import cn.stylefeng.roses.kernel.system.RoleServiceApi;
|
||||
import cn.stylefeng.roses.kernel.system.UserServiceApi;
|
||||
import cn.stylefeng.roses.kernel.system.constants.SystemConstants;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.resource.request.ResourceRequest;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.role.response.SysRoleResourceResponse;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.role.response.SysRoleResponse;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.user.SysUserResponse;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
|
@ -46,6 +56,12 @@ public class SysResourceServiceImpl extends ServiceImpl<SysResourceMapper, SysRe
|
|||
@Resource
|
||||
private ResourceCache resourceCache;
|
||||
|
||||
@Resource
|
||||
private RoleServiceApi roleServiceApi;
|
||||
|
||||
@Resource
|
||||
private UserServiceApi userServiceApi;
|
||||
|
||||
@Override
|
||||
public PageResult<SysResource> getResourceList(ResourceRequest resourceRequest) {
|
||||
LambdaQueryWrapper<SysResource> wrapper = createWrapper(resourceRequest);
|
||||
|
@ -103,12 +119,104 @@ public class SysResourceServiceImpl extends ServiceImpl<SysResourceMapper, SysRe
|
|||
sysResourceLambdaQueryWrapper.eq(SysResource::getResourceCode, resourceRequest.getResourceCode());
|
||||
SysResource sysResource = this.getOne(sysResourceLambdaQueryWrapper);
|
||||
if (sysResource != null) {
|
||||
return ResourceFactory.createResourceDefinition(sysResource);
|
||||
ResourceDefinition definition = ResourceFactory.createResourceDefinition(sysResource);
|
||||
|
||||
// 翻译创建人
|
||||
if (sysResource.getCreateUser().equals(RuleConstants.TREE_ROOT_ID)) {
|
||||
definition.setCreateUser("超级管理员");
|
||||
} else {
|
||||
SysUserResponse userInfo = userServiceApi.getUserInfoByUserId(sysResource.getCreateUser());
|
||||
if (ObjectUtil.isNotEmpty(userInfo)) {
|
||||
definition.setCreateUser(userInfo.getRealName());
|
||||
}
|
||||
}
|
||||
return definition;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ResourceTreeNode> getResourceLateralTree(Long roleId) {
|
||||
// 结果
|
||||
List<ResourceTreeNode> res = new ArrayList<>();
|
||||
|
||||
// 获取所有的资源
|
||||
LambdaQueryWrapper<SysResource> sysResourceLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
sysResourceLambdaQueryWrapper.select(SysResource::getAppCode, SysResource::getModularCode, SysResource::getModularName, SysResource::getResourceCode, SysResource::getUrl, SysResource::getResourceName);
|
||||
|
||||
// 只查询需要授权的接口
|
||||
sysResourceLambdaQueryWrapper.eq(SysResource::getRequiredPermissionFlag, YesOrNotEnum.Y.getCode());
|
||||
|
||||
LoginUserApi loginUserApi = LoginContext.me();
|
||||
if (!loginUserApi.getSuperAdminFlag()) {
|
||||
// 获取权限列表
|
||||
List<Long> roleIds = loginUserApi.getLoginUser().getSimpleRoleInfoList().parallelStream().map(SimpleRoleInfo::getRoleId).collect(Collectors.toList());
|
||||
List<String> resourceCodeList = roleServiceApi.getRoleResourceCodeList(roleIds);
|
||||
if (!resourceCodeList.isEmpty()) {
|
||||
sysResourceLambdaQueryWrapper.in(SysResource::getResourceCode, resourceCodeList);
|
||||
}
|
||||
}
|
||||
|
||||
List<SysResource> allResource = this.list(sysResourceLambdaQueryWrapper);
|
||||
|
||||
// 查询当前角色已有的接口
|
||||
List<SysRoleResourceResponse> resourceList = roleServiceApi.getRoleResourceList(Collections.singletonList(roleId));
|
||||
|
||||
// 该角色已拥有权限
|
||||
Map<String, SysRoleResourceResponse> alreadyHave = new HashMap<>(resourceList.size());
|
||||
for (SysRoleResourceResponse sysRoleResponse : resourceList) {
|
||||
alreadyHave.put(sysRoleResponse.getResourceCode(), sysRoleResponse);
|
||||
}
|
||||
|
||||
// 根据模块名称把资源分类
|
||||
Map<String, List<SysResource>> modularMap = new HashMap<>();
|
||||
for (SysResource sysResource : allResource) {
|
||||
List<SysResource> sysResources = modularMap.get(sysResource.getModularName());
|
||||
|
||||
// 没有就新建一个
|
||||
if (ObjectUtil.isEmpty(sysResources)) {
|
||||
sysResources = new ArrayList<>();
|
||||
modularMap.put(sysResource.getModularName(), sysResources);
|
||||
}
|
||||
// 把自己加入进去
|
||||
sysResources.add(sysResource);
|
||||
}
|
||||
|
||||
// 创建一级节点
|
||||
for (Map.Entry<String, List<SysResource>> entry : modularMap.entrySet()) {
|
||||
ResourceTreeNode item = new ResourceTreeNode();
|
||||
item.setResourceFlag(false);
|
||||
String id = IdWorker.get32UUID();
|
||||
item.setCode(id);
|
||||
item.setParentCode(RuleConstants.TREE_ROOT_ID.toString());
|
||||
item.setNodeName(entry.getKey());
|
||||
item.setChecked(false);
|
||||
//创建二级节点
|
||||
for (SysResource resource : entry.getValue()) {
|
||||
ResourceTreeNode subItem = new ResourceTreeNode();
|
||||
// 判断是否已经拥有
|
||||
SysRoleResourceResponse resourceResponse = alreadyHave.get(resource.getResourceCode());
|
||||
if (ObjectUtil.isEmpty(resourceResponse)) {
|
||||
subItem.setChecked(false);
|
||||
} else {
|
||||
// 让父类也选择
|
||||
item.setChecked(true);
|
||||
subItem.setChecked(true);
|
||||
}
|
||||
subItem.setResourceFlag(true);
|
||||
subItem.setNodeName(resource.getResourceName());
|
||||
subItem.setCode(resource.getResourceCode());
|
||||
subItem.setParentCode(id);
|
||||
res.add(subItem);
|
||||
}
|
||||
res.add(item);
|
||||
}
|
||||
|
||||
// 根据map组装资源树
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void reportResources(@RequestBody ReportResourceParam reportResourceReq) {
|
||||
|
@ -315,4 +423,49 @@ public class SysResourceServiceImpl extends ServiceImpl<SysResourceMapper, SysRe
|
|||
return finalTree;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据归好类的资源,创建资源平级树
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/1/9 15:10
|
||||
*/
|
||||
private List<ResourceTreeNode> createResourceLateralTree(Map<String, Map<String, List<ResourceTreeNode>>> appModularResources, Map<String, String> modularCodeName) {
|
||||
|
||||
List<ResourceTreeNode> finalTree = new ArrayList<>();
|
||||
|
||||
// 按应用遍历应用模块资源集合
|
||||
for (String appName : appModularResources.keySet()) {
|
||||
|
||||
// 创建当前应用节点
|
||||
ResourceTreeNode appNode = new ResourceTreeNode();
|
||||
appNode.setCode(appName);
|
||||
appNode.setNodeName(appName);
|
||||
appNode.setResourceFlag(false);
|
||||
appNode.setParentCode(SystemConstants.DEFAULT_PARENT_ID.toString());
|
||||
|
||||
// 遍历当前应用下的模块资源
|
||||
Map<String, List<ResourceTreeNode>> modularResources = appModularResources.get(appName);
|
||||
|
||||
// 创建模块节点
|
||||
ArrayList<ResourceTreeNode> modularNodes = new ArrayList<>();
|
||||
for (String modularCode : modularResources.keySet()) {
|
||||
ResourceTreeNode modularNode = new ResourceTreeNode();
|
||||
modularNode.setCode(modularCode);
|
||||
modularNode.setNodeName(modularCodeName.get(modularCode));
|
||||
modularNode.setResourceFlag(false);
|
||||
modularNode.setParentCode(appName);
|
||||
modularNode.setChildren(modularResources.get(modularCode));
|
||||
modularNodes.add(modularNode);
|
||||
}
|
||||
|
||||
// 当前应用下添加模块的资源
|
||||
appNode.setChildren(modularNodes);
|
||||
|
||||
// 添加到最终结果
|
||||
finalTree.add(appNode);
|
||||
}
|
||||
|
||||
return finalTree;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -83,6 +83,18 @@ public class SysRoleController {
|
|||
return new SuccessResponseData();
|
||||
}
|
||||
|
||||
/**
|
||||
* 授权角色授权菜单和按钮
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/1/9 18:04
|
||||
*/
|
||||
@PostResource(name = "授权资源", path = "/sysRole/grantMenuAndButton")
|
||||
public ResponseData grantMenuAndButton(@RequestBody @Validated(SysRoleRequest.grantMenuButton.class) SysRoleRequest sysRoleRequest) {
|
||||
sysRoleService.grantMenuAndButton(sysRoleRequest);
|
||||
return new SuccessResponseData();
|
||||
}
|
||||
|
||||
/**
|
||||
* 授权数据
|
||||
*
|
||||
|
|
|
@ -25,8 +25,8 @@ Guns采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意
|
|||
package cn.stylefeng.roses.kernel.role.modular.service;
|
||||
|
||||
import cn.stylefeng.roses.kernel.role.modular.entity.SysRoleResource;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.role.request.SysRoleRequest;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
|
|
@ -136,4 +136,11 @@ public interface SysRoleService extends IService<SysRole> {
|
|||
*/
|
||||
String getNameByRoleId(Long roleId);
|
||||
|
||||
/**
|
||||
* 授权菜单和按钮
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/1/9 18:13
|
||||
*/
|
||||
void grantMenuAndButton(SysRoleRequest sysRoleMenuButtonRequest);
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ Guns采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意
|
|||
*/
|
||||
package cn.stylefeng.roses.kernel.role.modular.service.impl;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.stylefeng.roses.kernel.role.modular.entity.SysRoleResource;
|
||||
import cn.stylefeng.roses.kernel.role.modular.mapper.SysRoleResourceMapper;
|
||||
import cn.stylefeng.roses.kernel.role.modular.service.SysRoleResourceService;
|
||||
|
@ -45,6 +46,8 @@ import java.util.List;
|
|||
@Service
|
||||
public class SysRoleResourceServiceImpl extends ServiceImpl<SysRoleResourceMapper, SysRoleResource> implements SysRoleResourceService {
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void grantResource(SysRoleRequest sysRoleRequest) {
|
||||
|
@ -85,4 +88,5 @@ public class SysRoleResourceServiceImpl extends ServiceImpl<SysRoleResourceMappe
|
|||
queryWrapper.eq(SysRoleResource::getRoleId, roleId);
|
||||
this.remove(queryWrapper);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -47,7 +47,11 @@ import cn.stylefeng.roses.kernel.system.UserServiceApi;
|
|||
import cn.stylefeng.roses.kernel.system.constants.SymbolConstant;
|
||||
import cn.stylefeng.roses.kernel.system.exception.SystemModularException;
|
||||
import cn.stylefeng.roses.kernel.system.exception.enums.SysRoleExceptionEnum;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.role.request.SysRoleMenuButtonRequest;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.role.request.SysRoleRequest;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.role.response.SysRoleMenuButtonResponse;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.role.response.SysRoleMenuResponse;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.role.response.SysRoleResourceResponse;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.role.response.SysRoleResponse;
|
||||
import cn.stylefeng.roses.kernel.system.util.DataScopeUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
|
@ -329,9 +333,18 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
|||
@Override
|
||||
public List<String> getRoleResourceCodeList(List<Long> roleIdList) {
|
||||
LambdaQueryWrapper<SysRoleResource> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.select(SysRoleResource::getResourceCode);
|
||||
queryWrapper.in(SysRoleResource::getRoleId, roleIdList);
|
||||
List<SysRoleResource> sysRoleResources = sysRoleResourceService.list(queryWrapper);
|
||||
return sysRoleResources.stream().map(SysRoleResource::getResourceCode).collect(Collectors.toList());
|
||||
return sysRoleResources.parallelStream().map(SysRoleResource::getResourceCode).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysRoleResourceResponse> getRoleResourceList(List<Long> roleIdList) {
|
||||
LambdaQueryWrapper<SysRoleResource> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.in(SysRoleResource::getRoleId, roleIdList);
|
||||
List<SysRoleResource> sysRoleResources = sysRoleResourceService.list(queryWrapper);
|
||||
return sysRoleResources.parallelStream().map(item -> BeanUtil.copyProperties(item, SysRoleResourceResponse.class)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -343,6 +356,66 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
|||
return list.stream().map(SysRoleMenuButton::getButtonCode).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysRoleMenuResponse> getRoleMenuList(List<Long> roleIdList) {
|
||||
LambdaQueryWrapper<SysRoleMenu> sysRoleMenuLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
sysRoleMenuLambdaQueryWrapper.in(SysRoleMenu::getRoleId, roleIdList);
|
||||
List<SysRoleMenu> roleMenus = roleMenuService.list(sysRoleMenuLambdaQueryWrapper);
|
||||
List<SysRoleMenuResponse> sysRoleMenuResponses = roleMenus.parallelStream().map(item -> BeanUtil.copyProperties(item, SysRoleMenuResponse.class)).collect(Collectors.toList());
|
||||
return sysRoleMenuResponses;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysRoleMenuButtonResponse> getRoleMenuButtonList(List<Long> roleIdList) {
|
||||
LambdaQueryWrapper<SysRoleMenuButton> sysRoleMenuButtonLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
sysRoleMenuButtonLambdaQueryWrapper.in(SysRoleMenuButton::getRoleId, roleIdList);
|
||||
List<SysRoleMenuButton> sysRoleMenuButtons = sysRoleMenuButtonService.list(sysRoleMenuButtonLambdaQueryWrapper);
|
||||
List<SysRoleMenuButtonResponse> sysRoleMenuButtonResponses = sysRoleMenuButtons.parallelStream().map(item -> BeanUtil.copyProperties(item, SysRoleMenuButtonResponse.class)).collect(Collectors.toList());
|
||||
return sysRoleMenuButtonResponses;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void grantMenuAndButton(SysRoleRequest sysRoleMenuButtonRequest) {
|
||||
// 清除该角色之前的菜单
|
||||
LambdaQueryWrapper<SysRoleMenu> sysRoleMenuLqw = new LambdaQueryWrapper<>();
|
||||
sysRoleMenuLqw.eq(SysRoleMenu::getRoleId, sysRoleMenuButtonRequest.getRoleId());
|
||||
roleMenuService.remove(sysRoleMenuLqw);
|
||||
|
||||
// 清除该角色之前的按钮授权
|
||||
LambdaQueryWrapper<SysRoleMenuButton> menuButtonLqw = new LambdaQueryWrapper<>();
|
||||
menuButtonLqw.eq(SysRoleMenuButton::getRoleId, sysRoleMenuButtonRequest.getRoleId());
|
||||
sysRoleMenuButtonService.remove(menuButtonLqw);
|
||||
|
||||
// 新增菜单
|
||||
List<Long> menuIdList = sysRoleMenuButtonRequest.getGrantMenuIdList();
|
||||
if (ObjectUtil.isNotEmpty(menuIdList)) {
|
||||
List<SysRoleMenu> sysRoleMenus = new ArrayList<>();
|
||||
for (Long menuId : menuIdList) {
|
||||
SysRoleMenu item = new SysRoleMenu();
|
||||
item.setRoleId(sysRoleMenuButtonRequest.getRoleId());
|
||||
item.setMenuId(menuId);
|
||||
sysRoleMenus.add(item);
|
||||
}
|
||||
roleMenuService.saveBatch(sysRoleMenus);
|
||||
}
|
||||
|
||||
// 新增按钮
|
||||
List<SysRoleMenuButtonRequest> menuButtonList = sysRoleMenuButtonRequest.getGrantMenuButtonIdList();
|
||||
if (ObjectUtil.isNotEmpty(menuButtonList)) {
|
||||
List<SysRoleMenuButton> sysRoleMenuButtons = new ArrayList<>();
|
||||
for (SysRoleMenuButtonRequest menuButton : menuButtonList) {
|
||||
SysRoleMenuButton item = new SysRoleMenuButton();
|
||||
item.setRoleId(sysRoleMenuButtonRequest.getRoleId());
|
||||
item.setButtonId(menuButton.getButtonId());
|
||||
item.setButtonCode(menuButton.getButtonCode());
|
||||
sysRoleMenuButtons.add(item);
|
||||
}
|
||||
sysRoleMenuButtonService.saveBatch(sysRoleMenuButtons);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取系统角色
|
||||
*
|
||||
|
|
|
@ -170,9 +170,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|||
|
||||
// 更新枚举,更新只能更新未删除状态的
|
||||
LambdaUpdateWrapper<SysUser> updateWrapper = new LambdaUpdateWrapper<>();
|
||||
updateWrapper.eq(SysUser::getUserId, id)
|
||||
.and(i -> i.ne(SysUser::getDelFlag, YesOrNotEnum.Y.getCode()))
|
||||
.set(SysUser::getStatusFlag, statusFlag);
|
||||
updateWrapper.eq(SysUser::getUserId, id).and(i -> i.ne(SysUser::getDelFlag, YesOrNotEnum.Y.getCode())).set(SysUser::getStatusFlag, statusFlag);
|
||||
|
||||
boolean update = this.update(updateWrapper);
|
||||
if (!update) {
|
||||
|
@ -319,8 +317,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|||
@Override
|
||||
public PageResult<SysUserResponse> page(SysUserRequest sysUserRequest) {
|
||||
|
||||
Page<SysUserResponse> userPage =
|
||||
this.baseMapper.findUserPage(PageFactory.defaultPage(), sysUserRequest);
|
||||
Page<SysUserResponse> userPage = this.baseMapper.findUserPage(PageFactory.defaultPage(), sysUserRequest);
|
||||
|
||||
return PageResultFactory.createPageResult(userPage);
|
||||
}
|
||||
|
@ -478,6 +475,15 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|||
return sessionManagerApi.onlineUserList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public cn.stylefeng.roses.kernel.system.pojo.user.SysUserResponse getUserInfoByUserId(Long userId) {
|
||||
SysUser sysUser = this.getById(userId);
|
||||
if (ObjectUtil.isNotEmpty(sysUser)) {
|
||||
return BeanUtil.copyProperties(sysUser, cn.stylefeng.roses.kernel.system.pojo.user.SysUserResponse.class);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取系统用户
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue