feat(): ApplyFileUploadLease 申请文档上传租约

master
DongZeLiang 2025-02-22 16:29:59 +08:00
parent 952595dbb7
commit c2f011a63b
7 changed files with 92 additions and 45 deletions

View File

@ -58,5 +58,10 @@
<artifactId>tea-util</artifactId> <artifactId>tea-util</artifactId>
<version>0.2.23</version> <version>0.2.23</version>
</dependency> </dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>alibabacloud-bailian20231229</artifactId>
<version>2.0.0</version>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -19,7 +19,7 @@ import java.util.Map;
public class AddDataManagement { public class AddDataManagement {
@Autowired // @Autowired
private Client client; private Client client;
public AddFileResponseBodyDataMode addFile(UploadDataManagementMode uploadDataManagementMode) { public AddFileResponseBodyDataMode addFile(UploadDataManagementMode uploadDataManagementMode) {

View File

@ -1,48 +1,45 @@
// This file is auto-generated, don't edit it. Thanks.
package com.muyu.aliyun.bailian; package com.muyu.aliyun.bailian;
import com.aliyun.bailian20231229.Client; import com.aliyun.sdk.service.bailian20231229.AsyncClient;
import com.aliyun.bailian20231229.models.ApplyFileUploadLeaseResponse; import com.aliyun.sdk.service.bailian20231229.models.ApplyFileUploadLeaseRequest;
import com.aliyun.bailian20231229.models.ApplyFileUploadLeaseResponseBody; import com.aliyun.sdk.service.bailian20231229.models.ApplyFileUploadLeaseResponse;
import com.aliyun.bailian20231229.models.ApplyFileUploadLeaseRequest; import com.aliyun.sdk.service.bailian20231229.models.ApplyFileUploadLeaseResponseBody;
import com.aliyun.tea.*; import com.aliyun.tea.*;
import com.aliyun.teautil.models.RuntimeOptions;
import com.muyu.aliyun.bailian.data.FileUploadLeaseMode; import com.muyu.aliyun.bailian.data.FileUploadLeaseMode;
import com.muyu.aliyun.bailian.data.fixed.UploadLeaseParamsMode; import com.muyu.aliyun.bailian.data.fixed.UploadLeaseParamsMode;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.HashMap; import java.util.concurrent.CompletableFuture;
import java.util.Map;
@Component @Component
@Log4j2 @Log4j2
public class ApplyLease { public class ApplyLease {
@Autowired @Autowired
private Client client; private AsyncClient asyncClient;
public UploadLeaseParamsMode applyFileUploadLease(FileUploadLeaseMode fileUploadLeaseModel) { public UploadLeaseParamsMode applyFileUploadLease(FileUploadLeaseMode fileUploadLeaseModel) {
ApplyFileUploadLeaseRequest applyFileUploadLeaseRequest = new ApplyFileUploadLeaseRequest(); ApplyFileUploadLeaseRequest applyFileUploadLeaseRequest = ApplyFileUploadLeaseRequest.builder()
RuntimeOptions runtime = new RuntimeOptions(); .fileName(fileUploadLeaseModel.getFileName())
Map<String, String> headers = new HashMap<>(); .md5(fileUploadLeaseModel.getMd5())
.sizeInBytes(fileUploadLeaseModel.getSizeInBytes())
applyFileUploadLeaseRequest.setFileName(fileUploadLeaseModel.getFileName()); .categoryId(fileUploadLeaseModel.getCategoryId())
applyFileUploadLeaseRequest.setMd5(fileUploadLeaseModel.getMd5()); .workspaceId(fileUploadLeaseModel.getWorkspaceId())
applyFileUploadLeaseRequest.setSizeInBytes(fileUploadLeaseModel.getSizeInBytes()); .build();
applyFileUploadLeaseRequest.setCategoryType(fileUploadLeaseModel.getCategoryId()); String exceptionName = "";
try { try {
// 复制代码运行请自行打印 API 的返回值 // 复制代码运行请自行打印 API 的返回值
ApplyFileUploadLeaseResponse applyFileUploadLeaseResponse = CompletableFuture<ApplyFileUploadLeaseResponse> applyFileUploadLeaseResponseCompletableFuture = asyncClient.applyFileUploadLease(applyFileUploadLeaseRequest);
client.applyFileUploadLeaseWithOptions(fileUploadLeaseModel.getCategoryId(), fileUploadLeaseModel.getWorkspaceId(), applyFileUploadLeaseRequest, headers, runtime); ApplyFileUploadLeaseResponse applyFileUploadLeaseResponse = applyFileUploadLeaseResponseCompletableFuture.get();
if (applyFileUploadLeaseResponse.getStatusCode() != 200) { if (applyFileUploadLeaseResponse.getStatusCode() != 200) {
throw new RuntimeException(applyFileUploadLeaseResponse.toString()); throw new RuntimeException(applyFileUploadLeaseResponse.toString());
} }
ApplyFileUploadLeaseResponseBody body = applyFileUploadLeaseResponse.getBody(); ApplyFileUploadLeaseResponseBody applyFileUploadLeaseResponseBody = applyFileUploadLeaseResponse.getBody();
ApplyFileUploadLeaseResponseBody.ApplyFileUploadLeaseResponseBodyData data = body.getData(); ApplyFileUploadLeaseResponseBody.Param param = applyFileUploadLeaseResponseBody.getData().getParam();
ApplyFileUploadLeaseResponseBody.ApplyFileUploadLeaseResponseBodyDataParam param = data.getParam();
log.info("param:「{}」", param); log.info("param:「{}」", param);
return UploadLeaseParamsMode.builder() return UploadLeaseParamsMode.builder()
.Url(param.getUrl()) .Url(param.getUrl())
@ -50,7 +47,6 @@ public class ApplyLease {
.build(); .build();
} catch (TeaException error) { } catch (TeaException error) {
String exceptionName;
switch (error.getCode()) { switch (error.getCode()) {
case "SDK.ConnectTimeout": case "SDK.ConnectTimeout":
exceptionName = "网络连接超时"; exceptionName = "网络连接超时";
@ -80,16 +76,11 @@ public class ApplyLease {
exceptionName = "未知阿里云 API 异常"; exceptionName = "未知阿里云 API 异常";
} }
log.error("异常名称:「{}」,错误码: {}, 错误信息: {}, 错误数据: {}", exceptionName, error.getCode(), error.getMessage(), error.getData()); log.error("异常名称:「{}」,错误码: {}, 错误信息: {}, 错误数据: {}", exceptionName, error.getCode(), error.getMessage(), error.getData());
} catch (NullPointerException e) { }catch (Exception exception) {
log.error("异常名称:「空指针异常」,错误信息: {}", e.getMessage(), e); log.error("异常名称:「未知通用异常」,错误信息: {}", exception.getMessage(), exception);
} catch (ClassCastException e) { throw new RuntimeException(exception);
log.error("异常名称:「类型转换异常」,错误信息: {}", e.getMessage(), e);
} catch (ArrayIndexOutOfBoundsException e) {
log.error("异常名称:「数组越界异常」,错误信息: {}", e.getMessage(), e);
} catch (Exception _error) {
log.error("异常名称:「未知通用异常」,错误信息: {}", _error.getMessage(), _error);
} }
return null; throw new RuntimeException(String.format("API调用异常「%S」",exceptionName));
} }
} }

View File

@ -16,7 +16,7 @@ import java.util.Map;
@Log4j2 @Log4j2
public class ReviewResolution { public class ReviewResolution {
@Autowired // @Autowired
private Client client; private Client client;
public DescribeFileResponseBodyDataMode DescribeFile(UploadDescribeFileMode uploadDescribeFileMode) { public DescribeFileResponseBodyDataMode DescribeFile(UploadDescribeFileMode uploadDescribeFileMode) {

View File

@ -1,7 +1,11 @@
package com.muyu.aliyun.bailian.config; package com.muyu.aliyun.bailian.config;
import com.aliyun.bailian20231229.Client; import com.aliyun.auth.credentials.Credential;
import com.aliyun.auth.credentials.provider.StaticCredentialProvider;
import com.aliyun.sdk.service.bailian20231229.AsyncClient;
import com.aliyun.teaopenapi.models.Config; import com.aliyun.teaopenapi.models.Config;
import com.muyu.aliyun.bailian.properties.AliYunBaiLianProperties;
import com.muyu.aliyun.config.OssConfig; import com.muyu.aliyun.config.OssConfig;
import darabonba.core.client.ClientOverrideConfiguration;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@ -11,7 +15,7 @@ import org.springframework.context.annotation.Configuration;
public class AlibabaCloudClientConfig { public class AlibabaCloudClientConfig {
@Autowired @Autowired
private OssConfig ossConfig; private AliYunBaiLianProperties aliYunBaiLianProperties;
/** /**
* Client Bean * Client Bean
@ -19,12 +23,17 @@ public class AlibabaCloudClientConfig {
* @throws Exception * @throws Exception
*/ */
@Bean @Bean
public Client createClient() throws Exception { public AsyncClient createClient() throws Exception {
Config config = new Config() StaticCredentialProvider provider = StaticCredentialProvider.create(Credential.builder()
.setAccessKeyId(ossConfig.getAccessKeyId()) .accessKeyId(aliYunBaiLianProperties.getAccessKeyId())
.setAccessKeySecret(ossConfig.getAccessKeySecret()); .accessKeySecret(aliYunBaiLianProperties.getAccessKeySecret())
.build());
config.endpoint = ossConfig.getEndpoint(); return AsyncClient.builder()
return new Client(config); .credentialsProvider(provider)
.overrideConfiguration(
ClientOverrideConfiguration.create()
.setEndpointOverride(aliYunBaiLianProperties.getEndpoint())
)
.build();
} }
} }

View File

@ -0,0 +1,37 @@
package com.muyu.aliyun.bailian.properties;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
/**
* @author dongzeliang
* @version 1.0
* @description:
* @date 2025/2/22 16:23
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Configuration
@ConfigurationProperties(prefix = "aliyun.bailian")
public class AliYunBaiLianProperties {
/**
* OSS
*/
private String endpoint;
/**
* 访ID
*/
private String accessKeyId;
/**
* 访accessKeyId
*/
private String accessKeySecret;
}

View File

@ -4,4 +4,9 @@ oss:
endpoint: https://oss-cn-hangzhou.aliyuncs.com endpoint: https://oss-cn-hangzhou.aliyuncs.com
accessKeyId: LTAI5tLvo45NpqjoH11G1beU accessKeyId: LTAI5tLvo45NpqjoH11G1beU
accessKeySecret: NjfA4hBwban4W8Db7RBwDJd0pBHJeM accessKeySecret: NjfA4hBwban4W8Db7RBwDJd0pBHJeM
bucketName: idicc-pangu-prod bucketName: idicc-pangu-prod
aliyun:
bailian:
endpoint: bailian.cn-beijing.aliyuncs.com
accessKeyId: LTAI5tLvo45NpqjoH11G1beU
accessKeySecret: NjfA4hBwban4W8Db7RBwDJd0pBHJeM