inleft
2022-02-09 9bcb19959eeb9da9bde2561e7278f6d0a55eb151
commit | author | age
9bcb19 1 /*
I 2 Copyright [2020] [https://www.xiaonuo.vip]
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8   http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15
16 Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
17
18 1.请不要删除和修改根目录下的LICENSE文件。
19 2.请不要删除和修改Snowy源码头部的版权声明。
20 3.请保留源码和相关描述文件的项目出处,作者声明等。
21 4.分发源码时候,请注明软件出处 https://gitee.com/xiaonuobase/snowy
22 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/xiaonuobase/snowy
23 6.若您的项目无法满足以上几点,可申请商业授权,获取Snowy商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip
24  */
25 package vip.xiaonuo.sys.modular.menu.controller;
26
27 import org.springframework.validation.annotation.Validated;
28 import org.springframework.web.bind.annotation.GetMapping;
29 import org.springframework.web.bind.annotation.PostMapping;
30 import org.springframework.web.bind.annotation.RequestBody;
31 import org.springframework.web.bind.annotation.RestController;
32 import vip.xiaonuo.core.annotion.BusinessLog;
33 import vip.xiaonuo.core.annotion.Permission;
34 import vip.xiaonuo.core.context.login.LoginContextHolder;
35 import vip.xiaonuo.core.enums.LogAnnotionOpTypeEnum;
36 import vip.xiaonuo.core.pojo.node.LoginMenuTreeNode;
37 import vip.xiaonuo.core.pojo.response.ResponseData;
38 import vip.xiaonuo.core.pojo.response.SuccessResponseData;
39 import vip.xiaonuo.sys.modular.menu.entity.SysMenu;
40 import vip.xiaonuo.sys.modular.menu.param.SysMenuParam;
41 import vip.xiaonuo.sys.modular.menu.service.SysMenuService;
42 import vip.xiaonuo.sys.modular.role.service.SysRoleMenuService;
43 import vip.xiaonuo.sys.modular.user.service.SysUserRoleService;
44
45 import javax.annotation.Resource;
46 import java.util.List;
47
48 /**
49  * 系统菜单控制器
50  *
51  * @author xuyuxiang
52  * @date 2020/3/20 18:54
53  */
54 @RestController
55 public class SysMenuController {
56
57     @Resource
58     private SysMenuService sysMenuService;
59
60     @Resource
61     private SysRoleMenuService sysRoleMenuService;
62
63     @Resource
64     private SysUserRoleService sysUserRoleService;
65
66     /**
67      * 系统菜单列表(树)
68      *
69      * @author xuyuxiang
70      * @date 2020/3/20 21:23
71      */
72     @Permission
73     @GetMapping("/sysMenu/list")
74     @BusinessLog(title = "系统菜单_列表", opType = LogAnnotionOpTypeEnum.QUERY)
75     public ResponseData list(SysMenuParam sysMenuParam) {
76         return new SuccessResponseData(sysMenuService.list(sysMenuParam));
77     }
78
79     /**
80      * 添加系统菜单
81      *
82      * @author xuyuxiang
83      * @date 2020/3/27 8:57
84      */
85     @Permission
86     @PostMapping("/sysMenu/add")
87     @BusinessLog(title = "系统菜单_增加", opType = LogAnnotionOpTypeEnum.ADD)
88     public ResponseData add(@RequestBody @Validated(SysMenuParam.add.class) SysMenuParam sysMenuParam) {
89         sysMenuService.add(sysMenuParam);
90         return new SuccessResponseData();
91     }
92
93     /**
94      * 删除系统菜单
95      *
96      * @author xuyuxiang
97      * @date 2020/3/27 8:58
98      */
99     @Permission
100     @PostMapping("/sysMenu/delete")
101     @BusinessLog(title = "系统菜单_删除", opType = LogAnnotionOpTypeEnum.DELETE)
102     public ResponseData delete(@RequestBody @Validated(SysMenuParam.delete.class) SysMenuParam sysMenuParam) {
103         sysMenuService.delete(sysMenuParam);
104         return new SuccessResponseData();
105     }
106
107     /**
108      * 编辑系统菜单
109      *
110      * @author xuyuxiang
111      * @date 2020/3/27 8:59
112      */
113     @Permission
114     @PostMapping("/sysMenu/edit")
115     @BusinessLog(title = "系统菜单_编辑", opType = LogAnnotionOpTypeEnum.EDIT)
116     public ResponseData edit(@RequestBody @Validated(SysMenuParam.edit.class) SysMenuParam sysMenuParam) {
117         sysMenuService.edit(sysMenuParam);
118         return new SuccessResponseData();
119     }
120
121     /**
122      * 查看系统菜单
123      *
124      * @author xuyuxiang
125      * @date 2020/3/27 9:01
126      */
127     @Permission
128     @PostMapping("/sysMenu/detail")
129     @BusinessLog(title = "系统菜单_查看", opType = LogAnnotionOpTypeEnum.DETAIL)
130     public ResponseData detail(@Validated(SysMenuParam.detail.class) SysMenuParam sysMenuParam) {
131         return new SuccessResponseData(sysMenuService.detail(sysMenuParam));
132     }
133
134     /**
135      * 获取系统菜单树,用于新增,编辑时选择上级节点
136      *
137      * @author xuyuxiang
138      * @date 2020/3/27 15:55
139      */
140     @Permission
141     @GetMapping("/sysMenu/tree")
142     @BusinessLog(title = "系统菜单_树", opType = LogAnnotionOpTypeEnum.TREE)
143     public ResponseData tree(SysMenuParam sysMenuParam) {
144         return new SuccessResponseData(sysMenuService.tree(sysMenuParam));
145     }
146
147     /**
148      * 获取系统菜单树,用于给角色授权时选择
149      *
150      * @author xuyuxiang
151      * @date 2020/4/5 15:00
152      */
153     @Permission
154     @GetMapping("/sysMenu/treeForGrant")
155     @BusinessLog(title = "系统菜单_授权树", opType = LogAnnotionOpTypeEnum.TREE)
156     public ResponseData treeForGrant(SysMenuParam sysMenuParam) {
157         return new SuccessResponseData(sysMenuService.treeForGrant(sysMenuParam));
158     }
159
160     /**
161      * 根据系统切换菜单
162      *
163      * @author xuyuxiang
164      * @date 2020/4/19 15:50
165      */
166     @PostMapping("/sysMenu/change")
167     @BusinessLog(title = "系统菜单_切换", opType = LogAnnotionOpTypeEnum.TREE)
168     public ResponseData change(@RequestBody @Validated(SysMenuParam.change.class) SysMenuParam sysMenuParam) {
169         Long sysLoginUserId = LoginContextHolder.me().getSysLoginUserId();
170         List<Long> userRoleIdList = sysUserRoleService.getUserRoleIdList(sysLoginUserId);
171         List<Long> menuIdList = sysRoleMenuService.getRoleMenuIdList(userRoleIdList);
172         //转换成登录菜单
173         List<SysMenu> sysMenuList = sysMenuService.getLoginMenus(sysLoginUserId, sysMenuParam.getApplication(), menuIdList);
174         List<LoginMenuTreeNode> menuTreeNodeList = sysMenuService.convertSysMenuToLoginMenu(sysMenuList);
175         return new SuccessResponseData(menuTreeNodeList);
176     }
177 }