RoleController.java 5.6 KB
Newer Older
苗卫卫 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
package com.boco.nbd.wios.manage.controller;

import com.boco.nbd.cams.core.constant.MessageConstant;
import com.boco.nbd.wios.manage.contants.WiosConstant;
import com.boco.nbd.wios.manage.entity.bo.AbstractTreeNode;
import com.boco.nbd.wios.manage.entity.bo.MenuTreeVo;
import com.boco.nbd.wios.manage.entity.bo.RoleBo;
import com.boco.nbd.wios.manage.entity.bo.Role;
import com.boco.nbd.wios.manage.service.impl.RoleService;
import com.ihidea.component.api.v2.BaseResponse;
import com.ihidea.core.support.exception.ServiceException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.List;

/**
 * 角色相关api
 *
 * @author lilin
 * @version [版本号, 2020年5月20日]
 */
@RestController
@RequestMapping("api")
@Api(tags = "角色管理接口")
@ApiIgnore
public class RoleController {
    /**
     * 角色service
     */
    @Resource
    private RoleService roleService;

    /**
     * 查询角色列表
     *
     * @param role 查询条件
     * @return 角色列表
     */
    @GetMapping(value = "role/list")
    @ApiOperation(value = "查询角色列表")
    public BaseResponse<List<Role>> queryList(RoleBo role) {
        return new BaseResponse<List<Role>>(roleService.queryList(role));
    }

    /**
     * 新增角色
     *
     * @param role 角色信息
     * @return 新增成功的数量
     */
    @PostMapping(value = "role/add")
    @ApiOperation(value = "添加角色")
    public BaseResponse<Integer> addRole(RoleBo role) {
        if (!StringUtils.isEmpty(role.getName()) && role.getName().length() > WiosConstant.MAX_ROLE_NAME_LENGTH) {
            throw new ServiceException("角色名称过长");
        }
        return new BaseResponse<>(roleService.addRole(role));
    }

    /**
     * 修改角色
     *
     * @param role 角色信息
     * @return 修改成功的数量
     */
    @PostMapping(value = "role/update")
    @ApiOperation(value = "修改角色")
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "主键", dataType = "int", paramType = "query", required = true),})
    public BaseResponse<Integer> updateRole(RoleBo role) {
        if (role.getId() == null) {
            throw new ServiceException(MessageConstant.MISSING_PARAM);
        }
        return new BaseResponse<>(roleService.updateRole(role));
    }

    /**
     * 删除角色
     *
     * @param id 角色id
     * @return 删除成功的数量
     */
    @PostMapping(value = "role/delete")
    @ApiOperation(value = "删除角色")
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "主键", dataType = "int", paramType = "query", required = true),})
    public BaseResponse<Integer> deleteRole(Integer id) {
        return new BaseResponse<>(roleService.deleteRole(id));
    }


    /**
     * 查询角色菜单权限
     *
     * @param roleId 角色id
     * @return 角色菜单权限
     */
    @GetMapping(value = "role/menuList")
    @ApiOperation(value = "查询角色菜单权限")
    @ApiImplicitParams({@ApiImplicitParam(name = "roleId", value = "角色id", dataType = "int", paramType = "query", required = true),
    })
    public BaseResponse<List<MenuTreeVo>> getRoleMenuList(Integer roleId) {
        return new BaseResponse<>(roleService.getRoleMenuList(roleId));
    }

    /**
     * 获取左侧菜单列表
     *
     * @param accountId
     * @return
     */
    @GetMapping(value = "menuList")
    @ApiOperation(value = "获取左侧菜单列表")
    @ApiImplicitParams({@ApiImplicitParam(name = "accountId", value = "账号id", dataType = "int", paramType = "query", required = true),})
    public BaseResponse<List<AbstractTreeNode>> getMenuList(Integer accountId) {
        return new BaseResponse<>(roleService.getMenuList(accountId));
    }

    /**
     * 获取某个页面配置的按钮列表
     *
     * @param menuId
     * @return
     */
    @GetMapping(value = "role/getBtnList")
    @ApiOperation(value = "获取某个页面配置的按钮列表")
    @ApiImplicitParams({@ApiImplicitParam(name = "menuId", value = "菜单id", dataType = "String", paramType = "query", required = true),})
    public BaseResponse<Object> getPageBtnList(String menuId) {
        if (StringUtils.isEmpty(menuId)) {
            throw new ServiceException(MessageConstant.MISSING_PARAM);
        }
        return new BaseResponse<Object>(roleService.getPageBtnList(menuId));
    }

    /**
     * 角色启用/禁用
     *
     * @param roleId
     * @param status
     * @return
     */
    @PostMapping(value = "role/updateStatus")
    @ApiOperation(value = "角色启用/禁用")
    @ApiImplicitParams({@ApiImplicitParam(name = "roleId", value = "角色id", dataType = "int", paramType = "query", required = true),
        @ApiImplicitParam(name = "status", value = "状态(0:禁用,1:正常)", dataType = "int", paramType = "query", required = true),})
    public BaseResponse<Object> updateStatus(Integer roleId, Integer status) {
        if (roleId == null || status == null) {
            throw new ServiceException(MessageConstant.MISSING_PARAM);
        }
        roleService.updateStatus(roleId, status);
        return new BaseResponse<>();
    }
}