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.ProEconPowerstationInfoDay6Mapper;
import com.gyee.runeconomy.model.auto.ProEconPowerstationInfoDay6;
import com.gyee.runeconomy.service.auto.IProEconPowerstationInfoDay6Service;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * <p>
 * 测风塔出线功率 服务实现类
 * </p>
 *
 * @author wang
 * @since 2022-11-22
 */
@Service
public class ProEconPowerstationInfoDay6ServiceImpl extends ServiceImpl<ProEconPowerstationInfoDay6Mapper, ProEconPowerstationInfoDay6> implements IProEconPowerstationInfoDay6Service {

    @Override
    public Map<String, ProEconPowerstationInfoDay6> getEconPowerOfField(String foreignKeyId, String staType, String dateType, Date date) {
        Map<String, ProEconPowerstationInfoDay6> resultmap = new HashMap<>();

        QueryWrapper<ProEconPowerstationInfoDay6> qw = null;


        //当前数据
        List<ProEconPowerstationInfoDay6> currlist = new ArrayList<>();
        if (null != date) {
            qw = new QueryWrapper<>();
            if (StringUtils.isNotEmpty(staType)) {
                qw.lambda().eq(ProEconPowerstationInfoDay6::getForeignKeyId, foreignKeyId + staType);
            }
            qw.lambda().eq(ProEconPowerstationInfoDay6::getRecordDate, date);
            currlist = getBaseMapper().selectList(qw);
            resultmap.put("currGlInfo", currlist.size() > 0 ? currlist.get(0) : null);
        }


        //环比数据
        List<ProEconPowerstationInfoDay6> ringlist = new ArrayList<>();
        if (null != date) {
            qw = new QueryWrapper<>();
            if (StringUtils.isNotEmpty(staType)) {
                qw.lambda().eq(ProEconPowerstationInfoDay6::getForeignKeyId, foreignKeyId + staType);
            }
            Date ring = DateUtils.addMonths(date, -1);
            qw.lambda().eq(ProEconPowerstationInfoDay6::getRecordDate, ring);
            ringlist = getBaseMapper().selectList(qw);
            resultmap.put("ringGlInfo", ringlist.size() > 0 ? ringlist.get(0) : null);
        }

        //同比
        List<ProEconPowerstationInfoDay6> withlist = new ArrayList<>();
        if (null != date) {
            qw = new QueryWrapper<>();
            if (StringUtils.isNotEmpty(staType)) {
                qw.lambda().eq(ProEconPowerstationInfoDay6::getForeignKeyId, foreignKeyId + staType);
            }
            Date with = DateUtils.addYears(date, -1);
            qw.lambda().eq(ProEconPowerstationInfoDay6::getRecordDate, with);
            withlist = getBaseMapper().selectList(qw);
            resultmap.put("withGlInfo", withlist.size() > 0 ? withlist.get(0) : null);
        }

        return resultmap;
    }
}
