package com.jxy.marketall.task;

import com.jxy.common.core.utils.DateUtils;
import com.jxy.common.redis.service.RedisService;
import com.jxy.marketall.dto.DateBigDecimalDto;
import com.jxy.marketall.dto.GoldenRatioMultiplierDto;
import com.jxy.marketall.dto.PiCycleTIDto;
import com.jxy.marketall.mapper.BTCMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;


/**
 * @Description TODO
 * @Date 2022/7/7 18:03
 * @Author 杜懿
 */
@Configuration
@EnableScheduling
public class BTCNoChainV2Task {

    @Autowired
    private BTCMapper btcMapper;

    @Autowired
    private RedisService redisService;

    /** Stablecoin Supply Ratio (SSR) 稳定币供应比所有数据 */
    @Scheduled(cron = "20 0 0/1 * * ?")
    //@Scheduled(cron = "10 0/2 * * * ?")
    public void SSRDataToRedis(){

        List<DateBigDecimalDto> list = btcMapper.getListByTableAndField("nochainv3b", "ssr");

        Date date = DateUtils.parseDate("2015-01-09");
        list = list.stream().filter(dto -> (dto.getDate().after(date) || dto.getDate().equals(date))).collect(Collectors.toList());

        if(list.size()>0){
            //存入redis 先删除原有数据再重新插入数据
            redisService.deleteObject("StablecoinSupplyRatioList");
            redisService.setCacheList("StablecoinSupplyRatioList",list);
        }

    }

    /** Stablecoin Supply Ratio (SSR) Oscillator稳定币供应比振荡器所有数据 */
    @Scheduled(cron = "20 0 0/1 * * ?")
    //@Scheduled(cron = "10 0/2 * * * ?")
    public void SSRODataToRedis(){


        List<DateBigDecimalDto> list = btcMapper.getListByTableAndField("nochainv3b", "ssrosc");

        if(list.size()>0){
            //存入redis 先删除原有数据再重新插入数据
            redisService.deleteObject("StablecoinSupplyRatioOscillatorList");
            redisService.setCacheList("StablecoinSupplyRatioOscillatorList",list);
        }

    }

    /** Stock-to-Flow Ratio 库存/新发行比所有数据 */
    @Scheduled(cron = "20 0 0/1 * * ?")
    //@Scheduled(cron = "10 0/2 * * * ?")
    public void STFRatioDataToRedis(){

        List<DateBigDecimalDto> list = btcMapper.getListByTableAndField("nochainv3c", "s2fratio");

        if(list.size()>0){
            //存入redis 先删除原有数据再重新插入数据
            redisService.deleteObject("STFRatioList");
            redisService.setCacheList("STFRatioList",list);
        }

    }

    /** Stock-to-Flow Deflection 库存/新发行偏差所有数据 */
    //@Scheduled(cron = "20 0 0/1 * * ?")
    @Scheduled(cron = "10 0/2 * * * ?")
    public void STFRatioDeflectionDataToRedis(){

        List<DateBigDecimalDto> list = btcMapper.getListByTableAndField("nochainv3c", "s2fdeflection");

        if(list.size()>0){
            //存入redis 先删除原有数据再重新插入数据
            redisService.deleteObject("STFRatioDeflectionList");
            redisService.setCacheList("STFRatioDeflectionList",list);
        }

    }

    /** Pi Cycle Top Indicator PI周期顶指标所有数据 */
    @Scheduled(cron = "20 1 0/1 * * ?")
    //@Scheduled(cron = "10 0/2 * * * ?")
    public void PiCycleTopIndicatorDataToRedis(){

        List<PiCycleTIDto> list = btcMapper.getPiCycleTIList();
        Date start = DateUtils.parseDate("2015-01-09");
        list = list.stream().filter(dto -> (dto.getDate().after(start) || dto.getDate().equals(start))).collect(Collectors.toList());

        if(list.size()>0){
            //存入redis 先删除原有数据再重新插入数据
            redisService.deleteObject("BTCPiCTIList");
            redisService.setCacheList("BTCPiCTIList",list);
        }

    }

    /** Golden Ratio Multiplier 黄金比例乘数 所有数据 */
    @Scheduled(cron = "20 1 0/1 * * ?")
    //@Scheduled(cron = "10 0/2 * * * ?")
    public void GRMDataToRedis(){

        List<GoldenRatioMultiplierDto> list = btcMapper.getGoldenRatioMultiplier();

        if(list.size()>0){
            //存入redis 先删除原有数据再重新插入数据
            redisService.deleteObject("BTCGoldenRatioMultiplierList");
            redisService.setCacheList("BTCGoldenRatioMultiplierList",list);
        }

    }
}
