package com.jiayue.ipfcst.controller;

import com.jiayue.ipfcst.common.core.web.vo.ResponseVO;
import com.jiayue.ipfcst.service.AccuracyPassRateService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.Map;

/**
 * 准确率合格率restful接口
 *
 * @author yh
 * @version 1.0
 * @since 2019/8/7 10:12
 */
@RestController
@Slf4j
@RequestMapping("accuracyPassRate")
public class AccuracyPassRateController {
  private final AccuracyPassRateService accuracyPassRateService;

  @Autowired
  public AccuracyPassRateController(AccuracyPassRateService accuracyPassRateService){
    this.accuracyPassRateService = accuracyPassRateService;
  }

  /**
   * 根据时间查询准确合格率
   * @param startTime 开始时间
   * @param endTime 结束时间
   * @param sortOrder 排序
   * @return result
   */
  @GetMapping(value="table/{startTime}/{endTime}/{showCode}/{sortOrder}")
  public ResponseVO findByTimeBetween(@PathVariable("startTime") Long startTime,
                                      @PathVariable("endTime") Long endTime,
                                      @PathVariable("showCode") String showCode,
                                      @PathVariable("sortOrder") String sortOrder) {
    Map<String,Object> map = new HashMap<>();
    try{
      map = accuracyPassRateService.findByTimeBetweenTable(startTime,endTime,showCode,sortOrder);
      return ResponseVO.success(map);

    }catch(Exception e){
      e.printStackTrace();
      log.error("查询准确合格率错误");
      return ResponseVO.fail(e.toString());
    }
  }

  /**
   * 根据时间查询日准确合格率(均方根误差)
   * @param startTime 开始时间
   * @param endTime 结束时间
   * @param sortOrder 排序
   * @author zcl
   * @return result
   */
  @GetMapping(value="tableDay/{startTime}/{endTime}/{showCode}/{sortOrder}")
  public ResponseVO findByTimeBetweenDay(@PathVariable("startTime") Long startTime,
                                      @PathVariable("endTime") Long endTime,
                                      @PathVariable("showCode") String showCode,
                                      @PathVariable("sortOrder") String sortOrder) {
    Map<String,Object> map = new HashMap<>();
    try{
      map = accuracyPassRateService.findByTimeBetweenTableDay(startTime,endTime,showCode,sortOrder);
      return ResponseVO.success(map);

    }catch(Exception e){
      e.printStackTrace();
      log.error("查询准确合格率错误");
      return ResponseVO.fail(e.toString());
    }
  }

  /**
   * 根据时间查询月准确合格率
   * @param startTime 开始时间
   * @param endTime 结束时间
   * @param sortOrder 排序
   * @return result
   */
  @GetMapping(value="tableMonth/{startTime}/{endTime}/{showCode}/{sortOrder}")
  public ResponseVO findByTimeBetweenMonth(@PathVariable("startTime") Long startTime,
                                      @PathVariable("endTime") Long endTime,
                                      @PathVariable("showCode") String showCode,
                                      @PathVariable("sortOrder") String sortOrder) {
    Map<String,Object> map = new HashMap<>();
    try{
      map = accuracyPassRateService.findByTimeBetweenTableMonth(startTime,endTime,showCode,sortOrder);
      return ResponseVO.success(map);

    }catch(Exception e){
      e.printStackTrace();
      log.error("查询准确合格率错误");
      return ResponseVO.fail(e.toString());
    }
  }


  /**
   * 实时查询准确合格率（用于图表）
   * @param startTime 开始时间 当天凌晨
   * @param endTime 结束时间 当前时间
   * @return result
   */
  @GetMapping(value="realTimeCharts/{startTime}/{endTime}/{showCode}")
  public ResponseVO accuracyPassRateQueryForCharts(@PathVariable("startTime") Long startTime,
                                                   @PathVariable("endTime") Long endTime,
                                                   @PathVariable("showCode") String showCode) {
    Map<String,Object> map = new HashMap<>();
    try{
      map = accuracyPassRateService.findByTimeBetweenForRealTimeCharts(startTime, endTime,showCode);
      return ResponseVO.success(map);
    }catch(Exception e){
      e.printStackTrace();
      return ResponseVO.fail(e.toString());
    }
  }

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

}
