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.ForecastPowerUltraShortTerm;
import com.jiayue.ipp.idp.service.ForecastPowerUltraShortTermService;
import com.jiayue.ipp.idp.util.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Date;


/**
 * idp_forecast_power_ultra_short_term
 *
 * @author whc
 * @date 2022-03-18 15:48:59
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/forecastpowerultrashortterm")
@Api(value = "forecastpowerultrashortterm", tags = "idp_forecast_power_ultra_short_term管理")
public class ForecastPowerUltraShortTermController {

    private final ForecastPowerUltraShortTermService forecastPowerUltraShortTermService;

    /**
     * 分页查询
     *
     * @param page                        分页对象
     * @param forecastPowerUltraShortTerm idp_forecast_power_ultra_short_term
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page")
    ////@PreAuthorize("@pms.hasPermission('idp_forecastpowerdata_get')")
    public R getForecastPowerUltraShortTermPage(Page page, ForecastPowerUltraShortTerm forecastPowerUltraShortTerm) {
        return R.ok(forecastPowerUltraShortTermService.page(page, Wrappers.query(forecastPowerUltraShortTerm)));
    }

    /**
     * 通过id查询idp_forecast_power_ultra_short_term
     *
     * @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(forecastPowerUltraShortTermService.getById(id));
    }


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