刘光辉
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
45
46
47
48
49
package jnpf.bizcommon.onlyoffice.service.impl;
 
import jnpf.base.model.uploadedit.UploadEditLease;
import jnpf.bizcommon.onlyoffice.entity.OnlyOfficeConfigParam;
import jnpf.dmsEntity.qianpiye.DmsQianpiyeOnlyOfficeConstants;
import jnpf.exception.DataException;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import java.util.Objects;
 
@Component
@RequiredArgsConstructor
public class UploadEditSceneConfigBuilder implements OnlyOfficeSceneConfigBuilder {
    public static final String SCENE = "visualdev.uploadFile";
    public static final String MODULE = "visualdev";
    private final UploadEditSessionSupport support;
    private final jnpf.bizcommon.onlyoffice.entity.OnlyOfficeProperties properties;
    private final DmsQianpiyeTicketIssuer qianpiyeTicketIssuer;
    @Override public String scene() { return SCENE; }
    @Override public String bizModule() { return MODULE; }
    @Override public OnlyOfficeSceneBuildPlan build(OnlyOfficeSceneBuildContext context) {
        if (!properties.getUploadFile().isEditEnabled()) throw new DataException("上传控件在线编辑尚未启用");
        OnlyOfficeConfigParam param = context.getParam();
        if (!"annex".equals(param.getFileType())) throw new DataException("通用附件编辑仅支持 annex 存储");
        UploadEditLease lease = support.lease(context.getTenantId(), context.getUser().getUserId(), param.getFileId());
        if (!Objects.equals(lease.getDraftId(), param.getBizDataId()) || !Objects.equals(lease.getFile().get("name"), param.getFileName())) {
            throw new DataException("编辑请求与当前工作附件不一致");
        }
        String sourceFileId = Objects.toString(lease.getFile().get("fileId"), "");
        if (sourceFileId.isBlank()) throw new DataException("编辑租约缺少来源附件");
        return OnlyOfficeSceneBuildPlan.builder().editAdmission(() -> true)
                .reviewOnly("review".equals(lease.getMode()))
                .sourceFileId(sourceFileId)
                .uploadFileAllowDownload(lease.isAllowDownload())
                .uploadQianpiyeAnnotatorEnabled(lease.isQianpiyeAnnotatorEnabled())
                .pluginContextCustomizer((pluginCode, pluginGuid, pluginContext, writable) -> {
                    if (!DmsQianpiyeOnlyOfficeConstants.PLUGIN_CODE.equals(pluginCode)) return;
                    pluginContext.put("canAnnotate", writable);
                    if (!writable) return;
                    OnlyOfficeConfigParam qianpiyeParam = new OnlyOfficeConfigParam();
                    qianpiyeParam.setFileId(sourceFileId);
                    qianpiyeParam.setFileType(param.getFileType());
                    qianpiyeParam.setBizModule(DmsQianpiyeOnlyOfficeConstants.BIZ_MODULE);
                    qianpiyeParam.setBizScene(DmsQianpiyeOnlyOfficeConstants.BIZ_SCENE);
                    pluginContext.put("scope", DmsQianpiyeOnlyOfficeConstants.SCOPE);
                    pluginContext.put("ticket", qianpiyeTicketIssuer.issue(qianpiyeParam, context.getUser(), pluginGuid));
                }).build();
    }
}