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

import com.usoftchina.bi.core.base.RepEntity;
import com.usoftchina.bi.server.model.pojo.annotation.CheckToken;
import com.usoftchina.bi.server.model.vo.configVo.*;
import com.usoftchina.bi.server.service.chart.*;
import com.usoftchina.bi.server.service.dataSource.ColumnScreenService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.SQLException;
import java.util.List;

@RestController
@Api(description = "图表展现相关接口")
public class ShowChartsController {

    @Autowired
    ShowHistogramService showHistogramService;
    @Autowired
    ShowPieService showPieService;
    @Autowired
    ShowLineService showLineService;
    @Autowired
    ShowScatterService showScatterService;
    @Autowired
    ShowIndividualService showIndividualService;
    @Autowired
    ShowPopulationService showPopulationService;
    @Autowired
    ColumnScreenService columnScreenService;
    @Autowired
    GetChartsDataUtilService getChartsDataUtilService;
    /*
    展示柱状图
     */
    @ApiOperation(value = "展示柱状图", notes = "展示柱状图", response = RepEntity.class)
    @CheckToken
    @PostMapping("/showHistogram")
    public RepEntity showHistogram(@RequestHeader String token,@RequestBody HistogramConfigInfo body){
        return showHistogramService.showHistogram(body, token, 0);
    }

    /*
    展示饼图
     */
    @ApiOperation(value = "展示饼图", notes = "展示图表", response = RepEntity.class)
    @CheckToken
    @PostMapping("/showPie")
    public RepEntity showPie(@RequestHeader String token,@RequestBody PieConfigInfo body){
        return showPieService.showPie(body, token, 0, null);
    }

    /*
    展示Line
     */
    @ApiOperation(value = "展示line", notes = "展示line", response = RepEntity.class)
    @CheckToken
    @PostMapping("/showLine")
    public RepEntity showLine(@RequestHeader String token,@RequestBody LineConfigInfo body){
        return showLineService.showLine(body, token, 0, null);
    }

    /*
    showScatter
     */
    @ApiOperation(value = "展示scatter", notes = "展示scatter", response = RepEntity.class)
    @CheckToken
    @PostMapping("/showScatter")
    public RepEntity showScatter(@RequestHeader String token,@RequestBody ScatterConfigInfo body){
        return showScatterService.showScatter(body, token, 0, null);
    }

    /*
    show个体统计表
     */
    @ApiOperation(value = "展示个体统计表", notes = "展示个体统计表", response = RepEntity.class)
    @CheckToken
    @PostMapping("/showIndividual")
    public RepEntity showIndividual(@RequestHeader String token,@RequestBody IndividualConfigInfo body){
        return showIndividualService.showIndividual(body, token, 0);
    }

    /*
    show总体统计表
     */
    @ApiOperation(value = "展示总体统计表", notes = "展示总体统计表", response = RepEntity.class)
    @CheckToken
    @PostMapping("/showPopulation")
    public RepEntity showPopulation(@RequestHeader String token,@RequestBody PopulationInfo body) throws SQLException {
        return showPopulationService.showPopulation(body, token, 0);
    }

    /*
    展示列数据
     */
    @ApiOperation(value = "展示列数据", notes = "展示列数据", response = RepEntity.class)
    @CheckToken
    @PostMapping("/showScreenData")
    public RepEntity showScreenData(@RequestHeader String token,@RequestBody ColumnScreenInfo body){
        return columnScreenService.getScreenData(body, token);
    }

    /*
    展示列数据（数据源）
     */
    @ApiOperation(value = "展示数据源列数据", notes = "展示数据源列数据", response = RepEntity.class)
    @PostMapping("/getScreenByBaseId")
    public RepEntity getScreenByBaseId(@RequestBody ColumnScreenInfo body){
        return columnScreenService.getScreenByBaseId(body);
    }

    /*
  展示列数据（数据源）
   */
    @ApiOperation(value = "展示数据源列数据(多个)", notes = "展示数据源列数据(多个)", response = RepEntity.class)
    @PostMapping("/getScreenByBaseIds")
    public RepEntity getScreenByBaseIds(@RequestBody List<ColumnScreenInfo> body){
        return columnScreenService.getScreenByBaseIds(body);
    }
    /*
    展示图表数据信息
     */
    @ApiOperation(value = "展示图表数据信息", notes = "展示图表数据信息", response = RepEntity.class)
    @CheckToken
    @PostMapping("/getChartsData")
    public RepEntity getChartsData(@RequestHeader String token,@RequestBody ShowDataChartInfo body){
        return getChartsDataUtilService.getChartsData(token, body);
    }
}
