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.ProEconBrownoutsEvent2;
import com.gyee.runeconomy.service.auto.IProEconBrownoutsEvent2Service;
import com.gyee.runeconomy.util.StringUtils;
import org.springframework.stereotype.Service;

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

@Service
public class BrownoutsEvent2Service {

    @Resource
    private IProEconBrownoutsEvent2Service proEconBrownoutsEvent2Service;

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

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

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


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

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

        return pageInfo;

    }
}
