|
@@ -89,39 +89,38 @@ public class FileMangerService {
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public byte[] downloadFile(String fileId) {
|
|
|
- if (fileId != null) {
|
|
|
- //1.新建一个对象
|
|
|
- DownloadSysFileDTO downloadSysFileDTO = new DownloadSysFileDTO();
|
|
|
- //2.根据传入文件id查询到文件信息
|
|
|
- LambdaQueryWrapper<SystemFile> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
- queryWrapper.eq(SystemFile::getGuid, fileId);
|
|
|
- SystemFile systemFileVO = systemFileService.getOne(queryWrapper);
|
|
|
- //3.文件信息标记为已经删除的,返回null
|
|
|
- if (systemFileVO.getIsDelete().equals(1)) {
|
|
|
- return null;
|
|
|
- } else {
|
|
|
- //3.对象赋值给新的
|
|
|
- BeanUtils.copyProperties(systemFileVO, downloadSysFileDTO);
|
|
|
- //4.设置pType(存储在哪条路径下)
|
|
|
- Integer id = downloadSysFileDTO.getPType();
|
|
|
- //5.调用解析配置方法,获取配置信息
|
|
|
- List<ConfigSettingVO> configSettingVOS = ExcuteConfigUtils.excuteConfigVO();
|
|
|
- if(configSettingVOS == null && configSettingVOS.size() == 0){
|
|
|
- throw new XiaoShiException("缺失配置文件");
|
|
|
- }
|
|
|
- //6.根据id获取需要的配置类
|
|
|
- ConfigSettingVO configSettingVO = configSettingVOS.stream().filter(item -> item.getId().equals(id)).findFirst().orElse(null);
|
|
|
- //7.设置sourceId为数据库中的sourceId字段
|
|
|
- downloadSysFileDTO.setSourceId(systemFileVO.getSourceId());
|
|
|
- //8.调用工厂类下载方法
|
|
|
- String sourceName = configSettingVO.getSourceName();
|
|
|
- //TODO 调用工厂方法,工厂方法会根据sourceName创建并返回对应的方法的对象
|
|
|
- IFileFactory fileFactoryObject = fileFactory.createObject(sourceName);
|
|
|
- byte[] fileData = fileFactoryObject.downloadFile(downloadSysFileDTO, configSettingVO);
|
|
|
- return fileData;
|
|
|
+
|
|
|
+ //1.新建一个对象
|
|
|
+ DownloadSysFileDTO downloadSysFileDTO = new DownloadSysFileDTO();
|
|
|
+ //2.根据传入文件id查询到文件信息
|
|
|
+ LambdaQueryWrapper<SystemFile> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(SystemFile::getGuid, fileId);
|
|
|
+ SystemFile systemFile = systemFileService.getOne(queryWrapper, false);
|
|
|
+ //外层做过判断,一定可以查到
|
|
|
+ //3.文件信息标记为已经删除的,返回null
|
|
|
+ if (systemFile.getIsDelete().equals(1)) {
|
|
|
+ return new byte[0];
|
|
|
+ } else {
|
|
|
+ //3.对象赋值给新的
|
|
|
+ BeanUtils.copyProperties(systemFile, downloadSysFileDTO);
|
|
|
+ //4.设置pType(存储在哪条路径下)
|
|
|
+ Integer id = downloadSysFileDTO.getPType();
|
|
|
+ //5.调用解析配置方法,获取配置信息
|
|
|
+ List<ConfigSettingVO> configSettingVOS = ExcuteConfigUtils.excuteConfigVO();
|
|
|
+ if(configSettingVOS == null && configSettingVOS.size() == 0){
|
|
|
+ throw new XiaoShiException("缺失配置文件");
|
|
|
}
|
|
|
+ //6.根据id获取需要的配置类
|
|
|
+ ConfigSettingVO configSettingVO = configSettingVOS.stream().filter(item -> item.getId().equals(id)).findFirst().orElse(null);
|
|
|
+ //7.设置sourceId为数据库中的sourceId字段
|
|
|
+ downloadSysFileDTO.setSourceId(systemFile.getSourceId());
|
|
|
+ //8.调用工厂类下载方法
|
|
|
+ String sourceName = configSettingVO.getSourceName();
|
|
|
+ //TODO 调用工厂方法,工厂方法会根据sourceName创建并返回对应的方法的对象
|
|
|
+ IFileFactory fileFactoryObject = fileFactory.createObject(sourceName);
|
|
|
+ byte[] fileData = fileFactoryObject.downloadFile(downloadSysFileDTO, configSettingVO);
|
|
|
+ return fileData;
|
|
|
}
|
|
|
- return null;
|
|
|
}
|
|
|
|
|
|
/**
|