package com.jiayue.ipfcst.dataexchange.controller;

import com.jiayue.ipfcst.common.core.web.vo.ResponseVO;
import com.jiayue.ipfcst.dataexchange.service.SendLogService;
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;
/**
 * 回传日志的controller
 *
 * @author zy
 * @version 3.0
 */
@Slf4j
@RestController
@RequestMapping("/sendLog")
public class SendLogController {
  @Autowired SendLogService sendLogService;

  /**
   * 获取数据
   * @param page          第几页
   * @param size          每页多少数据
   * @param startTime     开始时间
   * @param endTime       结束时间
   * @return
   */
  @GetMapping("/{page}/{size}/{startTime}/{endTime}")
  public ResponseVO getAll(@PathVariable("page") Integer page,
    @PathVariable("size") Integer size,
    @PathVariable("startTime") Long startTime,
    @PathVariable("endTime") Long endTime) {
    try {
      return ResponseVO.success(sendLogService.getAll(startTime,endTime,page,size));
    } catch (Exception e) {
      e.printStackTrace();
      log.error("查询回传日志错误：" + e.getMessage());
      return ResponseVO.fail();
    }
  }

  /**
   * 获取数据
   * @param page          第几页
   * @param size          每页多少数据
   * @param startTime     开始时间
   * @param endTime       结束时间
   * @param tunnelId       通道id
   * @return
   */
  @GetMapping("/{page}/{size}/{startTime}/{endTime}/{tunnelId}")
  public ResponseVO getAll(@PathVariable("page") Integer page,
    @PathVariable("size") Integer size,
    @PathVariable("startTime") Long startTime,
    @PathVariable("endTime") Long endTime,
    @PathVariable("tunnelId") String tunnelId) {
    try {
      return ResponseVO.success(sendLogService.getAllById(startTime,endTime,page,size,tunnelId));
    } catch (Exception e) {
      e.printStackTrace();
      log.error("查询回传日志错误：" + e.getMessage());
      return ResponseVO.fail();
    }
  }

  /**
   * 详细回传信息
   */
  @GetMapping("/{startTime}/{tunnelId}")
  public ResponseVO getProDataPoint(@PathVariable("startTime") Long startTime,
    @PathVariable("tunnelId") String tunnelId){
    try {
      return ResponseVO.success(sendLogService.getProDataPoint(startTime,tunnelId));
    }catch (Exception e){
      e.printStackTrace();
      log.error("查询详细回传内容错误：" + e.getMessage());
      return ResponseVO.fail();
    }

  }
}
