| | |
| | | package com.gkhy.exam.admin.controller.system; |
| | | |
| | | |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import com.gkhy.exam.common.api.CommonResult; |
| | | import com.gkhy.exam.common.domain.entity.SysMenu; |
| | | import com.gkhy.exam.common.domain.entity.SysUser; |
| | | import com.gkhy.exam.common.domain.model.LoginBody; |
| | | import com.gkhy.exam.common.domain.model.LoginUserDetails; |
| | | import com.gkhy.exam.common.utils.SecurityUtils; |
| | | import com.gkhy.exam.framework.web.service.SysLoginService; |
| | | import com.gkhy.exam.framework.web.service.SysPermissionService; |
| | | import com.gkhy.exam.framework.web.service.TokenService; |
| | | import com.gkhy.exam.system.service.ISysMenuService; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | |
| | | |
| | | @Api(tags = "用户登录前端控制器") |
| | |
| | | public class SysLoginController { |
| | | @Autowired |
| | | private SysLoginService sysLoginService; |
| | | @Autowired |
| | | private SysPermissionService permissionService; |
| | | |
| | | @Autowired |
| | | private TokenService tokenService; |
| | | |
| | | |
| | | @Autowired |
| | | private ISysMenuService menuService; |
| | | |
| | | @ApiOperation(value = "用户登录") |
| | | @PostMapping("/login") |
| | |
| | | } |
| | | |
| | | |
| | | // @ApiOperation(value = "获取用户信息(角色和权限)") |
| | | // @GetMapping("getInfo") |
| | | // public CommonResult getInfo() |
| | | // { |
| | | // SysUser user = SecurityUtils.getLoginUser().getUser(); |
| | | // user.setPassword(null); |
| | | // Map<String,Object> map = new HashMap<>(); |
| | | // map.put("user", user); |
| | | // return CommonResult.success(map); |
| | | // } |
| | | // |
| | | // |
| | | // @ApiOperation(value = "获取前端路由(根据用户权限过滤)") |
| | | // @GetMapping("getRouters") |
| | | // public CommonResult getRouters() |
| | | // { |
| | | // return null; |
| | | // } |
| | | /** |
| | | * 获取用户信息 |
| | | * |
| | | * @return 用户信息 |
| | | */ |
| | | @GetMapping("getInfo") |
| | | @ApiOperation("获取用户信息") |
| | | public CommonResult getInfo() |
| | | { |
| | | LoginUserDetails loginUser = SecurityUtils.getLoginUser(); |
| | | |
| | | SysUser user = loginUser.getUser(); |
| | | // 角色集合 |
| | | Set<String> roles = permissionService.getRolePermission(user); |
| | | // 权限集合 |
| | | Set<String> permissions = permissionService.getMenuPermission(user); |
| | | if (ObjectUtil.isEmpty(loginUser.getPermissions()) || !loginUser.getPermissions().equals(permissions)) |
| | | { |
| | | loginUser.setPermissions(permissions); |
| | | tokenService.refreshToken(loginUser); |
| | | } |
| | | Map<String,Object> ajax = new HashMap<>(); |
| | | ajax.put("user", user); |
| | | ajax.put("roles", roles); |
| | | ajax.put("permissions", permissions); |
| | | return CommonResult.success(ajax); |
| | | } |
| | | /** |
| | | * 获取路由信息 |
| | | * |
| | | * @return 路由信息 |
| | | */ |
| | | @GetMapping("getRouters") |
| | | @ApiOperation("获取路由信息") |
| | | public CommonResult getRouters() |
| | | { |
| | | Long userId = SecurityUtils.getUserId(); |
| | | List<SysMenu> menus = menuService.selectMenuTreeByUserId(userId); |
| | | return CommonResult.success(menuService.buildMenus(menus)); |
| | | } |
| | | |
| | | } |