审查视图

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

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


@RestController()
shenhailong authored
19
@RequestMapping("/perm")
20 21 22 23 24
public class PermssionController {

    @Autowired
    PermissionService permissionService;
shenhailong authored
25
    @GetMapping("/list")
26 27 28
    public PageInfo<PERMISSION> list(@RequestParam(value = "pageNum",required = false,defaultValue = "1")
                                             int pageNum,
                                     @RequestParam(value = "pageSize",required = false,defaultValue = "5")
shenhailong authored
29 30 31
                                             int pageSize,
                                     @RequestParam(value = "name", required = false) String name){
        return permissionService.findAll(pageNum,pageSize, name);
32 33 34

    }
朱兆平 authored
35
    @LogAnnotation(moduleName = "权限管理",operate = "权限添加")
shenhailong authored
36
    @PostMapping("/add")
37 38 39 40 41
    public ResultJson add(@RequestBody PERMISSION permission){
        int i =permissionService.insertSelective(permission);

        ResultJson resultJson = new ResultJson();
        if (1==i){
shenhailong authored
42 43 44 45 46 47 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 75 76 77 78 79 80 81 82 83 84 85 86 87
            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){

        int i =permissionService.deleteByPrimaryKey(permission.getPermissionId().toString());

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

    @LogAnnotation(moduleName = "权限管理",operate = "权限批量删除")
    @GetMapping("/batchremove")
    public ResultJson reomve(String ids, HttpServletRequest request, HttpServletResponse response){

        ResultJson resultJson = new ResultJson();

        if (permissionService.deleteByPrimaryKey(ids)>0){
            resultJson = new ResultJson("200","删除成功");
88 89 90 91 92
        }else {
            resultJson = new ResultJson("500","insert faild");
        }
        return resultJson;
    }
93
//    @LogAnnotation(moduleName = "权限管理",operate = "查找权限")
zhangFan authored
94 95 96 97 98 99 100 101 102 103 104
    @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;
    }
105 106 107 108 109 110

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

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

    }
118 119 120 121 122 123 124

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

    }
125
}