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(); } }