feat(): ApplyFileUploadLease 申请文档上传租约
parent
952595dbb7
commit
c2f011a63b
5
pom.xml
5
pom.xml
|
@ -58,5 +58,10 @@
|
|||
<artifactId>tea-util</artifactId>
|
||||
<version>0.2.23</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>alibabacloud-bailian20231229</artifactId>
|
||||
<version>2.0.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -19,7 +19,7 @@ import java.util.Map;
|
|||
public class AddDataManagement {
|
||||
|
||||
|
||||
@Autowired
|
||||
// @Autowired
|
||||
private Client client;
|
||||
|
||||
public AddFileResponseBodyDataMode addFile(UploadDataManagementMode uploadDataManagementMode) {
|
||||
|
|
|
@ -1,48 +1,45 @@
|
|||
// This file is auto-generated, don't edit it. Thanks.
|
||||
package com.muyu.aliyun.bailian;
|
||||
|
||||
import com.aliyun.bailian20231229.Client;
|
||||
import com.aliyun.bailian20231229.models.ApplyFileUploadLeaseResponse;
|
||||
import com.aliyun.bailian20231229.models.ApplyFileUploadLeaseResponseBody;
|
||||
import com.aliyun.bailian20231229.models.ApplyFileUploadLeaseRequest;
|
||||
import com.aliyun.sdk.service.bailian20231229.AsyncClient;
|
||||
import com.aliyun.sdk.service.bailian20231229.models.ApplyFileUploadLeaseRequest;
|
||||
import com.aliyun.sdk.service.bailian20231229.models.ApplyFileUploadLeaseResponse;
|
||||
import com.aliyun.sdk.service.bailian20231229.models.ApplyFileUploadLeaseResponseBody;
|
||||
import com.aliyun.tea.*;
|
||||
import com.aliyun.teautil.models.RuntimeOptions;
|
||||
import com.muyu.aliyun.bailian.data.FileUploadLeaseMode;
|
||||
import com.muyu.aliyun.bailian.data.fixed.UploadLeaseParamsMode;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Component
|
||||
@Log4j2
|
||||
public class ApplyLease {
|
||||
|
||||
@Autowired
|
||||
private Client client;
|
||||
private AsyncClient asyncClient;
|
||||
|
||||
public UploadLeaseParamsMode applyFileUploadLease(FileUploadLeaseMode fileUploadLeaseModel) {
|
||||
ApplyFileUploadLeaseRequest applyFileUploadLeaseRequest = new ApplyFileUploadLeaseRequest();
|
||||
RuntimeOptions runtime = new RuntimeOptions();
|
||||
Map<String, String> headers = new HashMap<>();
|
||||
|
||||
applyFileUploadLeaseRequest.setFileName(fileUploadLeaseModel.getFileName());
|
||||
applyFileUploadLeaseRequest.setMd5(fileUploadLeaseModel.getMd5());
|
||||
applyFileUploadLeaseRequest.setSizeInBytes(fileUploadLeaseModel.getSizeInBytes());
|
||||
applyFileUploadLeaseRequest.setCategoryType(fileUploadLeaseModel.getCategoryId());
|
||||
|
||||
ApplyFileUploadLeaseRequest applyFileUploadLeaseRequest = ApplyFileUploadLeaseRequest.builder()
|
||||
.fileName(fileUploadLeaseModel.getFileName())
|
||||
.md5(fileUploadLeaseModel.getMd5())
|
||||
.sizeInBytes(fileUploadLeaseModel.getSizeInBytes())
|
||||
.categoryId(fileUploadLeaseModel.getCategoryId())
|
||||
.workspaceId(fileUploadLeaseModel.getWorkspaceId())
|
||||
.build();
|
||||
String exceptionName = "";
|
||||
try {
|
||||
// 复制代码运行请自行打印 API 的返回值
|
||||
ApplyFileUploadLeaseResponse applyFileUploadLeaseResponse =
|
||||
client.applyFileUploadLeaseWithOptions(fileUploadLeaseModel.getCategoryId(), fileUploadLeaseModel.getWorkspaceId(), applyFileUploadLeaseRequest, headers, runtime);
|
||||
CompletableFuture<ApplyFileUploadLeaseResponse> applyFileUploadLeaseResponseCompletableFuture = asyncClient.applyFileUploadLease(applyFileUploadLeaseRequest);
|
||||
ApplyFileUploadLeaseResponse applyFileUploadLeaseResponse = applyFileUploadLeaseResponseCompletableFuture.get();
|
||||
if (applyFileUploadLeaseResponse.getStatusCode() != 200) {
|
||||
throw new RuntimeException(applyFileUploadLeaseResponse.toString());
|
||||
}
|
||||
ApplyFileUploadLeaseResponseBody body = applyFileUploadLeaseResponse.getBody();
|
||||
ApplyFileUploadLeaseResponseBody.ApplyFileUploadLeaseResponseBodyData data = body.getData();
|
||||
ApplyFileUploadLeaseResponseBody.ApplyFileUploadLeaseResponseBodyDataParam param = data.getParam();
|
||||
ApplyFileUploadLeaseResponseBody applyFileUploadLeaseResponseBody = applyFileUploadLeaseResponse.getBody();
|
||||
ApplyFileUploadLeaseResponseBody.Param param = applyFileUploadLeaseResponseBody.getData().getParam();
|
||||
|
||||
|
||||
log.info("param:「{}」", param);
|
||||
return UploadLeaseParamsMode.builder()
|
||||
.Url(param.getUrl())
|
||||
|
@ -50,7 +47,6 @@ public class ApplyLease {
|
|||
.build();
|
||||
|
||||
} catch (TeaException error) {
|
||||
String exceptionName;
|
||||
switch (error.getCode()) {
|
||||
case "SDK.ConnectTimeout":
|
||||
exceptionName = "网络连接超时";
|
||||
|
@ -80,16 +76,11 @@ public class ApplyLease {
|
|||
exceptionName = "未知阿里云 API 异常";
|
||||
}
|
||||
log.error("异常名称:「{}」,错误码: {}, 错误信息: {}, 错误数据: {}", exceptionName, error.getCode(), error.getMessage(), error.getData());
|
||||
} catch (NullPointerException e) {
|
||||
log.error("异常名称:「空指针异常」,错误信息: {}", e.getMessage(), e);
|
||||
} catch (ClassCastException e) {
|
||||
log.error("异常名称:「类型转换异常」,错误信息: {}", e.getMessage(), e);
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
log.error("异常名称:「数组越界异常」,错误信息: {}", e.getMessage(), e);
|
||||
} catch (Exception _error) {
|
||||
log.error("异常名称:「未知通用异常」,错误信息: {}", _error.getMessage(), _error);
|
||||
}catch (Exception exception) {
|
||||
log.error("异常名称:「未知通用异常」,错误信息: {}", exception.getMessage(), exception);
|
||||
throw new RuntimeException(exception);
|
||||
}
|
||||
return null;
|
||||
throw new RuntimeException(String.format("API调用异常:「%S」",exceptionName));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ import java.util.Map;
|
|||
@Log4j2
|
||||
public class ReviewResolution {
|
||||
|
||||
@Autowired
|
||||
// @Autowired
|
||||
private Client client;
|
||||
|
||||
public DescribeFileResponseBodyDataMode DescribeFile(UploadDescribeFileMode uploadDescribeFileMode) {
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
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.muyu.aliyun.bailian.properties.AliYunBaiLianProperties;
|
||||
import com.muyu.aliyun.config.OssConfig;
|
||||
import darabonba.core.client.ClientOverrideConfiguration;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
@ -11,7 +15,7 @@ import org.springframework.context.annotation.Configuration;
|
|||
public class AlibabaCloudClientConfig {
|
||||
|
||||
@Autowired
|
||||
private OssConfig ossConfig;
|
||||
private AliYunBaiLianProperties aliYunBaiLianProperties;
|
||||
|
||||
/**
|
||||
* 创建 Client Bean
|
||||
|
@ -19,12 +23,17 @@ public class AlibabaCloudClientConfig {
|
|||
* @throws Exception 创建过程中可能抛出的异常
|
||||
*/
|
||||
@Bean
|
||||
public Client createClient() throws Exception {
|
||||
Config config = new Config()
|
||||
.setAccessKeyId(ossConfig.getAccessKeyId())
|
||||
.setAccessKeySecret(ossConfig.getAccessKeySecret());
|
||||
|
||||
config.endpoint = ossConfig.getEndpoint();
|
||||
return new Client(config);
|
||||
public AsyncClient createClient() throws Exception {
|
||||
StaticCredentialProvider provider = StaticCredentialProvider.create(Credential.builder()
|
||||
.accessKeyId(aliYunBaiLianProperties.getAccessKeyId())
|
||||
.accessKeySecret(aliYunBaiLianProperties.getAccessKeySecret())
|
||||
.build());
|
||||
return AsyncClient.builder()
|
||||
.credentialsProvider(provider)
|
||||
.overrideConfiguration(
|
||||
ClientOverrideConfiguration.create()
|
||||
.setEndpointOverride(aliYunBaiLianProperties.getEndpoint())
|
||||
)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -4,4 +4,9 @@ oss:
|
|||
endpoint: https://oss-cn-hangzhou.aliyuncs.com
|
||||
accessKeyId: LTAI5tLvo45NpqjoH11G1beU
|
||||
accessKeySecret: NjfA4hBwban4W8Db7RBwDJd0pBHJeM
|
||||
bucketName: idicc-pangu-prod
|
||||
bucketName: idicc-pangu-prod
|
||||
aliyun:
|
||||
bailian:
|
||||
endpoint: bailian.cn-beijing.aliyuncs.com
|
||||
accessKeyId: LTAI5tLvo45NpqjoH11G1beU
|
||||
accessKeySecret: NjfA4hBwban4W8Db7RBwDJd0pBHJeM
|
Loading…
Reference in New Issue