package com.usoftchina.bi.server.controller.chart;

import com.usoftchina.bi.auth.annotation.Auth;
import com.usoftchina.bi.core.base.RepEntity;
import com.usoftchina.bi.core.base.TestPage;
import com.usoftchina.bi.server.model.bo.GroupUpdateId;
import com.usoftchina.bi.server.model.pojo.annotation.CheckToken;
import com.usoftchina.bi.server.model.pojo.annotation.Log;
import com.usoftchina.bi.server.model.vo.configVo.ChangeOrderInfo;
import com.usoftchina.bi.server.model.vo.configVo.ChartConfigInfo;
import com.usoftchina.bi.server.model.vo.configVo.GroupInfo;
import com.usoftchina.bi.server.service.chart.ChartsConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(description = "图表配置相关接口")
public class ChartsConfigController {
    @Autowired
    ChartsConfigService chartsConfigService;

   /*
   添加
    */
    @ApiOperation(value = "添加图表", notes = "添加图表", response = RepEntity.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", required = true, dataType = "String",paramType = "header"),
            @ApiImplicitParam(name = "body", value = "图表配置", required = true, dataType = "ChartConfigInfo", paramType = "body")
    })
    @CheckToken
    @Log(module = "图表", name = "#body.chartName", token = "#token")
    @PostMapping("/inputCharts")
    public RepEntity saveCharts(@RequestHeader String token, @RequestBody ChartConfigInfo body){
        return chartsConfigService.setChartsConfig(body, token);
    }

    /*
   更新
    */
    @ApiOperation(value = "更新图表", notes = "更新图表", response = RepEntity.class)
    @CheckToken
    @Log(module = "图表", name = "#body.chartName", token = "#token")
    @PostMapping("/updateCharts")
    public RepEntity updateCharts(@RequestHeader String token,@RequestBody ChartConfigInfo body){
        return chartsConfigService.updateChartsConfig(body, token);
    }

    /*
    移交图表
     */
    @ApiOperation(value = "移交图表", notes = "移交图表", response = RepEntity.class)
    @CheckToken
    @PostMapping("/changeChartOrder")
    public RepEntity changeChartOrder(@RequestHeader String token, @RequestBody ChangeOrderInfo body){
        return chartsConfigService.changeChartOrder(body, token);
    }

    /*
    更新图表的分组
     */
    @ApiOperation(value = "更新图表分组", notes = "更新图表分组", response = RepEntity.class)
    @CheckToken
    @Auth(user = "admin")
    @PostMapping("/updateChartConfigGroup")
    public RepEntity updateConfigGroup(@RequestHeader String token, @RequestBody GroupUpdateId body){
        return chartsConfigService.updateConfigGroup(token, body);
    }

    /*
    删除
     */
    @ApiOperation(value = "删除图表", notes = "删除图表", response = RepEntity.class)
    @CheckToken
    @PostMapping("/delChartsConfig")
    public RepEntity deleteChartsConfig(@RequestHeader String token, @RequestBody Long body){
        return chartsConfigService.delChartsConfig(token, body);
    }

    /*
    查询图表列表
     */
    @ApiOperation(value = "查询图表列表", notes = "查询图表列表", response = RepEntity.class)
    @CheckToken
    @GetMapping("/getListCharts")
    public RepEntity getListCharts(@RequestHeader String token, TestPage body){
        return chartsConfigService.getListCharts(token, body);
    }

    /*
    查询单个图表
     */
    @ApiOperation(value = "查询单个图表", notes = "查询单个图表", response = RepEntity.class)
    @CheckToken
    @GetMapping("/getChartsConfig")
    public RepEntity getChartsConfig(@RequestHeader String token, @RequestParam("id") int id){
        return chartsConfigService.getOneCharts(id);
    }

    /*
    添加图表分组
     */
    @ApiOperation(value = "添加图表分组", notes = "添加图表分组", response = RepEntity.class)
    @CheckToken
    @Auth(user = "admin")
    @PostMapping("/setChartsGroup")
    public RepEntity setChartsGroup(@RequestHeader String token, @RequestBody GroupInfo body){
        return chartsConfigService.setDataConnectorGroup(token, body);
    }

    /*
    更新图表分组
     */
    @ApiOperation(value = "更新图表分组", notes = "更新图表分组", response = RepEntity.class)
    @CheckToken
    @Auth(user = "admin")
    @PostMapping("/updataChartsGroup")
    public RepEntity updataChartsGroup(@RequestHeader String token,@RequestBody GroupInfo body){
        return chartsConfigService.updataDataConnectorGroup(token, body);
    }

    @ApiOperation(value = "批量更新数据源分组", notes = "批量更新数据源分组", response = RepEntity.class)
    @CheckToken
    @Auth(user = "admin")
    @PostMapping("/batchUpdateChartsGroup")
    public RepEntity saveChartsGroup(@RequestHeader String token, @RequestBody List<GroupInfo> groupInfoList){
        return chartsConfigService.saveChartsGroup(token, groupInfoList);
    }

    /*
    批量更新图表
     */
    @ApiOperation(value = "批量更新图表", notes = "批量更新图表", response = RepEntity.class)
    @CheckToken
    @PostMapping("/updataListGroup")
    public RepEntity updataListGroup(@RequestHeader String token,@RequestBody List<GroupInfo> body){
        return chartsConfigService.updataListGroup(token, body);
    }

    /*
    删除图表分组
     */
    @ApiOperation(value = "删除图表分组", notes = "删除图表分组", response = RepEntity.class)
    @CheckToken
    @Auth(user = "admin")
    @PostMapping("/delChartsGroup")
    public RepEntity delChartsGroup(@RequestHeader String token,@RequestBody List<Integer> body){
        return chartsConfigService.delDataConnectorGroup(token, body);
    }

    /*
    查询图表分组
     */
    @ApiOperation(value = "查询图表分组", notes = "查询图表分组", response = RepEntity.class)
    @CheckToken
    @PostMapping("/getChartsGroup")
    public RepEntity getChartsGroup(@RequestHeader String token){
        return chartsConfigService.getConnectorGroup();
    }

}
