【7.2.3】更新角色授权菜单接口,返回授权后信息

pull/30/head
fengshuonan 2022-06-27 18:36:28 +08:00
parent 946b2f7f9d
commit b5af67d1fe
7 changed files with 41 additions and 13 deletions

View File

@ -25,6 +25,8 @@
package cn.stylefeng.roses.kernel.system.api; package cn.stylefeng.roses.kernel.system.api;
import cn.stylefeng.roses.kernel.system.api.pojo.login.v3.IndexMenuInfo; import cn.stylefeng.roses.kernel.system.api.pojo.login.v3.IndexMenuInfo;
import cn.stylefeng.roses.kernel.system.api.pojo.menu.MenuAndButtonTreeResponse;
import cn.stylefeng.roses.kernel.system.api.pojo.role.request.SysRoleRequest;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -90,4 +92,13 @@ public interface MenuServiceApi {
*/ */
List<IndexMenuInfo> buildAuthorities(Integer menuFrontType); List<IndexMenuInfo> buildAuthorities(Integer menuFrontType);
/**
*
*
* @author fengshuonan
* @date 2021/8/10 22:23
*/
List<MenuAndButtonTreeResponse> getRoleMenuAndButtons(SysRoleRequest sysRoleRequest);
} }

View File

@ -31,6 +31,7 @@ import cn.stylefeng.roses.kernel.rule.tree.ztree.ZTreeNode;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource; import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource; import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource; import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
import cn.stylefeng.roses.kernel.system.api.MenuServiceApi;
import cn.stylefeng.roses.kernel.system.api.pojo.menu.MenuAndButtonTreeResponse; import cn.stylefeng.roses.kernel.system.api.pojo.menu.MenuAndButtonTreeResponse;
import cn.stylefeng.roses.kernel.system.api.pojo.menu.SysMenuRequest; import cn.stylefeng.roses.kernel.system.api.pojo.menu.SysMenuRequest;
import cn.stylefeng.roses.kernel.system.api.pojo.menu.antd.AntdMenuSelectTreeNode; import cn.stylefeng.roses.kernel.system.api.pojo.menu.antd.AntdMenuSelectTreeNode;
@ -59,6 +60,9 @@ public class SysMenuController {
@Resource @Resource
private SysMenuService sysMenuService; private SysMenuService sysMenuService;
@Resource
private MenuServiceApi menuServiceApi;
/** /**
* *
* *
@ -196,7 +200,7 @@ public class SysMenuController {
*/ */
@GetResource(name = "新版角色分配菜单和按钮界面使用的接口v2", path = "/sysMenu/menuAndButtonTreeChildrenV2") @GetResource(name = "新版角色分配菜单和按钮界面使用的接口v2", path = "/sysMenu/menuAndButtonTreeChildrenV2")
public ResponseData<List<MenuAndButtonTreeResponse>> menuAndButtonTreeChildrenV2(SysRoleRequest sysRoleRequest) { public ResponseData<List<MenuAndButtonTreeResponse>> menuAndButtonTreeChildrenV2(SysRoleRequest sysRoleRequest) {
List<MenuAndButtonTreeResponse> treeResponseList = sysMenuService.getRoleMenuAndButtons(sysRoleRequest); List<MenuAndButtonTreeResponse> treeResponseList = menuServiceApi.getRoleMenuAndButtons(sysRoleRequest);
return new SuccessResponseData<>(treeResponseList); return new SuccessResponseData<>(treeResponseList);
} }

View File

@ -25,7 +25,6 @@
package cn.stylefeng.roses.kernel.system.modular.menu.service; package cn.stylefeng.roses.kernel.system.modular.menu.service;
import cn.stylefeng.roses.kernel.rule.tree.ztree.ZTreeNode; import cn.stylefeng.roses.kernel.rule.tree.ztree.ZTreeNode;
import cn.stylefeng.roses.kernel.system.api.pojo.menu.MenuAndButtonTreeResponse;
import cn.stylefeng.roses.kernel.system.api.pojo.menu.SysMenuRequest; import cn.stylefeng.roses.kernel.system.api.pojo.menu.SysMenuRequest;
import cn.stylefeng.roses.kernel.system.api.pojo.menu.antd.AntdMenuSelectTreeNode; import cn.stylefeng.roses.kernel.system.api.pojo.menu.antd.AntdMenuSelectTreeNode;
import cn.stylefeng.roses.kernel.system.api.pojo.menu.antd.AntdSysMenuDTO; import cn.stylefeng.roses.kernel.system.api.pojo.menu.antd.AntdSysMenuDTO;
@ -146,14 +145,6 @@ public interface SysMenuService extends IService<SysMenu> {
*/ */
List<LayuiMenuAndButtonTreeResponse> getMenuAndButtonTree(SysRoleRequest sysRoleRequest, Boolean lateralFlag); List<LayuiMenuAndButtonTreeResponse> getMenuAndButtonTree(SysRoleRequest sysRoleRequest, Boolean lateralFlag);
/**
*
*
* @author fengshuonan
* @date 2021/8/10 22:23
*/
List<MenuAndButtonTreeResponse> getRoleMenuAndButtons(SysRoleRequest sysRoleRequest);
/** /**
* *
* *

View File

@ -71,6 +71,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -433,6 +434,7 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
} }
@Override @Override
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
public List<MenuAndButtonTreeResponse> getRoleMenuAndButtons(SysRoleRequest sysRoleRequest) { public List<MenuAndButtonTreeResponse> getRoleMenuAndButtons(SysRoleRequest sysRoleRequest) {
List<MenuAndButtonTreeResponse> menuTreeNodeList = CollectionUtil.newArrayList(); List<MenuAndButtonTreeResponse> menuTreeNodeList = CollectionUtil.newArrayList();

View File

@ -33,6 +33,7 @@ import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource; import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource; import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource; import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
import cn.stylefeng.roses.kernel.system.api.pojo.menu.MenuAndButtonTreeResponse;
import cn.stylefeng.roses.kernel.system.api.pojo.role.dto.SysRoleDTO; import cn.stylefeng.roses.kernel.system.api.pojo.role.dto.SysRoleDTO;
import cn.stylefeng.roses.kernel.system.api.pojo.role.request.SysRoleRequest; import cn.stylefeng.roses.kernel.system.api.pojo.role.request.SysRoleRequest;
import cn.stylefeng.roses.kernel.system.modular.role.entity.SysRole; import cn.stylefeng.roses.kernel.system.modular.role.entity.SysRole;
@ -189,9 +190,8 @@ public class SysRoleController {
* @date 2021/8/11 9:58 * @date 2021/8/11 9:58
*/ */
@PostResource(name = "角色绑定或取消绑定菜单和按钮", path = "/sysRole/grantMenusAndButtons") @PostResource(name = "角色绑定或取消绑定菜单和按钮", path = "/sysRole/grantMenusAndButtons")
public ResponseData<?> grantMenusAndButtons(@RequestBody @Validated(SysRoleRequest.grantMenusAndButtons.class) SysRoleRequest sysRoleRequest) { public ResponseData<List<MenuAndButtonTreeResponse>> grantMenusAndButtons(@RequestBody @Validated(SysRoleRequest.grantMenusAndButtons.class) SysRoleRequest sysRoleRequest) {
sysRoleService.grantMenusAndButtons(sysRoleRequest); return new SuccessResponseData<>(sysRoleService.grantMenusAndButtonsAndGetResult(sysRoleRequest));
return new SuccessResponseData<>();
} }
/** /**

View File

@ -27,6 +27,7 @@ package cn.stylefeng.roses.kernel.system.modular.role.service;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult; import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.rule.pojo.dict.SimpleDict; import cn.stylefeng.roses.kernel.rule.pojo.dict.SimpleDict;
import cn.stylefeng.roses.kernel.system.api.RoleServiceApi; import cn.stylefeng.roses.kernel.system.api.RoleServiceApi;
import cn.stylefeng.roses.kernel.system.api.pojo.menu.MenuAndButtonTreeResponse;
import cn.stylefeng.roses.kernel.system.api.pojo.role.dto.SysRoleDTO; import cn.stylefeng.roses.kernel.system.api.pojo.role.dto.SysRoleDTO;
import cn.stylefeng.roses.kernel.system.api.pojo.role.request.SysRoleRequest; import cn.stylefeng.roses.kernel.system.api.pojo.role.request.SysRoleRequest;
import cn.stylefeng.roses.kernel.system.modular.role.entity.SysRole; import cn.stylefeng.roses.kernel.system.modular.role.entity.SysRole;
@ -158,4 +159,12 @@ public interface SysRoleService extends IService<SysRole>, RoleServiceApi {
* @date 2022/6/21 9:55 * @date 2022/6/21 9:55
*/ */
void grantMenusAndButtons(SysRoleRequest sysRoleRequest); void grantMenusAndButtons(SysRoleRequest sysRoleRequest);
/**
*
*
* @author fengshuonan
* @date 2022/6/27 17:08
*/
List<MenuAndButtonTreeResponse> grantMenusAndButtonsAndGetResult(SysRoleRequest sysRoleRequest);
} }

