From 3fe2aea7827eafc7513159db9a337fdf567584c8 Mon Sep 17 00:00:00 2001
From: Your Name <you@example.com>
Date: 星期一, 08 五月 2023 01:21:13 +0800
Subject: [PATCH] Merge branch 'master' of http://git.homecommunity.cn/supervip/MicroCommunity
---
service-common/src/main/java/com/java110/common/smo/impl/FileInnerServiceSMOImpl.java | 77 ++++++++++++++++++++++++++++----------
1 files changed, 57 insertions(+), 20 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 af86cac..d25071a
--- 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,17 @@
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.common.IFileInnerServiceSMO;
-import com.java110.dto.file.FileDto;
+import com.java110.core.client.CosUploadTemplate;
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.constant.MappingConstant;
+import com.java110.utils.util.COSUtil;
+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;
@@ -16,6 +23,8 @@
@RestController
public class FileInnerServiceSMOImpl extends BaseServiceSMO implements IFileInnerServiceSMO {
+
+ private static final String ROOT_PATH = "hc/";
@Autowired
private IFileServiceDao fileServiceDaoImpl;
@@ -29,20 +38,38 @@
@Autowired
private JSchFtpUploadTemplate jSchFtpUploadTemplate;
+ @Autowired
+ private OssUploadTemplate ossUploadTemplate;
+
+ @Autowired
+ private CosUploadTemplate cosUploadTemplate;
@Override
public String saveFile(@RequestBody FileDto fileDto) {
//int saveFileFlag = fileServiceDaoImpl.saveFile(BeanConvertUtil.beanCovertMap(fileDto));
+ String fileName = "";
+ String ossSwitch = MappingCache.getValue(MappingConstant.FILE_DOMAIN, OSSUtil.OSS_SWITCH);
+ if (OSSUtil.OSS_SWITCH_OSS.equals(ossSwitch)) {
+ fileName = ossUploadTemplate.upload(fileDto.getContext(), java110Properties.getFtpServer(),
+ java110Properties.getFtpPort(), java110Properties.getFtpUserName(),
+ java110Properties.getFtpUserPassword(), ROOT_PATH);
+ } else if (COSUtil.COS_SWITCH_COS.equals(ossSwitch)) {
+ fileName = cosUploadTemplate.upload(fileDto.getContext(), java110Properties.getFtpServer(),
+ java110Properties.getFtpPort(), java110Properties.getFtpUserName(),
+ java110Properties.getFtpUserPassword(), ROOT_PATH);
+ } else {
+ String ftpServer = MappingCache.getValue(FtpUploadTemplate.FTP_DOMAIN, FtpUploadTemplate.FTP_SERVER);
+ int ftpPort = Integer.parseInt(MappingCache.getValue(FtpUploadTemplate.FTP_DOMAIN, FtpUploadTemplate.FTP_PORT));
+ String ftpUserName = MappingCache.getValue(FtpUploadTemplate.FTP_DOMAIN, FtpUploadTemplate.FTP_USERNAME);
+ String ftpUserPassword = MappingCache.getValue(FtpUploadTemplate.FTP_DOMAIN, FtpUploadTemplate.FTP_USERPASSWORD);
+ //String ftpPath = "hc/";
- 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());
+ fileName = ftpUploadTemplate.upload(fileDto.getContext(), ftpServer,
+ ftpPort, ftpUserName,
+ ftpUserPassword, ROOT_PATH);
+ }
return fileName;
}
@@ -51,21 +78,31 @@
//return BeanConvertUtil.covertBeanList(fileServiceDaoImpl.getFiles(BeanConvertUtil.beanCovertMap(fileDto)), FileDto.class);
List<FileDto> fileDtos = new ArrayList<>();
String fileName = fileDto.getFileSaveName();
- String ftpPath = java110Properties.getFtpPath();
+ String ftpPath = "hc/";
String suffix = fileName.substring(fileName.lastIndexOf(".") + 1);
if (fileName.contains("/")) {
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(MappingConstant.FILE_DOMAIN, OSSUtil.OSS_SWITCH);
+ if (OSSUtil.OSS_SWITCH_OSS.equals(ossSwitch)) {
+ context = ossUploadTemplate.download(ftpPath, fileName, java110Properties.getFtpServer(),
+ java110Properties.getFtpPort(), java110Properties.getFtpUserName(),
+ java110Properties.getFtpUserPassword());
+ } else if (COSUtil.COS_SWITCH_COS.equals(ossSwitch)) {
+ context = cosUploadTemplate.download(ftpPath, fileName, java110Properties.getFtpServer(),
+ java110Properties.getFtpPort(), java110Properties.getFtpUserName(),
+ java110Properties.getFtpUserPassword());
+ } else {
+ String ftpServer = MappingCache.getValue(FtpUploadTemplate.FTP_DOMAIN, FtpUploadTemplate.FTP_SERVER);
+ int ftpPort = Integer.parseInt(MappingCache.getValue(FtpUploadTemplate.FTP_DOMAIN, FtpUploadTemplate.FTP_PORT));
+ String ftpUserName = MappingCache.getValue(FtpUploadTemplate.FTP_DOMAIN, FtpUploadTemplate.FTP_USERNAME);
+ String ftpUserPassword = MappingCache.getValue(FtpUploadTemplate.FTP_DOMAIN, FtpUploadTemplate.FTP_USERPASSWORD);
+ context = ftpUploadTemplate.download(ftpPath, fileName, ftpServer,
+ ftpPort, ftpUserName,
+ ftpUserPassword);
+ }
fileDto.setContext(context);
fileDto.setSuffix(suffix);
--
Gitblit v1.8.0