From 6e8c95d31d85b53857e4e3ce12ea303eb0ea42eb Mon Sep 17 00:00:00 2001
From: java110 <928255095@qq.com>
Date: 星期四, 19 八月 2021 00:47:48 +0800
Subject: [PATCH] 优化代码
---
service-common/src/main/java/com/java110/common/smo/impl/FileInnerServiceSMOImpl.java | 59 ++++++++++++++++++++++++++++++++---------------------------
1 files changed, 32 insertions(+), 27 deletions(-)
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
old mode 100644
new mode 100755
index 8ebdff8..ca8edb4
--- 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,22 +3,20 @@
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.core.smo.file.IFileInnerServiceSMO;
-import com.java110.dto.file.FileDto;
import com.java110.core.client.FtpUploadTemplate;
-import com.java110.utils.util.Base64Convert;
+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;
-import sun.misc.BASE64Encoder;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
-import java.util.UUID;
@RestController
public class FileInnerServiceSMOImpl extends BaseServiceSMO implements IFileInnerServiceSMO {
@@ -35,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;
}
@@ -63,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