View File

@ -46,6 +46,7 @@ import cn.stylefeng.roses.kernel.system.api.UserServiceApi;
import cn.stylefeng.roses.kernel.system.api.constants.SystemConstants; import cn.stylefeng.roses.kernel.system.api.constants.SystemConstants;
import cn.stylefeng.roses.kernel.system.api.exception.SystemModularException; import cn.stylefeng.roses.kernel.system.api.exception.SystemModularException;
import cn.stylefeng.roses.kernel.system.api.exception.enums.role.SysRoleExceptionEnum; import cn.stylefeng.roses.kernel.system.api.exception.enums.role.SysRoleExceptionEnum;
import cn.stylefeng.roses.kernel.system.api.pojo.menu.MenuAndButtonTreeResponse;
import cn.stylefeng.roses.kernel.system.api.pojo.role.dto.SysRoleDTO; import cn.stylefeng.roses.kernel.system.api.pojo.role.dto.SysRoleDTO;
import cn.stylefeng.roses.kernel.system.api.pojo.role.dto.SysRoleMenuButtonDTO; import cn.stylefeng.roses.kernel.system.api.pojo.role.dto.SysRoleMenuButtonDTO;
import cn.stylefeng.roses.kernel.system.api.pojo.role.dto.SysRoleMenuDTO; import cn.stylefeng.roses.kernel.system.api.pojo.role.dto.SysRoleMenuDTO;
@ -426,6 +427,10 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
// 如果是新增绑定菜单 // 如果是新增绑定菜单
if (selectBindFlag) { if (selectBindFlag) {
// 获取所有菜单的父级节点,把选中状态的菜单的所有父级节点都选择上
Set<Long> allParentMenuId = menuServiceApi.getMenuAllParentMenuId(new HashSet<>(grantMenuIdList));
grantMenuIdList.addAll(allParentMenuId);
// 批量保存绑定的菜单集合 // 批量保存绑定的菜单集合
List<SysRoleMenu> sysRoleMenus = new ArrayList<>(); List<SysRoleMenu> sysRoleMenus = new ArrayList<>();
for (Long menuId : grantMenuIdList) { for (Long menuId : grantMenuIdList) {
@ -449,6 +454,12 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
} }
} }
@Override
public List<MenuAndButtonTreeResponse> grantMenusAndButtonsAndGetResult(SysRoleRequest sysRoleRequest) {
this.grantMenusAndButtons(sysRoleRequest);
return menuServiceApi.getRoleMenuAndButtons(sysRoleRequest);
}
@Override @Override
public List<SysRoleDTO> getRolesByIds(List<Long> roleIds) { public List<SysRoleDTO> getRolesByIds(List<Long> roleIds) {
ArrayList<SysRoleDTO> sysRoleResponses = new ArrayList<>(); ArrayList<SysRoleDTO> sysRoleResponses = new ArrayList<>();