package com.qmth.distributed.print.api;

import com.qmth.boot.api.constant.ApiConstant;
import com.qmth.teachcloud.common.entity.SysPrivilege;
import com.qmth.teachcloud.common.service.SysPrivilegeService;
import com.qmth.teachcloud.common.util.Result;
import com.qmth.teachcloud.common.util.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 菜单权限表 前端控制器
 * </p>
 *
 * @author xf
 * @since 2021-03-23
 */
@Api(tags = "菜单权限Controller")
@RestController
@RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + "/${prefix.url.sys}/privilege")
public class SysPrivilegeController {

    @Autowired
    private SysPrivilegeService sysPrivilegeService;

    /**
     * 查询
     *
     * @return
     */
    @ApiOperation(value = "查询")
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public Result list() {
        return ResultUtil.ok(sysPrivilegeService.listPrivilegeTreeNew());
    }

    /**
     * 查询需要授权的菜单
     *
     * @return
     */
    @ApiOperation(value = "查询需要授权的菜单")
    @RequestMapping(value = "/list_auth", method = RequestMethod.POST)
    public Result listAuth() {
        return ResultUtil.ok(sysPrivilegeService.listPrivilegeTreeAuth());
    }

    /**
     * 新增/修改
     *
     * @param privilege
     * @return
     */
    @ApiOperation(value = "新增/修改")
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public Result save(@RequestBody SysPrivilege privilege) {
        return ResultUtil.ok(sysPrivilegeService.savePrivilege(privilege));
    }

    /**
     * 删除
     *
     * @param privilege
     * @return
     */
    @ApiOperation(value = "删除")
    @RequestMapping(value = "/remove", method = RequestMethod.POST)
    public Result remove(@RequestBody SysPrivilege privilege) {
        return ResultUtil.ok(sysPrivilegeService.remove(privilege.getId()));
    }

    /**
     * 角色已绑定权限列表
     *
     * @param roleId
     * @return
     */
    @ApiOperation(value = "角色已绑定权限列表")
    @RequestMapping(value = "/get_role_privileges", method = RequestMethod.POST)
    public Result getRolePrivileges(@RequestParam(value = "roleId", required = true) Long roleId) {
        return ResultUtil.ok(sysPrivilegeService.getRolePrivileges(roleId));
    }
}

