package com.aiotagro.cattletrade.business.controller;


import cn.dev33.satoken.annotation.SaCheckPermission;
import com.aiotagro.cattletrade.business.dto.SysRoleDto;
import com.aiotagro.cattletrade.business.entity.SysRole;
import com.aiotagro.cattletrade.business.service.ISysRoleService;
import com.aiotagro.common.core.web.domain.AjaxResult;
import com.aiotagro.common.core.web.domain.PageResultResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 岗色管理表 前端控制器
 * </p>
 *
 * @author admin
 * @since 2024-12-26
 */
@RestController
@RequestMapping("/sysRole")
public class SysRoleController {

    @Autowired
    private ISysRoleService roleService;

    /**
     * 查询分页列表
     */
    @SaCheckPermission("permission:operation:list")
    @PostMapping(value = "/queryList")
    public PageResultResponse queryList(@RequestBody SysRoleDto dto) {
        return roleService.queryList(dto);
    }

    /**
     * 查询角色列表（权限管理页面使用）
     */
    @SaCheckPermission("permission:operation:list")
    @PostMapping(value = "/list")
    public PageResultResponse list(@RequestBody SysRoleDto dto) {
        return roleService.queryList(dto);
    }

    /**
     * 新增、编辑
     **/
    @SaCheckPermission("permission:operation:role")
    @PostMapping("/save")
    public AjaxResult saveRole(@RequestBody SysRole role) {
        return roleService.saveRole(role);
    }

    /**
     * 新增角色
     **/
    @SaCheckPermission("permission:operation:role")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody SysRole role) {
        return roleService.saveRole(role);
    }

    /**
     * 更新角色
     **/
    @SaCheckPermission("permission:operation:role")
    @PostMapping("/update")
    public AjaxResult update(@RequestBody SysRole role) {
        return roleService.saveRole(role);
    }

    /**
     * 删除
     **/
    @SaCheckPermission("permission:operation:role")
    @GetMapping("/delete")
    public AjaxResult delete(@RequestParam Integer id) {
        return roleService.delete(id);
    }

    /**
     * 查询菜单列表
     **/
    @SaCheckPermission("permission:menu:list")
    @GetMapping("/getMenus")
    public AjaxResult getMenus(@RequestParam(required = false) Integer id) {
        return roleService.getMenus(id);
    }
}
