java110 лет назад: 5
Родитель
Сommit
66119b66f1

+ 35 - 19
java110-core/src/main/java/com/java110/core/client/FtpUploadTemplate.java

@@ -2,7 +2,6 @@ package com.java110.core.client;
 
 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 @@ public class FtpUploadTemplate {
                          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 @@ public class FtpUploadTemplate {
 
 
             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 @@ public class FtpUploadTemplate {
         } finally {
             try {
                 ftpClient.disconnect();
+                if (is != null) {
+                    is.close();
+                }
             } catch (IOException e) {
                 e.printStackTrace();
                 logger.error("关闭ftpClient 失败", e);
@@ -117,7 +120,7 @@ public class FtpUploadTemplate {
         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 @@ public class FtpUploadTemplate {
         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 class FtpUploadTemplate {
 
     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 @@ public class FtpUploadTemplate {
             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 @@ public class FtpUploadTemplate {
             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 {
-            try {
-                if(bos != null){
-                    bos.close();
+                if (bos != null) {
+                    try {
+                        bos.close();
+                    } catch (IOException e) {
+                        e.printStackTrace();
+                    }
                 }
-                if(is !=null) {
-                    is.close();
+                if (is != null) {
+                    try {
+                        is.close();
+                    } catch (IOException e) {
+                        e.printStackTrace();
+                    }
                 }
+                if(fis != null){
+                    try {
+                        fis.close();
+                    } catch (IOException e) {
+                        e.printStackTrace();
+                    }
+                }
+            try {
                 closeConnect(ftpClient);
             } catch (Exception e) {
                 e.printStackTrace();

+ 246 - 0
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:/";//下载到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("从ftp读取文件失败", 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;
+    }
+
+}

+ 2 - 18
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>

+ 169 - 0
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拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维,请登录https://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 上传文件目录和(包括文件名)例如“test/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  上传文件目录和(包括文件名) 例如“test/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 上传文件目录和(包括文件名) 例如“test/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        文件路径/名称,例如“test/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实例,包含此次listObject请求的返回结果。
+            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;
+    }
+}

+ 7 - 58
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>
@@ -355,30 +345,6 @@
             </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>
                 <artifactId>ehcache</artifactId>
@@ -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>

+ 4 - 8
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>

+ 31 - 20
service-common/src/main/java/com/java110/common/smo/impl/FileInnerServiceSMOImpl.java

@@ -3,10 +3,14 @@ package com.java110.common.smo.impl;
 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.FtpUploadTemplate;
 import com.java110.core.client.JSchFtpUploadTemplate;
-import com.java110.intf.common.IFileInnerServiceSMO;
+import com.java110.core.client.OssUploadTemplate;
 import com.java110.dto.file.FileDto;
-import com.java110.core.client.FtpUploadTemplate;
+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 @@ public class FileInnerServiceSMOImpl extends BaseServiceSMO implements IFileInne
     @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 @@ public class FileInnerServiceSMOImpl extends BaseServiceSMO implements IFileInne
             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);