TSQ 2021-01-09 13:56:30 +08:00
commit 3fa19c2d22
33 changed files with 738 additions and 335 deletions

View File

@ -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);
}

View File

@ -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();

View File

@ -68,6 +68,11 @@ public class LoginUser implements Serializable {
*/
private Set<String> resourceUrls;
/**
*
*/
private Set<String> buttonCodes;
/**
* DictMap
*/

View File

@ -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);
}
}
}

View File

@ -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

View File

@ -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;

View File

@ -32,4 +32,13 @@ public interface AppServiceApi {
*/
String getAppNameByAppCode(String appCode);
/**
*
*
* @return
* @author fengshuonan
* @date 2021/1/8 19:01
*/
String getActiveAppCode();
}

View File

@ -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);
}

View File

@ -58,4 +58,9 @@ public interface SystemConstants {
*/
String DEFAULT_SYSTEM_NAME = "Guns快速开发平台";
}
/**
*
*/
String SYSTEM_ADMIN_ROLE_CODE = "superAdmin";
}

View File

@ -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", "超级管理员不能被删除");
/**
*

View File

@ -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;
/**
*

View File

@ -34,11 +34,6 @@ public class AntdSysMenuResponse {
*/
private String antdvRouter;
/**
* antdvue
*/
private String antdvPath;
/**
* antd vue
*/

View File

@ -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})

View File

@ -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();
}
}
/**
*
*

View File

@ -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();

View File

@ -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
*

View File

@ -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,

View File

@ -34,11 +34,6 @@ public class AntdvMenuItem implements AbstractTreeNode {
*/
private String icon;
/**
*
*/
private String path;
/**
*
*/

View File

@ -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

View File

@ -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);
}

View File

@ -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);
}
}

View File

@ -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;
}
}
}

View File

@ -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));
}

View File

@ -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;
}

View File

@ -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> {
}

View File

@ -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>

View File

@ -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> {
}

View File

@ -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 {
}

View File

@ -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());
}
/**
*
*

View File

@ -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;

View File

@ -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;
/**

View File

@ -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)