package com.cpp.web.controller.stationDataQuery;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cpp.common.core.domain.R;
import com.cpp.system.service.ISysConfigService;
import com.cpp.web.service.station.PowerStationStatusDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.net.URLEncoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;


/**
 * idp_power_station_status_data
 *
 * @author whc
 * @date 2022-03-18 15:49:20
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/powerstationstatusdata")
@Api(value = "powerstationstatusdata", tags = "idp_power_station_status_data管理")
public class PowerStationStatusDataController {
    @Autowired
    private ISysConfigService configService;
    private final PowerStationStatusDataService powerStationStatusDataService;

    @ApiOperation(value = "通过条件查询", notes = "通过条件查询")
    @GetMapping("/queryDays")
    public R queryDays() {
        String queryDays = configService.selectConfigByKey("queryDays");
        if (StrUtil.isBlankIfStr(queryDays)){
            queryDays = "10";
        }
        return R.ok(queryDays);
    }

    @ApiOperation(value = "通过条件查询", notes = "通过条件查询")
    @GetMapping("/getCompositeData")
    public R getCompositeData(String stationCode,
                                       Long startTime,
                                       Long endTime) {
        return R.ok(powerStationStatusDataService.getCompositeData(stationCode, startTime, endTime));
    }


    @ApiOperation(value = "中心测数据查询", notes = "中心测数据查询")
    @GetMapping("/cloudDataQuery")
    public R cloudDataQuery(Long startTime,
                              Long endTime,
                              Integer forecastHowLongAgo,
                              String stationCode) {
        return R.ok(powerStationStatusDataService.cloudDataQuery(new Date(startTime), new Date(endTime), forecastHowLongAgo, stationCode));
    }
}
