增加定时任务,每天凌晨五点清理90天前的数据

This commit is contained in:
panshuling321 2021-12-28 17:23:15 +08:00
parent e0be09ffab
commit 9a5d2bce56
3 changed files with 38 additions and 0 deletions

View File

@ -13,4 +13,8 @@ import org.apache.ibatis.annotations.Mapper;
public interface XhpcMessageMapper { public interface XhpcMessageMapper {
int insertItemsBy(XhpcMessage xhpcMessage); int insertItemsBy(XhpcMessage xhpcMessage);
// void deleteByLastThreeMonth(String expireDate);
void deleteByLastThreeMonth(String expireDate);
} }

View File

@ -0,0 +1,29 @@
package com.xhpc.pp.server;
import cn.hutool.core.convert.Convert;
import com.xhpc.common.util.DateUtil;
import com.xhpc.mapper.XhpcMessageMapper;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Date;
@Component
public class MessageCLeanTask {
@Resource
XhpcMessageMapper messageMapper;
/**
* 每天定时清理message表三个月前的数据
*/
@Scheduled(cron = "0 0 05 1/1 * ?")
private void run(){
String expireDate = DateUtil.date2String(DateUtil.addDay(new Date(), -90), DateUtil.DATE_FORMAT_DATE_TIME) ;
messageMapper.deleteByLastThreeMonth(expireDate);
}
}

View File

@ -36,4 +36,9 @@
sysdate() sysdate()
) )
</insert> </insert>
<delete id="deleteByLastThreeMonth">
delete from xhpc_message
where create_time <![CDATA[ <= ]]> #{expireDate};
</delete>
</mapper> </mapper>