package com.cpop.oam.business.controller.backstage;

import com.cpop.core.base.entity.R;
import com.cpop.oam.business.bo.MenuListBo;
import com.cpop.oam.business.bo.RoleBo;
import com.cpop.oam.business.bo.RolePageBo;
import com.cpop.oam.business.bo.RoleStatusBo;
import com.cpop.oam.business.service.MenuService;
import com.cpop.oam.business.service.RoleService;
import com.cpop.oam.business.vo.MenuVo;
import com.cpop.oam.business.vo.RolePageVo;
import com.mybatisflex.core.paginate.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 系统角色表 控制层。
 *
 * @author DB
 * @since 2023-10-19
 */
@RestController
@Tag(name = "系统角色表接口")
@RequestMapping("/backstage/role")
public class BackstageRoleController {

    @Autowired
    private RoleService roleService;

    @Autowired
    private MenuService menuService;

    /**
     * 查询角色分页列表
     * @author DB
     * @since 2023/09/10 16:51
     * @param bo 请求参数
     * @return R<PageVo<SysRolePageVo>>
     */
    @Operation(summary = "查询角色分页列表")
    @GetMapping("/getSysRolePageList")
    public R<Page<RolePageVo>> getSysRolePageList(RolePageBo bo) {
        Page<RolePageVo> pageVo = roleService.getSysRolePage(bo);
        return R.ok(pageVo);
    }

    /**
     * 新增角色
     * @author DB
     * @since  2023/10/12 10:48
     * @param bo 请求参数
     * @return com.cpop.core.base.entity.R<java.lang.Void>
     */
    @Operation(summary = "新增角色")
    @PostMapping("/insertSysRole")
    public R<Void> insertSysRole(@RequestBody @Validated RoleBo bo) {
        roleService.insertSysRole(bo);
        return R.ok();
    }

    /**
     * 获取系统菜单树列表
     * @author DB
     * @since 2023/5/10 14:39
     **/
    @Operation(summary = "获取菜单树列表")
    @GetMapping("/getSysMenuTreeList")
    public R<List<MenuVo>> getSysMenuTreeList() {
        MenuListBo menuListBo = new MenuListBo();
        menuListBo.setStatus(true);
        List<MenuVo> list = menuService.getSysMenuTreeList(menuListBo);
        //过滤掉没有权限的数据
        return R.ok(list);
    }

    /**
     * 修改角色
     * @author DB
     * @since 2023/09/10 17:45
     * @param bo 请求参数
     * @return com.jambox.core.base.R<java.lang.Void>
     */
    @Operation(summary = "修改角色")
    @PutMapping("/updateSysRole")
    public R<Void> updateSysRole(@RequestBody @Validated RoleBo bo) {
        roleService.updateSysRole(bo);
        return R.ok();
    }

    /**
     * 删除角色
     * @author DB
     * @since 2024/4/17
     * @param id 主键
     * @return R<Void>
     */
    @Operation(summary = "删除角色")
    @DeleteMapping("/removeSysRole/{id}")
    public R<Void> removeSysRole(@PathVariable String id) {
        roleService.removeSysRole(id);
        return R.ok();
    }

    /**
     * 设置角色状态
     * @param bo 请求参数
     * @return R<Void>
     * @author DB
     * @since 2023/5/9 14:13
     **/
    @Operation(description = "设置角色状态")
    @PutMapping("/setSysRoleStatus")
    public R<Void> setSysRoleStatus(@RequestBody @Validated RoleStatusBo bo) {
        roleService.setSysRoleStatus(bo);
        return R.ok();
    }

}
