package com.jxy.marketall.task;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jxy.common.core.utils.StringUtils;
import com.jxy.common.redis.service.RedisService;
import com.jxy.marketall.dto.HolderBalanceDto;
import com.jxy.marketall.dto.HolderDto;
import com.jxy.marketall.entity.HolderBalance;
import com.jxy.marketall.mapper.HolderBalanceMapper;
import com.jxy.marketall.mapper.HolderMapper;
import org.springframework.beans.BeanUtils;
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;


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

    @Autowired
    private HolderMapper holderMapper;

    @Autowired
    private HolderBalanceMapper holderBalanceMapper;

    @Autowired
    private RedisService redisService;

    /** Holder最新数据 */
    @Scheduled(cron = "0 22 0/4 * * ?")
    //@Scheduled(cron = "0 0/5 * * * ?")
    public void HolderDataToRedis(){
        HolderDto newHolder = holderMapper.getNewHolder();

        if(StringUtils.isNotNull(newHolder)){
            //存入redis 先删除原有数据再重新插入数据
            redisService.deleteObject("HolderData");
            redisService.setCacheObject("HolderData",newHolder);
       }
    }

    /** HolderBalance最新数据 */
    @Scheduled(cron = "0 22 0/4 * * ?")
    //@Scheduled(cron = "0 0/5 * * * ?")
    public void HolderBalanceDataToRedis(){

        HolderBalanceDto holderBalanceDto = holderBalanceMapper.getNewHolderBalance();

        if(StringUtils.isNotNull(holderBalanceDto)){
            //存入redis 先删除原有数据再重新插入数据
            redisService.deleteObject("HolderBalanceData");
            redisService.setCacheObject("HolderBalanceData",holderBalanceDto);
        }
    }

}
