提交 | 用户 | 时间
|
1ac2bc
|
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.stylefeng.guns.base.auth.context.LoginContextHolder; |
|
19 |
import cn.stylefeng.guns.base.auth.model.LoginUser; |
|
20 |
import cn.stylefeng.guns.sys.modular.rest.service.RestUserService; |
|
21 |
import cn.stylefeng.roses.core.base.controller.BaseController; |
|
22 |
import cn.stylefeng.roses.kernel.model.response.ErrorResponseData; |
|
23 |
import cn.stylefeng.roses.kernel.model.response.ResponseData; |
|
24 |
import cn.stylefeng.roses.kernel.model.response.SuccessResponseData; |
|
25 |
import org.springframework.web.bind.annotation.RequestMapping; |
|
26 |
import org.springframework.web.bind.annotation.RequestMethod; |
|
27 |
import org.springframework.web.bind.annotation.RestController; |
|
28 |
|
|
29 |
import javax.annotation.Resource; |
|
30 |
import java.util.List; |
|
31 |
|
|
32 |
import static cn.stylefeng.guns.base.auth.exception.enums.AuthExceptionEnum.NO_ROLE_ERROR; |
|
33 |
|
|
34 |
/** |
|
35 |
* 首页信息 |
|
36 |
* |
|
37 |
* @author fengshuonan |
|
38 |
* @Date 2019/7/24 22:09 |
|
39 |
*/ |
|
40 |
@RestController |
|
41 |
@RequestMapping("/rest") |
|
42 |
public class RestIndexController extends BaseController { |
|
43 |
|
|
44 |
@Resource |
|
45 |
private RestUserService restUserService; |
|
46 |
|
|
47 |
/** |
|
48 |
* 获取用户菜单列表 |
|
49 |
* |
|
50 |
* @author fengshuonan |
|
51 |
* @Date 2018/12/23 5:41 PM |
|
52 |
*/ |
|
53 |
@RequestMapping(value = "/menus", method = RequestMethod.POST) |
|
54 |
public ResponseData menus() { |
|
55 |
|
|
56 |
//获取当前用户角色列表 |
|
57 |
LoginUser user = LoginContextHolder.getContext().getUser(); |
|
58 |
List<Long> roleList = user.getRoleList(); |
|
59 |
|
|
60 |
//如果角色为空 |
|
61 |
if (roleList == null || roleList.size() == 0) { |
|
62 |
return new ErrorResponseData(NO_ROLE_ERROR.getCode(), NO_ROLE_ERROR.getMessage()); |
|
63 |
} |
|
64 |
|
|
65 |
//渲染菜单 |
|
66 |
return new SuccessResponseData(restUserService.getUserMenuNodes(roleList)); |
|
67 |
} |
|
68 |
|
|
69 |
/** |
|
70 |
* 获取用户菜单列表 |
|
71 |
* |
|
72 |
* @author fengshuonan |
|
73 |
* @Date 2018/12/23 5:41 PM |
|
74 |
*/ |
|
75 |
@RequestMapping(value = "/getUserInfo", method = RequestMethod.POST) |
|
76 |
public ResponseData getUserInfo() { |
|
77 |
LoginUser user = LoginContextHolder.getContext().getUser(); |
|
78 |
return new SuccessResponseData(user); |
|
79 |
} |
|
80 |
|
|
81 |
} |