提交 | 用户 | 时间
|
fd2207
|
1 |
package com.jcdm.web.controller.system; |
懒 |
2 |
|
|
3 |
import java.util.List; |
|
4 |
import java.util.Set; |
|
5 |
import org.springframework.beans.factory.annotation.Autowired; |
|
6 |
import org.springframework.web.bind.annotation.GetMapping; |
|
7 |
import org.springframework.web.bind.annotation.PostMapping; |
|
8 |
import org.springframework.web.bind.annotation.RequestBody; |
|
9 |
import org.springframework.web.bind.annotation.RestController; |
|
10 |
import com.jcdm.common.constant.Constants; |
|
11 |
import com.jcdm.common.core.domain.AjaxResult; |
|
12 |
import com.jcdm.common.core.domain.entity.SysMenu; |
|
13 |
import com.jcdm.common.core.domain.entity.SysUser; |
|
14 |
import com.jcdm.common.core.domain.model.LoginBody; |
|
15 |
import com.jcdm.common.utils.SecurityUtils; |
|
16 |
import com.jcdm.framework.web.service.SysLoginService; |
|
17 |
import com.jcdm.framework.web.service.SysPermissionService; |
|
18 |
import com.jcdm.system.service.ISysMenuService; |
|
19 |
|
|
20 |
/** |
|
21 |
* 登录验证 |
|
22 |
* |
|
23 |
* @author jc |
|
24 |
*/ |
|
25 |
@RestController |
|
26 |
public class SysLoginController |
|
27 |
{ |
|
28 |
@Autowired |
|
29 |
private SysLoginService loginService; |
|
30 |
|
|
31 |
@Autowired |
|
32 |
private ISysMenuService menuService; |
|
33 |
|
|
34 |
@Autowired |
|
35 |
private SysPermissionService permissionService; |
|
36 |
|
|
37 |
/** |
|
38 |
* 登录方法 |
|
39 |
* |
|
40 |
* @param loginBody 登录信息 |
|
41 |
* @return 结果 |
|
42 |
*/ |
|
43 |
@PostMapping("/login") |
|
44 |
public AjaxResult login(@RequestBody LoginBody loginBody) |
|
45 |
{ |
|
46 |
AjaxResult ajax = AjaxResult.success(); |
|
47 |
// 生成令牌 |
|
48 |
String token = loginService.login(loginBody.getUsername(), loginBody.getPassword(), loginBody.getCode(), |
|
49 |
loginBody.getUuid()); |
|
50 |
ajax.put(Constants.TOKEN, token); |
|
51 |
return ajax; |
|
52 |
} |
|
53 |
|
|
54 |
/** |
|
55 |
* 获取用户信息 |
|
56 |
* |
|
57 |
* @return 用户信息 |
|
58 |
*/ |
|
59 |
@GetMapping("getInfo") |
|
60 |
public AjaxResult getInfo() |
|
61 |
{ |
|
62 |
SysUser user = SecurityUtils.getLoginUser().getUser(); |
|
63 |
// 角色集合 |
|
64 |
Set<String> roles = permissionService.getRolePermission(user); |
|
65 |
// 权限集合 |
|
66 |
Set<String> permissions = permissionService.getMenuPermission(user); |
|
67 |
AjaxResult ajax = AjaxResult.success(); |
|
68 |
ajax.put("user", user); |
|
69 |
ajax.put("roles", roles); |
|
70 |
ajax.put("permissions", permissions); |
|
71 |
return ajax; |
|
72 |
} |
|
73 |
|
|
74 |
/** |
|
75 |
* 获取路由信息 |
|
76 |
* |
|
77 |
* @return 路由信息 |
|
78 |
*/ |
|
79 |
@GetMapping("getRouters") |
|
80 |
public AjaxResult getRouters() |
|
81 |
{ |
|
82 |
Long userId = SecurityUtils.getUserId(); |
|
83 |
List<SysMenu> menus = menuService.selectMenuTreeByUserId(userId); |
|
84 |
return AjaxResult.success(menuService.buildMenus(menus)); |
|
85 |
} |
|
86 |
} |