package com.jiayue.ipp.idp.controller;

import com.jiayue.ipp.common.data.entity.AccuracyCalculation;
import com.jiayue.ipp.idp.service.AccuracyCalculationService;
import com.jiayue.ipp.idp.util.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * idp_accuracy_calculation
 *
 * @author whc
 * @date 2022-10-17 15:08:48
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/accuracyCalculation")
@Api(value = "accuracyCalculation", tags = "idp_accuracy_calculation管理")
public class AccuracyCalculationController {

    private final AccuracyCalculationService accuracyCalculationService;

    @ApiOperation(value = "根据时间查询准确合格率", notes = "根据时间查询准确合格率")
    //    @SysLog("根据时间查询准确合格率")
    @PostMapping("/table")
    public R findByTimeBetween(Long startTime,
                               Long endTime,
                               String showCode,
                               String sortOrder,
                               String stationCode,
                               String type,
                               String forecastManufactor) {
        try {
            return R.ok(accuracyCalculationService.findByTimeBetweenTable(startTime, endTime, showCode, sortOrder, stationCode, type, forecastManufactor));
        } catch (Exception e) {
            e.printStackTrace();
            return R.failed(e.toString());
        }
    }

    @ApiOperation(value = "根据时间查询日准确合格率", notes = "根据时间查询日准确合格率")
    //    @SysLog("根据时间查询日准确合格率")
    @PostMapping("/tableDay")
    public R findByTimeBetweenDay(Long startTime,
                                  Long endTime,
                                  String showCode,
                                  String sortOrder,
                                  String stationCode,
                                  String type,
                                  String forecastManufactor) {
        try {
            return R.ok(accuracyCalculationService.findByTimeBetweenTableDay(startTime, endTime, showCode, sortOrder, stationCode, type, forecastManufactor));
        } catch (Exception e) {
            e.printStackTrace();
            return R.failed(e.toString());
        }
    }

    @ApiOperation(value = "根据时间查询月准确合格率", notes = "根据时间查询月准确合格率")
    //    @SysLog("根据时间查询月准确合格率")
    @PostMapping("/tableMonth")
    public R findByTimeBetweenMonth(Long startTime,
                                    Long endTime,
                                    String showCode,
                                    String sortOrder,
                                    String stationCode,
                                    String type,
                                    String forecastManufactor) {

        Map<String, Object> map = new HashMap<>();
        try {
            map = accuracyCalculationService.findByTimeBetweenTableMonth(startTime, endTime, showCode, sortOrder, stationCode, type, forecastManufactor);
            return R.ok(map);

        } catch (Exception e) {
            e.printStackTrace();
            return R.failed(e.toString());
        }
    }

    /**
     * 实时查询准确合格率（用于图表）
     *
     * @param startTime 开始时间 当天凌晨
     * @param endTime   结束时间 当前时间
     * @return result
     */
    @ApiOperation(value = "实时查询准确合格率（用于图表）", notes = "实时查询准确合格率（用于图表）")
    //    @SysLog("实时查询准确合格率（用于图表）")
    @PostMapping(value = "/realTimeCharts")
    public R accuracyPassRateQueryForCharts(Long startTime,
                                            Long endTime,
                                            String showCode,
                                            String stationCode,
                                            String type,
                                            String forecastManufactor) {
        Map<String, Object> map = new HashMap<>();
        try {
            map = accuracyCalculationService.findByTimeBetweenForRealTimeCharts(startTime, endTime, showCode, stationCode, type, forecastManufactor);
            return R.ok(map);
        } catch (Exception e) {
            e.printStackTrace();
            return R.failed(e.toString());
        }
    }

    /**
     * 实时查询日准确率（均方根误差、用于图表）
     *
     * @param startTime 开始时间 当天凌晨
     * @param endTime   结束时间 当前时间
     * @return result
     * @author zcl
     */
    @ApiOperation(value = "实时查询日准确率（均方根误差、用于图表）", notes = "实时查询日准确率（均方根误差、用于图表）")
    //    @SysLog("实时查询日准确率（均方根误差、用于图表）")
    @PostMapping(value = "/realTimeChartsDay")
    public R accuracyPassRateQueryForChartsDay(Long startTime,
                                               Long endTime,
                                               String showCode,
                                               String stationCode,
                                               String type,
                                               String forecastManufactor) {
        Map<String, Object> findResultMap = new HashMap<>();
        try {
            findResultMap = accuracyCalculationService.findByTimeBetweenForRealTimeChartsDay(startTime, endTime, showCode, stationCode, type, forecastManufactor);
            return R.ok(findResultMap);
        } catch (Exception e) {
            e.printStackTrace();
            return R.failed(e.toString());
        }
    }

    /**
     * 首页查询短期准确率
     *
     * @return result
     */

    @GetMapping(value = "/homePageShortAccuracy")
    public R homePageShortAccuracy() {
        try {
            List<AccuracyCalculation> accuracyCalculations = accuracyCalculationService.homePageShortAccuracy();
            return R.ok(accuracyCalculations);
        } catch (Exception e) {
            e.printStackTrace();
            return R.failed(e.toString());
        }
    }

    /**
     * 首页查询短期准确率
     *
     * @return result
     */

    @GetMapping(value = "/homePageUltraShortAccuracy")
    public R homePageUltraShortAccuracy() {
        try {
            List<AccuracyCalculation> accuracyCalculations = accuracyCalculationService.homePageUltraShortAccuracy();
            return R.ok(accuracyCalculations);
        } catch (Exception e) {
            e.printStackTrace();
            return R.failed(e.toString());
        }
    }

}
