package com.xhpc.activity.task;


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

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

@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);

    }
}
