Commit e106ed6e authored by 张辰's avatar 张辰

rank log 定时清理

parent 7eb7cb82
...@@ -95,18 +95,19 @@ public class RankLogService { ...@@ -95,18 +95,19 @@ public class RankLogService {
// 定时清除ranklog,并上传到oss // 定时清除ranklog,并上传到oss
public void clearRankLog() { public void clearRankLog() {
LocalDateTime t = LocalDateTime.now().minusDays(7L); LocalDateTime t = LocalDateTime.now().minusDays(7L);
log.info("start clearRankLog job before {}", t.format(DateTimeFormatter.BASIC_ISO_DATE)); String d = t.format(DateTimeFormatter.BASIC_ISO_DATE);
log.info("start clearRankLog job before {}", d);
for (RankLogTypeEnum type : RankLogTypeEnum.values()) { for (RankLogTypeEnum type : RankLogTypeEnum.values()) {
int idx = 0; int idx = 0;
while (true) { while (true) {
List<RankLogEntity> logs = rankLogMapper.selectByTypeLimit(type.getCode(), 50); List<RankLogEntity> logs = rankLogMapper.selectByTypeLimit(type.getCode(), 100);
if (logs.isEmpty() || logs.get(0).getRankTime().isAfter(t)) { if (logs.isEmpty() || logs.get(0).getRankTime().isAfter(t)) {
break; break;
} }
try { try {
String fileName = "ranklog_" + type.getCode() + "_" + t.format(DateTimeFormatter.BASIC_ISO_DATE) + "_" + idx; String fileName = "ranklog_" + type.getCode() + "_" + idx;
ByteArrayOutputStream os = new ByteArrayOutputStream(); ByteArrayOutputStream os = new ByteArrayOutputStream();
IOUtils.writeLines(logs.stream().map(JSON::toJSONString).collect(Collectors.toList()), null, os); IOUtils.writeLines(logs.stream().map(JSON::toJSONString).collect(Collectors.toList()), null, os);
ossFileService.uploadFileNoRecord(os.toByteArray(), fileName, ".txt", "rankLog/"); ossFileService.uploadFileNoRecord(os.toByteArray(), fileName, ".txt", "rankLog/");
...@@ -118,7 +119,8 @@ public class RankLogService { ...@@ -118,7 +119,8 @@ public class RankLogService {
} }
// delete // delete
rankLogMapper.deleteBatchIds(logs.stream().map(RankLogEntity::getId).collect(Collectors.toList())); List<Long> ids = logs.stream().map(RankLogEntity::getId).collect(Collectors.toList());
rankLogMapper.deleteBatchIds(ids);
idx++; idx++;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment