package com.cpp.web.controller.stationDataQuery;

import com.baomidou.mybatisplus.core.metadata.OrderItem;
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.web.domain.station.WindTurbineStatusData;
import com.cpp.web.service.station.WindTurbineStatusDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;


/**
 * idp_wind_turbine_status_data
 *
 * @author whc
 * @date 2022-03-18 15:50:07
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/windturbinestatusdata")
@Api(value = "windturbinestatusdata", tags = "idp_wind_turbine_status_data管理")
public class WindTurbineStatusDataController {

    private final WindTurbineStatusDataService windTurbineStatusDataService;

    /**
     * 分页查询
     *
     * @param page                  分页对象
     * @param windTurbineStatusData idp_wind_turbine_status_data
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page")
    public R getWindTurbineStatusDataPage(Page page, WindTurbineStatusData windTurbineStatusData) {
        return R.ok(windTurbineStatusDataService.page(page, Wrappers.query(windTurbineStatusData)));
    }

    /**
     * 根据场站编号和设备ID分页查询
     *
     * @param stationCode 场站编号
     * @return
     */
    @ApiOperation(value = "根据场站编号和设备ID和时间范围分页查询", notes = "分页查询")
    @GetMapping("/getByStationCodeAndEquipmentIdAndTimeBetween")
    public R getByStationCodeAndEquipmentIdAndTimeBetween(Long currentPage, Long pageSize, String stationCode, String equipmentId, Long startTime, Long endTime) {
        Page page = new Page(currentPage, pageSize);
        page.addOrder(OrderItem.asc("time"));
        page.setMaxLimit((long) -1);
        return R.ok(windTurbineStatusDataService.page(page, windTurbineStatusDataService.getByStationCodeAndEquipmentIdAndTimeBetween(stationCode, equipmentId, new Date(startTime), new Date(endTime))));
    }
}
