package com.tzld.piaoquan.ad.engine.service.predict.container;

import com.tzld.piaoquan.ad.engine.commons.redis.AlgorithmRedisHelper;
import com.tzld.piaoquan.ad.engine.service.predict.constant.RuleRedisKeyConst;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.Objects;

@Component
public class RoiPredictParamContainer {
    @Autowired
    AlgorithmRedisHelper redisHelper;
    private final Double zeroDefault=new Double(0);
    Double adArpu;

    Double adRoi;
    @PostConstruct
    private void initParams(){
        refreshAdArpu();
        refreshAdRoi();
    }

    private void refreshAdArpu(){
        adArpu = redisHelper.getDouble(RuleRedisKeyConst.KEY_NAME_AD_ARPU);
        if(Objects.isNull(adArpu)){
            adArpu=zeroDefault;
        }
    }
    private void refreshAdRoi(){
        adRoi = redisHelper.getDouble(RuleRedisKeyConst.KEY_NAME_AD_ROI_PARAM);
        if(Objects.isNull(adRoi)){
            adRoi=zeroDefault;
        }
    }

    public Double getAdRoi(){
        return adRoi;
    }

    public Double getAdArpu(){
        return adArpu;
    }

}
