package com.xhpc.activity.task;


import com.xhpc.activity.mapper.XhpcDeviceMessageMapper;
import com.xhpc.common.util.DateUtil;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.Date;
import java.util.Map;

import static com.xhpc.common.data.redis.StaticBeanUtil.REDIS;

@Component
public class AutoClearDataTask {


    @Resource
    XhpcDeviceMessageMapper messageMapper;

    /**
     * 清理7天前的数据
     */
    @Scheduled(cron = "0 0 5 * * ?")
    private void autoClearDeviceMessageData(){

        String date = DateUtil.date2String(DateUtil.addDay(new Date(), -7), "yyyy-MM-dd");
        messageMapper.deleteMessageByDate(date);
    }

    @Scheduled(cron = "0 0/10 * * * ? ")
    private void getNotificationPlaceholderOrderInfo(){
        String orderKey = "notificationPlaceholderOrderInfo:*";

        Collection<String> orderKeys = REDIS.keys(orderKey);
        for (String okey : orderKeys) {
            REDIS.deleteObject(okey);
        }
    }

    public static void main(String[] args) {

        String substring = "notificationPlaceholderOrderInfo:80836000010001012505142200439549".substring(49, 57);

        System.out.println("substring="+substring);

        String format = cn.hutool.core.date.DateUtil.format(cn.hutool.core.date.DateUtil.offsetDay(new Date(), -3), "yyMMdd");

        System.out.println("format="+format);

    }
}
