package com.jiayue.ipp.idp.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jiayue.ipp.common.data.entity.PowerStationStatusData;
import com.jiayue.ipp.idp.service.PowerStationStatusDataService;
import com.jiayue.ipp.idp.util.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.Date;


/**
 * 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 {

    private final PowerStationStatusDataService powerStationStatusDataService;

    /**
     * 分页查询
     *
     * @param page                   分页对象
     * @param powerStationStatusData idp_power_station_status_data
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page")
    //@PreAuthorize("@pms.hasPermission('idp_forecastpowerdata_get')")
    public R getPowerStationStatusDataPage(Page page, PowerStationStatusData powerStationStatusData) {
        return R.ok(powerStationStatusDataService.page(page, Wrappers.query(powerStationStatusData)));
    }

    /**
     * 通过id查询idp_power_station_status_data
     *
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}")
    //@PreAuthorize("@pms.hasPermission('idp_forecastpowerdata_get')")
    public R getById(@PathVariable("id") String id) {
        return R.ok(powerStationStatusDataService.getById(id));
    }

    @ApiOperation(value = "通过条件查询", notes = "通过条件查询")
    @PostMapping("/getPowerStationStatusData")
    //@PreAuthorize("@pms.hasPermission('idp_forecastpowerdata_get')")
    public R getPowerStationStatusData(String stationCode,
                                       Long startTime,
                                       Long endTime) {
        return R.ok(powerStationStatusDataService.findByStationCodeAndStartTimeAndEndTime(stationCode, new Date(startTime), new Date(endTime)));
    }

    @ApiOperation(value = "通过时间查询时间轴", notes = "通过时间查询时间轴")
    @PostMapping("/getTimeStamp")
    //@PreAuthorize("@pms.hasPermission('idp_forecastpowerdata_get')")
    public R getTimeStamp(
            Long startTime,
            Long endTime) throws ParseException {
        return R.ok(powerStationStatusDataService.timeStamp(new Date(startTime), new Date(endTime)));
    }

    @ApiOperation(value = "通过时间范围查询短期超短期实际功率", notes = "通过时间范围查询短期超短期实际功率")
    @PostMapping("/getCompositeData")
    //@PreAuthorize("@pms.hasPermission('idp_forecastpowerdata_get')")
    public R getCompositeData(
            String stationCode,
            Long startTime,
            Long endTime,
            String forecastManufactor,
            Integer cdqPoint,
            Integer dqPoint) {
        return R.ok(powerStationStatusDataService.getCompositeData(stationCode, new Date(startTime), new Date(endTime), forecastManufactor, cdqPoint,dqPoint));
    }

}
