刘光辉
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
package jnpf.bizcommon.onlyoffice.service.impl;
 
import jnpf.base.ActionResult;
import jnpf.base.ActionResultCode;
import jnpf.bizcommon.onlyoffice.entity.OnlyOfficeSessionEntity;
import jnpf.eln.TemplateEditabilityApi;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.core.annotation.Order;
import org.springframework.util.StringUtils;
 
@Slf4j
@Component
@Order(100)
@RequiredArgsConstructor
public class ElnTemplateAnnotateConfigBuilder implements OnlyOfficeSceneConfigBuilder {
 
    private final TemplateEditabilityApi templateEditabilityApi;
    private final OnlyOfficeAnnotateTicketIssuer ticketIssuer;
 
    @Override
    public String scene() {
        return OnlyOfficeAnnotateTicketIssuer.BIZ_SCENE;
    }
 
    @Override
    public String bizModule() {
        return OnlyOfficeAnnotateTicketIssuer.BIZ_MODULE;
    }
 
    @Override
    public OnlyOfficeSceneBuildPlan build(OnlyOfficeSceneBuildContext context) {
        boolean locatingControl = StringUtils.hasText(context.getParam().getLocateControlTag());
        return OnlyOfficeSceneBuildPlan.builder()
                .editAdmission(() -> canAnnotate(context))
                .hideCommentsWhenWritable(true)
                .pluginHiddenInReadOnly(OnlyOfficeAnnotateTicketIssuer.PLUGIN_CODE)
                .keepHiddenPluginForLocate(locatingControl)
                .pluginContextCustomizer((pluginCode, pluginGuid, pluginContext, writable) -> {
                    if (!OnlyOfficeAnnotateTicketIssuer.PLUGIN_CODE.equals(pluginCode)) {
                        return;
                    }
                    pluginContext.put("canAnnotate", writable);
                    if (writable) {
                        pluginContext.put("scope", OnlyOfficeAnnotateTicketIssuer.SCOPE);
                        pluginContext.put("ticket", ticketIssuer.issue(
                                context.getParam(), context.getUser(), pluginGuid));
                        if (StringUtils.hasText(context.getParam().getRepairBindingId())) {
                            pluginContext.put("repairBindingId", context.getParam().getRepairBindingId());
                        }
                    }
                    if (locatingControl) {
                        pluginContext.put("locateControlTag", context.getParam().getLocateControlTag());
                    }
                })
                .build();
    }
 
    @Override
    public boolean acceptsFencedStatus(Integer status) {
        return Integer.valueOf(OnlyOfficeSessionEntity.SessionStatus.PUBLISHING).equals(status);
    }
 
    private boolean canAnnotate(OnlyOfficeSceneBuildContext context) {
        try {
            ActionResult<Boolean> result = templateEditabilityApi.canAnnotate(
                    context.getTenantId(), context.getUser() == null ? null : context.getUser().getUserId(),
                    context.getSession().getBizDataId(), context.getSession().getFileId());
            return result != null && ActionResultCode.SUCCESS.getCode().equals(result.getCode())
                    && Boolean.TRUE.equals(result.getData());
        } catch (RuntimeException e) {
            log.warn("ELN 模板标注准入探针调用失败,template={} file={}",
                    context.getSession().getBizDataId(), context.getSession().getFileId());
            return false;
        }
    }
}