刘光辉
8 小时以前 06f314545ac3514d7ce28939920866ae8188d31c
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
package jnpf.bizcommon.onlyoffice.service.impl;
 
import cn.hutool.crypto.digest.DigestUtil;
import jnpf.exception.DataException;
import lombok.RequiredArgsConstructor;
import org.redisson.api.RBucket;
import org.redisson.api.RedissonClient;
import org.springframework.stereotype.Component;
 
import java.util.concurrent.TimeUnit;
 
/** 跨实例保存响应丢失后的冻结取消意图,阻止迟到请求重新取得 fence。 */
@Component
@RequiredArgsConstructor
class OnlyOfficeFreezeCancellationStore {
    private static final String KEY_PREFIX = "jnpf:onlyoffice:record-freeze-cancel:";
    private static final long RETENTION_DAYS = 7L;
 
    private final RedissonClient redissonClient;
 
    void cancel(String tenantId, String recordId, String fileId, String fileType, String token) {
        try {
            bucket(tenantId, recordId, fileId, fileType, token)
                    .set("1", RETENTION_DAYS, TimeUnit.DAYS);
        } catch (RuntimeException e) {
            throw new DataException("记录冻结取消状态写入失败,已拒绝继续处理");
        }
    }
 
    boolean isCancelled(String tenantId, String recordId, String fileId, String fileType, String token) {
        try {
            return bucket(tenantId, recordId, fileId, fileType, token).get() != null;
        } catch (RuntimeException e) {
            throw new DataException("记录冻结取消状态读取失败,已拒绝继续处理");
        }
    }
 
    private RBucket<String> bucket(String tenantId, String recordId, String fileId,
                                   String fileType, String token) {
        String identity = tenantId + '\u001f' + recordId + '\u001f' + fileId
                + '\u001f' + fileType + '\u001f' + token;
        return redissonClient.getBucket(KEY_PREFIX + DigestUtil.sha256Hex(identity));
    }
}