From c7276f4dd1968b739ff5098d517f77a4f0b7d52c Mon Sep 17 00:00:00 2001
From: ChenJiaHe <763432473@qq.com>
Date: 星期一, 10 五月 2021 16:49:37 +0800
Subject: [PATCH] 华为云OBS优化

---
 src/main/java/com/hx/mybatisTool/SqlSentence.java |   15 +++++++
 src/main/java/com/hx/util/OBSUtil.java            |   53 +++++++++++++++++++++++---
 2 files changed, 62 insertions(+), 6 deletions(-)

diff --git a/src/main/java/com/hx/mybatisTool/SqlSentence.java b/src/main/java/com/hx/mybatisTool/SqlSentence.java
index e0705c9..dd7c9a7 100644
--- a/src/main/java/com/hx/mybatisTool/SqlSentence.java
+++ b/src/main/java/com/hx/mybatisTool/SqlSentence.java
@@ -13,7 +13,11 @@
  */
 public class SqlSentence {
 
+	/**鎵ц璇彞*/
 	private String sqlSentence;
+
+	/**鏂板瀛樺湪鏌ヨ鍒ゆ柇*/
+	private String whereExist;
 
 	private Map<String,Object> m;
     /**鎺掑簭*/
@@ -161,6 +165,17 @@
     {
         return (startPage - 1) * pageNum;
     }
+
+	public String getWhereExist() {
+		return whereExist;
+	}
+
+	public void setWhereExist(String whereExist) {
+		if(StringUtils.isNull(whereExist)){
+			whereExist = null;
+		}
+		this.whereExist = whereExist;
+	}
 }
 
 
diff --git a/src/main/java/com/hx/util/OBSUtil.java b/src/main/java/com/hx/util/OBSUtil.java
index 26ce457..fc74c7b 100644
--- a/src/main/java/com/hx/util/OBSUtil.java
+++ b/src/main/java/com/hx/util/OBSUtil.java
@@ -2,6 +2,8 @@
 
 import com.obs.services.ObsClient;
 import com.obs.services.exception.ObsException;
+import com.obs.services.model.HeaderResponse;
+import com.obs.services.model.ObsBucket;
 import com.obs.services.model.PutObjectResult;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -24,12 +26,13 @@
 	 * @param localFile 鍥剧墖鏂囦欢
 	 * @param ak 璁块棶绉橀挜
 	 * @param sk 璁块棶绉橀挜
-	 * @param endPoint 瀛樺偍妗�
+	 * @param endPoint 鍖哄煙
+	 * @param bucketName 瀛樺偍妗�
 	 * @param fileName 鏂囦欢鍚嶇О锛堝甫鍚庣紑锛夛紝涓虹┖鏃惰嚜鍔ㄧ敓鎴�
 	 * @return
 	 * @throws IOException
 	 */
-	public static PutObjectResult uploadImg(MultipartFile localFile,String ak,String sk,String endPoint,String fileName) throws IOException {
+	public static PutObjectResult uploadImg(MultipartFile localFile,String ak,String sk,String endPoint,String bucketName,String fileName) throws IOException {
 
 		//娌℃湁鍚嶆鐨勬椂鍊欒嚜鍔ㄧ敓鎴�
 		if(StringUtils.isNull(fileName)){
@@ -44,7 +47,7 @@
 		//鍒濆鍖朞BS瀹㈡埛绔�
 		ObsClient obsClient = new ObsClient(ak, sk, endPoint);
 		try{
-			putObjectResult = obsClient.putObject(endPoint, fileName,localFile.getInputStream());
+			putObjectResult = obsClient.putObject(bucketName, fileName,localFile.getInputStream());
 		}catch (ObsException e){
 			logger.error("鍗庝负浜� OBS 涓婁紶鏂囦欢鎶ラ敊 ");
 			logger.error("HTTP Code: " + e.getResponseCode());
@@ -53,6 +56,7 @@
 
 			logger.error("Request ID:" + e.getErrorRequestId());
 			logger.error("Host ID:" + e.getErrorHostId());
+			e.printStackTrace();
 		}finally {
 			if(obsClient != null){
 				obsClient.close();
@@ -67,12 +71,13 @@
 	 * @param localFile 瀛樺偍鏂囦欢
 	 * @param ak 璁块棶绉橀挜
 	 * @param sk 璁块棶绉橀挜
-	 * @param endPoint 瀛樺偍妗�
+	 * @param endPoint 鍖哄煙
+	 * @param bucketName 瀛樺偍妗�
 	 * @param fileName 鏂囦欢鍚嶇О锛堝甫鍚庣紑锛夛紝涓虹┖鏃惰嚜鍔ㄧ敓鎴�
 	 * @return
 	 * @throws IOException
 	 */
-	public static PutObjectResult uploadImg(File localFile,String ak,String sk,String endPoint,String fileName) throws IOException {
+	public static PutObjectResult uploadImg(File localFile,String ak,String sk,String endPoint,String bucketName,String fileName) throws IOException {
 
 		//娌℃湁鍚嶆鐨勬椂鍊欒嚜鍔ㄧ敓鎴�
 		if(StringUtils.isNull(fileName)){
@@ -87,7 +92,7 @@
 		//鍒濆鍖朞BS瀹㈡埛绔�
 		ObsClient obsClient = new ObsClient(ak, sk, endPoint);
 		try{
-			putObjectResult = obsClient.putObject(endPoint, fileName,localFile);
+			putObjectResult = obsClient.putObject(bucketName, fileName,localFile);
 		}catch (ObsException e){
 			logger.error("鍗庝负浜� OBS 涓婁紶鏂囦欢鎶ラ敊 ");
 			logger.error("HTTP Code: " + e.getResponseCode());
@@ -96,6 +101,7 @@
 
 			logger.error("Request ID:" + e.getErrorRequestId());
 			logger.error("Host ID:" + e.getErrorHostId());
+			e.printStackTrace();
 		}finally {
 			if(obsClient != null){
 				obsClient.close();
@@ -105,4 +111,39 @@
 
 	}
 
+	/** 鍒涘缓妗�
+	 * @param ak 璁块棶绉橀挜
+	 * @param sk 璁块棶绉橀挜
+	 * @param endPoint 鍖哄煙
+	 * @param bucketName 瀛樺偍妗�
+	 * @return
+	 * @throws IOException
+	 */
+	public static HeaderResponse createBucket(String ak,String sk,String endPoint,String bucketName) throws IOException {
+
+		HeaderResponse response = null;
+
+		//鍒濆鍖朞BS瀹㈡埛绔�
+		ObsClient obsClient = new ObsClient(ak, sk, endPoint);
+		try{
+			response = obsClient.createBucket(bucketName);
+		}catch (ObsException e){
+
+			logger.error("鍗庝负浜� OBS 鍒涘缓妗舵姤閿� ");
+			logger.error("HTTP Code: " + e.getResponseCode());
+			logger.error("Error Code:" + e.getErrorCode());
+			logger.error("Error Message: " + e.getErrorMessage());
+
+			logger.error("Request ID:" + e.getErrorRequestId());
+			logger.error("Host ID:" + e.getErrorHostId());
+			e.printStackTrace();
+		}finally {
+			if(obsClient != null){
+				obsClient.close();
+			}
+		}
+		return response;
+	}
+
+
 }

--
Gitblit v1.8.0