增加定时任务,每天凌晨五点清理90天前的数据
This commit is contained in:
parent
2ac0e06f70
commit
73424f0034
@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -38,4 +38,9 @@
|
|||||||
sysdate()
|
sysdate()
|
||||||
)
|
)
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
|
<delete id="deleteByLastThreeMonth">
|
||||||
|
delete from xhpc_message
|
||||||
|
where create_time <![CDATA[ <= ]]> #{expireDate};
|
||||||
|
</delete>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user