diff --git a/fw-valhalla-server/src/main/java/cn/fw/valhalla/controller/task/ReportPrepareTask.java b/fw-valhalla-server/src/main/java/cn/fw/valhalla/controller/task/ReportPrepareTask.java index 9403ce2..3ec6249 100644 --- a/fw-valhalla-server/src/main/java/cn/fw/valhalla/controller/task/ReportPrepareTask.java +++ b/fw-valhalla-server/src/main/java/cn/fw/valhalla/controller/task/ReportPrepareTask.java @@ -31,9 +31,8 @@ public class ReportPrepareTask { /** * 保持率进站率报表数据准备 */ - @Scheduled(cron = "0 0 0 ? * * ") + @Scheduled(cron = "30 0 0 ? * * ") public void extractingData() { -// CompletableFuture.runAsync(() -> retentionRatioBizService.extracting(DateUtil.startDate(new Date())), ThreadPoolUtil.getInstance().getExecutor()); retentionRatioBizService.extracting(DateUtil.startDate(new Date())); } diff --git a/fw-valhalla-service/src/main/java/cn/fw/valhalla/service/report/PublicReportBizService.java b/fw-valhalla-service/src/main/java/cn/fw/valhalla/service/report/PublicReportBizService.java index 3e493fc..8063fe8 100644 --- a/fw-valhalla-service/src/main/java/cn/fw/valhalla/service/report/PublicReportBizService.java +++ b/fw-valhalla-service/src/main/java/cn/fw/valhalla/service/report/PublicReportBizService.java @@ -1,9 +1,14 @@ package cn.fw.valhalla.service.report; +import cn.fw.common.cache.locker.DistributedLocker; +import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.redisson.api.RLock; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.Assert; import java.time.LocalDate; @@ -20,6 +25,11 @@ import java.time.LocalDate; @Slf4j @RequiredArgsConstructor public class PublicReportBizService { + private final DistributedLocker distributedLocker; + + @Value("${spring.cache.custom.global-prefix}:PublicReport:extracting") + @Getter + private String keyPrefix; /** * 抽取集团公共池数据 @@ -28,8 +38,24 @@ public class PublicReportBizService { * @param groupId 集团id */ @Transactional(rollbackFor = Exception.class) - public void extracting(LocalDate nowDate, Long groupId) { + public void extracting(final LocalDate nowDate, final Long groupId) { log.info("开始抽取公共池报表数据,日期:{} 集团:{}", nowDate, groupId); - // TODO: 2023/5/4 完成方法 + final String lockKey = generateKey(groupId); + RLock lock = (RLock) distributedLocker.lock(lockKey); + if (lock == null || !lock.isLocked()) { + return; + } + try { + // TODO: 2023/5/4 完成方法 + } finally { + if (lock.isLocked()) { + lock.unlock(); + } + } + } + + private String generateKey(final Long groupId) { + Assert.notNull(groupId, "groupId cannot be null"); + return String.format("%s:%s", getKeyPrefix(), groupId); } }