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

import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

@Service
public class WtAlysisDayService {

    @Resource
    private IProEconWtAlysisDayService proEconWtAlysisDayService;


    public Page<ProEconWtAlysisDay> wtAlysisDayList(Integer pageNum, Integer pageSize, String wtId, String beginDate, String endDate) {

        if (StringUtils.empty(pageNum)) {
            pageNum = 1;
        }
        if (StringUtils.empty(pageSize)) {
            pageSize = 10;
        }
        //构造分页构造器
        Page<ProEconWtAlysisDay> pageInfo = new Page<>(pageNum, pageSize);
        if (StringUtils.notEmp(wtId) && StringUtils.notEmp(beginDate) && StringUtils.notEmp(endDate)) {
            String format = "yyyy-MM-dd";
            SimpleDateFormat df = new SimpleDateFormat(format);
            Date begin = null;
            Date end = null;
            try {
                begin = df.parse(beginDate);
                end = df.parse(endDate);
            } catch (ParseException e) {
                e.printStackTrace();
            }


            //构造条件构造器
            LambdaQueryWrapper<ProEconWtAlysisDay> queryWrapper = new LambdaQueryWrapper<>();
            //添加过滤条件
            queryWrapper.eq(ProEconWtAlysisDay::getWindturbineId, wtId).
                    ge(ProEconWtAlysisDay::getRecordDate, begin).
                    le(ProEconWtAlysisDay::getRecordDate, end);
            queryWrapper.orderByAsc(ProEconWtAlysisDay::getRecordDate);
            //执行查询
            proEconWtAlysisDayService.page(pageInfo, queryWrapper);
        }

        return pageInfo;
    }


}
