package com.sky.ioc.controller.system;

import com.sky.ioc.entity.Index;
import com.sky.ioc.service.system.IndexService;
import com.sky.ioc.service.system.SystemMenusService;
import com.sky.ioc.tool.ReturnMsg;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "系统配置--指标")
@Slf4j
@RestController
@RequestMapping("/system_index")
public class IndexController {

    @Autowired
    IndexService indexService;

    @Autowired
    SystemMenusService systemMenusService;

    @ApiOperation("指标列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "parentId", value = "父id", dataType = "Integer"),
            @ApiImplicitParam(name = "page", value = "页码",defaultValue="1", dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "页大小", defaultValue="10",dataType = "Integer")
    })
    @GetMapping(value = "/getIndexList")
    public ReturnMsg getJobList(@RequestParam(name = "parentId", required = true) Integer parentId,
                                @RequestParam(name = "page", required = false,defaultValue = "1") Integer page,
                                @RequestParam(name = "pageSize", required = false,defaultValue = "10") Integer pageSize) {
        return  indexService.pageList(parentId,page,pageSize);
    }

    @ApiOperation("新建指标")
    @PostMapping(value = "/addIndex")
    public ReturnMsg addIndex(@RequestBody Index index) {
        return  indexService.addIndex(index);
    }

    @ApiOperation("编辑指标")
    @PostMapping(value = "/editIndex")
    public ReturnMsg editIndex(@RequestBody Index index) {
        return  indexService.editIndex(index);
    }

    @ApiOperation("删除指标")
    @PostMapping(value = "/delIndex")
    public ReturnMsg delIndex(@RequestParam(name = "id", required = true) Integer id) {
        return  indexService.delIndexById(id);
    }

    @ApiOperation("批量删除指标")
    @PostMapping(value = "/batchDelByIds")
    public ReturnMsg batchDelByIds(@RequestBody List<Integer> ids) {
        return indexService.delBatchById(ids);
    }

    @ApiOperation("查询所有菜单")
    @GetMapping("getSystemMenusList")
    public ReturnMsg getSystemMenusList( @RequestParam(value = "parentId", required=false,defaultValue = "-1")  long parentId){
        return systemMenusService.getSystemMenusInfoList(parentId);
    }
}
