IRole.java 4.33 KB
package com.dituhui.pea.user;

import com.dituhui.pea.common.PageResult;
import com.dituhui.pea.pojo.PageRequest;
import com.dituhui.pea.pojo.ResourceInfo;
import com.dituhui.pea.pojo.RoleInfo;
import com.dituhui.pea.pojo.WebResult;
import com.dituhui.pea.pojo.role.UserRoleInfo;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * 角色相关接口
 */
@FeignClient(value = "project-user", contextId = "role")
public interface IRole {

    /**
     * 添加角色
     *
     * @param roleInfo 角色信息
     * @return
     */
    @RequestMapping(value = "/v1/role/add", method = RequestMethod.POST)
    WebResult<RoleInfo> addRole(@RequestBody RoleInfo roleInfo);


    /**
     * 修改角色
     *
     * @param roleInfo 角色信息
     * @return
     */
    @RequestMapping(value = "/v1/role/update", method = RequestMethod.POST)
    WebResult<RoleInfo> updateRole(@RequestBody RoleInfo roleInfo);

    /**
     * 删除角色
     *
     * @param roleId 角色ID
     * @return
     */
    @RequestMapping(value = "/v1/role/delete", method = RequestMethod.POST)
    WebResult<Boolean> deleteRole(@RequestParam("id") String roleId);

    /**
     * 添加用户角色
     *
     * @param roleId 角色ID
     * @param userId 用户ID
     * @return
     */
    @RequestMapping(value = "/v1/role/addUser", method = RequestMethod.POST)
    WebResult<Boolean> addUserRole(@RequestParam("id") String roleId, @RequestParam("userId") String userId);

    /**
     * 删除用户角色
     *
     * @param userId 用户ID
     * @param roleId 角色ID
     * @return
     */
    @RequestMapping(value = "/v1/role/deleteUser", method = RequestMethod.POST)
    WebResult<Boolean> deleteUserRole(@RequestParam("id") String roleId, @RequestParam("userId") String userId);

    /**
     * 添加资源
     *
     * @param resourceInfo 资源信息
     * @return
     */
    @RequestMapping(value = "/v1/resource/add", method = RequestMethod.POST)
    WebResult<ResourceInfo> addResource(@RequestBody ResourceInfo resourceInfo);

    /**
     * 删除资源
     *
     * @param resourceId 资源ID
     * @return
     */
    @RequestMapping(value = "/v1/resource/delete", method = RequestMethod.POST)
    WebResult<Boolean> deleteResource(@RequestParam("id") String resourceId);

    /**
     * 添加角色资源
     *
     * @param roleId     角色ID
     * @param resourceId 资源ID
     * @return
     */
    @RequestMapping(value = "/v1/role/addResource", method = RequestMethod.POST)
    WebResult<Boolean> addRoleResource(@RequestParam("id") String roleId, @RequestParam("resource_id") String resourceId);

    /**
     * 批量更新/替换角色权限/资源,会清空原来的权限/资源
     *
     * @param roleId      角色Id
     * @param resourceIds 资源ID集合
     * @return
     */
    @RequestMapping(value = "/v1/role/replaceResources", method = RequestMethod.POST)
    WebResult<Boolean> replaceRoleResource(@RequestParam("id") String roleId, @RequestParam("resource_ids") String resourceIds);

    /**
     * 删除角色资源
     *
     * @param roleId     角色ID
     * @param resourceId 资源ID
     * @return
     */
    @RequestMapping(value = "/v1/role/deleteResource", method = RequestMethod.POST)
    WebResult<Boolean> deleteRoleResource(@RequestParam("id") String roleId, @RequestParam("resource_id") String resourceId);


    /**
     * 获取角色列表
     *
     * @param pageRequest 分页参数
     * @return
     */
    @RequestMapping(value = "/v1/role/list", method = RequestMethod.GET)
    WebResult<PageResult<RoleInfo>> listRole(PageRequest pageRequest);

    /**
     * 获取用户角色权限列表
     *
     * @param roleId 用户id
     * @return
     */
    @RequestMapping(value = "/v1/role/info", method = RequestMethod.GET)
    WebResult<RoleInfo> info(@RequestParam("roleId") String roleId);

    /**
     * 获取用户角色权限列表
     *
     * @param userId 用户id
     * @return
     */
    @RequestMapping(value = "/v1/role/allResource", method = RequestMethod.GET)
    WebResult<List<ResourceInfo>> allResource();
}