package jnpf.bizcommon.onlyoffice.controller; import cn.dev33.satoken.same.SaSameUtil; import jnpf.base.ActionResult; import jnpf.bizcommon.onlyoffice.service.impl.OnlyOfficeTemplatePublishFenceService; import jnpf.onlyoffice.TemplatePublishFenceApi; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; /** 仅供 ELN 服务调用的模板发布 fence 内部端点。 */ @RestController @RequestMapping("/Internal/onlyoffice/template-publish") public class OnlyOfficeTemplatePublishFenceController implements TemplatePublishFenceApi { private final SameTokenChecker sameTokenChecker; private final OnlyOfficeTemplatePublishFenceService fenceService; @Autowired public OnlyOfficeTemplatePublishFenceController( OnlyOfficeTemplatePublishFenceService fenceService) { this(SaSameUtil::checkCurrentRequestToken, fenceService); } OnlyOfficeTemplatePublishFenceController(SameTokenChecker sameTokenChecker, OnlyOfficeTemplatePublishFenceService fenceService) { this.sameTokenChecker = sameTokenChecker; this.fenceService = fenceService; } @Override @PostMapping("/acquire") public ActionResult acquire(@RequestParam("tenantId") String tenantId, @RequestParam("templateId") String templateId, @RequestParam("fileId") String fileId, @RequestParam("fileType") String fileType) { sameTokenChecker.check(); return ActionResult.success("发布 fence 获取成功", fenceService.acquire( tenantId, templateId, fileId, fileType)); } @Override @PostMapping("/release") public ActionResult release(@RequestParam("tenantId") String tenantId, @RequestParam("templateId") String templateId, @RequestParam("fileId") String fileId, @RequestParam("fileType") String fileType, @RequestParam("token") String token) { sameTokenChecker.check(); return ActionResult.success(fenceService.release( tenantId, templateId, fileId, fileType, token)); } @FunctionalInterface interface SameTokenChecker { void check(); } }