新增每天清理一个月前的设备流水

This commit is contained in:
panshuling321 2022-04-11 09:58:39 +08:00
parent 1be13586d6
commit aa1c7f7a9f
4 changed files with 40 additions and 0 deletions

View File

@ -6,8 +6,10 @@ import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.scheduling.annotation.EnableScheduling;
@EnableScheduling
@EnableCustomConfig @EnableCustomConfig
@SpringBootApplication @SpringBootApplication
@EnableRyFeignClients @EnableRyFeignClients

View File

@ -24,4 +24,7 @@ public interface XhpcDeviceMessageMapper {
List<Map<String, Object>> getOrderMessageByParams(@Param("params")Map params); List<Map<String, Object>> getOrderMessageByParams(@Param("params")Map params);
int deleteMessageByDate(@Param("date")String date);
} }

View File

@ -0,0 +1,29 @@
package com.xhpc.log.task;
import com.xhpc.common.util.DateUtil;
import com.xhpc.log.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;
/**
* 清理一个月前的数据
*/
@Scheduled(cron = "0 0 5 * * ?")
private void autoClearDeviceMessageData(){
String date = DateUtil.date2String(DateUtil.addDay(new Date(), -30), "yyyy-MM-dd");
messageMapper.deleteMessageByDate(date);
}
}

View File

@ -3,6 +3,12 @@
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.xhpc.log.mapper.XhpcDeviceMessageMapper"> <mapper namespace="com.xhpc.log.mapper.XhpcDeviceMessageMapper">
<delete id="deleteMessageByDate">
delete from xhpc_device_message where create_time create_time <![CDATA[ <= ]]> #{date}
</delete>
<select id="selectListByTypeAndSerialNumber" resultType="map"> <select id="selectListByTypeAndSerialNumber" resultType="map">
select select
device_message_id as 'deviceMessageId', device_message_id as 'deviceMessageId',