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.ProEconEquipmentInfoDay5Mapper;
import com.gyee.runeconomy.model.auto.ProEconEquipmentInfoDay5;
import com.gyee.runeconomy.service.auto.IProEconEquipmentInfoDay5Service;
import org.springframework.stereotype.Service;

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

/**
 * <p>
 * 三率 服务实现类
 * </p>
 *
 * @author shilin
 * @since 2022-11-01
 */
@Service
public class ProEconEquipmentInfoDay5ServiceImpl extends ServiceImpl<ProEconEquipmentInfoDay5Mapper, ProEconEquipmentInfoDay5> implements IProEconEquipmentInfoDay5Service {

    @Resource
    private ProEconEquipmentInfoDay5Mapper proEconEquipmentInfoDay5Mapper;

    @Override
    public List<ProEconEquipmentInfoDay5> getResetTimelyRateList(String companyId, String windpowerstationId, String beginDate, String endDate) {

        QueryWrapper<ProEconEquipmentInfoDay5> qw = new QueryWrapper<>();
        StringBuilder sb = new StringBuilder();
        sb.append("windpowerstation_id, sum(TIMERATE20) TIMERATE20, sum(TIMERATE16) TIMERATE16, sum(TIMERATE17) TIMERATE17,sum(TIMERATE18) TIMERATE18, sum(TIMERATE19) TIMERATE19 ");

        qw.select(sb.toString());

        qw.ge("record_date", DateUtils.parseDate(beginDate)).le("record_date", DateUtils.parseDate(endDate));
        //判断后缀是区域还是公司
        if (StringUtils.isNotEmpty(companyId) && companyId.endsWith("_ZGS")) {
            qw.lambda().eq(ProEconEquipmentInfoDay5::getCompanyId, companyId);
        }
        if (StringUtils.isNotEmpty(companyId) && companyId.endsWith("_RGN")) {
            qw.lambda().eq(ProEconEquipmentInfoDay5::getRegionId, companyId);
        }

        //场站模糊查询
        if (StringUtils.isNotEmpty(windpowerstationId)) {
            qw.lambda().like(ProEconEquipmentInfoDay5::getWindpowerstationId, windpowerstationId);
        }
        //分组查询
        qw.lambda().groupBy(ProEconEquipmentInfoDay5::getWindpowerstationId);
        List<ProEconEquipmentInfoDay5> list = baseMapper.selectList(qw);

        return list;
    }

    @Override
    public List<ProEconEquipmentInfoDay5> getStateConversionRateList(String companyId, String windpowerstationId, String beginDate, String endDate) {


        QueryWrapper<ProEconEquipmentInfoDay5> qw = new QueryWrapper<>();
        StringBuilder sb = new StringBuilder();
        sb.append("windpowerstation_id,sum(TIMERATE13) TIMERATE13,sum(TIMERATE1) TIMERATE1,sum(TIMERATE2) TIMERATE2,sum(TIMERATE3) TIMERATE3,sum(TIMERATE4) TIMERATE4,sum(TIMERATE14) TIMERATE14,sum(TIMERATE5) TIMERATE5,sum(TIMERATE6) TIMERATE6,sum(TIMERATE7) TIMERATE7,sum(TIMERATE8)  TIMERATE8,sum(TIMERATE15) TIMERATE15,sum(TIMERATE9) TIMERATE9,sum(TIMERATE10) TIMERATE10,sum(TIMERATE11) TIMERATE11,sum(TIMERATE12) TIMERATE12");

        qw.select(sb.toString());
        qw.ge("record_date", DateUtils.parseDate(beginDate)).le("record_date", DateUtils.parseDate(endDate));
        //判断后缀是区域还是公司
        if (StringUtils.isNotEmpty(companyId) && companyId.endsWith("_ZGS")) {
            qw.lambda().eq(ProEconEquipmentInfoDay5::getCompanyId, companyId);
        }
        if (StringUtils.isNotEmpty(companyId) && companyId.endsWith("_RGN")) {
            qw.lambda().eq(ProEconEquipmentInfoDay5::getRegionId, companyId);
        }

        //场站模糊查询
        if (StringUtils.isNotEmpty(windpowerstationId)) {
            qw.lambda().like(ProEconEquipmentInfoDay5::getWindpowerstationId, windpowerstationId);
        }
        //分组查询
        qw.lambda().groupBy(ProEconEquipmentInfoDay5::getWindpowerstationId);
        List<ProEconEquipmentInfoDay5> list = baseMapper.selectList(qw);
        return list;
    }
}
