package com.usky.backend.controller;
import com.usky.backend.domain.StatusVO;
import com.usky.backend.domain.request.HistoryQueryVo;
import com.usky.backend.domain.request.LastQueryVo;
import com.usky.backend.domain.response.HistoryResultVo;
import com.usky.backend.domain.response.LastResultVo;
import com.usky.backend.domain.DataAverageExportVO;
import com.usky.backend.domain.DataAverageRequestVO;
import com.usky.backend.domain.DataAverageResponseVO;
import com.usky.backend.domain.DataTotalRequestVO;
import com.usky.backend.service.DataQueryService;
import com.usky.common.core.bean.ApiResult;
import com.usky.common.core.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  数据统一查询 前端控制器
 * </p>
 *
 */
@RestController
@Api(tags = "数据统一查询")
@RequestMapping("/dataQuery")
public class DataQueryController {
    @Autowired
    private DataQueryService dataQueryService;

    /**
     * 获取单个设备单属性历史数据
     *
     * @param startTime 开始时间
     * @param endTime 结束时间
     * @param deviceId 设备Id
     * @param metric 属性
     * @param typeAbbrevia 设备类型简称
     * @return
     */
    @GetMapping("/historyMetric")
    @ApiOperation("获取单个设备单属性历史数据")
    public ApiResult<HistoryResultVo> historyMetric(@RequestParam("startTime") String startTime,
                                              @RequestParam("endTime") String endTime,
                                              @RequestParam("deviceId") String deviceId,
                                              @RequestParam("metric") String metric,
                                              @RequestParam("typeAbbrevia") String typeAbbrevia) {
        return ApiResult.success(dataQueryService.historyMetric(deviceId,metric,startTime,endTime,typeAbbrevia));
    }

    @PostMapping("/historyMetrics")
    @ApiOperation("获取单个设备多属性历史数据")
    public ApiResult<List<HistoryResultVo>> historyMetrics(@RequestBody HistoryQueryVo historyQueryVo) {
        return ApiResult.success(dataQueryService.historyMetrics(historyQueryVo));
    }

    /**
     * 获取单个设备多指标实时数据
     * @param lastQueryVo
     * @return
     */
    @PostMapping("/last")
    @ApiOperation("获取单个设备多指标实时数据")
    public ApiResult<List<LastResultVo>> last(@RequestBody LastQueryVo lastQueryVo) {
        return ApiResult.success(dataQueryService.last(lastQueryVo));
    }

}

