|
@@ -19,9 +19,11 @@ import org.springframework.web.multipart.MultipartFile;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 文件管理外部调用接口Service层
|
|
* 文件管理外部调用接口Service层
|
|
|
|
+ *
|
|
* @Author xiexiang
|
|
* @Author xiexiang
|
|
* @Date 2023/8/9
|
|
* @Date 2023/8/9
|
|
*/
|
|
*/
|
|
@@ -36,7 +38,8 @@ public class FileMangerService {
|
|
|
|
|
|
/**
|
|
/**
|
|
* 上传文件的最外部接口
|
|
* 上传文件的最外部接口
|
|
- * @param files 需要上传的文件
|
|
|
|
|
|
+ *
|
|
|
|
+ * @param files 需要上传的文件
|
|
* @param sourceId configSettingVO的主键id,判断存储在哪个服务器路径之下
|
|
* @param sourceId configSettingVO的主键id,判断存储在哪个服务器路径之下
|
|
* @return insertIds 文件在数据库中的id集合
|
|
* @return insertIds 文件在数据库中的id集合
|
|
* @throws IOException
|
|
* @throws IOException
|
|
@@ -64,7 +67,7 @@ public class FileMangerService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- public String replaceFile(MultipartFile file, String fileGuid, Integer sourceId){
|
|
|
|
|
|
+ public String replaceFile(MultipartFile file, String fileGuid, Integer sourceId) {
|
|
List<String> deleteFileGuids = new ArrayList<>();
|
|
List<String> deleteFileGuids = new ArrayList<>();
|
|
Integer type = 2;
|
|
Integer type = 2;
|
|
deleteFileGuids.add(fileGuid);
|
|
deleteFileGuids.add(fileGuid);
|
|
@@ -84,6 +87,7 @@ public class FileMangerService {
|
|
|
|
|
|
/**
|
|
/**
|
|
* 下载文件
|
|
* 下载文件
|
|
|
|
+ *
|
|
* @param fileId 文件id
|
|
* @param fileId 文件id
|
|
* @return fileData 文件流
|
|
* @return fileData 文件流
|
|
* @throws Exception
|
|
* @throws Exception
|
|
@@ -121,19 +125,23 @@ public class FileMangerService {
|
|
byte[] fileData = fileFactoryObject.downloadFile(downloadSysFileDTO, configSettingVO);
|
|
byte[] fileData = fileFactoryObject.downloadFile(downloadSysFileDTO, configSettingVO);
|
|
return fileData;
|
|
return fileData;
|
|
}
|
|
}
|
|
|
|
+ return null;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* 删除系统文件
|
|
* 删除系统文件
|
|
* 分为物理删除和逻辑删除,逻辑删除只更新数据库中isDelete字段,物理删除需要调用工厂类方法
|
|
* 分为物理删除和逻辑删除,逻辑删除只更新数据库中isDelete字段,物理删除需要调用工厂类方法
|
|
|
|
+ *
|
|
* @param guIds 需要删除的GUID集合
|
|
* @param guIds 需要删除的GUID集合
|
|
- * @param type 删除方式判断字段,1为逻辑删除,2为物理删除
|
|
|
|
|
|
+ * @param type 删除方式判断字段,1为逻辑删除,2为物理删除
|
|
*/
|
|
*/
|
|
public String deleteFile(List<String> guIds, Integer type) {
|
|
public String deleteFile(List<String> guIds, Integer type) {
|
|
|
|
+
|
|
//1.首先判断传入的需要删除的id集合不能为空
|
|
//1.首先判断传入的需要删除的id集合不能为空
|
|
if (CollectionUtils.isEmpty(guIds)) {
|
|
if (CollectionUtils.isEmpty(guIds)) {
|
|
throw new XiaoShiException("需要删除的GUID集合不能为空");
|
|
throw new XiaoShiException("需要删除的GUID集合不能为空");
|
|
}
|
|
}
|
|
|
|
+
|
|
//2.其次判断传入的删除类型不能为空
|
|
//2.其次判断传入的删除类型不能为空
|
|
if (type == null) {
|
|
if (type == null) {
|
|
throw new XiaoShiException("删除类型不能为空");
|
|
throw new XiaoShiException("删除类型不能为空");
|
|
@@ -169,26 +177,32 @@ public class FileMangerService {
|
|
LambdaQueryWrapper<SystemFile> queryWrapper = new LambdaQueryWrapper<>();
|
|
LambdaQueryWrapper<SystemFile> queryWrapper = new LambdaQueryWrapper<>();
|
|
queryWrapper.eq(SystemFile::getGuid, guIds.get(i));
|
|
queryWrapper.eq(SystemFile::getGuid, guIds.get(i));
|
|
SystemFile systemFileVO = systemFileService.getOne(queryWrapper);
|
|
SystemFile systemFileVO = systemFileService.getOne(queryWrapper);
|
|
- //3.2.3 根据pType判断存储在服务器的哪个地址下
|
|
|
|
- int pType = systemFileVO.getPType();
|
|
|
|
- //3.2.4 文件路径
|
|
|
|
- String filePath = systemFileVO.getFilePath();
|
|
|
|
- //3.2.5 调用解析配置方法,获取指定配置信息
|
|
|
|
- List<ConfigSettingVO> configSettingVOS = ExcuteConfigUtils.excuteConfigVO();
|
|
|
|
- ConfigSettingVO configSettingVO = configSettingVOS.stream().filter(item -> item.getId().equals(pType)).findFirst().orElse(null);
|
|
|
|
- //3.2.6 配置类的删除方法
|
|
|
|
- String sourceName = configSettingVO.getSourceName();
|
|
|
|
- //TODO 调用工厂方法,工厂方法会根据sourceName创建并返回对应的方法的对象
|
|
|
|
- IFileFactory fileFactoryObject = fileFactory.createObject(sourceName);
|
|
|
|
- fileFactoryObject.deleteFile(filePath, configSettingVO);
|
|
|
|
- deleteIds.add(systemFileVO.getId());
|
|
|
|
|
|
+ if (systemFileVO != null) {
|
|
|
|
+ //3.2.3 根据pType判断存储在服务器的哪个地址下
|
|
|
|
+ int pType = systemFileVO.getPType();
|
|
|
|
+ //3.2.4 文件路径
|
|
|
|
+ String filePath = systemFileVO.getFilePath();
|
|
|
|
+ //3.2.5 调用解析配置方法,获取指定配置信息
|
|
|
|
+ List<ConfigSettingVO> configSettingVOS = ExcuteConfigUtils.excuteConfigVO();
|
|
|
|
+ ConfigSettingVO configSettingVO = configSettingVOS.stream().filter(item -> item.getId().equals(pType)).findFirst().orElse(null);
|
|
|
|
+ //3.2.6 配置类的删除方法
|
|
|
|
+ String sourceName = configSettingVO.getSourceName();
|
|
|
|
+ //TODO 调用工厂方法,工厂方法会根据sourceName创建并返回对应的方法的对象
|
|
|
|
+ IFileFactory fileFactoryObject = fileFactory.createObject(sourceName);
|
|
|
|
+ fileFactoryObject.deleteFile(filePath, configSettingVO);
|
|
|
|
+ deleteIds.add(systemFileVO.getId());
|
|
// //3.2.7 调用removeById删除此条记录,主键为根据GUID查询到的对象的id
|
|
// //3.2.7 调用removeById删除此条记录,主键为根据GUID查询到的对象的id
|
|
// Boolean isDelete = systemFileService.removeById(systemFileVO.getId());
|
|
// Boolean isDelete = systemFileService.removeById(systemFileVO.getId());
|
|
// if (isDelete != true) {
|
|
// if (isDelete != true) {
|
|
// throw new XiaoShiException("第" + i + "条删除异常");
|
|
// throw new XiaoShiException("第" + i + "条删除异常");
|
|
// }
|
|
// }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ Boolean isDelete = true;
|
|
|
|
+
|
|
|
|
+ if (deleteIds.size() != 0) {
|
|
|
|
+ isDelete = systemFileService.removeByIds(deleteIds);
|
|
}
|
|
}
|
|
- Boolean isDelete = systemFileService.removeByIds(deleteIds);
|
|
|
|
if (isDelete != true) {
|
|
if (isDelete != true) {
|
|
throw new XiaoShiException("删除异常");
|
|
throw new XiaoShiException("删除异常");
|
|
}
|
|
}
|
|
@@ -200,4 +214,15 @@ public class FileMangerService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+ public List<String> getPatentPictureGuids(String appNo) {
|
|
|
|
+ String likeGuid = "%" + appNo + "_p" + "%";
|
|
|
|
+ LambdaQueryWrapper<SystemFile> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
+ queryWrapper.select(SystemFile::getGuid);
|
|
|
|
+ queryWrapper.like(SystemFile::getGuid, likeGuid);
|
|
|
|
+ List<SystemFile> systemFiles =systemFileService.list(queryWrapper);
|
|
|
|
+ List<String> guids =systemFiles.stream().map(SystemFile::getGuid).collect(Collectors.toList());
|
|
|
|
+ return guids;
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|