package com.jiayue.ipfcst.controller;

import com.jiayue.ipfcst.common.core.web.vo.ResponseVO;
import com.jiayue.ipfcst.service.ForecastPowerUltraShortTermService;
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.RestController;

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

/**
 * 超短期预测信息restful接口
 *
 * @author yh
 * @version 1.0
 * @since 2019/8/7 10:12
 */
@RestController
@Slf4j
public class ForecastPowerUltraShortTermController {
  private final ForecastPowerUltraShortTermService forecastPowerUltraShortTermService;
  @Autowired
  public ForecastPowerUltraShortTermController(ForecastPowerUltraShortTermService forecastPowerUltraShortTermService){
    this.forecastPowerUltraShortTermService = forecastPowerUltraShortTermService;
  }

  /**
   * 按时间查询实时超预测短期 yh
   * @param startTime 开始时间
   * @param endTime 结束时间
   * @return 结果集
   */
  @GetMapping(value = "/forecastPowerUltraShortTerm/{startTime}/{endTime}")
  public ResponseVO findByForecastTimeBetween(@PathVariable("startTime") Long startTime,
                                          @PathVariable("endTime") Long endTime){
    Map<String,Object> map = new HashMap<>();
    try{
      map = forecastPowerUltraShortTermService.findByForecastTimeBetween(startTime,endTime);
      return ResponseVO.success(map);
    }catch(Exception e){
      e.printStackTrace();
      return ResponseVO.fail(e.toString());
    }
  }

  /**
   * 分页查询  实时超短期预测
   * @param startTime 开始时间
   * @param endTime 结束时间
   * @param page 页码
   * @param size 条数
   * @param sortOrder 排序
   * @return
   */
  @GetMapping(value = "/forecastPowerUltraShortTerm/{startTime}/{endTime}/{page}/{size}")
  public ResponseVO findByTimeBetweenForPaging(@PathVariable("startTime") Long startTime,
                                               @PathVariable("endTime") Long endTime,
                                               @PathVariable("page") Integer page,
                                               @PathVariable("size") Integer size,
                                               String sortOrder){
    Map<String,Object> map = new HashMap<>();
    try{
      map =  forecastPowerUltraShortTermService.findByTimeBetweenAndNoForPaging(startTime,endTime,page,size,sortOrder);
      return ResponseVO.success(map);
    }catch(Exception e){
      e.printStackTrace();
      return ResponseVO.fail(e.toString());
    }
  }


}
