Commit b085dca5b93cad5457c76370ed6df02c384d3176
1 parent
b5de742c
feature(*): 公共池报表准备
- 公共池报表准备
Showing
2 changed files
with
29 additions
and
4 deletions
fw-valhalla-server/src/main/java/cn/fw/valhalla/controller/task/ReportPrepareTask.java
... | ... | @@ -31,9 +31,8 @@ public class ReportPrepareTask { |
31 | 31 | /** |
32 | 32 | * 保持率进站率报表数据准备 |
33 | 33 | */ |
34 | - @Scheduled(cron = "0 0 0 ? * * ") | |
34 | + @Scheduled(cron = "30 0 0 ? * * ") | |
35 | 35 | public void extractingData() { |
36 | -// CompletableFuture.runAsync(() -> retentionRatioBizService.extracting(DateUtil.startDate(new Date())), ThreadPoolUtil.getInstance().getExecutor()); | |
37 | 36 | retentionRatioBizService.extracting(DateUtil.startDate(new Date())); |
38 | 37 | } |
39 | 38 | ... | ... |
fw-valhalla-service/src/main/java/cn/fw/valhalla/service/report/PublicReportBizService.java
1 | 1 | package cn.fw.valhalla.service.report; |
2 | 2 | |
3 | +import cn.fw.common.cache.locker.DistributedLocker; | |
4 | +import lombok.Getter; | |
3 | 5 | import lombok.RequiredArgsConstructor; |
4 | 6 | import lombok.extern.slf4j.Slf4j; |
7 | +import org.redisson.api.RLock; | |
8 | +import org.springframework.beans.factory.annotation.Value; | |
5 | 9 | import org.springframework.stereotype.Service; |
6 | 10 | import org.springframework.transaction.annotation.Transactional; |
11 | +import org.springframework.util.Assert; | |
7 | 12 | |
8 | 13 | import java.time.LocalDate; |
9 | 14 | |
... | ... | @@ -20,6 +25,11 @@ import java.time.LocalDate; |
20 | 25 | @Slf4j |
21 | 26 | @RequiredArgsConstructor |
22 | 27 | public class PublicReportBizService { |
28 | + private final DistributedLocker distributedLocker; | |
29 | + | |
30 | + @Value("${spring.cache.custom.global-prefix}:PublicReport:extracting") | |
31 | + @Getter | |
32 | + private String keyPrefix; | |
23 | 33 | |
24 | 34 | /** |
25 | 35 | * 抽取集团公共池数据 |
... | ... | @@ -28,8 +38,24 @@ public class PublicReportBizService { |
28 | 38 | * @param groupId 集团id |
29 | 39 | */ |
30 | 40 | @Transactional(rollbackFor = Exception.class) |
31 | - public void extracting(LocalDate nowDate, Long groupId) { | |
41 | + public void extracting(final LocalDate nowDate, final Long groupId) { | |
32 | 42 | log.info("开始抽取公共池报表数据,日期:{} 集团:{}", nowDate, groupId); |
33 | - // TODO: 2023/5/4 完成方法 | |
43 | + final String lockKey = generateKey(groupId); | |
44 | + RLock lock = (RLock) distributedLocker.lock(lockKey); | |
45 | + if (lock == null || !lock.isLocked()) { | |
46 | + return; | |
47 | + } | |
48 | + try { | |
49 | + // TODO: 2023/5/4 完成方法 | |
50 | + } finally { | |
51 | + if (lock.isLocked()) { | |
52 | + lock.unlock(); | |
53 | + } | |
54 | + } | |
55 | + } | |
56 | + | |
57 | + private String generateKey(final Long groupId) { | |
58 | + Assert.notNull(groupId, "groupId cannot be null"); | |
59 | + return String.format("%s:%s", getKeyPrefix(), groupId); | |
34 | 60 | } |
35 | 61 | } | ... | ... |