mirror of https://gitee.com/stylefeng/roses
Merge branch 'master' of https://git.stylefeng.cn/guns-technology/roses-kernel
commit
3fa19c2d22
|
@ -63,4 +63,14 @@ public interface LoginUserApi {
|
|||
*/
|
||||
boolean hasLogin();
|
||||
|
||||
/**
|
||||
* 是否包含某个按钮的权限
|
||||
*
|
||||
* @param buttonCode 按钮的编码
|
||||
* @return true-有权限,false-没有权限
|
||||
* @author fengshuonan
|
||||
* @date 2021/1/9 11:32
|
||||
*/
|
||||
boolean haveButton(String buttonCode);
|
||||
|
||||
}
|
||||
|
|
|
@ -26,6 +26,16 @@ public interface SessionManagerApi {
|
|||
*/
|
||||
void createSession(String token, LoginUser loginUser);
|
||||
|
||||
/**
|
||||
* 更新当前会话的loginUser对象的内容
|
||||
*
|
||||
* @param token 用户的当前token
|
||||
* @param loginUser 新的登录用户信息
|
||||
* @author fengshuonan
|
||||
* @date 2021/1/9 10:43
|
||||
*/
|
||||
void updateSession(String token, LoginUser loginUser);
|
||||
|
||||
/**
|
||||
* 通过token获取会话
|
||||
*
|
||||
|
@ -87,7 +97,9 @@ public interface SessionManagerApi {
|
|||
|
||||
/**
|
||||
* 获取在线用户列表
|
||||
* @return
|
||||
*
|
||||
* @author peihongwei
|
||||
* @date 2021/1/9 10:41
|
||||
*/
|
||||
List<LoginUser> onlineUserList();
|
||||
|
||||
|
|
|
@ -68,6 +68,11 @@ public class LoginUser implements Serializable {
|
|||
*/
|
||||
private Set<String> resourceUrls;
|
||||
|
||||
/**
|
||||
* 用户拥有的按钮编码集合
|
||||
*/
|
||||
private Set<String> buttonCodes;
|
||||
|
||||
/**
|
||||
* 其他信息,Dict为Map的拓展
|
||||
*/
|
||||
|
|
|
@ -121,4 +121,14 @@ public class LoginUserImpl implements LoginUserApi {
|
|||
return sessionManagerApi.haveSession(token);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean haveButton(String buttonCode) {
|
||||
LoginUser loginUser = getLoginUser();
|
||||
if (loginUser.getButtonCodes() == null) {
|
||||
return false;
|
||||
} else {
|
||||
return loginUser.getButtonCodes().contains(buttonCode);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@ import cn.stylefeng.roses.kernel.rule.util.HttpServletUtil;
|
|||
import javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
@ -86,6 +85,18 @@ public class DefaultSessionManager implements SessionManagerApi {
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSession(String token, LoginUser loginUser) {
|
||||
LoginUser session = this.getSession(token);
|
||||
|
||||
// 该用户session为空不能更新
|
||||
if (session == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
loginUserCache.put(token, loginUser, sessionExpiredSeconds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoginUser getSession(String token) {
|
||||
return loginUserCache.get(token);
|
||||
|
@ -173,4 +184,5 @@ public class DefaultSessionManager implements SessionManagerApi {
|
|||
public List<LoginUser> onlineUserList() {
|
||||
return new ArrayList<>(loginUserCache.getAllValues());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,15 @@
|
|||
-- 分离版本唯一区别是这个配置的值是false
|
||||
UPDATE `guns`.`sys_config`
|
||||
SET `config_name` = '会话信息是否增加保存在cookie中',
|
||||
`config_code` = 'SYS_SESSION_ADD_TO_COOKIE',
|
||||
`config_value` = 'false',
|
||||
`sys_flag` = 'Y',
|
||||
`remark` = NULL,
|
||||
`status_flag` = 1,
|
||||
`group_code` = 'auth_config',
|
||||
`del_flag` = 'N',
|
||||
`create_time` = NULL,
|
||||
`create_user` = NULL,
|
||||
`update_time` = NULL,
|
||||
`update_user` = NULL
|
||||
WHERE `config_id` = 13;
|
|
@ -32,4 +32,13 @@ public interface AppServiceApi {
|
|||
*/
|
||||
String getAppNameByAppCode(String appCode);
|
||||
|
||||
/**
|
||||
* 获取当前激活的应用编码
|
||||
*
|
||||
* @return 激活的应用编码
|
||||
* @author fengshuonan
|
||||
* @date 2021/1/8 19:01
|
||||
*/
|
||||
String getActiveAppCode();
|
||||
|
||||
}
|
||||
|
|
|
@ -62,4 +62,14 @@ public interface RoleServiceApi {
|
|||
*/
|
||||
List<String> getRoleResourceCodeList(List<Long> roleIdList);
|
||||
|
||||
/**
|
||||
* 获取角色对应的按钮编码集合
|
||||
*
|
||||
* @param roleIdList 角色id集合
|
||||
* @return 角色拥有的按钮编码集合
|
||||
* @author fengshuonan
|
||||
* @date 2021/1/9 11:08
|
||||
*/
|
||||
Set<String> getRoleButtonCodes(List<Long> roleIdList);
|
||||
|
||||
}
|
||||
|
|
|
@ -58,4 +58,9 @@ public interface SystemConstants {
|
|||
*/
|
||||
String DEFAULT_SYSTEM_NAME = "Guns快速开发平台";
|
||||
|
||||
}
|
||||
/**
|
||||
* 超级管理员角色编码
|
||||
*/
|
||||
String SYSTEM_ADMIN_ROLE_CODE = "superAdmin";
|
||||
|
||||
}
|
||||
|
|
|
@ -51,7 +51,12 @@ public enum SysRoleExceptionEnum implements AbstractExceptionEnum {
|
|||
/**
|
||||
* 角色名称重复
|
||||
*/
|
||||
ROLE_NAME_REPEAT(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + SystemConstants.SYSTEM_EXCEPTION_STEP_CODE + "43", "角色名称重复,请检查name参数");
|
||||
ROLE_NAME_REPEAT(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + SystemConstants.SYSTEM_EXCEPTION_STEP_CODE + "43", "角色名称重复,请检查name参数"),
|
||||
|
||||
/**
|
||||
* 超级管理员不能被删除
|
||||
*/
|
||||
SUPER_ADMIN_CANT_DELETE(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + SystemConstants.SYSTEM_EXCEPTION_STEP_CODE + "44", "超级管理员不能被删除");
|
||||
|
||||
/**
|
||||
* 错误编码
|
||||
|
|
|
@ -10,6 +10,7 @@ import javax.validation.constraints.Max;
|
|||
import javax.validation.constraints.Min;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 系统菜单参数
|
||||
|
@ -75,7 +76,7 @@ public class SysMenuRequest extends BaseRequest {
|
|||
* 排序
|
||||
*/
|
||||
@NotNull(message = "排序不能为空", groups = {add.class, edit.class})
|
||||
private Integer menuSort;
|
||||
private BigDecimal menuSort;
|
||||
|
||||
/**
|
||||
* 图标
|
||||
|
|
|
@ -34,11 +34,6 @@ public class AntdSysMenuResponse {
|
|||
*/
|
||||
private String antdvRouter;
|
||||
|
||||
/**
|
||||
* 前端用路径,适用于antdvue版本
|
||||
*/
|
||||
private String antdvPath;
|
||||
|
||||
/**
|
||||
* 图标,适用于antd vue版本
|
||||
*/
|
||||
|
|
|
@ -77,7 +77,7 @@ public class SysRoleRequest extends BaseRequest {
|
|||
private BigDecimal roleSort;
|
||||
|
||||
/**
|
||||
* 数据范围类型:10-全部数据,20-本部门及以下数据,30-本部门数据,40-仅本人数据,50-自定义数据
|
||||
* 数据范围类型:10-仅本人数据,20-本部门数据,30-本部门及以下数据,40-指定部门数据,50-全部数据
|
||||
*/
|
||||
@Null(message = "数据范围类型应该为空, 请移除dataScopeType参数", groups = {add.class, edit.class})
|
||||
@NotNull(message = "数据范围类型不能为空,请检查dataScopeType参数", groups = {grantData.class})
|
||||
|
|
|
@ -183,6 +183,20 @@ public class SysAppServiceImpl extends ServiceImpl<SysAppMapper, SysApp> impleme
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getActiveAppCode() {
|
||||
LambdaQueryWrapper<SysApp> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.select(SysApp::getAppCode);
|
||||
queryWrapper.eq(SysApp::getActiveFlag, YesOrNotEnum.Y.getCode());
|
||||
queryWrapper.eq(SysApp::getDelFlag, YesOrNotEnum.N.getCode());
|
||||
List<SysApp> list = this.list(queryWrapper);
|
||||
if (list.isEmpty()) {
|
||||
return null;
|
||||
} else {
|
||||
return list.get(0).getAppCode();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取系统应用
|
||||
*
|
||||
|
|
|
@ -100,12 +100,6 @@ public class SysMenu extends BaseEntity implements AbstractTreeNode {
|
|||
@TableField("antdv_router")
|
||||
private String antdvRouter;
|
||||
|
||||
/**
|
||||
* 前端用路径,适用于antdvue版本
|
||||
*/
|
||||
@TableField("antdv_path")
|
||||
private String antdvPath;
|
||||
|
||||
/**
|
||||
* 图标,适用于antd vue版本
|
||||
*/
|
||||
|
@ -148,6 +142,12 @@ public class SysMenu extends BaseEntity implements AbstractTreeNode {
|
|||
@TableField(exist = false)
|
||||
private String appName;
|
||||
|
||||
/**
|
||||
* 父级菜单的名称
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private String menuParentName;
|
||||
|
||||
@Override
|
||||
public String getNodeId() {
|
||||
return menuId.toString();
|
||||
|
|
|
@ -43,7 +43,6 @@ public class AntdMenusFactory {
|
|||
// 填充路由等信息
|
||||
antdvMenuItem.setRouter(antdSysMenuResponse.getAntdvRouter());
|
||||
antdvMenuItem.setIcon(antdSysMenuResponse.getAntdvIcon());
|
||||
antdvMenuItem.setPath(antdSysMenuResponse.getAntdvPath());
|
||||
|
||||
// 填充哪个角色绑定了这个菜单
|
||||
List<SimpleRoleInfo> roles = antdSysMenuResponse.getRoles();
|
||||
|
@ -61,10 +60,32 @@ public class AntdMenusFactory {
|
|||
antdvMenuItems.add(antdvMenuItem);
|
||||
}
|
||||
|
||||
// 加入根节点
|
||||
antdvMenuItems.add(createAntdVMenuRoot());
|
||||
|
||||
// 构造菜单树
|
||||
return new DefaultTreeBuildFactory<AntdvMenuItem>().doTreeBuild(antdvMenuItems);
|
||||
return new DefaultTreeBuildFactory<AntdvMenuItem>(SystemConstants.VIRTUAL_ROOT_PARENT_ID.toString()).doTreeBuild(antdvMenuItems);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建虚拟根节点
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2020/12/30 20:38
|
||||
*/
|
||||
private static AntdvMenuItem createAntdVMenuRoot() {
|
||||
AntdvMenuItem antdvMenuItem = new AntdvMenuItem();
|
||||
antdvMenuItem.setRouter("root");
|
||||
antdvMenuItem.setName("根节点");
|
||||
antdvMenuItem.setMenuId(SystemConstants.DEFAULT_PARENT_ID);
|
||||
antdvMenuItem.setMenuParentId(SystemConstants.VIRTUAL_ROOT_PARENT_ID);
|
||||
|
||||
antdvMenuItem.setAuthority(null);
|
||||
|
||||
return antdvMenuItem;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 将数据库表的菜单,转化为vue antd admin识别的菜单路由格式
|
||||
*
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
<result column="menu_parent_id" property="menuParentId"/>
|
||||
<result column="menu_name" property="menuName"/>
|
||||
<result column="antdv_router" property="antdvRouter"/>
|
||||
<result column="antdv_path" property="antdvPath"/>
|
||||
<result column="antdv_icon" property="antdvIcon"/>
|
||||
<collection property="roles" ofType="cn.stylefeng.roses.kernel.auth.api.pojo.login.basic.SimpleRoleInfo">
|
||||
<id column="role_id" property="roleId"/>
|
||||
|
@ -21,7 +20,6 @@
|
|||
sm.menu_parent_id,
|
||||
sm.menu_name,
|
||||
sm.antdv_router,
|
||||
sm.antdv_path,
|
||||
sm.antdv_icon,
|
||||
sr.role_id,
|
||||
sr.role_name,
|
||||
|
|
|
@ -34,11 +34,6 @@ public class AntdvMenuItem implements AbstractTreeNode {
|
|||
*/
|
||||
private String icon;
|
||||
|
||||
/**
|
||||
* 路径信息
|
||||
*/
|
||||
private String path;
|
||||
|
||||
/**
|
||||
* 菜单名称
|
||||
*/
|
||||
|
|
|
@ -142,7 +142,25 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
|||
|
||||
@Override
|
||||
public SysMenu detail(SysMenuRequest sysMenuRequest) {
|
||||
return this.querySysMenu(sysMenuRequest);
|
||||
SysMenu sysMenu = this.querySysMenu(sysMenuRequest);
|
||||
|
||||
// 设置父级菜单名称
|
||||
if (sysMenu != null) {
|
||||
Long menuParentId = sysMenu.getMenuParentId();
|
||||
if (SystemConstants.DEFAULT_PARENT_ID.equals(menuParentId)) {
|
||||
sysMenu.setMenuParentName("顶级");
|
||||
} else {
|
||||
Long parentId = sysMenu.getMenuParentId();
|
||||
SysMenu parentMenu = this.getById(parentId);
|
||||
if (parentMenu == null) {
|
||||
sysMenu.setMenuParentName("无");
|
||||
} else {
|
||||
sysMenu.setMenuParentName(parentMenu.getMenuName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return sysMenu;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -235,7 +253,18 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
|||
List<SysMenu> currentUserMenus = this.getCurrentUserMenus();
|
||||
|
||||
// 组装每个应用的菜单树
|
||||
return LayuiMenusFactory.createLayuiAppIndexMenus(currentUserMenus);
|
||||
List<LayuiAppIndexMenus> layuiAppIndexMenus = LayuiMenusFactory.createLayuiAppIndexMenus(currentUserMenus);
|
||||
|
||||
// 给应用排序,激活的应用放在前边
|
||||
String activeAppCode = appServiceApi.getActiveAppCode();
|
||||
if (activeAppCode != null) {
|
||||
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;
|
||||
}
|
||||
|
||||
return layuiAppIndexMenus;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package cn.stylefeng.roses.kernel.resource.modular.controller;
|
||||
|
||||
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
|
||||
import cn.stylefeng.roses.kernel.resource.api.annotation.ApiResource;
|
||||
import cn.stylefeng.roses.kernel.resource.api.annotation.GetResource;
|
||||
import cn.stylefeng.roses.kernel.resource.api.pojo.resource.ResourceDefinition;
|
||||
|
@ -10,11 +11,10 @@ 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 com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -27,7 +27,7 @@ import java.util.List;
|
|||
@ApiResource(name = "资源管理")
|
||||
public class ResourceController {
|
||||
|
||||
@Autowired
|
||||
@Resource
|
||||
private SysResourceService sysResourceService;
|
||||
|
||||
/**
|
||||
|
@ -38,7 +38,7 @@ public class ResourceController {
|
|||
*/
|
||||
@GetResource(name = "获取资源列表", path = "/resource/pageList")
|
||||
public ResponseData pageList(ResourceRequest resourceRequest) {
|
||||
Page<SysResource> result = this.sysResourceService.getResourceList(resourceRequest);
|
||||
PageResult<SysResource> result = this.sysResourceService.getResourceList(resourceRequest);
|
||||
return new SuccessResponseData(result);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package cn.stylefeng.roses.kernel.resource.modular.service;
|
||||
|
||||
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
|
||||
import cn.stylefeng.roses.kernel.resource.api.pojo.resource.ResourceDefinition;
|
||||
import cn.stylefeng.roses.kernel.resource.modular.entity.SysResource;
|
||||
import cn.stylefeng.roses.kernel.resource.modular.pojo.ResourceTreeNode;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.resource.request.ResourceRequest;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -25,7 +25,7 @@ public interface SysResourceService extends IService<SysResource> {
|
|||
* @author fengshuonan
|
||||
* @date 2020/11/24 20:45
|
||||
*/
|
||||
Page<SysResource> getResourceList(ResourceRequest resourceRequest);
|
||||
PageResult<SysResource> getResourceList(ResourceRequest resourceRequest);
|
||||
|
||||
/**
|
||||
* 通过应用code获取获取资源下拉列表
|
||||
|
@ -67,4 +67,4 @@ public interface SysResourceService extends IService<SysResource> {
|
|||
*/
|
||||
ResourceDefinition getResourceDetail(ResourceRequest resourceRequest);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@ package cn.stylefeng.roses.kernel.resource.modular.service.impl;
|
|||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
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;
|
||||
import cn.stylefeng.roses.kernel.resource.api.ResourceReportApi;
|
||||
import cn.stylefeng.roses.kernel.resource.api.pojo.resource.ReportResourceParam;
|
||||
import cn.stylefeng.roses.kernel.resource.api.pojo.resource.ResourceDefinition;
|
||||
|
@ -21,11 +23,11 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
@ -38,17 +40,17 @@ import java.util.stream.Collectors;
|
|||
@Service
|
||||
public class SysResourceServiceImpl extends ServiceImpl<SysResourceMapper, SysResource> implements SysResourceService, ResourceReportApi, ResourceServiceApi {
|
||||
|
||||
@Autowired
|
||||
@Resource
|
||||
private SysResourceMapper resourceMapper;
|
||||
|
||||
@Autowired
|
||||
@Resource
|
||||
private ResourceCache resourceCache;
|
||||
|
||||
@Override
|
||||
public Page<SysResource> getResourceList(ResourceRequest resourceRequest) {
|
||||
Page<SysResource> page = PageFactory.defaultPage();
|
||||
public PageResult<SysResource> getResourceList(ResourceRequest resourceRequest) {
|
||||
LambdaQueryWrapper<SysResource> wrapper = createWrapper(resourceRequest);
|
||||
return this.page(page, wrapper);
|
||||
Page<SysResource> page = this.page(PageFactory.defaultPage(), wrapper);
|
||||
return PageResultFactory.createPageResult(page);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -204,6 +206,11 @@ public class SysResourceServiceImpl extends ServiceImpl<SysResourceMapper, SysRe
|
|||
if (ObjectUtil.isNotEmpty(resourceRequest.getResourceName())) {
|
||||
queryWrapper.like(SysResource::getResourceName, resourceRequest.getResourceName());
|
||||
}
|
||||
|
||||
// 根据资源url
|
||||
if (ObjectUtil.isNotEmpty(resourceRequest.getUrl())) {
|
||||
queryWrapper.like(SysResource::getUrl, resourceRequest.getUrl());
|
||||
}
|
||||
}
|
||||
|
||||
return queryWrapper;
|
||||
|
@ -308,4 +315,4 @@ public class SysResourceServiceImpl extends ServiceImpl<SysResourceMapper, SysRe
|
|||
return finalTree;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -113,7 +113,7 @@ public class SysRoleController {
|
|||
* @date 2020/11/5 上午10:19
|
||||
*/
|
||||
@GetResource(name = "查询角色", path = "/sysRole/page")
|
||||
public ResponseData page(@RequestBody SysRoleRequest sysRoleRequest) {
|
||||
public ResponseData page(SysRoleRequest sysRoleRequest) {
|
||||
return new SuccessResponseData(sysRoleService.page(sysRoleRequest));
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
package cn.stylefeng.roses.kernel.role.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;
|
||||
|
||||
/**
|
||||
* 角色按钮关联
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2021/01/09 11:48
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("sys_role_menu_button")
|
||||
public class SysRoleMenuButton extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId("role_button_id")
|
||||
private Long roleButtonId;
|
||||
|
||||
/**
|
||||
* 角色id
|
||||
*/
|
||||
@TableField("role_id")
|
||||
private Long roleId;
|
||||
|
||||
/**
|
||||
* 按钮id
|
||||
*/
|
||||
@TableField("button_id")
|
||||
private Long buttonId;
|
||||
|
||||
/**
|
||||
* 按钮编码
|
||||
*/
|
||||
@TableField("button_code")
|
||||
private String buttonCode;
|
||||
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package cn.stylefeng.roses.kernel.role.modular.mapper;
|
||||
|
||||
import cn.stylefeng.roses.kernel.role.modular.entity.SysRoleMenuButton;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* 角色按钮关联 Mapper 接口
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2021/01/09 11:48
|
||||
*/
|
||||
public interface SysRoleMenuButtonMapper extends BaseMapper<SysRoleMenuButton> {
|
||||
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
<?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.role.modular.mapper.SysRoleMenuButtonMapper">
|
||||
|
||||
<!-- 通用查询映射结果 -->
|
||||
<resultMap id="BaseResultMap" type="cn.stylefeng.roses.kernel.role.modular.entity.SysRoleMenuButton">
|
||||
<id column="role_button_id" property="roleButtonId"/>
|
||||
<result column="role_id" property="roleId"/>
|
||||
<result column="button_id" property="buttonId"/>
|
||||
<result column="button_code" property="buttonCode"/>
|
||||
<result column="create_time" property="createTime"/>
|
||||
<result column="create_user" property="createUser"/>
|
||||
<result column="update_time" property="updateTime"/>
|
||||
<result column="update_user" property="updateUser"/>
|
||||
</resultMap>
|
||||
|
||||
</mapper>
|
|
@ -0,0 +1,15 @@
|
|||
package cn.stylefeng.roses.kernel.role.modular.service;
|
||||
|
||||
import cn.stylefeng.roses.kernel.role.modular.entity.SysRoleMenuButton;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* 角色按钮关联 服务类
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2021/01/09 11:48
|
||||
*/
|
||||
public interface SysRoleMenuButtonService extends IService<SysRoleMenuButton> {
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package cn.stylefeng.roses.kernel.role.modular.service.impl;
|
||||
|
||||
import cn.stylefeng.roses.kernel.role.modular.entity.SysRoleMenuButton;
|
||||
import cn.stylefeng.roses.kernel.role.modular.mapper.SysRoleMenuButtonMapper;
|
||||
import cn.stylefeng.roses.kernel.role.modular.service.SysRoleMenuButtonService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 角色按钮关联 服务实现类
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2021/01/09 11:48
|
||||
*/
|
||||
@Service
|
||||
public class SysRoleMenuButtonServiceImpl extends ServiceImpl<SysRoleMenuButtonMapper, SysRoleMenuButton> implements SysRoleMenuButtonService {
|
||||
|
||||
}
|
|
@ -35,17 +35,12 @@ 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;
|
||||
import cn.stylefeng.roses.kernel.role.modular.entity.SysRole;
|
||||
import cn.stylefeng.roses.kernel.role.modular.entity.SysRoleDataScope;
|
||||
import cn.stylefeng.roses.kernel.role.modular.entity.SysRoleMenu;
|
||||
import cn.stylefeng.roses.kernel.role.modular.entity.SysRoleResource;
|
||||
import cn.stylefeng.roses.kernel.role.modular.entity.*;
|
||||
import cn.stylefeng.roses.kernel.role.modular.mapper.SysRoleMapper;
|
||||
import cn.stylefeng.roses.kernel.role.modular.service.SysRoleDataScopeService;
|
||||
import cn.stylefeng.roses.kernel.role.modular.service.SysRoleMenuService;
|
||||
import cn.stylefeng.roses.kernel.role.modular.service.SysRoleResourceService;
|
||||
import cn.stylefeng.roses.kernel.role.modular.service.SysRoleService;
|
||||
import cn.stylefeng.roses.kernel.role.modular.service.*;
|
||||
import cn.stylefeng.roses.kernel.rule.enums.StatusEnum;
|
||||
import cn.stylefeng.roses.kernel.rule.enums.YesOrNotEnum;
|
||||
import cn.stylefeng.roses.kernel.rule.exception.base.ServiceException;
|
||||
import cn.stylefeng.roses.kernel.rule.pojo.dict.SimpleDict;
|
||||
import cn.stylefeng.roses.kernel.system.RoleServiceApi;
|
||||
import cn.stylefeng.roses.kernel.system.UserServiceApi;
|
||||
|
@ -67,6 +62,9 @@ import java.util.List;
|
|||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static cn.stylefeng.roses.kernel.system.constants.SystemConstants.SYSTEM_ADMIN_ROLE_CODE;
|
||||
import static cn.stylefeng.roses.kernel.system.exception.enums.SysRoleExceptionEnum.SUPER_ADMIN_CANT_DELETE;
|
||||
|
||||
/**
|
||||
* 系统角色service接口实现类
|
||||
*
|
||||
|
@ -88,6 +86,9 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
|||
@Resource
|
||||
private SysRoleMenuService roleMenuService;
|
||||
|
||||
@Resource
|
||||
private SysRoleMenuButtonService sysRoleMenuButtonService;
|
||||
|
||||
@Override
|
||||
public void add(SysRoleRequest sysRoleRequest) {
|
||||
SysRole sysRole = new SysRole();
|
||||
|
@ -115,6 +116,11 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
|||
public void delete(SysRoleRequest sysRoleRequest) {
|
||||
SysRole sysRole = this.querySysRole(sysRoleRequest);
|
||||
|
||||
// 超级管理员不能删除
|
||||
if (SYSTEM_ADMIN_ROLE_CODE.equals(sysRole.getRoleCode())) {
|
||||
throw new ServiceException(SUPER_ADMIN_CANT_DELETE);
|
||||
}
|
||||
|
||||
// 逻辑删除,设为删除标志
|
||||
sysRole.setDelFlag(YesOrNotEnum.Y.getCode());
|
||||
|
||||
|
@ -328,6 +334,15 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
|||
return sysRoleResources.stream().map(SysRoleResource::getResourceCode).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getRoleButtonCodes(List<Long> roleIdList) {
|
||||
LambdaQueryWrapper<SysRoleMenuButton> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.in(SysRoleMenuButton::getRoleId, roleIdList);
|
||||
queryWrapper.select(SysRoleMenuButton::getButtonCode);
|
||||
List<SysRoleMenuButton> list = sysRoleMenuButtonService.list(queryWrapper);
|
||||
return list.stream().map(SysRoleMenuButton::getButtonCode).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取系统角色
|
||||
*
|
||||
|
|
|
@ -34,6 +34,7 @@ public class UserLoginInfoFactory {
|
|||
* @param dataScopeResponse 数据范围信息
|
||||
* @param userOrgInfo 组织机构信息
|
||||
* @param resourceUrlsListByCodes 用户的所有资源url
|
||||
* @param roleButtonCodes
|
||||
* @author fengshuonan
|
||||
* @date 2020/12/26 17:53
|
||||
*/
|
||||
|
@ -41,7 +42,8 @@ public class UserLoginInfoFactory {
|
|||
List<SysRoleResponse> roleResponseList,
|
||||
DataScopeResponse dataScopeResponse,
|
||||
SysUserOrgResponse userOrgInfo,
|
||||
Set<String> resourceUrlsListByCodes) {
|
||||
Set<String> resourceUrlsListByCodes,
|
||||
Set<String> roleButtonCodes) {
|
||||
|
||||
UserLoginInfoDTO userLoginInfoDTO = new UserLoginInfoDTO();
|
||||
|
||||
|
@ -97,6 +99,9 @@ public class UserLoginInfoFactory {
|
|||
}
|
||||
}
|
||||
|
||||
// 填充用户拥有的按钮编码
|
||||
loginUser.setButtonCodes(roleButtonCodes);
|
||||
|
||||
// 响应dto
|
||||
userLoginInfoDTO.setLoginUser(loginUser);
|
||||
return userLoginInfoDTO;
|
||||
|
|
|
@ -26,7 +26,7 @@ public class SysUserRequest extends BaseRequest {
|
|||
/**
|
||||
* 主键
|
||||
*/
|
||||
@NotNull(message = "userId不能为空", groups = {edit.class, delete.class, detail.class, grantRole.class, grantData.class, updateInfo.class, resetPwd.class, changeStatus.class, updateAvatar.class})
|
||||
@NotNull(message = "userId不能为空", groups = {edit.class, delete.class, detail.class, grantRole.class, grantData.class, updateInfo.class, resetPwd.class, changeStatus.class})
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
|
|
|
@ -7,6 +7,7 @@ import cn.stylefeng.roses.kernel.auth.api.context.LoginContext;
|
|||
import cn.stylefeng.roses.kernel.auth.api.expander.AuthConfigExpander;
|
||||
import cn.stylefeng.roses.kernel.auth.api.password.PasswordStoredEncryptApi;
|
||||
import cn.stylefeng.roses.kernel.auth.api.pojo.login.LoginUser;
|
||||
import cn.stylefeng.roses.kernel.auth.api.pojo.login.basic.SimpleUserInfo;
|
||||
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;
|
||||
|
@ -216,9 +217,23 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|||
|
||||
@Override
|
||||
public void updateAvatar(SysUserRequest sysUserRequest) {
|
||||
|
||||
// 新头像文件id
|
||||
Long fileId = sysUserRequest.getAvatar();
|
||||
|
||||
// 从当前用户获取用户id
|
||||
LoginUser loginUser = LoginContext.me().getLoginUser();
|
||||
sysUserRequest.setUserId(loginUser.getUserId());
|
||||
|
||||
// 更新用户头像
|
||||
SysUser sysUser = this.querySysUser(sysUserRequest);
|
||||
sysUser.setAvatar(sysUserRequest.getAvatar());
|
||||
sysUser.setAvatar(fileId);
|
||||
this.updateById(sysUser);
|
||||
|
||||
// 更新当前用户的session信息
|
||||
SimpleUserInfo simpleUserInfo = loginUser.getSimpleUserInfo();
|
||||
simpleUserInfo.setAvatar(fileId);
|
||||
sessionManagerApi.updateSession(LoginContext.me().getToken(), loginUser);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -397,8 +412,11 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|||
List<String> resourceCodeList = roleServiceApi.getRoleResourceCodeList(roleIds);
|
||||
Set<String> resourceUrlsListByCodes = resourceServiceApi.getResourceUrlsListByCodes(resourceCodeList);
|
||||
|
||||
// 5. 组装响应结果
|
||||
return UserLoginInfoFactory.userLoginInfoDTO(sysUser, roleResponseList, dataScopeResponse, userOrgInfo, resourceUrlsListByCodes);
|
||||
// 6. 获取用户的所有按钮code集合
|
||||
Set<String> roleButtonCodes = roleServiceApi.getRoleButtonCodes(roleIds);
|
||||
|
||||
// 7. 组装响应结果
|
||||
return UserLoginInfoFactory.userLoginInfoDTO(sysUser, roleResponseList, dataScopeResponse, userOrgInfo, resourceUrlsListByCodes, roleButtonCodes);
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
|
|
Loading…
Reference in New Issue