管道基础大数据平台系统开发-【后端】-Server
1
13693261870
2022-10-25 653ab219fdf13b30ff4b2c6c298df8f3929b283a
src/main/java/com/lf/server/controller/all/PermsController.java
@@ -5,14 +5,15 @@
import com.lf.server.entity.all.PermsAuthEntity;
import com.lf.server.entity.all.ResAuthEntity;
import com.lf.server.entity.all.ResponseMsg;
import com.lf.server.entity.sys.UserEntity;
import com.lf.server.service.all.PermsService;
import com.lf.server.service.sys.TokenService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
/**
@@ -21,20 +22,25 @@
 */
@Api(tags = "运维管理\\授权管理")
@RestController
@RequestMapping("/file")
@RequestMapping("/perms")
public class PermsController extends BaseController {
    @Autowired
    PermsService permsService;
    @Autowired
    TokenService tokenService;
    @SysLog()
    @ApiOperation(value = "根据用户Uid查询资源授权")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "uid", value = "用户Uid", dataType = "String", paramType = "query", example = "admin")
    })
    @ApiOperation(value = "查询当前用户的资源授权")
    @GetMapping(value = "/selectRes")
    public ResponseMsg<List<ResAuthEntity>> selectRes(String uid) {
    public ResponseMsg<List<ResAuthEntity>> selectRes(HttpServletRequest req) {
        try {
            List<ResAuthEntity> rs = permsService.selectRes(uid);
            UserEntity ue = tokenService.getCurrentUser(req);
            if (ue == null) {
                return fail("用户未登录", null);
            }
            List<ResAuthEntity> rs = permsService.selectRes(ue.getUid());
            return success(rs);
        } catch (Exception ex) {
@@ -43,14 +49,16 @@
    }
    @SysLog()
    @ApiOperation(value = "根据用户Uid查询菜单授权")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "uid", value = "用户Uid", dataType = "String", paramType = "query", example = "admin")
    })
    @ApiOperation(value = "查询当前用户的菜单授权")
    @GetMapping(value = "/selectMenus")
    public ResponseMsg<List<MenusAuthEntity>> selectMenus(String uid) {
    public ResponseMsg<List<MenusAuthEntity>> selectMenus(HttpServletRequest req) {
        try {
            List<MenusAuthEntity> rs = permsService.selectMenus(uid);
            UserEntity ue = tokenService.getCurrentUser(req);
            if (ue == null) {
                return fail("用户未登录", null);
            }
            List<MenusAuthEntity> rs = permsService.selectMenus(ue.getUid());
            return success(rs);
        } catch (Exception ex) {
@@ -59,14 +67,16 @@
    }
    @SysLog()
    @ApiOperation(value = "根据用户Uid查询权限授权")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "uid", value = "用户Uid", dataType = "String", paramType = "query", example = "admin")
    })
    @ApiOperation(value = "查询当前用户的权限授权")
    @GetMapping(value = "/selectPerms")
    public ResponseMsg<List<PermsAuthEntity>> selectPerms(String uid) {
    public ResponseMsg<List<String>> selectPerms(HttpServletRequest req) {
        try {
            List<PermsAuthEntity> rs = permsService.selectPerms(uid);
            UserEntity ue = tokenService.getCurrentUser(req);
            if (ue == null) {
                return fail("用户未登录", null);
            }
            List<String> rs = permsService.selectPerms(ue.getUid());
            return success(rs);
        } catch (Exception ex) {
@@ -75,18 +85,33 @@
    }
    @SysLog()
    @ApiOperation(value = "根据用户Uid查询权限授权2")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "uid", value = "用户Uid", dataType = "String", paramType = "query", example = "admin")
    })
    @GetMapping(value = "/selectPerms2")
    public ResponseMsg<List<String>> selectPerms2(String uid) {
    @ApiOperation(value = "查询当前用户的权限授权实体集合")
    @GetMapping(value = "/selectPermsEntity")
    public ResponseMsg<List<PermsAuthEntity>> selectPermsEntity(HttpServletRequest req) {
        try {
            List<String> rs = permsService.selectPerms2(uid);
            UserEntity ue = tokenService.getCurrentUser(req);
            if (ue == null) {
                return fail("用户未登录", null);
            }
            List<PermsAuthEntity> rs = permsService.selectPermsEntity(ue.getUid());
            return success(rs);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
        }
    }
    @SysLog()
    @ApiOperation(value = "清空所有授权缓存")
    @GetMapping(value = "/clearAllCache")
    public ResponseMsg<Boolean> clearAllCache() {
        try {
            permsService.clearAllCache();
            return success(true);
        } catch (Exception ex) {
            return fail(ex.getMessage(), false);
        }
    }
}