Merge remote-tracking branch 'base-version/main' into dev
This commit is contained in:
@@ -12,9 +12,9 @@ public class IWorkFileCallbackReqVO {
|
||||
@NotBlank(message = "文件 URL 不能为空")
|
||||
private String fileUrl;
|
||||
|
||||
@Schema(description = "业务 ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "123456")
|
||||
@NotBlank(message = "业务 ID 不能为空")
|
||||
private String businessId;
|
||||
@Schema(description = "业务编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "DJ-2025-0001")
|
||||
@NotBlank(message = "业务编码不能为空")
|
||||
private String businessCode;
|
||||
|
||||
@Schema(description = "文件名称,可选", example = "合同附件.pdf")
|
||||
private String fileName;
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.zt.plat.framework.common.exception.ServiceException;
|
||||
import com.zt.plat.framework.common.exception.util.ServiceExceptionUtil;
|
||||
import com.zt.plat.framework.common.pojo.CommonResult;
|
||||
import com.zt.plat.module.infra.api.businessfile.BusinessFileApi;
|
||||
import com.zt.plat.module.infra.api.businessfile.dto.BusinessFileRespDTO;
|
||||
import com.zt.plat.module.infra.api.businessfile.dto.BusinessFileSaveReqDTO;
|
||||
import com.zt.plat.module.infra.api.file.FileApi;
|
||||
import com.zt.plat.module.infra.api.file.dto.FileCreateReqDTO;
|
||||
@@ -161,20 +162,16 @@ public class IWorkIntegrationServiceImpl implements IWorkIntegrationService {
|
||||
throw new ServiceException(IWORK_CONFIGURATION_INVALID.getCode(), "回调请求不能为空");
|
||||
}
|
||||
String fileUrl = Optional.ofNullable(reqVO.getFileUrl()).map(String::trim).orElse("");
|
||||
String businessIdStr = Optional.ofNullable(reqVO.getBusinessId()).map(String::trim).orElse("");
|
||||
String businessCode = Optional.ofNullable(reqVO.getBusinessCode()).map(String::trim).orElse("");
|
||||
if (!StringUtils.hasText(fileUrl)) {
|
||||
throw new ServiceException(IWORK_CONFIGURATION_INVALID.getCode(), "文件 URL 不能为空");
|
||||
}
|
||||
if (!StringUtils.hasText(businessIdStr)) {
|
||||
throw new ServiceException(IWORK_CONFIGURATION_INVALID.getCode(), "业务 ID 不能为空");
|
||||
if (!StringUtils.hasText(businessCode)) {
|
||||
throw new ServiceException(IWORK_CONFIGURATION_INVALID.getCode(), "业务编码不能为空");
|
||||
}
|
||||
|
||||
Long businessId;
|
||||
try {
|
||||
businessId = Long.valueOf(businessIdStr);
|
||||
} catch (NumberFormatException ex) {
|
||||
throw new ServiceException(IWORK_CONFIGURATION_INVALID.getCode(), "业务 ID 必须是数字: " + businessIdStr);
|
||||
}
|
||||
BusinessFileRespDTO referenceBusinessFile = loadBusinessFileByBusinessCode(businessCode);
|
||||
Long businessId = referenceBusinessFile.getBusinessId();
|
||||
|
||||
// 通过文件 API 创建文件
|
||||
FileCreateReqDTO fileCreateReqDTO = new FileCreateReqDTO();
|
||||
@@ -191,7 +188,8 @@ public class IWorkIntegrationServiceImpl implements IWorkIntegrationService {
|
||||
Long fileId = fileResult.getData().getId();
|
||||
|
||||
BusinessFileSaveReqDTO businessReq = BusinessFileSaveReqDTO.builder()
|
||||
.businessId(businessId)
|
||||
.businessId(businessId)
|
||||
.businessCode(referenceBusinessFile.getBusinessCode())
|
||||
.fileId(fileId)
|
||||
.fileName(fileResult.getData().getName())
|
||||
.source("iwork")
|
||||
@@ -204,6 +202,21 @@ public class IWorkIntegrationServiceImpl implements IWorkIntegrationService {
|
||||
return bizResult.getData();
|
||||
}
|
||||
|
||||
private BusinessFileRespDTO loadBusinessFileByBusinessCode(String businessCode) {
|
||||
CommonResult<BusinessFileRespDTO> businessResult = businessFileApi.getBusinessFileByBusinessCode(businessCode);
|
||||
if (businessResult == null || !businessResult.isSuccess() || businessResult.getData() == null) {
|
||||
throw new ServiceException(IWORK_CONFIGURATION_INVALID.getCode(),
|
||||
"根据业务编码获取业务附件关联失败: " + Optional.ofNullable(businessResult)
|
||||
.map(CommonResult::getMsg)
|
||||
.orElse("未知错误"));
|
||||
}
|
||||
BusinessFileRespDTO businessFile = businessResult.getData();
|
||||
if (businessFile.getBusinessId() == null) {
|
||||
throw new ServiceException(IWORK_CONFIGURATION_INVALID.getCode(), "业务编码未绑定业务 ID: " + businessCode);
|
||||
}
|
||||
return businessFile;
|
||||
}
|
||||
|
||||
private byte[] downloadFileBytes(String fileUrl) {
|
||||
OkHttpClient client = okHttpClient();
|
||||
Request request = new Request.Builder().url(fileUrl).get().build();
|
||||
|
||||
Reference in New Issue
Block a user