package com.gyee.runeconomy.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gyee.runeconomy.model.auto.ProEconShutdownEvent2;
import com.gyee.runeconomy.service.auto.IProEconShutdownEvent2Service;
import com.gyee.runeconomy.util.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

@Service
public class ShutdownEvent2Service {

    @Resource
    private IProEconShutdownEvent2Service proEconShutdownEvent2Service;

    public Page<ProEconShutdownEvent2> getShutdownEventList(Integer pageNum, Integer pageSize, String wtId, Date beginDate, Date endDate) {

        if (StringUtils.empty(pageNum)) {
            pageNum = 1;
        }
        if (StringUtils.empty(pageSize)) {
            pageSize = 10;
        }
        //构造分页构造器
        Page<ProEconShutdownEvent2> pageInfo = new Page<>(pageNum, pageSize);
        if (StringUtils.notEmp(wtId) && StringUtils.notEmp(beginDate) && StringUtils.notEmp(endDate)) {

            //构造条件构造器
            LambdaQueryWrapper<ProEconShutdownEvent2> queryWrapper = new LambdaQueryWrapper<>();
            //添加过滤条件


            queryWrapper.eq(ProEconShutdownEvent2::getWindturbineId, wtId).
                    ge(ProEconShutdownEvent2::getStopTime, beginDate).
                    le(ProEconShutdownEvent2::getStopTime, endDate);

            //执行查询
            proEconShutdownEvent2Service.page(pageInfo, queryWrapper);
        }

        return pageInfo;

    }
}
