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