增加定时任务,每天凌晨五点清理90天前的数据
This commit is contained in:
parent
e0be09ffab
commit
9a5d2bce56
@ -13,4 +13,8 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
public interface XhpcMessageMapper {
|
||||
|
||||
int insertItemsBy(XhpcMessage xhpcMessage);
|
||||
|
||||
// void deleteByLastThreeMonth(String expireDate);
|
||||
|
||||
void deleteByLastThreeMonth(String expireDate);
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
}
|
||||
}
|
||||
@ -36,4 +36,9 @@
|
||||
sysdate()
|
||||
)
|
||||
</insert>
|
||||
|
||||
<delete id="deleteByLastThreeMonth">
|
||||
delete from xhpc_message
|
||||
where create_time <![CDATA[ <= ]]> #{expireDate};
|
||||
</delete>
|
||||
</mapper>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user