审查视图

src/main/java/com/tianbo/warehouse/controller/PermssionController.java 5.5 KB
1 2 3
package com.tianbo.warehouse.controller;

import com.github.pagehelper.PageInfo;
朱兆平 authored
4
import com.tianbo.warehouse.annotation.LogAnnotation;
5 6
import com.tianbo.warehouse.controller.response.ResultJson;
import com.tianbo.warehouse.model.PERMISSION;
朱兆平 authored
7
import com.tianbo.warehouse.model.USERS;
8
import com.tianbo.warehouse.service.PermissionService;
朱兆平 authored
9
import com.tianbo.warehouse.service.UserService;
10
import io.swagger.annotations.ApiOperation;
唐俊升 authored
11
import org.apache.ibatis.annotations.Param;
12 13 14
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
shenhailong authored
15 16 17
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
18 19 20 21
import java.util.List;


@RestController()
shenhailong authored
22
@RequestMapping("/perm")
23 24 25 26 27
public class PermssionController {

    @Autowired
    PermissionService permissionService;
朱兆平 authored
28 29 30
    @Autowired
    UserService userService;
shenhailong authored
31
    @GetMapping("/list")
32 33 34
    public PageInfo<PERMISSION> list(@RequestParam(value = "pageNum",required = false,defaultValue = "1")
                                             int pageNum,
                                     @RequestParam(value = "pageSize",required = false,defaultValue = "5")
shenhailong authored
35 36 37
                                             int pageSize,
                                     @RequestParam(value = "name", required = false) String name){
        return permissionService.findAll(pageNum,pageSize, name);
38 39 40

    }
朱兆平 authored
41
    @LogAnnotation(moduleName = "权限管理",operate = "权限添加")
shenhailong authored
42
    @PostMapping("/add")
43 44 45 46 47
    public ResultJson add(@RequestBody PERMISSION permission){
        int i =permissionService.insertSelective(permission);

        ResultJson resultJson = new ResultJson();
        if (1==i){
shenhailong authored
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
            resultJson = new ResultJson("200","添加成功");
        }else {
            resultJson = new ResultJson("500","insert faild");
        }
        return resultJson;
    }

    @LogAnnotation(moduleName = "权限管理",operate = "权限修改")
    @PutMapping("/edit")
    @ResponseBody
    public ResultJson edit(@RequestBody @Valid PERMISSION permission){

        int i =permissionService.updateByPrimaryKeySelective(permission);

        ResultJson resultJson = new ResultJson();
        if (1==i){
            resultJson = new ResultJson("200","修改成功");
        }else {
            resultJson = new ResultJson("500","insert faild");
        }
        return resultJson;
    }

    @LogAnnotation(moduleName = "权限管理",operate = "权限删除")
    @DeleteMapping("/del")
    public ResultJson reomve(@RequestBody PERMISSION permission, HttpServletRequest request, HttpServletResponse response){
唐俊升 authored
75 76
        Integer permissionId = permission.getPermissionId();
        int i =permissionService.deleteByPrimaryKey(permission.getPermissionId());
shenhailong authored
77 78 79 80 81 82 83 84 85 86 87

        ResultJson resultJson = new ResultJson();
        if (1==i){
            resultJson = new ResultJson("200","删除成功");
        }else {
            resultJson = new ResultJson("500","insert faild");
        }
        return resultJson;
    }

    @LogAnnotation(moduleName = "权限管理",operate = "权限批量删除")
唐俊升 authored
88 89
    @PostMapping("/batchremove")
    public ResultJson reomve(@RequestBody List<Integer> ids, HttpServletRequest request, HttpServletResponse response){
shenhailong authored
90 91 92

        ResultJson resultJson = new ResultJson();
唐俊升 authored
93
        if (permissionService.deleteByPrimaryKeys(ids)>0){
shenhailong authored
94
            resultJson = new ResultJson("200","删除成功");
95
        }else {
唐俊升 authored
96
            resultJson = new ResultJson("400","删除失败");
97 98 99
        }
        return resultJson;
    }
100
//    @LogAnnotation(moduleName = "权限管理",operate = "查找权限")
zhangFan authored
101 102 103 104 105 106 107 108 109 110 111
    @GetMapping("/findByRoleId")
    public ResultJson findByRoleId(@RequestParam Integer roleId){

        ResultJson resultJson = new ResultJson();

        List<PERMISSION> list = permissionService.findByRoleId(roleId);
        resultJson.setData(list);
        resultJson.setCode("1");
        resultJson.setMsg("SUCCESS");
        return resultJson;
    }
112 113 114 115 116 117

    @GetMapping("/flushPermCache")
    public ResultJson flushPermCache(){
        permissionService.flushCache();
        return new ResultJson("200","清理缓存成功");
    }
朱兆平 authored
118 119 120

    @GetMapping("/userMenu")
    public ResultJson<List<PERMISSION>> userMenu(
121
            @RequestParam(value = "userId") Integer userId){
朱兆平 authored
122 123 124
        return new ResultJson<List<PERMISSION>>("200","success",permissionService.getUserMenuTreeByUserId(userId));

    }
125 126 127 128 129 130 131

    @ApiOperation(value = "所有目录列表", notes = "查询所有目录菜单的树形结构信息")
    @GetMapping("/menu")
    public ResultJson<List<PERMISSION>> menu(){
        return new ResultJson<List<PERMISSION>>("200","success",permissionService.getUserMenuTreeByUserId(0));

    }
132 133 134 135 136

    @ApiOperation(value = "根据用户ID查询用户权限", notes = "根据用户ID查询用户权限")
    @GetMapping("/getPermission")
    public ResultJson getPermission(
            @RequestHeader("Authorization") String token,
137 138
            @RequestParam(value = "url",required = false)String url,
            @RequestParam(value = "name",required = false)String name){
139 140 141 142
        Boolean result = permissionService.getPermission(token, url, name);
        return new ResultJson("200","success",result);

    }
朱兆平 authored
143 144 145 146 147 148 149 150 151 152

    @GetMapping("/getUserPermByToken")
    public ResultJson get(
            @RequestHeader("Authorization") String token,
            @RequestParam(value = "path") String path
    ){
        System.out.println("im in");
        USERS userInfo = userService.getUserDataPermissionsByPath(token, path);
        return new ResultJson("200","get user data permissions success",userInfo);
    }
153
}