| @@ -0,0 +1,23 @@ | |||||
| package com.iformall.schedule; | |||||
| import com.iformall.service.WxMsgRecordService; | |||||
| import org.springframework.beans.factory.annotation.Value; | |||||
| import org.springframework.scheduling.annotation.Scheduled; | |||||
| import org.springframework.stereotype.Component; | |||||
| import javax.annotation.Resource; | |||||
| @Component | |||||
| public class WxMsgRecordSchedule { | |||||
| @Resource | |||||
| private WxMsgRecordService msgRecordService; | |||||
| @Value("${fm.clear_data_before_msg_record}") | |||||
| private int monthBefore; | |||||
| @Scheduled(cron = "0 0 1 1 * ?") // 每月1日凌晨01:00清理过期的wx_msg_record表 | |||||
| public void clearOldData() { | |||||
| msgRecordService.clearOldData(monthBefore); | |||||
| } | |||||
| } | |||||
| @@ -111,6 +111,7 @@ fm: | |||||
| upload_dir: /home/test/server/uploads/ | upload_dir: /home/test/server/uploads/ | ||||
| monitor_emails: houtaikaifa@iformall.com,xiaochengxufabu@iformall.com | monitor_emails: houtaikaifa@iformall.com,xiaochengxufabu@iformall.com | ||||
| monitor_enable: true | monitor_enable: true | ||||
| clear_data_before_msg_record: 1 | |||||
| logging: | logging: | ||||
| level: | level: | ||||
| @@ -96,6 +96,7 @@ fm: | |||||
| upload_dir: /home/ec2-user/server/uploads/ | upload_dir: /home/ec2-user/server/uploads/ | ||||
| monitor_emails: houtaikaifa@iformall.com,xiaochengxufabu@iformall.com | monitor_emails: houtaikaifa@iformall.com,xiaochengxufabu@iformall.com | ||||
| monitor_enable: false | monitor_enable: false | ||||
| clear_data_before_msg_record: 1 | |||||
| logging: | logging: | ||||
| level: | level: | ||||
| @@ -96,6 +96,7 @@ fm: | |||||
| upload_dir: /home/ec2-user/server/uploads/ | upload_dir: /home/ec2-user/server/uploads/ | ||||
| monitor_emails: houtaikaifa@iformall.com,xiaochengxufabu@iformall.com | monitor_emails: houtaikaifa@iformall.com,xiaochengxufabu@iformall.com | ||||
| monitor_enable: false | monitor_enable: false | ||||
| clear_data_before_msg_record: 1 | |||||
| logging: | logging: | ||||
| level: | level: | ||||
| @@ -10,4 +10,10 @@ public interface WxMsgRecordService { | |||||
| List<WxMsgRecord> findList(WxMsgRecord record); | List<WxMsgRecord> findList(WxMsgRecord record); | ||||
| void update(WxMsgRecord record); | void update(WxMsgRecord record); | ||||
| /** | |||||
| * | |||||
| * @param monthBefore 距离当前月份数 | |||||
| */ | |||||
| void clearOldData(int monthBefore) ; | |||||
| } | } | ||||
| @@ -1,5 +1,7 @@ | |||||
| package com.iformall.service.impl; | package com.iformall.service.impl; | ||||
| import com.baomidou.mybatisplus.core.conditions.Wrapper; | |||||
| import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |||||
| import com.iformall.common.IdWorker; | import com.iformall.common.IdWorker; | ||||
| import com.iformall.domain.po.msg.*; | import com.iformall.domain.po.msg.*; | ||||
| import com.iformall.enums.EnumMsgRecordStatus; | import com.iformall.enums.EnumMsgRecordStatus; | ||||
| @@ -8,6 +10,11 @@ import com.iformall.service.WxMsgRecordService; | |||||
| import com.iformall.utils.JsonUtil; | import com.iformall.utils.JsonUtil; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.stereotype.Service; | import org.springframework.stereotype.Service; | ||||
| import java.time.LocalDate; | |||||
| import java.time.LocalDateTime; | |||||
| import java.time.format.DateTimeFormatter; | |||||
| import java.util.Arrays; | |||||
| import java.util.List; | import java.util.List; | ||||
| /** | /** | ||||
| @@ -59,4 +66,15 @@ public class WxMsgRecordServiceImpl implements WxMsgRecordService { | |||||
| public void update(WxMsgRecord record) { | public void update(WxMsgRecord record) { | ||||
| wxMsgRecordMapper.updateByBaseMsg(record); | wxMsgRecordMapper.updateByBaseMsg(record); | ||||
| } | } | ||||
| @Override | |||||
| public void clearOldData(int monthBefore) { | |||||
| if (monthBefore == 0) { | |||||
| monthBefore = 1; | |||||
| } | |||||
| LocalDate ld = LocalDate.now().minusMonths(monthBefore); | |||||
| wxMsgRecordMapper.delete(new QueryWrapper<WxMsgRecord>(). | |||||
| in("msg_status", Arrays.asList(EnumMsgRecordStatus.CONSUME_SUCC.getCode())) | |||||
| .le("createtime", DateTimeFormatter.ofPattern("yyyy-MM-dd").format(ld))); | |||||
| } | |||||
| } | } | ||||