package com.gyee.frame.controller.export;


import com.gyee.frame.common.conf.AjaxStatus;
import com.gyee.frame.common.domain.AjaxResult;
import com.gyee.frame.service.WindpowerstationService;
import com.gyee.frame.service.export.GoldenService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.Optional;

@RestController
@RequestMapping("/export")
@Api(value = "golden数据导出功能",tags =  "golden数据导出功能")
public class GoldenController {

    @Resource
    private GoldenService goldenService;
    @Resource
    private WindpowerstationService stationService;

    /**
     * 查询所有的场站
     *
     * @return
     */
    @GetMapping("/databases")
    @ApiOperation(value = "查询风电场", notes = "查询风电场")
    public AjaxResult getDatabases() {
        List<Map<String, String>> list = stationService.findStationAll();
        return AjaxResult.successData(AjaxStatus.success.code, list);
    }



    /**
     * 通过模板导出单个风机数据
     *
     * @param station  场站
     * @param wtId     风机ID
     * @param id       模板ID
     * @param startTs  开始时间
     * @param endTs    结束时间
     * @param interval 时间间隔
     * @return
     */
//    @GetMapping("/history/snap")
//    public AjaxResult getHistory(
//            @RequestParam(value = "station") String station,
//            @RequestParam(value = "wtId", required = false) String wtId,
//            @RequestParam(value = "templateId") Integer id,
//            @RequestParam(value = "startTs") Long startTs,
//            @RequestParam(value = "endTs") Long endTs,
//            @RequestParam(value = "interval", required = false) Optional<Integer> interval) {
//
//        int val = interval.isPresent() ? interval.get() : 1800;
//
//        List<Object> list = goldenService.getHistoryDataSingle(station, wtId, id, startTs, endTs, val);
//        return AjaxResult.successData(AjaxStatus.success.code, list);
//    }

    /**
     * 通过模板导出所有风机数据
     *
     * @param id       模板ID
     * @param startTs  开始时间
     * @param endTs    结束时间
     * @param interval 时间间隔
     * @return
     */
    @GetMapping("/history/all")
    public AjaxResult getHistoryAll(
            @RequestParam(value = "station") String station,
            @RequestParam(value = "templateId") Integer id,
            @RequestParam(value = "startTs") Long startTs,
            @RequestParam(value = "endTs") Long endTs,
            @RequestParam(value = "interval", required = false) Optional<Integer> interval) {

        int val = interval.isPresent() ? interval.get() : 1800;

        Map<String, List<Object>> map = goldenService.getHistoryDataAll(station, id, startTs, endTs, val);
        return AjaxResult.successData(AjaxStatus.success.code, map);
    }
}