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.InverterStatusData;
import com.jiayue.ipp.idp.service.InverterStatusDataService;
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_inverter_status_data
 *
 * @author whc
 * @date 2022-03-18 15:49:14
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/inverterstatusdata")
@Api(value = "inverterstatusdata", tags = "idp_inverter_status_data管理")
public class InverterStatusDataController {

    private final InverterStatusDataService inverterStatusDataService;

    /**
     * 分页查询
     *
     * @param page               分页对象
     * @param inverterStatusData idp_inverter_status_data
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page")
    public R getInverterStatusDataPage(Page page, InverterStatusData inverterStatusData) {
        return R.ok(inverterStatusDataService.page(page, Wrappers.query(inverterStatusData)));
    }

    /**
     * 根据场站编号和设备ID分页查询
     *
     * @param currentPage
     * @param pageSize
     * @param stationCode 场站编号
     * @param equipmentId 设备id
     * @param startTime   开始时间
     * @param endTime     结束时间
     * @return
     */
    @ApiOperation(value = "根据场站编号和设备ID和时间范围分页查询", notes = "分页查询")
    @PostMapping("/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(inverterStatusDataService.page(page, inverterStatusDataService.getByStationCodeAndEquipmentIdAndTimeBetween(stationCode, equipmentId, new Date(startTime), new Date(endTime))));
    }
}
