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.ForecastPowerUltraShortTermHis;
import com.jiayue.ipp.idp.service.ForecastPowerUltraShortTermHisService;
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.util.Date;


/**
 * idp_forecast_power_ultra_short_term_his
 *
 * @author whc
 * @date 2022-03-18 15:49:01
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/forecastpowerultrashorttermhis")
@Api(value = "forecastpowerultrashorttermhis", tags = "idp_forecast_power_ultra_short_term_his管理")
public class ForecastPowerUltraShortTermHisController {

    private final ForecastPowerUltraShortTermHisService forecastPowerUltraShortTermHisService;

    /**
     * 分页查询
     *
     * @param page                           分页对象
     * @param forecastPowerUltraShortTermHis idp_forecast_power_ultra_short_term_his
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page")
    //@PreAuthorize("@pms.hasPermission('idp_forecastpowerdata_get')")
    public R getForecastPowerUltraShortTermHisPage(Page page, ForecastPowerUltraShortTermHis forecastPowerUltraShortTermHis) {
        return R.ok(forecastPowerUltraShortTermHisService.page(page, Wrappers.query(forecastPowerUltraShortTermHis)));
    }

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

    /**
     * 新增idp_forecast_power_ultra_short_term_his
     *
     * @param forecastPowerUltraShortTermHis idp_forecast_power_ultra_short_term_his
     * @return R
     */
    @ApiOperation(value = "新增idp_forecast_power_ultra_short_term_his", notes = "新增idp_forecast_power_ultra_short_term_his")
    //    // ("新增idp_forecast_power_ultra_short_term_his")
    @PostMapping
    //@PreAuthorize("@pms.hasPermission('idp_forecastpowerdata_get')")
    public R save(@RequestBody ForecastPowerUltraShortTermHis forecastPowerUltraShortTermHis) {
        return R.ok(forecastPowerUltraShortTermHisService.save(forecastPowerUltraShortTermHis));
    }

    /**
     * 修改idp_forecast_power_ultra_short_term_his
     *
     * @param forecastPowerUltraShortTermHis idp_forecast_power_ultra_short_term_his
     * @return R
     */
    @ApiOperation(value = "修改idp_forecast_power_ultra_short_term_his", notes = "修改idp_forecast_power_ultra_short_term_his")
    //    // ("修改idp_forecast_power_ultra_short_term_his")
    @PutMapping
    //@PreAuthorize("@pms.hasPermission('idp_forecastpowerdata_get')")
    public R updateById(@RequestBody ForecastPowerUltraShortTermHis forecastPowerUltraShortTermHis) {
        return R.ok(forecastPowerUltraShortTermHisService.updateById(forecastPowerUltraShortTermHis));
    }

    /**
     * 通过id删除idp_forecast_power_ultra_short_term_his
     *
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除idp_forecast_power_ultra_short_term_his", notes = "通过id删除idp_forecast_power_ultra_short_term_his")
    //    // ("通过id删除idp_forecast_power_ultra_short_term_his")
    @DeleteMapping("/{id}")
    //@PreAuthorize("@pms.hasPermission('idp_forecastpowerdata_get')")
    public R removeById(@PathVariable String id) {
        return R.ok(forecastPowerUltraShortTermHisService.removeById(id));
    }

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