刘光辉
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
package jnpf.bizcommon.onlyoffice.service.impl;
 
import jnpf.base.ActionResult;
import jnpf.base.ActionResultCode;
import jnpf.bizcommon.onlyoffice.entity.OnlyOfficeSessionEntity;
import jnpf.eln.RecordFillApi;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.core.annotation.Order;
 
@Slf4j
@Component
@Order(200)
@RequiredArgsConstructor
public class ElnRecordFillConfigBuilder implements OnlyOfficeSceneConfigBuilder {
 
    private final RecordFillApi recordFillApi;
    private final ElnRecordFillTicketIssuer ticketIssuer;
 
    @Override
    public String scene() {
        return ElnRecordFillTicketIssuer.BIZ_SCENE;
    }
 
    @Override
    public String bizModule() {
        return ElnRecordFillTicketIssuer.BIZ_MODULE;
    }
 
    @Override
    public OnlyOfficeSceneBuildPlan build(OnlyOfficeSceneBuildContext context) {
        return OnlyOfficeSceneBuildPlan.builder()
                .editAdmission(() -> canFill(context))
                .allowSameUserLockReopen(true)
                .hideCommentsWhenWritable(true)
                .pluginContextCustomizer((pluginCode, pluginGuid, pluginContext, writable) -> {
                    if (!ElnRecordFillTicketIssuer.PLUGIN_CODE.equals(pluginCode)) {
                        return;
                    }
                    pluginContext.put("canFill", writable);
                    pluginContext.put("scope", ElnRecordFillTicketIssuer.SCOPE);
                    pluginContext.put("ticket", ticketIssuer.issue(
                            context.getParam(), context.getUser(), pluginGuid));
                })
                .build();
    }
 
    @Override
    public boolean acceptsFencedStatus(Integer status) {
        return Integer.valueOf(OnlyOfficeSessionEntity.SessionStatus.RECORD_RETIRING).equals(status)
                || Integer.valueOf(OnlyOfficeSessionEntity.SessionStatus.RECORD_HISTORICAL).equals(status);
    }
 
    private boolean canFill(OnlyOfficeSceneBuildContext context) {
        try {
            ActionResult<Boolean> result = recordFillApi.canFill(
                    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 记录填写准入探针调用失败,record={} file={}",
                    context.getSession().getBizDataId(), context.getSession().getFileId());
            return false;
        }
    }
}