package com.skr.mdm.api.company.controller;

import com.skr.mdm.api.company.service.FunctionScopeService;
import com.skr.mdm.result.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author nfq
 * @date 2020/9/8 11:11
 */
@RestController
@RequestMapping("function/scope")
@Api(tags = "功能范围")
public class FunctionScopeController {

    @Autowired
    private FunctionScopeService functionScopeService;

    @PostMapping("add")
    @ApiOperation(value = "添加功能范围")
    public ResponseResult addFunctionScope(@RequestParam @ApiParam(value = "功能策略名称", required = true) String functionScopeName) {
        return functionScopeService.addFunctionScope(functionScopeName);
    }

    @PostMapping("list")
    @ApiOperation(value = "功能范围列表")
    public ResponseResult addFunctionScope(@RequestParam Integer pageNum, @RequestParam Integer pageSize) {
        return functionScopeService.listFunctionScope(pageNum, pageSize);
    }

    @PostMapping("menuTree")
    @ApiOperation(value = "菜单树")
    public ResponseResult menuTree(@RequestParam Integer functionScopeId) {
        return ResponseResult.success(functionScopeService.menuTree(0, functionScopeId));
    }

    @PostMapping("config")
    @ApiOperation(value = "配置功能范围")
    public ResponseResult configFunctionScope(@RequestParam Integer functionScopeId, @RequestBody List<Integer> menuIdList) {
        return functionScopeService.configFunctionScope(functionScopeId, menuIdList);
    }

    @PostMapping("all")
    @ApiOperation(value = "所有功能范围")
    public ResponseResult allFunctionScope() {
        return functionScopeService.allFunctionScope();
    }

    @PostMapping("delete")
    @ApiOperation(value = "删除功能范围")
    public ResponseResult deleteFunctionScope(Integer functionScopeId) {
        return functionScopeService.deleteFunctionScope(functionScopeId);
    }

    @PostMapping("update")
    @ApiOperation(value = "编辑功能范围")
    public ResponseResult updateFunctionScope(@RequestParam Integer functionScopeId, @RequestParam String functionScopeName) {
        return functionScopeService.updateFunctionScope(functionScopeId, functionScopeName);
    }
}
