刘光辉
3 小时以前 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package jnpf.bizcommon.onlyoffice.controller;
 
import cn.dev33.satoken.same.SaSameUtil;
import jnpf.base.ActionResult;
import jnpf.bizcommon.onlyoffice.service.impl.OnlyOfficeRecordRevisionFenceService;
import jnpf.onlyoffice.RecordRevisionFenceApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
 
/** 仅供 ELN 服务调用的记录修订 fence 内部端点。 */
@RestController
@RequestMapping("/Internal/onlyoffice/record-revision")
public class OnlyOfficeRecordRevisionFenceController implements RecordRevisionFenceApi {
 
    private final SameTokenChecker sameTokenChecker;
    private final OnlyOfficeRecordRevisionFenceService fenceService;
 
    @Autowired
    public OnlyOfficeRecordRevisionFenceController(
            OnlyOfficeRecordRevisionFenceService fenceService) {
        this(SaSameUtil::checkCurrentRequestToken, fenceService);
    }
 
    OnlyOfficeRecordRevisionFenceController(
            SameTokenChecker sameTokenChecker,
            OnlyOfficeRecordRevisionFenceService fenceService) {
        this.sameTokenChecker = sameTokenChecker;
        this.fenceService = fenceService;
    }
 
    @Override
    @PostMapping("/acquire")
    public ActionResult<String> acquire(@RequestParam("tenantId") String tenantId,
                                        @RequestParam("recordId") String recordId,
                                        @RequestParam("fileId") String fileId,
                                        @RequestParam("fileType") String fileType) {
        sameTokenChecker.check();
        return ActionResult.success("记录修订 fence 获取成功", fenceService.acquire(
                tenantId, recordId, fileId, fileType));
    }
 
    @Override
    @PostMapping("/acquire-for-operation")
    public ActionResult<String> acquireForOperation(@RequestParam("tenantId") String tenantId,
                                                     @RequestParam("recordId") String recordId,
                                                     @RequestParam("fileId") String fileId,
                                                     @RequestParam("fileType") String fileType,
                                                     @RequestParam("operationCode") String operationCode) {
        sameTokenChecker.check();
        return ActionResult.success("记录冻结 fence 获取成功", fenceService.acquireForOperation(
                tenantId, recordId, fileId, fileType, operationCode));
    }
 
    @Override
    @PostMapping("/complete")
    public ActionResult<Boolean> complete(@RequestParam("tenantId") String tenantId,
                                          @RequestParam("recordId") String recordId,
                                          @RequestParam("fileId") String fileId,
                                          @RequestParam("fileType") String fileType,
                                          @RequestParam("token") String token) {
        sameTokenChecker.check();
        return ActionResult.success(fenceService.complete(
                tenantId, recordId, fileId, fileType, token));
    }
 
    @Override
    @PostMapping("/release")
    public ActionResult<Boolean> release(@RequestParam("tenantId") String tenantId,
                                         @RequestParam("recordId") String recordId,
                                         @RequestParam("fileId") String fileId,
                                         @RequestParam("fileType") String fileType,
                                         @RequestParam("token") String token) {
        sameTokenChecker.check();
        return ActionResult.success(fenceService.release(
                tenantId, recordId, fileId, fileType, token));
    }
 
    @Override
    @PostMapping("/release-after-document-update")
    public ActionResult<Boolean> releaseAfterDocumentUpdate(
            @RequestParam("tenantId") String tenantId,
            @RequestParam("recordId") String recordId,
            @RequestParam("fileId") String fileId,
            @RequestParam("fileType") String fileType,
            @RequestParam("token") String token) {
        sameTokenChecker.check();
        return ActionResult.success(fenceService.releaseAfterDocumentUpdate(
                tenantId, recordId, fileId, fileType, token));
    }
 
    @FunctionalInterface
    interface SameTokenChecker {
        void check();
    }
}