OtherTask.java
2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package cn.fw.dalaran.server.task;
import cn.fw.dalaran.domain.db.ActivityTheme;
import cn.fw.dalaran.service.Common;
import cn.fw.dalaran.service.data.ActivityThemeService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.io.File;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author wmy3969
* @version 1.0
* @date 2022/7/27 09:04
* @Description 系统其他定时任务
*/
@Slf4j
@Component
@ConditionalOnProperty(prefix = "task", name = "switch", havingValue = "on")
@RequiredArgsConstructor
public class OtherTask {
private final ActivityThemeService activityThemeService;// 活动主题业务
private final Common common;
/**
* 每天都找已经停止抓数据7天及其更久的主题, 删除缓存封面图
*/
@Scheduled(fixedRate = 60 * 60 * 1000, initialDelay = 5 * 1000)
public void deleteCoverFiles() {
final List<ActivityTheme> themeList = activityThemeService.lambdaQuery()
.list()
.stream()
.filter(item -> activityThemeService.themeHaveStopCatchData(item.getEndTime(), 7))
.collect(Collectors.toList());// 找到需要删除的主题
themeList.addAll(activityThemeService.getHasDelActivityTheme());// 找到已经逻辑删除的主题
if (CollectionUtils.isEmpty(themeList))
return;
String tempDir = common.getActivityThemeCoverDir();
StringBuilder sb = new StringBuilder();
themeList.forEach(item -> {
sb.append(tempDir);
sb.append("activityTheme");
sb.append(File.separator);
sb.append(item.getId());
sb.append("#");
sb.append(item.getTheme());
String dirPath = sb.toString();
File file = new File(dirPath);
if (file.isDirectory())
common.deleteAllFile(dirPath, file);
sb.setLength(0);
});
}
}