package com.jiayue.ipfcst.dataexchange.controller;

import com.jiayue.ipfcst.common.core.web.vo.ResponseVO;
import com.jiayue.ipfcst.common.data.entity.ForecastForSendAttribute;
import com.jiayue.ipfcst.dataexchange.repository.ForecastForSendAttributeRepository;
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.List;

/**
 * 转发点表的controller
 *
 * @author zy
 * @version 3.0
 */
@Slf4j
@RestController
@RequestMapping("/dataExchange/ForecastForSendAttribute")
public class
ForecastForSendAttributeController {
  private ForecastForSendAttributeRepository forecastForSendAttributeRepository;

  @Autowired
  public ForecastForSendAttributeController(ForecastForSendAttributeRepository forecastForSendAttributeRepository) {
    this.forecastForSendAttributeRepository = forecastForSendAttributeRepository;
  }

  /**
   * 根据预测功率的类型和预测节点查询点位
   *
   * @param forecastNode 预测功率的类型
   * @param forcastType1 预测节点
   * @return ResponseVO 统一返回值
   */
  @GetMapping(value = "/{forecastNode}/{forcastType}")
  public ResponseVO get(@PathVariable("forecastNode") Integer forecastNode, @PathVariable("forcastType") String forcastType1) {
    try {
      ForecastForSendAttribute.ForecastType forcastType = ForecastForSendAttribute.ForecastType.valueOf(forcastType1);
      List<ForecastForSendAttribute> list = forecastForSendAttributeRepository.findByForecastNodeAndForecastType(forecastNode, forcastType);
      return ResponseVO.success(list);
    } catch (Exception e) {
      e.printStackTrace();
      log.error("查询异常");
      return ResponseVO.fail();
    }
  }

  /**
   * 被点属性
   * 根据点位和预测功率类型查询预测属性的id
   *
   * @param pointNumber  点位
   * @param forcastType1 预测节点
   * @param forecastNode 预测节点
   * @return ResponseVO 统一返回值
   */
  @GetMapping(value = "/getAttributeBypoint/{pointNumber}/{forecastNode}/{forcastType}")
  public ResponseVO getAttributeByPoint(@PathVariable("pointNumber") Integer pointNumber, @PathVariable("forecastNode") Integer forecastNode, @PathVariable("forcastType") String forcastType1) {
    try {
      ForecastForSendAttribute.ForecastType forcastType = ForecastForSendAttribute.ForecastType.valueOf(forcastType1);
      List<ForecastForSendAttribute> list = forecastForSendAttributeRepository.findByPointNumberAndForecastNodeAndForecastType(pointNumber, forecastNode, forcastType);
      return ResponseVO.success(list);
    } catch (Exception e) {
      e.printStackTrace();
      log.error("查询预测属性id异常");
      return ResponseVO.fail();
    }
  }
}
