package com.diagbot.web;

import com.diagbot.annotation.SysLogger;
import com.diagbot.dto.RespDTO;
import com.diagbot.dto.SysRoleDTO;
import com.diagbot.dto.SysRoleMenuDTO;
import com.diagbot.facade.SysRoleFacade;
import com.diagbot.vo.SysRoleMenuQueryVO;
import com.diagbot.vo.SysRoleMenuSaveVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
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.validation.Valid;
import java.util.List;

/**
 * <p>
 * 系统角色表 前端控制器
 * </p>
 *
 * @author gaodm
 * @time: 2024-04-27
 */
@RestController
@Api(value = "用户角色API", tags = { "用户角色API" })
@RequestMapping("/sys/role")
@SuppressWarnings("unchecked")
public class SysRoleController {
    @Autowired
    private SysRoleFacade sysRoleFacade;

    @ApiOperation(value = "获取角色列表信息[by:gaodm]",
            notes = "")
    @PostMapping("/list")
    @SysLogger("list")
    public RespDTO<List<SysRoleDTO>> list() {
        return RespDTO.onSuc(sysRoleFacade.listFac());
    }

    @ApiOperation(value = "获取角色下拉列表信息[by:gaodm]",
            notes = "")
    @PostMapping("/listForUser")
    @SysLogger("listForUser")
    public RespDTO<List<SysRoleDTO>> listForUser() {
        return RespDTO.onSuc(sysRoleFacade.listFac());
    }

    @ApiOperation(value = "获取角色菜权限单等数据[by:gaodm]",
            notes = "")
    @PostMapping("/getRoleMenu")
    @SysLogger("getRoleMenu")
    public RespDTO<SysRoleMenuDTO> getRoleMenu(@RequestBody SysRoleMenuQueryVO sysRoleMenuQueryVO) {
        return RespDTO.onSuc(sysRoleFacade.getRoleMenu(sysRoleMenuQueryVO));
    }

    @ApiOperation(value = "修改角色菜单权限数据[by:gaodm]",
            notes = "")
    @PostMapping("/saveRoleMenu")
    @SysLogger("saveRoleMenu")
    @Transactional
    public RespDTO<Boolean> saveRoleMenu(@RequestBody @Valid SysRoleMenuSaveVO sysRoleMenuSaveVO) {
        return RespDTO.onSuc(sysRoleFacade.saveRoleMenu(sysRoleMenuSaveVO));
    }
}
