|
@@ -33,16 +33,17 @@ public class FileFactoryService {
|
|
|
* @param sourceId
|
|
|
* @return
|
|
|
*/
|
|
|
- public List<SystemFileDTO> uploadFiles(List<MultipartFile> files, Integer sourceId) {
|
|
|
- if (files != null && files.size() != 0) {
|
|
|
+ public List<SystemFileDTO> uploadFiles(List<MultipartFile> files, Integer sourceId){
|
|
|
+ if(files != null && files.size() != 0) {
|
|
|
//调用解析配置方法,获取配置信息
|
|
|
List<ConfigSettingVO> configSettingVOS = ExcuteConfigUtils.excuteConfigVO();
|
|
|
- ConfigSettingVO configSettingVO = configSettingVOS.stream().filter(item -> item.getSourceId().equals(sourceId)).findFirst().orElse(null);
|
|
|
+ //根据配置id获得配置
|
|
|
+ ConfigSettingVO configSettingVO = configSettingVOS.stream().filter(item -> item.getId().equals(sourceId)).findFirst().orElse(null);
|
|
|
if (configSettingVO == null) {
|
|
|
return null;
|
|
|
}
|
|
|
String sourceName = configSettingVO.getSourceName();
|
|
|
- if (sourceName.equals("FSS")) {
|
|
|
+ if(sourceName.equals("FSS")) {
|
|
|
return this.uploadToFSS(files, configSettingVO);
|
|
|
}
|
|
|
return null;
|
|
@@ -58,13 +59,14 @@ public class FileFactoryService {
|
|
|
* @param configSettingVO
|
|
|
* @return
|
|
|
*/
|
|
|
- public List<SystemFileDTO> uploadToFSS(List<MultipartFile> files, ConfigSettingVO configSettingVO) {
|
|
|
+ public List<SystemFileDTO> uploadToFSS(List<MultipartFile> files, ConfigSettingVO configSettingVO){
|
|
|
List<SystemFileDTO> systemFileDTOS = new ArrayList<>();
|
|
|
- for (MultipartFile file : files) {
|
|
|
+ for(MultipartFile file:files){
|
|
|
try {
|
|
|
String directoryName = fileUtils.getDirectoryName();
|
|
|
SystemFileDTO systemFileDTO = SftpService.upload(configSettingVO.getFilePath() + directoryName, file, configSettingVO);
|
|
|
- systemFileDTO.setPType(configSettingVO.getSourceId());
|
|
|
+ systemFileDTO.setPType(configSettingVO.getId());
|
|
|
+ systemFileDTO.setSourceId(configSettingVO.getSourceId());
|
|
|
systemFileDTO.setOriginalName(file.getOriginalFilename());
|
|
|
systemFileDTO.setFilePath(configSettingVO.getFilePath() + directoryName + "/" + systemFileDTO.getFileName());
|
|
|
systemFileDTOS.add(systemFileDTO);
|
|
@@ -78,7 +80,6 @@ public class FileFactoryService {
|
|
|
|
|
|
/**
|
|
|
* 下载文件
|
|
|
- *
|
|
|
* @param downloadSysFileDTO
|
|
|
* @throws Exception
|
|
|
*/
|
|
@@ -99,16 +100,16 @@ public class FileFactoryService {
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
/**
|
|
|
- * @param //directory 下载目录 根据SFTP设置的根目录来进行传输
|
|
|
+ * @param //directory 下载目录 根据SFTP设置的根目录来进行传输
|
|
|
* @param //downloadFile 下载的文件
|
|
|
- * @param //saveFile 存在本地的路径
|
|
|
+ * @param //saveFile 存在本地的路径
|
|
|
*/
|
|
|
public byte[] downloadFromFSS(DownloadSysFileDTO downloadSysFileDTO, ConfigSettingVO configSettingVO) throws Exception {
|
|
|
//下载目录,也是存储路径
|
|
|
String filePath = downloadSysFileDTO.getFilePath();
|
|
|
- String directory = filePath.substring(0, filePath.lastIndexOf("/"));
|
|
|
+ int index = filePath.lastIndexOf("/");
|
|
|
+ String directory = filePath.substring(0,index);
|
|
|
//下载的文件,也就是文件名
|
|
|
String downloadFile = downloadSysFileDTO.getFileName();
|
|
|
//存在本地的路径,随机生成
|
|
@@ -117,21 +118,19 @@ public class FileFactoryService {
|
|
|
byte[] fileData = SftpService.download(directory, downloadFile, configSettingVO);
|
|
|
return fileData;
|
|
|
}
|
|
|
-
|
|
|
/**
|
|
|
* 删除文件
|
|
|
*
|
|
|
* @param filePath
|
|
|
- * @param pType
|
|
|
+ * @param sourceId
|
|
|
*/
|
|
|
- public static void delete(String filePath, Integer pType) {
|
|
|
+ public static void delete(String filePath, Integer sourceId){
|
|
|
//调用解析配置方法,获取配置信息
|
|
|
List<ConfigSettingVO> configSettingVOS = ExcuteConfigUtils.excuteConfigVO();
|
|
|
+ ConfigSettingVO configSettingVO = configSettingVOS.stream().filter(item -> item.getSourceId().equals(sourceId)).findFirst().orElse(null);
|
|
|
//根据传入类型判断从哪里删除数据
|
|
|
//如果为1,则为服务器
|
|
|
- if (pType.equals(1)) {
|
|
|
- int sourceId = 1;
|
|
|
- ConfigSettingVO configSettingVO = configSettingVOS.stream().filter(item -> item.getSourceId().equals(sourceId)).findFirst().orElse(null);
|
|
|
+ if(sourceId.equals(1)){
|
|
|
//拆分路径字符串
|
|
|
int index = filePath.lastIndexOf('/');
|
|
|
//要删除文件所在目录
|
|
@@ -143,11 +142,10 @@ public class FileFactoryService {
|
|
|
} catch (Exception e) {
|
|
|
throw new XiaoShiException("删除错误");
|
|
|
}
|
|
|
- } else if (pType.equals(2)) {//类型为2,则为阿里云OSS
|
|
|
- int sourceId = 2;
|
|
|
- ConfigSettingVO configSettingVO = configSettingVOS.stream().filter(item -> item.getSourceId().equals(sourceId)).findFirst().orElse(null);
|
|
|
+ } else if(sourceId.equals(2)){//类型为2,则为阿里云OSS
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
}
|