package com.gyee.runeconomy.service.auto.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gyee.common.model.StringUtils;
import com.gyee.common.util.DateUtils;
import com.gyee.runeconomy.mapper.auto.ProEconStationPowerMapper;
import com.gyee.runeconomy.model.auto.ProEconStationPower;
import com.gyee.runeconomy.service.auto.IProEconStationPowerService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 预测功率合格 服务实现类
 * </p>
 *
 * @author wang
 * @since 2023-09-13
 */
@Service
public class ProEconStationPowerServiceImpl extends ServiceImpl<ProEconStationPowerMapper, ProEconStationPower> implements IProEconStationPowerService {

    @Override
    public List<ProEconStationPower> getlist(String Station, Date begindate) {
        QueryWrapper<ProEconStationPower> qw = null;

        Calendar calendar = Calendar.getInstance();
        calendar.setTime(begindate);
        calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
        calendar.set(Calendar.HOUR_OF_DAY, 23);
        calendar.set(Calendar.MINUTE, 59);
        calendar.set(Calendar.SECOND, 59);
        Date endOfDayOfLastDayOfMonth = calendar.getTime();
        //当前数据
        List<ProEconStationPower> currlist = new ArrayList<>();

        qw = new QueryWrapper<>();
        if (StringUtils.isNotEmpty(Station)) {
            qw.lambda().eq(ProEconStationPower::getWindpowerstationId, Station);
        }
        qw.lambda().between(ProEconStationPower::getRecordDate, DateUtils.getMonthFirst(begindate), endOfDayOfLastDayOfMonth);
        qw.lambda().orderByDesc(ProEconStationPower::getRecordDate);

        currlist = baseMapper.selectList(qw);

        return currlist;
    }

    @Override
    public List<ProEconStationPower> getlist1(String Station, Date begindate) {
        QueryWrapper<ProEconStationPower> qw = null;

        // 获取当前日期
        Calendar calendar = Calendar.getInstance();

        // 设置为当前月份的最后一天
        calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
        calendar.set(Calendar.HOUR_OF_DAY, calendar.getActualMaximum(Calendar.HOUR_OF_DAY));
        calendar.set(Calendar.MINUTE, calendar.getActualMaximum(Calendar.MINUTE));
        calendar.set(Calendar.SECOND, calendar.getActualMaximum(Calendar.SECOND));
        Date endOfDayOfLastDayOfMonth = calendar.getTime();
        //当前数据
        List<ProEconStationPower> currlist = new ArrayList<>();

        qw = new QueryWrapper<>();
        if (StringUtils.isNotEmpty(Station)) {
            qw.lambda().eq(ProEconStationPower::getWindpowerstationId, Station);
        }
        qw.lambda().between(ProEconStationPower::getRecordDate, DateUtils.getMonthFirst(begindate), endOfDayOfLastDayOfMonth);
        qw.lambda().orderByDesc(ProEconStationPower::getRecordDate);

        currlist = baseMapper.selectList(qw);

        return currlist;
    }

    @Override
    public List<ProEconStationPower> getlist2(String Station, Date begindate, int currentyear) {
        QueryWrapper<ProEconStationPower> qw = null;

        // 获取当前日期
        Calendar calendar = Calendar.getInstance();

        // 设置为当前月份的最后一天
        calendar.set(Calendar.MONTH, calendar.getActualMaximum(Calendar.MONTH));
        calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
        calendar.set(Calendar.HOUR_OF_DAY, calendar.getActualMaximum(Calendar.HOUR_OF_DAY));
        calendar.set(Calendar.MINUTE, calendar.getActualMaximum(Calendar.MINUTE));
        calendar.set(Calendar.SECOND, calendar.getActualMaximum(Calendar.SECOND));

        // 设置年份为传递的currentyear
        calendar.set(Calendar.YEAR, currentyear);

        Date endOfDayOfLastDayOfMonth = calendar.getTime();

        //当前数据
        List<ProEconStationPower> currlist = new ArrayList<>();

        qw = new QueryWrapper<>();
        if (StringUtils.isNotEmpty(Station)) {
            qw.lambda().eq(ProEconStationPower::getWindpowerstationId, Station);
        }
        qw.lambda().between(ProEconStationPower::getRecordDate, DateUtils.getMonthFirst(begindate), endOfDayOfLastDayOfMonth);
        qw.lambda().orderByDesc(ProEconStationPower::getRecordDate);

        currlist = baseMapper.selectList(qw);

        return currlist;
    }

}
