RoleController.java 3.5 KB
package com.tianbo.warehouse.controller;

import com.github.pagehelper.PageInfo;
import com.tianbo.warehouse.annotation.LogAnnotation;
import com.tianbo.warehouse.controller.response.ResultJson;
import com.tianbo.warehouse.model.ROLE;
import com.tianbo.warehouse.model.RolePermission;
import com.tianbo.warehouse.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

@RestController()
@RequestMapping("/role")
public class RoleController {

    @Autowired
    RoleService roleService;

    @GetMapping("/list")
    public PageInfo<ROLE> list(@RequestParam(value = "pageNum",required = false,defaultValue = "1")
                                        int pageNum,
                               @RequestParam(value = "pageSize",required = false,defaultValue = "10")
                                        int pageSize,
                               @RequestParam(value = "roleName",required = false)
                                           String roleName){

        return roleService.findAll(pageNum,pageSize, roleName);
    }

    @LogAnnotation(moduleName = "岗位/角色管理",operate = "岗位/角色添加")
    @PostMapping("/add")
    public ResultJson add(@RequestBody ROLE role){
        int i =roleService.insertSelective(role);
        return i==1 ? new ResultJson("200","添加权限成功") :new ResultJson("500","insert faild");

    }

    /**
     * 设置角色的权限
     * @return
     */
    @LogAnnotation(moduleName = "岗位/角色管理",operate = "权限设置")
    @PutMapping("/permSet")
    public ResultJson permissionSet(@RequestBody RolePermission rolePermission){
        int i = roleService.setRolePermissoin(rolePermission);
        return i==1 ? new ResultJson("200","设置权限成功") :new ResultJson("500","设置权限失败");
    }

    @LogAnnotation(moduleName = "岗位/角色管理",operate = "岗位/角色修改")
    @PutMapping("/edit")
    @ResponseBody
    public ResultJson edit(@RequestBody @Valid ROLE role){

        int i =roleService.updateByPrimaryKeySelective(role);

        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 ROLE role, HttpServletRequest request, HttpServletResponse response){

        int i =roleService.deleteByPrimaryKey(role.getRoleId());

        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 (roleService.deleteByPrimaryKey(Integer.valueOf(ids))>0){
            resultJson = new ResultJson("200","删除成功");
        }else {
            resultJson = new ResultJson("500","insert faild");
        }
        return resultJson;
    }

}