package com.jiayue.ipp.idp.controller;

import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jiayue.ipp.common.data.entity.WindTowerStatusData;
import com.jiayue.ipp.idp.service.WindTowerStatusDataService;
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.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;


/**
 * idp_wind_tower_status_data
 *
 * @author whc
 * @date 2022-03-18 15:50:05
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/windtowerstatusdata")
@Api(value = "windtowerstatusdata", tags = "idp_wind_tower_status_data管理")
public class WindTowerStatusDataController {

    private final WindTowerStatusDataService windTowerStatusDataService;

    /**
     * 分页查询
     *
     * @param page                分页对象
     * @param windTowerStatusData idp_wind_tower_status_data
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page")
    public R getWindTowerStatusDataPage(Page page, WindTowerStatusData windTowerStatusData) {
        return R.ok(windTowerStatusDataService.page(page, Wrappers.query(windTowerStatusData)));
    }

    @ApiOperation(value = "通过条件查询", notes = "通过条件查询")
    @PostMapping("/queryCharts")
    public R queryCharts(String stationCode,
                         Long startTime,
                         Long endTime,
                         String equipmentId) throws Exception {
        return R.ok(windTowerStatusDataService.queryCharts(stationCode, new Date(startTime), new Date(endTime), equipmentId));
    }

    @ApiOperation(value = "根据条件查询", notes = "分页查询")
    @PostMapping("/queryTableData")
    public R queryTableData(Long currentPage, Long pageSize, String stationCode, Long startTime, Long endTime, String equipmentId) {
        Page page = new Page(currentPage, pageSize);
        page.addOrder(OrderItem.asc("time"));
        page.setMaxLimit((long) -1);
        return R.ok(windTowerStatusDataService.page(page, windTowerStatusDataService.getByBetweenTimeAndEquipmentIdAndStationCode(new Date(startTime), new Date(endTime), equipmentId, stationCode)));
    }
}
