From 66119b66f1009157d662c9e9869e4c04f9472bf2 Mon Sep 17 00:00:00 2001
From: java110 <928255095@qq.com>
Date: 星期四, 24 十二月 2020 18:08:22 +0800
Subject: [PATCH] 加入 oss 存储 逻辑
---
java110-utils/src/main/java/com/java110/utils/util/OSSUtil.java | 169 +++++++++++++++
service-common/src/main/java/com/java110/common/smo/impl/FileInnerServiceSMOImpl.java | 53 ++-
java110-core/src/main/java/com/java110/core/client/OssUploadTemplate.java | 246 ++++++++++++++++++++++
java110-utils/pom.xml | 20 -
java110-core/src/main/java/com/java110/core/client/FtpUploadTemplate.java | 56 +++-
pom.xml | 65 -----
service-common/pom.xml | 12
7 files changed, 496 insertions(+), 125 deletions(-)
diff --git a/java110-core/src/main/java/com/java110/core/client/FtpUploadTemplate.java b/java110-core/src/main/java/com/java110/core/client/FtpUploadTemplate.java
index 9ffee77..c3acd86 100644
--- a/java110-core/src/main/java/com/java110/core/client/FtpUploadTemplate.java
+++ b/java110-core/src/main/java/com/java110/core/client/FtpUploadTemplate.java
@@ -2,7 +2,6 @@
import com.java110.utils.util.Base64Convert;
import com.java110.utils.util.DateUtil;
-import com.tencentcloudapi.tci.v20190318.models.FaceExpressionResult;
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
@@ -43,10 +42,11 @@
String userName, String userPassword, String ftpPath) {
String fileName = "";
FTPClient ftpClient = null;
+ ByteArrayInputStream is = null;
try {
ftpClient = new FTPClient();
// request.setCharacterEncoding("utf-8");
- if(!ftpClient.isConnected()){
+ if (!ftpClient.isConnected()) {
ftpClient.connect(server, port);
}
ftpClient.login(userName, userPassword);
@@ -86,9 +86,9 @@
byte[] context = Base64Convert.base64ToByte(imageBase64);
- ByteArrayInputStream is = new ByteArrayInputStream(context);
+ is = new ByteArrayInputStream(context);
boolean saveFlag = ftpClient.storeFile(fileName, is);
- is.close();
+
if (!saveFlag) {
throw new IllegalArgumentException("瀛樺偍鏂囦欢澶辫触");
}
@@ -98,6 +98,9 @@
} finally {
try {
ftpClient.disconnect();
+ if (is != null) {
+ is.close();
+ }
} catch (IOException e) {
e.printStackTrace();
logger.error("鍏抽棴ftpClient 澶辫触", e);
@@ -117,7 +120,7 @@
try {
// request.setCharacterEncoding("utf-8");
ftpClient = new FTPClient();
- if(!ftpClient.isConnected()){
+ if (!ftpClient.isConnected()) {
ftpClient.connect(server, port);
}
ftpClient.login(userName, userPassword);
@@ -166,7 +169,7 @@
FTPClient ftpClient = null;
try {
ftpClient = new FTPClient();
- if(!ftpClient.isConnected()){
+ if (!ftpClient.isConnected()) {
ftpClient.connect(server, port);
}
ftpClient.login(userName, userPassword);
@@ -212,18 +215,19 @@
public static void main(String[] args) {
FtpUploadTemplate ftpUploadTemplate = new FtpUploadTemplate();
- String img = ftpUploadTemplate.download("/hc/img/20200518/","ed05abae-2eca-40ff-81a8-b586ff2e6a36.jpg",
- "118.89.243.11",617,"hcdemo","45j74jpWTf7bNhnC");
+ String img = ftpUploadTemplate.download("/hc/img/20200518/", "ed05abae-2eca-40ff-81a8-b586ff2e6a36.jpg",
+ "118.89.243.11", 617, "hcdemo", "45j74jpWTf7bNhnC");
- System.out.printf("img="+img);
+ System.out.printf("img=" + img);
}
public String download(String remotePath, String fileName, String server, int port, String userName, String userPassword) {
InputStream is = null;
ByteArrayOutputStream bos = null;
+ ByteArrayInputStream fis = null;
FTPClient ftpClient = new FTPClient();
try {
- if(!ftpClient.isConnected()){
+ if (!ftpClient.isConnected()) {
ftpClient.connect(server, port);
}
ftpClient.login(userName, userPassword);
@@ -246,11 +250,9 @@
while (-1 != (length = is.read(buf, 0, buf.length))) {
bos.write(buf, 0, length);
}
- ByteArrayInputStream fis = new ByteArrayInputStream(
+ fis = new ByteArrayInputStream(
bos.toByteArray());
bos.flush();
- is.close();
- bos.close();
byte[] buffer = new byte[fis.available()];
int offset = 0;
int numRead = 0;
@@ -260,18 +262,32 @@
if (offset != buffer.length) {
throw new IOException("Could not completely read file ");
}
- fis.close();
return Base64Convert.byteToBase64(buffer);
} catch (Exception e) {
logger.error("ftp閫氳繃鏂囦欢鍚嶇О鑾峰彇杩滅▼鏂囦欢娴�", e);
} finally {
+ if (bos != null) {
+ try {
+ bos.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ if (is != null) {
+ try {
+ is.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ if(fis != null){
+ try {
+ fis.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
try {
- if(bos != null){
- bos.close();
- }
- if(is !=null) {
- is.close();
- }
closeConnect(ftpClient);
} catch (Exception e) {
e.printStackTrace();
diff --git a/java110-core/src/main/java/com/java110/core/client/OssUploadTemplate.java b/java110-core/src/main/java/com/java110/core/client/OssUploadTemplate.java
new file mode 100644
index 0000000..146c90f
--- /dev/null
+++ b/java110-core/src/main/java/com/java110/core/client/OssUploadTemplate.java
@@ -0,0 +1,246 @@
+package com.java110.core.client;
+
+import com.aliyun.oss.OSSClient;
+import com.java110.utils.util.Base64Convert;
+import com.java110.utils.util.DateUtil;
+import com.java110.utils.util.OSSUtil;
+import org.apache.commons.net.ftp.FTP;
+import org.apache.commons.net.ftp.FTPClient;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.*;
+import java.util.UUID;
+
+@Component
+public class OssUploadTemplate {
+ private static Logger logger = LoggerFactory.getLogger(OssUploadTemplate.class);
+
+ /*
+ * private static String server = "www.datasvisser.cn"; //鍦板潃 private static
+ * int port = 41023;//绔彛鍙� private static String userName = "jntechFTP1";//鐧诲綍鍚�
+ * private static String userPassword ="MXUsssMjhssE+*=a3C4\\0";//瀵嗙爜
+ */
+ private static String ftpPath = "uploadFiles"; // 鏂囦欢涓婁紶鐩綍
+
+ private static String LOCAL_CHARSET = "GBK";
+ private static String SERVER_CHARSET = "ISO-8859-1";
+ private final static String localpath = "F:/";//涓嬭浇鍒癋鐩樹笅
+ private final static String fileSeparator = System.getProperty("file.separator");
+
+ private final static String DEFAULT_IMG_SUFFIX = ".jpg";
+
+ private final static String IMAGE_DEFAULT_PATH = "img/";
+
+ /*
+ *鍥剧墖涓婁紶宸ュ叿鏂规硶
+ * 榛樿涓婁紶鑷� img 鏂囦欢涓嬬殑褰撳墠鏃ユ湡涓�
+ */
+ public String upload(String imageBase64, String server, int port,
+ String userName, String userPassword, String ftpPath) {
+ String fileName = "";
+ OSSClient ossClient = null;
+ ByteArrayInputStream is = null;
+ try {
+ ossClient = OSSUtil.getOSSClient();
+ fileName = UUID.randomUUID().toString();
+ ftpPath = ftpPath + IMAGE_DEFAULT_PATH + DateUtil.getNowII() + "/" + fileName;
+ if (imageBase64.contains("data:image/png;base64,")) {
+ imageBase64 = imageBase64.replace("data:image/png;base64,", "");
+ fileName += ".png";
+ } else if (imageBase64.contains("data:image/jpeg;base64,")) {
+ imageBase64 = imageBase64.replace("data:image/jpeg;base64,", "");
+ fileName += ".jpg";
+ } else if (imageBase64.contains("data:image/webp;base64,")) {
+ imageBase64 = imageBase64.replace("data:image/webp;base64,", "");
+ fileName += ".jpg";
+ } else if (imageBase64.contains("data:application/octet-stream;base64,")) {
+ imageBase64 = imageBase64.replace("data:application/octet-stream;base64,", "");
+ fileName += ".jpg";
+ } else {
+ fileName += ".jpg";
+ }
+
+ byte[] context = Base64Convert.base64ToByte(imageBase64);
+ is = new ByteArrayInputStream(context);
+ OSSUtil.uploadByInputStream(ossClient, is, "java110", ftpPath);
+ } catch (Exception e) {
+ logger.error("涓婁紶鏂囦欢澶辫触", e);
+ throw new IllegalArgumentException("涓婁紶鏂囦欢澶辫触");
+ } finally {
+ if (is != null) {
+ try {
+ is.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ return ftpPath;
+ }
+
+
+ /*
+ *鏂囦欢涓婁紶宸ュ叿鏂规硶
+ */
+ public String upload(MultipartFile uploadFile, String server, int port,
+ String userName, String userPassword, String ftpPath) {
+ String fileName = "";
+ OSSClient ossClient = null;
+ InputStream is = null;
+ try {
+ ossClient = OSSUtil.getOSSClient();
+ fileName = UUID.randomUUID().toString() + "." + uploadFile.getOriginalFilename().substring(uploadFile.getOriginalFilename().lastIndexOf(".") + 1);
+ is = uploadFile.getInputStream();
+ OSSUtil.uploadByInputStream(ossClient, is, "java110", ftpPath);
+ } catch (Exception e) {
+ // logger.error("涓婁紶鏂囦欢澶辫触", e);
+ throw new IllegalArgumentException("涓婁紶鏂囦欢澶辫触");
+ } finally {
+ if (is != null) {
+ try {
+ is.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ return fileName;
+ }
+
+ /*
+ *鏂囦欢涓嬭浇宸ュ叿鏂规硶
+ */
+ public byte[] downFileByte(String remotePath, String fileName, String server, int port, String userName, String userPassword) {
+ byte[] return_arraybyte = null;
+ OSSClient ossClient = null;
+ ByteArrayOutputStream byteOut = null;
+ InputStream ins = null;
+ ByteArrayInputStream fis = null;
+ try {
+ ossClient = OSSUtil.getOSSClient();
+ OSSUtil.getInputStreamByOSS(ossClient, "java110", remotePath + fileName);
+ byteOut = new ByteArrayOutputStream();
+ byte[] buf = new byte[2048];
+ int bufsize = 0;
+ while (ins != null && (bufsize = ins.read(buf, 0, buf.length)) != -1) {
+ byteOut.write(buf, 0, bufsize);
+ }
+ fis = new ByteArrayInputStream(byteOut.toByteArray());
+ byteOut.flush();
+ byteOut.close();
+ byte[] buffer = new byte[fis.available()];
+ int offset = 0;
+ int numRead = 0;
+ while (offset < buffer.length && (numRead = fis.read(buffer, offset, buffer.length - offset)) >= 0) {
+ offset += numRead;
+ }
+ if (offset != buffer.length) {
+ throw new IOException("Could not completely read file ");
+ }
+
+ return_arraybyte = buffer;
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ logger.error("浠巉tp璇诲彇鏂囦欢澶辫触", e);
+ } finally {
+ if (byteOut != null) {
+ try {
+ byteOut.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ if (fis != null) {
+ try {
+ fis.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ if (ins != null) {
+ try {
+ ins.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ return return_arraybyte;
+ }
+
+ public static void main(String[] args) {
+ OssUploadTemplate ftpUploadTemplate = new OssUploadTemplate();
+ String img = ftpUploadTemplate.download("/hc/img/20200518/", "ed05abae-2eca-40ff-81a8-b586ff2e6a36.jpg",
+ "118.89.243.11", 617, "hcdemo", "45j74jpWTf7bNhnC");
+
+ System.out.printf("img=" + img);
+ }
+
+ public String download(String remotePath, String fileName, String server, int port, String userName, String userPassword) {
+ OSSClient ossClient = null;
+ ByteArrayOutputStream bos = null;
+ InputStream is = null;
+ ByteArrayInputStream fis = null;
+ try {
+ ossClient = OSSUtil.getOSSClient();
+ String f = new String(
+ (remotePath + fileName).getBytes("GBK"),
+ FTP.DEFAULT_CONTROL_ENCODING);
+ is = OSSUtil.getInputStreamByOSS(ossClient, "java110", remotePath + fileName);
+ if (null == is) {
+ throw new FileNotFoundException(remotePath);
+ }
+ bos = new ByteArrayOutputStream();
+ int length;
+ byte[] buf = new byte[2048];
+ while (-1 != (length = is.read(buf, 0, buf.length))) {
+ bos.write(buf, 0, length);
+ }
+ fis = new ByteArrayInputStream(
+ bos.toByteArray());
+ bos.flush();
+
+ byte[] buffer = new byte[fis.available()];
+ int offset = 0;
+ int numRead = 0;
+ while (offset < buffer.length && (numRead = fis.read(buffer, offset, buffer.length - offset)) >= 0) {
+ offset += numRead;
+ }
+ if (offset != buffer.length) {
+ throw new IOException("Could not completely read file ");
+ }
+
+ return Base64Convert.byteToBase64(buffer);
+ } catch (Exception e) {
+ logger.error("ftp閫氳繃鏂囦欢鍚嶇О鑾峰彇杩滅▼鏂囦欢娴�", e);
+ } finally {
+ if (bos != null) {
+ try {
+ bos.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ if (fis != null) {
+ try {
+ fis.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ if (is != null) {
+ try {
+ is.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ return null;
+ }
+
+}
diff --git a/java110-utils/pom.xml b/java110-utils/pom.xml
index dae4ec6..a346146 100644
--- a/java110-utils/pom.xml
+++ b/java110-utils/pom.xml
@@ -30,26 +30,10 @@
<groupId>com.java110</groupId>
<artifactId>java110-interface</artifactId>
</dependency>
- <!--
<dependency>
- <groupId>org.apache.axis</groupId>
- <artifactId>axis</artifactId>
+ <groupId>com.aliyun.oss</groupId>
+ <artifactId>aliyun-sdk-oss</artifactId>
</dependency>
-
- <dependency>
- <groupId>org.apache.axis</groupId>
- <artifactId>axis-jaxrpc</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.axis</groupId>
- <artifactId>axis-saaj</artifactId>
- </dependency>
- <dependency>
- <groupId>wsdl4j</groupId>
- <artifactId>wsdl4j</artifactId>
- </dependency>
- -->
-
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
diff --git a/java110-utils/src/main/java/com/java110/utils/util/OSSUtil.java b/java110-utils/src/main/java/com/java110/utils/util/OSSUtil.java
new file mode 100644
index 0000000..8b3e3c9
--- /dev/null
+++ b/java110-utils/src/main/java/com/java110/utils/util/OSSUtil.java
@@ -0,0 +1,169 @@
+package com.java110.utils.util;
+
+import com.aliyun.oss.OSSClient;
+import com.aliyun.oss.model.OSSObject;
+import com.aliyun.oss.model.OSSObjectSummary;
+import com.aliyun.oss.model.ObjectListing;
+import com.java110.utils.cache.MappingCache;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+public class OSSUtil {
+
+ public static final String DOMAIN = "OSS";
+ public static final String OSS_SWITCH = "OSS_SWITCH";
+ public static final String OSS_SWITCH_OSS = "OSS";
+ public static final String ENDPOINT = "endpoint";
+ public static final String ACCESS_KEY_ID = "accessKeyId";
+ public static final String ACCESS_KEY_SECRET = "accessKeySecret";
+
+ /**
+ * @return OSSClient oss瀹㈡埛绔�
+ * @throws
+ * @Title: getOSSClient
+ * @Description: 鑾峰彇oss瀹㈡埛绔�
+ */
+ public static OSSClient getOSSClient() {
+ String endpoint = MappingCache.getValue(DOMAIN, ENDPOINT);
+ // 闃块噷浜戜富璐﹀彿AccessKey鎷ユ湁鎵�鏈堿PI鐨勮闂潈闄愶紝椋庨櫓寰堥珮銆傚己鐑堝缓璁偍鍒涘缓骞朵娇鐢≧AM璐﹀彿杩涜API璁块棶鎴栨棩甯歌繍缁达紝璇风櫥褰昲ttps://ram.console.aliyun.com 鍒涘缓RAM璐﹀彿銆�
+ String accessKeyId = MappingCache.getValue(DOMAIN, ACCESS_KEY_ID);
+ String accessKeySecret = MappingCache.getValue(DOMAIN, ACCESS_KEY_SECRET);
+ OSSClient ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret);
+ return ossClient;
+ }
+
+ /**
+ * @param ossClient oss瀹㈡埛绔�
+ * @param url URL
+ * @param bucketName bucket鍚嶇О
+ * @param objectName 涓婁紶鏂囦欢鐩綍鍜岋紙鍖呮嫭鏂囦欢鍚嶏級渚嬪鈥渢est/index.html鈥�
+ * @return void 杩斿洖绫诲瀷
+ * @throws
+ * @Title: uploadByNetworkStream
+ * @Description: 閫氳繃缃戠粶娴佷笂浼犳枃浠�
+ */
+ public static void uploadByNetworkStream(OSSClient ossClient, URL url, String bucketName, String objectName) {
+ try {
+ InputStream inputStream = url.openStream();
+ ossClient.putObject(bucketName, objectName, inputStream);
+ ossClient.shutdown();
+ } catch (IOException e) {
+ e.printStackTrace();
+ } finally {
+ if (ossClient != null) {
+ ossClient.shutdown();
+ }
+ }
+ }
+
+ /**
+ * @param ossClient oss瀹㈡埛绔�
+ * @param inputStream 杈撳叆娴�
+ * @param bucketName bucket鍚嶇О
+ * @param objectName 涓婁紶鏂囦欢鐩綍鍜岋紙鍖呮嫭鏂囦欢鍚嶏級 渚嬪鈥渢est/a.jpg鈥�
+ * @return void 杩斿洖绫诲瀷
+ * @throws
+ * @Title: uploadByInputStream
+ * @Description: 閫氳繃杈撳叆娴佷笂浼犳枃浠�
+ */
+ public static void uploadByInputStream(OSSClient ossClient, InputStream inputStream, String bucketName,
+ String objectName) {
+ try {
+ ossClient.putObject(bucketName, objectName, inputStream);
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ if (ossClient != null) {
+ ossClient.shutdown();
+ }
+ }
+ }
+
+ /**
+ * @param ossClient oss瀹㈡埛绔�
+ * @param file 涓婁紶鐨勬枃浠�
+ * @param bucketName bucket鍚嶇О
+ * @param objectName 涓婁紶鏂囦欢鐩綍鍜岋紙鍖呮嫭鏂囦欢鍚嶏級 渚嬪鈥渢est/a.jpg鈥�
+ * @return void 杩斿洖绫诲瀷
+ * @throws
+ * @Title: uploadByFile
+ * @Description: 閫氳繃file涓婁紶鏂囦欢
+ */
+ public static void uploadByFile(OSSClient ossClient, File file, String bucketName, String objectName) {
+ try {
+ ossClient.putObject(bucketName, objectName, file);
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ if (ossClient != null) {
+ ossClient.shutdown();
+ }
+ }
+ }
+
+
+ /**
+ * @param ossClient oss瀹㈡埛绔�
+ * @param bucketName bucket鍚嶇О
+ * @param key 鏂囦欢璺緞/鍚嶇О锛屼緥濡傗�渢est/a.txt鈥�
+ * @return void 杩斿洖绫诲瀷
+ * @throws
+ * @Title: deleteFile
+ * @Description: 鏍规嵁key鍒犻櫎oss鏈嶅姟鍣ㄤ笂鐨勬枃浠�
+ */
+ public static void deleteFile(OSSClient ossClient, String bucketName, String key) {
+ ossClient.deleteObject(bucketName, key);
+ }
+
+ /**
+ * @param ossClient oss瀹㈡埛绔�
+ * @param bucketName bucket鍚嶇О
+ * @param key 鏂囦欢璺緞鍜屽悕绉�
+ * @return InputStream 鏂囦欢杈撳叆娴�
+ * @throws
+ * @Title: getInputStreamByOSS
+ * @Description:鏍规嵁key鑾峰彇鏈嶅姟鍣ㄤ笂鐨勬枃浠剁殑杈撳叆娴�
+ */
+ public static InputStream getInputStreamByOSS(OSSClient ossClient, String bucketName, String key) {
+ InputStream content = null;
+ try {
+ OSSObject ossObj = ossClient.getObject(bucketName, key);
+ content = ossObj.getObjectContent();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return content;
+ }
+
+ /**
+ * @param ossClient oss瀹㈡埛绔�
+ * @param bucketName bucket鍚嶇О
+ * @return List<String> 鏂囦欢璺緞鍜屽ぇ灏忛泦鍚�
+ * @throws
+ * @Title: queryAllObject
+ * @Description: 鏌ヨ鏌愪釜bucket閲岄潰鐨勬墍鏈夋枃浠�
+ */
+ public static List<String> queryAllObject(OSSClient ossClient, String bucketName) {
+ List<String> results = new ArrayList<String>();
+ try {
+ // ossClient.listObjects杩斿洖ObjectListing瀹炰緥锛屽寘鍚娆istObject璇锋眰鐨勮繑鍥炵粨鏋溿��
+ ObjectListing objectListing = ossClient.listObjects(bucketName);
+ // objectListing.getObjectSummaries鑾峰彇鎵�鏈夋枃浠剁殑鎻忚堪淇℃伅銆�
+ for (OSSObjectSummary objectSummary : objectListing.getObjectSummaries()) {
+ results.add(" - " + objectSummary.getKey() + " " + "(size = " + objectSummary.getSize() + ")");
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ if (ossClient != null) {
+ ossClient.shutdown();
+ }
+ }
+ return results;
+ }
+}
diff --git a/pom.xml b/pom.xml
index b062785..e93ab3f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -72,6 +72,7 @@
<zookeeper.version>3.4.14</zookeeper.version>
<swagger.version>2.5.0</swagger.version>
<pinyin4j.version>2.5.0</pinyin4j.version>
+ <oss.aliyun>2.8.2</oss.aliyun>
</properties>
<dependencyManagement>
@@ -336,17 +337,6 @@
<version>${httpclient.verion}</version>
</dependency>
- <!--<dependency>
- <groupId>io.shardingsphere</groupId>
- <artifactId>sharding-jdbc</artifactId>
- <version>3.0.0.M3</version>
- </dependency>-->
-
- <!--<dependency>
- <groupId>io.shardingsphere</groupId>
- <artifactId>sharding-jdbc-core</artifactId>
- <version>3.1.0</version>
- </dependency>-->
<dependency>
<groupId>org.apache.shardingsphere</groupId>
@@ -354,30 +344,6 @@
<version>4.0.0-RC1</version>
</dependency>
-
- <!-- https://mvnrepository.com/artifact/org.apache.axis2/axis2
- <dependency>
- <groupId>org.apache.axis</groupId>
- <artifactId>axis</artifactId>
- <version>${axis.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.apache.axis</groupId>
- <artifactId>axis-jaxrpc</artifactId>
- <version>${axis.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.axis</groupId>
- <artifactId>axis-saaj</artifactId>
- <version>${axis.version}</version>
- </dependency>
- <dependency>
- <groupId>wsdl4j</groupId>
- <artifactId>wsdl4j</artifactId>
- <version>${axis.version}</version>
- </dependency>
- -->
<dependency>
<groupId>net.sf.ehcache</groupId>
@@ -392,11 +358,6 @@
</dependency>
- <!-- <dependency>
- <groupId>org.quartz-scheduler</groupId>
- <artifactId>quartz</artifactId>
- <version>2.3.0</version>
- </dependency>-->
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
@@ -504,12 +465,6 @@
<version>6.0.0.RC1</version>
</dependency>
- <!--<dependency>
- <groupId>org.activiti</groupId>
- <artifactId>activiti-modeler</artifactId>
- <version>6.0.0</version>
- </dependency>-->
-
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring-boot-starter-basic</artifactId>
@@ -530,18 +485,12 @@
<version>3.0.112</version>
</dependency>
- <!--<dependency>
- <groupId>org.activiti</groupId>
- <artifactId>activiti-modeler</artifactId>
- <version>5.22.0</version>
- <exclusions>
- <exclusion>
- <groupId>org.activiti</groupId>
- <artifactId>activiti-bpmn-model</artifactId>
- </exclusion>
- </exclusions>
- </dependency>-->
-
+ <!-- https://mvnrepository.com/artifact/com.aliyun.oss/aliyun-sdk-oss -->
+ <dependency>
+ <groupId>com.aliyun.oss</groupId>
+ <artifactId>aliyun-sdk-oss</artifactId>
+ <version>${oss.aliyun}</version>
+ </dependency>
</dependencies>
</dependencyManagement>
diff --git a/service-common/pom.xml b/service-common/pom.xml
index 3715bb0..1946b2e 100644
--- a/service-common/pom.xml
+++ b/service-common/pom.xml
@@ -26,22 +26,18 @@
<groupId>com.java110</groupId>
<artifactId>java110-service</artifactId>
</dependency>
- <!-- <dependency>
- <groupId>org.activiti</groupId>
- <artifactId>activiti-spring</artifactId>
- </dependency>-->
+
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-bpmn-layout</artifactId>
</dependency>
- <!-- <dependency>
- <groupId>org.activiti</groupId>
- <artifactId>activiti-modeler</artifactId>
- </dependency>-->
+
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring-boot-starter-basic</artifactId>
</dependency>
+
+
</dependencies>
<build>
diff --git a/service-common/src/main/java/com/java110/common/smo/impl/FileInnerServiceSMOImpl.java b/service-common/src/main/java/com/java110/common/smo/impl/FileInnerServiceSMOImpl.java
index 038e289..ca8edb4 100644
--- a/service-common/src/main/java/com/java110/common/smo/impl/FileInnerServiceSMOImpl.java
+++ b/service-common/src/main/java/com/java110/common/smo/impl/FileInnerServiceSMOImpl.java
@@ -3,10 +3,14 @@
import com.java110.common.dao.IFileServiceDao;
import com.java110.config.properties.code.Java110Properties;
import com.java110.core.base.smo.BaseServiceSMO;
-import com.java110.core.client.JSchFtpUploadTemplate;
-import com.java110.intf.common.IFileInnerServiceSMO;
-import com.java110.dto.file.FileDto;
import com.java110.core.client.FtpUploadTemplate;
+import com.java110.core.client.JSchFtpUploadTemplate;
+import com.java110.core.client.OssUploadTemplate;
+import com.java110.dto.file.FileDto;
+import com.java110.intf.common.IFileInnerServiceSMO;
+import com.java110.utils.cache.MappingCache;
+import com.java110.utils.util.OSSUtil;
+import com.java110.utils.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
@@ -29,20 +33,25 @@
@Autowired
private JSchFtpUploadTemplate jSchFtpUploadTemplate;
+ @Autowired
+ private OssUploadTemplate ossUploadTemplate;
+
@Override
public String saveFile(@RequestBody FileDto fileDto) {
//int saveFileFlag = fileServiceDaoImpl.saveFile(BeanConvertUtil.beanCovertMap(fileDto));
-
-
- String fileName = ftpUploadTemplate.upload(fileDto.getContext(), java110Properties.getFtpServer(),
- java110Properties.getFtpPort(), java110Properties.getFtpUserName(),
- java110Properties.getFtpUserPassword(), java110Properties.getFtpPath());
-
-// String fileName = jSchFtpUploadTemplate.upload(fileDto.getContext(), java110Properties.getFtpServer(),
-// java110Properties.getFtpPort(), java110Properties.getFtpUserName(),
-// java110Properties.getFtpUserPassword(), java110Properties.getFtpPath());
+ String fileName = "";
+ String ossSwitch = MappingCache.getValue(OSSUtil.DOMAIN, OSSUtil.OSS_SWITCH);
+ if (StringUtil.isEmpty(ossSwitch) || !OSSUtil.OSS_SWITCH_OSS.equals(ossSwitch)) {
+ fileName = ftpUploadTemplate.upload(fileDto.getContext(), java110Properties.getFtpServer(),
+ java110Properties.getFtpPort(), java110Properties.getFtpUserName(),
+ java110Properties.getFtpUserPassword(), java110Properties.getFtpPath());
+ } else {
+ fileName = ossUploadTemplate.upload(fileDto.getContext(), java110Properties.getFtpServer(),
+ java110Properties.getFtpPort(), java110Properties.getFtpUserName(),
+ java110Properties.getFtpUserPassword(), java110Properties.getFtpPath());
+ }
return fileName;
}
@@ -57,15 +66,17 @@
ftpPath += fileName.substring(0, fileName.lastIndexOf("/") + 1);
fileName = fileName.substring(fileName.lastIndexOf("/") + 1, fileName.length());
}
-// byte[] fileImg = ftpUploadTemplate.downFileByte(ftpPath, fileName, java110Properties.getFtpServer(),
-// java110Properties.getFtpPort(), java110Properties.getFtpUserName(),
-// java110Properties.getFtpUserPassword());
-//
-// //String context = new BASE64Encoder().encode(fileImg);
-// String context = Base64Convert.byteToBase64(fileImg);
- String context = ftpUploadTemplate.download(ftpPath, fileName, java110Properties.getFtpServer(),
- java110Properties.getFtpPort(), java110Properties.getFtpUserName(),
- java110Properties.getFtpUserPassword());
+ String context = "";
+ String ossSwitch = MappingCache.getValue(OSSUtil.DOMAIN, OSSUtil.OSS_SWITCH);
+ if (StringUtil.isEmpty(ossSwitch) || !OSSUtil.OSS_SWITCH_OSS.equals(ossSwitch)) {
+ context = ftpUploadTemplate.download(ftpPath, fileName, java110Properties.getFtpServer(),
+ java110Properties.getFtpPort(), java110Properties.getFtpUserName(),
+ java110Properties.getFtpUserPassword());
+ }else{
+ context = ossUploadTemplate.download(ftpPath, fileName, java110Properties.getFtpServer(),
+ java110Properties.getFtpPort(), java110Properties.getFtpUserName(),
+ java110Properties.getFtpUserPassword());
+ }
fileDto.setContext(context);
fileDto.setSuffix(suffix);
--
Gitblit v1.8.0