1. iwork 回调接口不带租户与认证限制,支持通过业务编号查询业务附件信息

This commit is contained in:
chenbowen
2025-12-03 12:09:14 +08:00
parent 45140c7f5a
commit 842155bfbd
6 changed files with 35 additions and 5 deletions

View File

@@ -24,6 +24,11 @@ public class BusinessFileRespDTO implements Serializable {
*/
private Long id;
/**
* 租户编号
*/
private Long tenantId;
/**
* 业务Id
*/

View File

@@ -16,6 +16,10 @@ public class BusinessFileRespVO {
@ExcelProperty("主键ID")
private Long id;
@Schema(description = "租户编号", example = "1024")
@ExcelProperty("租户编号")
private Long tenantId;
@Schema(description = "业务Id", requiredMode = Schema.RequiredMode.REQUIRED, example = "24322")
@ExcelProperty("业务Id")
private Long businessId;

View File

@@ -24,6 +24,11 @@ public class BusinessFileDO extends BaseDO {
@TableId(type = IdType.ASSIGN_ID)
private Long id;
/**
* 租户编号
*/
@TableField("TENANT_ID")
private Long tenantId;
/**
* 业务Id
*/
@TableField("BSN_ID")

View File

@@ -5,6 +5,7 @@ import com.zt.plat.framework.common.pojo.PageResult;
import com.zt.plat.framework.common.util.object.BeanUtils;
import com.zt.plat.framework.common.util.user.UserNameEnrichUtils;
import com.zt.plat.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.zt.plat.framework.tenant.core.aop.TenantIgnore;
import com.zt.plat.module.infra.controller.admin.businessfile.vo.BusinessFilePageReqVO;
import com.zt.plat.module.infra.controller.admin.businessfile.vo.BusinessFileRespVO;
import com.zt.plat.module.infra.controller.admin.businessfile.vo.BusinessFileSaveReqVO;
@@ -101,6 +102,7 @@ public class BusinessFileServiceImpl implements BusinessFileService {
}
@Override
@TenantIgnore
public BusinessFileDO getBusinessFileByBusinessCode(String businessCode) {
if (!StringUtils.hasText(businessCode)) {
throw exception(BUSINESS_FILE_NOT_EXISTS);

View File

@@ -1,12 +1,14 @@
package com.zt.plat.module.system.controller.admin.integration.iwork;
import com.zt.plat.framework.common.pojo.CommonResult;
import com.zt.plat.framework.tenant.core.aop.TenantIgnore;
import com.zt.plat.module.system.controller.admin.integration.iwork.vo.*;
import com.zt.plat.module.system.service.integration.iwork.IWorkIntegrationService;
import com.zt.plat.module.system.service.integration.iwork.IWorkOrgRestService;
import com.zt.plat.module.system.service.integration.iwork.IWorkSyncService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.security.PermitAll;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
@@ -14,7 +16,6 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import jakarta.annotation.security.PermitAll;
import static com.zt.plat.framework.common.pojo.CommonResult.success;
@@ -57,6 +58,7 @@ public class IWorkIntegrationController {
}
@PermitAll
@TenantIgnore
@PostMapping("/callback/file")
@Operation(summary = "iWork 文件回调:根据文件 URL 保存为附件并创建业务附件关联")
public CommonResult<Long> callbackFile(@Valid @RequestBody IWorkFileCallbackReqVO reqVO) {

View File

@@ -19,6 +19,7 @@ import com.zt.plat.module.infra.api.file.dto.FileRespDTO;
import com.zt.plat.module.system.controller.admin.integration.iwork.vo.*;
import com.zt.plat.module.system.framework.integration.iwork.config.IWorkProperties;
import com.zt.plat.module.system.service.integration.iwork.IWorkIntegrationService;
import com.zt.plat.framework.tenant.core.util.TenantUtils;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -37,6 +38,7 @@ import java.security.*;
import java.security.spec.X509EncodedKeySpec;
import java.time.Instant;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
import static com.zt.plat.module.system.service.integration.iwork.IWorkIntegrationErrorCodeConstants.*;
@@ -171,11 +173,21 @@ public class IWorkIntegrationServiceImpl implements IWorkIntegrationService {
}
BusinessFileRespDTO referenceBusinessFile = loadBusinessFileByBusinessCode(businessCode);
Long tenantId = referenceBusinessFile.getTenantId();
if (tenantId == null) {
throw new ServiceException(IWORK_CONFIGURATION_INVALID.getCode(), "业务附件缺少租户信息,无法创建回调附件: " + businessCode);
}
AtomicReference<Long> attachmentIdRef = new AtomicReference<>();
TenantUtils.execute(tenantId, () -> attachmentIdRef.set(saveCallbackAttachment(fileUrl, reqVO.getFileName(), referenceBusinessFile)));
return attachmentIdRef.get();
}
private Long saveCallbackAttachment(String fileUrl, String overrideFileName, BusinessFileRespDTO referenceBusinessFile) {
Long businessId = referenceBusinessFile.getBusinessId();
// 通过文件 API 创建文件
FileCreateReqDTO fileCreateReqDTO = new FileCreateReqDTO();
fileCreateReqDTO.setName(resolveFileName(reqVO.getFileName(), fileUrl));
fileCreateReqDTO.setName(resolveFileName(overrideFileName, fileUrl));
fileCreateReqDTO.setDirectory(null);
fileCreateReqDTO.setType(null);
fileCreateReqDTO.setContent(downloadFileBytes(fileUrl));