提交 | 用户 | 时间
|
8286c6
|
1 |
/** |
懒 |
2 |
* Copyright 2018-2020 stylefeng & fengshuonan (https://gitee.com/stylefeng) |
|
3 |
* <p> |
|
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 |
* <p> |
|
8 |
* http://www.apache.org/licenses/LICENSE-2.0 |
|
9 |
* <p> |
|
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 |
package cn.stylefeng.guns.sys.modular.rest.controller; |
|
17 |
|
|
18 |
import cn.hutool.core.bean.BeanUtil; |
|
19 |
import cn.stylefeng.guns.base.log.BussinessLog; |
|
20 |
import cn.stylefeng.guns.base.pojo.node.ZTreeNode; |
|
21 |
import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory; |
|
22 |
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo; |
|
23 |
import cn.stylefeng.guns.sys.core.constant.dictmap.DeleteDict; |
|
24 |
import cn.stylefeng.guns.sys.core.constant.dictmap.MenuDict; |
|
25 |
import cn.stylefeng.guns.sys.core.constant.factory.ConstantFactory; |
|
26 |
import cn.stylefeng.guns.sys.core.exception.enums.BizExceptionEnum; |
|
27 |
import cn.stylefeng.guns.sys.core.log.LogObjectHolder; |
|
28 |
import cn.stylefeng.guns.sys.modular.rest.entity.RestMenu; |
|
29 |
import cn.stylefeng.guns.sys.modular.rest.factory.MenuFactory; |
|
30 |
import cn.stylefeng.guns.sys.modular.rest.model.MenuQueryParam; |
|
31 |
import cn.stylefeng.guns.sys.modular.rest.model.MenuTreeNode; |
|
32 |
import cn.stylefeng.guns.sys.modular.rest.service.RestMenuService; |
|
33 |
import cn.stylefeng.guns.sys.modular.rest.service.RestUserService; |
|
34 |
import cn.stylefeng.guns.sys.modular.system.model.MenuDto; |
|
35 |
import cn.stylefeng.guns.sys.modular.system.warpper.MenuWrapper; |
|
36 |
import cn.stylefeng.roses.core.base.controller.BaseController; |
|
37 |
import cn.stylefeng.roses.core.util.ToolUtil; |
|
38 |
import cn.stylefeng.roses.kernel.model.exception.ServiceException; |
|
39 |
import cn.stylefeng.roses.kernel.model.response.ResponseData; |
|
40 |
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
41 |
import org.springframework.beans.factory.annotation.Autowired; |
|
42 |
import org.springframework.web.bind.annotation.*; |
|
43 |
|
|
44 |
import java.util.List; |
|
45 |
import java.util.Map; |
|
46 |
|
|
47 |
/** |
|
48 |
* 菜单控制器 |
|
49 |
* |
|
50 |
* @author fengshuonan |
|
51 |
* @Date 2017年2月12日21:59:14 |
|
52 |
*/ |
|
53 |
@RestController |
|
54 |
@RequestMapping("/rest/menu") |
|
55 |
public class RestMenuController extends BaseController { |
|
56 |
|
|
57 |
@Autowired |
|
58 |
private RestMenuService restMenuService; |
|
59 |
|
|
60 |
@Autowired |
|
61 |
private RestUserService restUserService; |
|
62 |
|
|
63 |
/** |
|
64 |
* 修该菜单 |
|
65 |
* |
|
66 |
* @author fengshuonan |
|
67 |
* @Date 2018/12/23 5:53 PM |
|
68 |
*/ |
|
69 |
@RequestMapping(value = "/edit") |
|
70 |
@BussinessLog(value = "修改菜单", key = "name", dict = MenuDict.class) |
|
71 |
public ResponseData edit(@RequestBody MenuDto menu) { |
|
72 |
|
|
73 |
//如果修改了编号,则该菜单的子菜单也要修改对应编号 |
|
74 |
this.restMenuService.updateMenu(menu); |
|
75 |
|
|
76 |
//刷新当前用户菜单 |
|
77 |
this.restUserService.refreshCurrentUser(); |
|
78 |
|
|
79 |
return SUCCESS_TIP; |
|
80 |
} |
|
81 |
|
|
82 |
/** |
|
83 |
* 获取菜单列表 |
|
84 |
* |
|
85 |
* @author fengshuonan |
|
86 |
* @Date 2018/12/23 5:53 PM |
|
87 |
*/ |
|
88 |
@RequestMapping(value = "/list") |
|
89 |
public LayuiPageInfo list(@RequestBody MenuQueryParam menuQueryParam) { |
|
90 |
Page<Map<String, Object>> menus = this.restMenuService.selectMenus( |
|
91 |
menuQueryParam.getMenuName(), menuQueryParam.getLevel(), menuQueryParam.getMenuId()); |
|
92 |
Page<Map<String, Object>> wrap = new MenuWrapper(menus).wrap(); |
|
93 |
return LayuiPageFactory.createPageInfo(wrap); |
|
94 |
} |
|
95 |
|
|
96 |
/** |
|
97 |
* 获取菜单列表(树形) |
|
98 |
* |
|
99 |
* @author fengshuonan |
|
100 |
* @Date 2019年2月23日22:01:47 |
|
101 |
*/ |
|
102 |
@RequestMapping(value = "/listTree") |
|
103 |
public LayuiPageInfo listTree(@RequestBody MenuQueryParam menuQueryParam) { |
|
104 |
List<Map<String, Object>> menus = this.restMenuService.selectMenuTree(menuQueryParam.getMenuName(), menuQueryParam.getLevel()); |
|
105 |
List<Map<String, Object>> menusWrap = new MenuWrapper(menus).wrap(); |
|
106 |
|
|
107 |
//构建树 |
|
108 |
List<MenuTreeNode> menuTreeNodes = MenuFactory.buildTreeNodes(menusWrap); |
|
109 |
|
|
110 |
LayuiPageInfo result = new LayuiPageInfo(); |
|
111 |
result.setData(menuTreeNodes); |
|
112 |
return result; |
|
113 |
} |
|
114 |
|
|
115 |
/** |
|
116 |
* 新增菜单 |
|
117 |
* |
|
118 |
* @author fengshuonan |
|
119 |
* @Date 2018/12/23 5:53 PM |
|
120 |
*/ |
|
121 |
@RequestMapping(value = "/add") |
|
122 |
@BussinessLog(value = "菜单新增", key = "name", dict = MenuDict.class) |
|
123 |
public ResponseData add(@RequestBody MenuDto menu) { |
|
124 |
this.restMenuService.addMenu(menu); |
|
125 |
return SUCCESS_TIP; |
|
126 |
} |
|
127 |
|
|
128 |
/** |
|
129 |
* 删除菜单 |
|
130 |
* |
|
131 |
* @author fengshuonan |
|
132 |
* @Date 2018/12/23 5:53 PM |
|
133 |
*/ |
|
134 |
@RequestMapping(value = "/remove") |
|
135 |
@BussinessLog(value = "删除菜单", key = "menuId", dict = DeleteDict.class) |
|
136 |
public ResponseData remove(@RequestParam Long menuId) { |
|
137 |
if (ToolUtil.isEmpty(menuId)) { |
|
138 |
throw new ServiceException(BizExceptionEnum.REQUEST_NULL); |
|
139 |
} |
|
140 |
|
|
141 |
//缓存菜单的名称 |
|
142 |
LogObjectHolder.me().set(ConstantFactory.me().getMenuName(menuId)); |
|
143 |
|
|
144 |
this.restMenuService.delMenuContainSubMenus(menuId); |
|
145 |
|
|
146 |
return SUCCESS_TIP; |
|
147 |
} |
|
148 |
|
|
149 |
/** |
|
150 |
* 查看菜单 |
|
151 |
* |
|
152 |
* @author fengshuonan |
|
153 |
* @Date 2018/12/23 5:53 PM |
|
154 |
*/ |
|
155 |
@RequestMapping(value = "/view/{menuId}") |
|
156 |
public ResponseData view(@PathVariable Long menuId) { |
|
157 |
if (ToolUtil.isEmpty(menuId)) { |
|
158 |
throw new ServiceException(BizExceptionEnum.REQUEST_NULL); |
|
159 |
} |
|
160 |
RestMenu menu = this.restMenuService.getById(menuId); |
|
161 |
return ResponseData.success(menu); |
|
162 |
} |
|
163 |
|
|
164 |
/** |
|
165 |
* 获取菜单信息 |
|
166 |
* |
|
167 |
* @author fengshuonan |
|
168 |
* @Date 2018/12/23 5:53 PM |
|
169 |
*/ |
|
170 |
@RequestMapping(value = "/getMenuInfo") |
|
171 |
public ResponseData getMenuInfo(@RequestParam Long menuId) { |
|
172 |
if (ToolUtil.isEmpty(menuId)) { |
|
173 |
throw new ServiceException(BizExceptionEnum.REQUEST_NULL); |
|
174 |
} |
|
175 |
|
|
176 |
RestMenu menu = this.restMenuService.getById(menuId); |
|
177 |
|
|
178 |
MenuDto menuDto = new MenuDto(); |
|
179 |
BeanUtil.copyProperties(menu, menuDto); |
|
180 |
|
|
181 |
//设置pid和父级名称 |
|
182 |
menuDto.setPid(ConstantFactory.me().getMenuIdByCode(menuDto.getPcode())); |
|
183 |
menuDto.setPcodeName(ConstantFactory.me().getMenuNameByCode(menuDto.getPcode())); |
|
184 |
|
|
185 |
return ResponseData.success(menuDto); |
|
186 |
} |
|
187 |
|
|
188 |
/** |
|
189 |
* 获取菜单列表(首页用) |
|
190 |
* |
|
191 |
* @author fengshuonan |
|
192 |
* @Date 2018/12/23 5:54 PM |
|
193 |
*/ |
|
194 |
@RequestMapping(value = "/menuTreeList") |
|
195 |
public List<ZTreeNode> menuTreeList() { |
|
196 |
return this.restMenuService.menuTreeList(); |
|
197 |
} |
|
198 |
|
|
199 |
/** |
|
200 |
* 获取菜单列表(选择父级菜单用) |
|
201 |
* |
|
202 |
* @author fengshuonan |
|
203 |
* @Date 2018/12/23 5:54 PM |
|
204 |
*/ |
|
205 |
@RequestMapping(value = "/selectMenuTreeList") |
|
206 |
public List<ZTreeNode> selectMenuTreeList() { |
|
207 |
List<ZTreeNode> roleTreeList = this.restMenuService.menuTreeList(); |
|
208 |
roleTreeList.add(ZTreeNode.createParent()); |
|
209 |
return roleTreeList; |
|
210 |
} |
|
211 |
|
|
212 |
/** |
|
213 |
* 获取角色的菜单列表 |
|
214 |
* |
|
215 |
* @author fengshuonan |
|
216 |
* @Date 2018/12/23 5:54 PM |
|
217 |
*/ |
|
218 |
@RequestMapping(value = "/menuTreeListByRoleId/{roleId}") |
|
219 |
public List<ZTreeNode> menuTreeListByRoleId(@PathVariable Long roleId) { |
|
220 |
List<Long> menuIds = this.restMenuService.getMenuIdsByRoleId(roleId); |
|
221 |
if (ToolUtil.isEmpty(menuIds)) { |
|
222 |
return this.restMenuService.menuTreeList(); |
|
223 |
} else { |
|
224 |
return this.restMenuService.menuTreeListByMenuIds(menuIds); |
|
225 |
} |
|
226 |
} |
|
227 |
|
|
228 |
} |