package com.securitycontrol.system.base.controller;

import com.securitycontrol.common.core.web.controller.BaseController;
import com.securitycontrol.common.core.web.domain.AjaxResult;
import com.securitycontrol.common.core.web.page.TableDataInfo;
import com.securitycontrol.common.log.annotation.Log;
import com.securitycontrol.common.log.enums.OperationType;
import com.securitycontrol.entity.system.dto.RoleDto;
import com.securitycontrol.entity.system.vo.RoleVo;
import com.securitycontrol.system.base.service.IRoleService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

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

/**
 * @author：cwchen
 * @date：2024-02-23-18:28
 * @version：1.0
 * @description：角色管理-web
 */
@RestController
@RequestMapping("/sys/role/")
public class RoleController extends BaseController {

    @Resource(name = "IRoleService")
    private IRoleService service;

    @ApiOperation(value = "获取角色列表")
    @GetMapping("getRoleLists")
    @Log(title = "系统管理", menu = "系统管理->角色管理", grade = OperationType.QUERY_SYS, details = "查询角色", type = "系统日志")
    public TableDataInfo getRoleLists(RoleDto dto) {
        startPage();
        List<RoleVo> list = service.getRoleLists(dto);
        return getDataTable(list);
    }

    @ApiOperation(value = "新增角色")
    @PostMapping("addRole")
    @Log(title = "系统管理", menu = "系统管理->角色管理", grade = OperationType.ADD_SYS, details = "新增角色", type = "系统日志")
    public AjaxResult addRole(@Valid @RequestBody RoleVo vo) {
        return service.addOrUpdateRole(vo);
    }

    @ApiOperation(value = "修改角色")
    @PostMapping("editRole")
    @Log(title = "系统管理", menu = "系统管理->角色管理", grade = OperationType.UPDATE_SYS, details = "修改角色", type = "系统日志")
    public AjaxResult editRole(@Valid @RequestBody RoleVo vo) {
        return service.addOrUpdateRole(vo);
    }

    @ApiOperation(value = "角色详情")
    @GetMapping("getRoleById")
    public AjaxResult getRoleById(RoleDto dto) {
        return service.getRoleById(dto);
    }

    @ApiOperation(value = "删除角色")
    @PostMapping("delRole")
    @Log(title = "系统管理", menu = "系统管理->角色管理", grade = OperationType.DELETE_SYS, details = "删除角色", type = "系统日志")
    public AjaxResult delRole(RoleDto dto) {
        return service.delRole(dto);
    }

    @ApiOperation(value = "角色授权菜单")
    @PostMapping("authMenu")
    @Log(title = "系统管理", menu = "系统管理->角色管理", grade = OperationType.ADD_SYS, details = "角色授权", type = "系统日志")
    public AjaxResult authMenu(@RequestBody RoleVo vo) {
        return service.authMenu(vo);
    }

    @ApiOperation(value = "获取角色授权的菜单")
    @GetMapping("getAuthMenus")
    public AjaxResult getAuthMenu(RoleDto dto) {
        return service.getAuthMenu(dto);
    }
}
