package com.gz.controller.system;

import cn.hutool.core.lang.tree.Tree;
import cn.hutool.json.JSONObject;
import com.github.pagehelper.PageInfo;
import com.gz.core.annotation.TraceLog;
import com.gz.dto.system.RoleDTO;
import com.gz.service.system.RoleService;
import com.gz.vo.system.RoleMenuVO;
import com.gz.vo.system.RoleVO;
import org.springframework.web.bind.annotation.*;

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

/**
 * @author LiuchangLan
 * @date 2020/9/4 20:44
 */
@RestController
@RequestMapping("system/role")
public class RoleController {
    @Resource
    private RoleService roleService;

    /**
     * @description 增
     * @author LiuChangLan
     * @since 2020/9/4 14:46
     */
    @PostMapping("insert")
    @TraceLog(module = "权限管理",business = "新增权限")
    public Integer insert(@RequestBody RoleDTO roleDTO){
        return roleService.insert(roleDTO);
    }

    /**
     * @description 删
     * @author LiuChangLan
     * @since 2020/9/4 14:46
     */
    @DeleteMapping("delete")
    @TraceLog(module = "权限管理",business = "删除权限")
    public Integer delete(Integer id){
        return roleService.delete(id);
    }

    /**
     * @description 改
     * @author LiuChangLan
     * @since 2020/9/4 14:46
     */
    @PostMapping("update")
    @TraceLog(module = "权限管理",business = "修改权限")
    public Integer update(@RequestBody RoleDTO roleDTO){
        return roleService.update(roleDTO);
    }

    /**
     * @description 查(分页)
     * @author LiuChangLan
     * @since 2020/9/4 14:46
     */
    @GetMapping("select")
    @TraceLog(module = "权限管理",business = "获取权限列表")
    public PageInfo<RoleDTO> select(RoleVO roleVO){
        return roleService.select(roleVO);
    }

    /**
     * @description 根据主键查询
     * @author LiuChangLan
     * @since 2020/9/4 16:36
     */
    @GetMapping("selectByPrimaryKey")
    @TraceLog(module = "权限管理",business = "查询权限详细信息")
    public RoleDTO selectByPrimaryKey(Integer id){
        return roleService.selectByPrimaryKey(id);
    }

    /**
     * @description 设置权限菜单
     * @author LiuChangLan
     * @since 2020/9/22 11:52
     */
    @PostMapping("setRole")
    @TraceLog(module = "权限管理",business = "修改权限可访问菜单")
    public Integer setRole(@RequestBody RoleMenuVO vo) {
        return roleService.setRole(vo);
    }

    /**
     * @description 查询权限菜单列表
     * @author LiuChangLan
     * @since 2020/9/22 11:52
     */
    @GetMapping("selectRoleList")
    @TraceLog(module = "权限管理",business = "查询权限可访问的菜单")
    public List<Tree<String>> selectRoleList(Integer roleId) {
        return roleService.selectRoleList(roleId);
    }

    /**
     * @description 查询所有权限
     * @author LiuChangLan
     * @since 2020/9/22 11:54
     */
    @GetMapping("selectAllRole")
    @TraceLog(module = "权限管理",business = "获取所有权限")
    public List<RoleDTO> selectAllRole(){
        return roleService.selectAllRole();
    }

    /**
     * @description 获取文档查询权限
     * @author LiuChangLan
     * @since 2021/3/31 14:39
     */
    @GetMapping("selectShowArchive")
    List<JSONObject> selectShowArchive(Integer roleId){
        return roleService.selectShowArchive(roleId);
    }

}
