package com.jiayue.ipfcst.console.controller;

import com.jiayue.ipfcst.common.core.web.vo.ResponseVO;
import com.jiayue.ipfcst.common.data.entity.ManualInterventionLog;
import com.jiayue.ipfcst.console.service.ForecastPowerShortTermService;
import com.jiayue.ipfcst.console.service.ManualInterventionLogService;
import com.jiayue.ipfcst.console.util.ForecastPowerAndManualIntervention;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * 人工干预数据控制类
 *
 * @author whc
 * @version 2.0
 * @since 2020/08/24 16:43
 */
@RestController
@RequestMapping("/manualInterventionLogController/")
@Slf4j
class ManualInterventionLogController {
  private final ManualInterventionLogService manualInterventionLogService;

  private final ForecastPowerShortTermService forecastPowerShortTermService;

  public ManualInterventionLogController(ManualInterventionLogService manualInterventionLogService, ForecastPowerShortTermService forecastPowerShortTermService) {

    this.manualInterventionLogService = manualInterventionLogService;
    this.forecastPowerShortTermService = forecastPowerShortTermService;
  }

  @GetMapping(value = "queryManualInterventionLogData/{startTime}/{endTime}/{fileType}")
  public ResponseVO queryManualInterventionLog(@PathVariable Long startTime,
                                               @PathVariable Long endTime,
                                               @PathVariable String fileType) {
    List<ManualInterventionLog> manualInterventionLogList = new ArrayList<>();
    try {
      manualInterventionLogList = manualInterventionLogService.queryManualInterventionLog(startTime, endTime, fileType);
    } catch (Exception e) {
      log.error("系统错误：", e);
    } finally {
      return ResponseVO.success(manualInterventionLogList);
    }
  }

  @GetMapping(value = "queryForecastAndManualInterventionData/{startTime}/{endTime}/{fileType}")
  public ResponseVO queryForecastAndManualInterventionData(@PathVariable Long startTime,
                                                           @PathVariable Long endTime,
                                                           @PathVariable String fileType) {
    List<List<Object>> lists=new ArrayList<>();
    List<ForecastPowerAndManualIntervention> forecastPowerAndManualInterventionList = new ArrayList<>();

    try {
      lists = manualInterventionLogService.queryForecastAndManualInterventionData(startTime, endTime, fileType);
    } catch (Exception e) {
      log.error("系统错误：", e);
    } finally {
      return ResponseVO.success(lists);
    }
  }

  /*
   */
/**
 * 获取人工干预后的数据
 *
 * @return map
 *//*

  @GetMapping(value = "queryForecastAndManualInterventionData2/{startTime}/{endTime}/{fileType}")
  public ResponseVO queryForecastAndManualInterventionData2(@PathVariable Long startTime,
                                                           @PathVariable Long endTime,
                                                           @PathVariable String fileType) {
    List<List<Object>> lists;
 */
  /*   List<ForecastPowerAndManualIntervention> forecastPowerAndManualInterventionList = new ArrayList<>();
   *//*
  try {
      lists = manualInterventionLogService.queryForecastAndManualInterventionData2(startTime, endTime, fileType);
    } catch (Exception e) {
      log.error("系统错误：", e);
    } finally {
      return ResponseVO.success(lists);
    }
  }
*/


  /**
   * 根据条件查询
   *
   * @param startTimeStr 开始时间
   * @param endTimeStr   结束时间
   * @return map
   */
  @GetMapping(value = "getForecastPowerShortTermDrawing/{startTimeStr}/{endTimeStr}")
  public ResponseVO getForecastPowerShortTermDrawing(
    @PathVariable String startTimeStr,
    @PathVariable String endTimeStr) {
    return ResponseVO.success(forecastPowerShortTermService.getForecastPowerShortTermDrawing(startTimeStr, endTimeStr));
  }

  @PutMapping("saveForecastPowerShortTerm")
  public ResponseVO save(@RequestBody ManualInterventionLog manualInterventionLog) {
    manualInterventionLogService.save(manualInterventionLog);
    return ResponseVO.success();
  }


  @GetMapping("getByFileType/{fileType}")
  public ResponseVO save(@PathVariable("fileType") String fileType) {
    return ResponseVO.success(manualInterventionLogService.findByFileTypeOrderByOperationalTimeDesc(fileType));
  }
}
