|
@@ -1,5 +1,6 @@
|
|
package com.example.fms.service;
|
|
package com.example.fms.service;
|
|
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.example.fms.common.model.dto.DownloadSysFileDTO;
|
|
import com.example.fms.common.model.dto.DownloadSysFileDTO;
|
|
import com.example.fms.common.model.dto.SystemFileDTO;
|
|
import com.example.fms.common.model.dto.SystemFileDTO;
|
|
import com.example.fms.common.model.vo.ConfigSettingVO;
|
|
import com.example.fms.common.model.vo.ConfigSettingVO;
|
|
@@ -16,6 +17,7 @@ import org.springframework.util.CollectionUtils;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
|
+import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -27,7 +29,6 @@ import java.util.List;
|
|
@Slf4j
|
|
@Slf4j
|
|
@Service
|
|
@Service
|
|
public class FileMangerService {
|
|
public class FileMangerService {
|
|
- private final OldFileFactoryService oldFileFactoryService;
|
|
|
|
private final SystemFileService systemFileService;
|
|
private final SystemFileService systemFileService;
|
|
private final SystemFileMapper systemFileMapper;
|
|
private final SystemFileMapper systemFileMapper;
|
|
private final FileFactory fileFactory;
|
|
private final FileFactory fileFactory;
|
|
@@ -70,12 +71,14 @@ public class FileMangerService {
|
|
* @return fileData 文件流
|
|
* @return fileData 文件流
|
|
* @throws Exception
|
|
* @throws Exception
|
|
*/
|
|
*/
|
|
- public byte[] downloadFile(Integer fileId) {
|
|
|
|
|
|
+ public byte[] downloadFile(String fileId) {
|
|
if (fileId != null) {
|
|
if (fileId != null) {
|
|
//1.新建一个对象
|
|
//1.新建一个对象
|
|
DownloadSysFileDTO downloadSysFileDTO = new DownloadSysFileDTO();
|
|
DownloadSysFileDTO downloadSysFileDTO = new DownloadSysFileDTO();
|
|
//2.根据传入文件id查询到文件信息
|
|
//2.根据传入文件id查询到文件信息
|
|
- SystemFileVO systemFileVO = systemFileService.query(fileId);
|
|
|
|
|
|
+ LambdaQueryWrapper<SystemFile> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
+ queryWrapper.eq(SystemFile::getGUID, fileId);
|
|
|
|
+ SystemFile systemFileVO = systemFileService.getOne(queryWrapper);
|
|
//3.文件信息标记为已经删除的,返回null
|
|
//3.文件信息标记为已经删除的,返回null
|
|
if (systemFileVO.getIsDelete().equals(1)) {
|
|
if (systemFileVO.getIsDelete().equals(1)) {
|
|
return null;
|
|
return null;
|
|
@@ -107,13 +110,13 @@ public class FileMangerService {
|
|
/**
|
|
/**
|
|
* 删除系统文件
|
|
* 删除系统文件
|
|
* 分为物理删除和逻辑删除,逻辑删除只更新数据库中isDelete字段,物理删除需要调用工厂类方法
|
|
* 分为物理删除和逻辑删除,逻辑删除只更新数据库中isDelete字段,物理删除需要调用工厂类方法
|
|
- * @param ids 需要删除的id集合
|
|
|
|
|
|
+ * @param guIds 需要删除的GUID集合
|
|
* @param type 删除方式判断字段,1为逻辑删除,2为物理删除
|
|
* @param type 删除方式判断字段,1为逻辑删除,2为物理删除
|
|
*/
|
|
*/
|
|
- public String deleteFile(List<Integer> ids, Integer type) {
|
|
|
|
|
|
+ public String deleteFile(List<String> guIds, Integer type) {
|
|
//1.首先判断传入的需要删除的id集合不能为空
|
|
//1.首先判断传入的需要删除的id集合不能为空
|
|
- if (CollectionUtils.isEmpty(ids)) {
|
|
|
|
- throw new XiaoShiException("需要删除的id集合不能为空");
|
|
|
|
|
|
+ if (CollectionUtils.isEmpty(guIds)) {
|
|
|
|
+ throw new XiaoShiException("需要删除的GUID集合不能为空");
|
|
}
|
|
}
|
|
//2.其次判断传入的删除类型不能为空
|
|
//2.其次判断传入的删除类型不能为空
|
|
if (type == null) {
|
|
if (type == null) {
|
|
@@ -122,9 +125,11 @@ public class FileMangerService {
|
|
//3.1 判断如果是逻辑删除(更新isDelete字段为1)
|
|
//3.1 判断如果是逻辑删除(更新isDelete字段为1)
|
|
if (type.equals(1)) {
|
|
if (type.equals(1)) {
|
|
//3.1.1 遍历传入的id集合
|
|
//3.1.1 遍历传入的id集合
|
|
- for (int i = 0; i < ids.size(); i++) {
|
|
|
|
|
|
+ for (int i = 0; i < guIds.size(); i++) {
|
|
//3.1.2 获取需要更新的对象
|
|
//3.1.2 获取需要更新的对象
|
|
- SystemFileVO systemFileVO = systemFileMapper.query(ids.get(i));
|
|
|
|
|
|
+ LambdaQueryWrapper<SystemFile> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
+ queryWrapper.eq(SystemFile::getGUID, guIds.get(i));
|
|
|
|
+ SystemFile systemFileVO = systemFileService.getOne(queryWrapper);
|
|
//3.1.3 将对象的是否删除字段置为1
|
|
//3.1.3 将对象的是否删除字段置为1
|
|
systemFileVO.setIsDelete(1);
|
|
systemFileVO.setIsDelete(1);
|
|
//3.1.4 将查询出来的vo赋值给实体类
|
|
//3.1.4 将查询出来的vo赋值给实体类
|
|
@@ -141,10 +146,13 @@ public class FileMangerService {
|
|
String mes = "逻辑删除成功";
|
|
String mes = "逻辑删除成功";
|
|
return mes;
|
|
return mes;
|
|
} else if (type.equals(2)) { //3.2 物理删除(先删除服务器文件,删除数据库中记录)
|
|
} else if (type.equals(2)) { //3.2 物理删除(先删除服务器文件,删除数据库中记录)
|
|
- //3.2.1 遍历传入的id集合
|
|
|
|
- for (int i = 0; i < ids.size(); i++) {
|
|
|
|
- //3.2.2 根据id到表中查询该文件记录的数据
|
|
|
|
- SystemFileVO systemFileVO = systemFileService.query(ids.get(i));
|
|
|
|
|
|
+ //3.2.1 遍历传入的GUID集合
|
|
|
|
+ List<Integer> deleteIds = new ArrayList<>();
|
|
|
|
+ for (int i = 0; i < guIds.size(); i++) {
|
|
|
|
+ //3.2.2 根据GUID到表中查询该文件记录的数据
|
|
|
|
+ LambdaQueryWrapper<SystemFile> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
+ queryWrapper.eq(SystemFile::getGUID, guIds.get(i));
|
|
|
|
+ SystemFile systemFileVO = systemFileService.getOne(queryWrapper);
|
|
//3.2.3 根据pType判断存储在服务器的哪个地址下
|
|
//3.2.3 根据pType判断存储在服务器的哪个地址下
|
|
int pType = systemFileVO.getPType();
|
|
int pType = systemFileVO.getPType();
|
|
//3.2.4 文件路径
|
|
//3.2.4 文件路径
|
|
@@ -157,12 +165,18 @@ public class FileMangerService {
|
|
//TODO 调用工厂方法,工厂方法会根据sourceName创建并返回对应的方法的对象
|
|
//TODO 调用工厂方法,工厂方法会根据sourceName创建并返回对应的方法的对象
|
|
IFileFactory fileFactoryObject = fileFactory.createObject(sourceName);
|
|
IFileFactory fileFactoryObject = fileFactory.createObject(sourceName);
|
|
fileFactoryObject.deleteFile(filePath, configSettingVO);
|
|
fileFactoryObject.deleteFile(filePath, configSettingVO);
|
|
- int row = systemFileMapper.deleteById(ids.get(i));
|
|
|
|
- if (row != 1) {
|
|
|
|
- throw new XiaoShiException("第" + i + "条删除异常");
|
|
|
|
- }
|
|
|
|
|
|
+ deleteIds.add(systemFileVO.getId());
|
|
|
|
+// //3.2.7 调用removeById删除此条记录,主键为根据GUID查询到的对象的id
|
|
|
|
+// Boolean isDelete = systemFileService.removeById(systemFileVO.getId());
|
|
|
|
+// if (isDelete != true) {
|
|
|
|
+// throw new XiaoShiException("第" + i + "条删除异常");
|
|
|
|
+// }
|
|
|
|
+ }
|
|
|
|
+ Boolean isDelete = systemFileService.removeByIds(deleteIds);
|
|
|
|
+ if (isDelete != true) {
|
|
|
|
+ throw new XiaoShiException("删除异常");
|
|
}
|
|
}
|
|
- String mes = "物理删除成功";
|
|
|
|
|
|
+ String mes = "文件删除成功,文件记录删除成功";
|
|
return mes;
|
|
return mes;
|
|
} else {
|
|
} else {
|
|
String mes = "删除类型错误";
|
|
String mes = "删除类型错误";
|