package cn.com.ty.lift.system.user.controller;

import cn.com.ty.lift.system.user.dao.entity.UserRole;
import cn.com.ty.lift.system.user.dao.entity.model.RoleRequest;
import cn.com.ty.lift.system.user.service.IRoleService;
import cn.com.xwy.boot.web.dto.RestResponse;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author huangyuan
 * @date 2019-12-01
 * @description 角色管理
 */
@RestController
@RequestMapping("/role")
public class RoleController {

    @Resource
    private IRoleService roleService;

    /**
     * @param roleRequest 角色请求类
     * @return
     * @description 获取角色列表
     * @date 2019/11/27 10:03 AM
     */
    @RequestMapping("/list")
    public RestResponse list(@RequestBody RoleRequest roleRequest) {
        return roleService.list(roleRequest);
    }

    /**
     * @param
     * @return
     * @description 获取用户公司角色列表
     * @date 2019-12-23 22:54
     */
    @RequestMapping("/companyRoleList")
    public RestResponse companyRoleList(@RequestBody RoleRequest roleRequest) {
        return roleService.companyRoleList(roleRequest);
    }

    /**
     * @param roleRequest 角色请求对象
     * @return
     * @description 添加角色
     * @date 2019/11/27 10:03 AM
     */
    @PostMapping("/add")
    public RestResponse addRole(@RequestBody RoleRequest roleRequest) {
        //设置创建者信息
        return roleService.addRole(roleRequest);
    }

    /**
     * @param
     * @return
     * @description 获取角色信息
     * @date 2019-12-20 15:58
     */
    @RequestMapping("/info")
    public RestResponse roleInfo(@RequestBody RoleRequest roleRequest) {
        return roleService.info(roleRequest);
    }

    /**
     * @param roleRequest 角色请求对象
     * @return
     * @description 添加角色
     * @date 2019/11/27 10:03 AM
     */
    @PostMapping("/update")
    public RestResponse updateRole(@RequestBody RoleRequest roleRequest) {
        //设置更新者信息
        return roleService.updateRole(roleRequest);
    }

    /**
     * @param roleRequest 角色请求类
     * @return
     * @description 删除角色信息
     * @date 2019/11/27 10:03 AM
     */
    @PostMapping("/delete")
    public RestResponse deleteRole(@RequestBody RoleRequest roleRequest) {
        return roleService.deleteRole(roleRequest);
    }

    /**
     * @param userRole 用户id和公司id
     * @return
     * @description 通过用户id获取用户对应的菜单信息
     * @date 2019/11/27 10:03 AM
     */
    @RequestMapping("/getUserMenus")
    public RestResponse getUserMenus(UserRole userRole) {
        return roleService.getUserMenus(userRole);
    }

}
