From 60acccaebef503315c852f31677b44eb3fd40a4f Mon Sep 17 00:00:00 2001
From: jiangping <jp@doumee.com>
Date: 星期三, 25 六月 2025 10:29:29 +0800
Subject: [PATCH] 提交一把订单

---
 server/service/src/main/java/com/doumee/core/utils/aliyun/ALiYunUtil.java |   62 ++++++++++++++++++++++++++++++
 1 files changed, 61 insertions(+), 1 deletions(-)

diff --git a/server/service/src/main/java/com/doumee/core/utils/aliyun/ALiYunUtil.java b/server/service/src/main/java/com/doumee/core/utils/aliyun/ALiYunUtil.java
index 8e465b6..400a43c 100644
--- a/server/service/src/main/java/com/doumee/core/utils/aliyun/ALiYunUtil.java
+++ b/server/service/src/main/java/com/doumee/core/utils/aliyun/ALiYunUtil.java
@@ -5,6 +5,9 @@
 import com.aliyun.oss.ClientException;
 import com.aliyun.oss.OSSClient;
 import com.aliyun.oss.OSSException;
+import com.aliyun.oss.event.ProgressEvent;
+import com.aliyun.oss.event.ProgressEventType;
+import com.aliyun.oss.event.ProgressListener;
 import com.aliyun.oss.model.*;
 import com.aliyun.sdk.service.cloudauth20190307.AsyncClient;
 import com.aliyun.sdk.service.cloudauth20190307.models.Id2MetaVerifyRequest;
@@ -17,6 +20,7 @@
 import java.io.InputStream;
 import java.net.URL;
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.CompletableFuture;
@@ -520,7 +524,7 @@
 
     }
 
-    public boolean uploadOnlineObject(InputStream inputStream, String bucketName, String key,
+    public boolean uploadOnlineObjectNew(InputStream inputStream, String bucketName, String key,
                                       String mime) throws OSSException, ClientException, IOException {
         if (inputStream != null) {
             // 鍒ゆ柇鏄惁瀛樺湪锛屼笉瀛樺湪鍒涘缓
@@ -564,7 +568,63 @@
         return false;
 
     }
+    public static ProgressModel queryProgressModel(String id){
+        return PutObjectProgressListenerBiz.queryProgressModel(id);
+    }
+    public boolean uploadOnlineObject(InputStream inputStream, String bucketName, String key,String tempId,
+                                      String mime) throws OSSException, ClientException, IOException {
+        try {
+            isExistBucket(bucketName);
+            ObjectMetadata objectMeta = new ObjectMetadata();
+            objectMeta.setContentLength(inputStream.available());
+            // 鍙互鍦╩etadata涓爣璁版枃浠剁被鍨�
+            if (StringUtils.isNotBlank(mime)) {
+                objectMeta.setContentType(mime);
+            }
+            PutObjectRequest putObjectRequest = null;
+            if(StringUtils.isNotBlank(tempId)){
+                ProgressModel pmodel = new ProgressModel();
+                pmodel.setKey(key);
+                pmodel.setId(tempId);
+                pmodel.setStartDate(new Date());
+                putObjectRequest = new PutObjectRequest(bucketName, key,
+                        inputStream).withProgressListener(new PutObjectProgressListenerBiz(pmodel));
+            }else{
+                putObjectRequest = new PutObjectRequest(bucketName, key,
+                        inputStream);
+            }
+            PutObjectResult putObjectResult = client.putObject(putObjectRequest);
 
+            // 涓嬭浇鏂囦欢鐨勫悓鏃舵寚瀹氳繘搴︽潯鍙傛暟銆傛澶凣etObjectProgressListenerDemo涓鸿皟鐢ㄧ被鐨勭被鍚嶏紝璇峰湪瀹為檯浣跨敤鏃舵浛鎹负鐩稿簲鐨勭被鍚嶃��
+//            ossClient.getObject(new GetObjectRequest(bucketName,objectName).
+//                    <GetObjectRequest>withProgressListener(new GetObjectProgressListenerDemo()));
+
+        } catch (OSSException oe) {
+            System.out.println("Caught an OSSException, which means your request made it to OSS, "
+                    + "but was rejected with an error response for some reason.");
+            System.out.println("Error Message:" + oe.getErrorMessage());
+            System.out.println("Error Code:" + oe.getErrorCode());
+            System.out.println("Request ID:" + oe.getRequestId());
+            System.out.println("Host ID:" + oe.getHostId());
+        } catch (ClientException ce) {
+            System.out.println("Caught an ClientException, which means the client encountered "
+                    + "a serious internal problem while trying to communicate with OSS, "
+                    + "such as not being able to access the network.");
+            System.out.println("Error Message:" + ce.getMessage());
+        } finally {
+            if (inputStream != null) {
+                // 鍒ゆ柇鏄惁瀛樺湪锛屼笉瀛樺湪鍒涘缓
+                inputStream.close();
+            }
+            if (client != null) {
+                client.shutdown();
+            }
+        }
+
+
+        return false;
+
+    }
 
 
 

--
Gitblit v1.9.3