c3b33c0a
张志伟
|
1
2
|
package cn.fw.valhalla.service.report;
|
b085dca5
张志伟
|
3
4
|
import cn.fw.common.cache.locker.DistributedLocker;
import lombok.Getter;
|
c3b33c0a
张志伟
|
5
6
|
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
|
b085dca5
张志伟
|
7
8
|
import org.redisson.api.RLock;
import org.springframework.beans.factory.annotation.Value;
|
c3b33c0a
张志伟
|
9
10
|
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
|
b085dca5
张志伟
|
11
|
import org.springframework.util.Assert;
|
c3b33c0a
张志伟
|
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
import java.time.LocalDate;
/**
* 公共池报表数据服务
*
* @author : kurisu
* @version : 2.0
* @className : PublicReportBizService
* @description : 公共池报表数据服务
* @date : 2023-05-04 15:07
*/
@Service
@Slf4j
@RequiredArgsConstructor
public class PublicReportBizService {
|
b085dca5
张志伟
|
28
29
30
31
32
|
private final DistributedLocker distributedLocker;
@Value("${spring.cache.custom.global-prefix}:PublicReport:extracting")
@Getter
private String keyPrefix;
|
c3b33c0a
张志伟
|
33
34
35
36
37
38
39
40
|
/**
* 抽取集团公共池数据
*
* @param nowDate 日期
* @param groupId 集团id
*/
@Transactional(rollbackFor = Exception.class)
|
b085dca5
张志伟
|
41
|
public void extracting(final LocalDate nowDate, final Long groupId) {
|
c3b33c0a
张志伟
|
42
|
log.info("开始抽取公共池报表数据,日期:{} 集团:{}", nowDate, groupId);
|
b085dca5
张志伟
|
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
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);
|
c3b33c0a
张志伟
|
60
61
|
}
}
|