|
@@ -1,13 +1,22 @@
|
|
|
package com.example.fms.service.impl;
|
|
|
|
|
|
import com.example.fms.common.model.dto.SystemFileDTO;
|
|
|
+import com.example.fms.common.model.vo.ConfigSettingVO;
|
|
|
+import com.example.fms.common.model.vo.SystemFileVO;
|
|
|
+import com.example.fms.common.utils.ExcuteConfigUtils;
|
|
|
+import com.example.fms.domain.SystemFile;
|
|
|
import com.example.fms.exception.XiaoShiException;
|
|
|
+import com.example.fms.mapper.SystemFileMapper;
|
|
|
import com.example.fms.service.FileFactoryService;
|
|
|
import com.example.fms.service.IFileManagerService;
|
|
|
import com.example.fms.service.ISystemFileService;
|
|
|
+import com.example.fms.service.SftpService;
|
|
|
+
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.util.List;
|
|
@@ -24,6 +33,7 @@ import java.util.List;
|
|
|
public class FileManagerServiceImpl implements IFileManagerService {
|
|
|
private final FileFactoryService fileFactoryService;
|
|
|
private final ISystemFileService systemFileService;
|
|
|
+ private final SystemFileMapper systemFileMapper;
|
|
|
|
|
|
@Override
|
|
|
public void add(List<MultipartFile> files, Integer sourceId){
|
|
@@ -33,12 +43,10 @@ public class FileManagerServiceImpl implements IFileManagerService {
|
|
|
//2.根据上传后的返回实体类信息,将实体类信息入库,调用systemFileService add
|
|
|
if(systemFileDTOS != null && systemFileDTOS.size() != 0 ) {
|
|
|
systemFileService.add(systemFileDTOS);
|
|
|
- }
|
|
|
- else {
|
|
|
+ } else {
|
|
|
throw new XiaoShiException("入表信息为空");
|
|
|
}
|
|
|
- }
|
|
|
- else {
|
|
|
+ } else {
|
|
|
throw new XiaoShiException("上传文件为空");
|
|
|
}
|
|
|
}
|
|
@@ -46,6 +54,53 @@ public class FileManagerServiceImpl implements IFileManagerService {
|
|
|
//取系统文件
|
|
|
|
|
|
//删除系统文件
|
|
|
-
|
|
|
+ @Override
|
|
|
+ public void delete(List<Integer> ids, Integer type){
|
|
|
+ //首先判断传入的需要删除的id集合不能为空
|
|
|
+ if(CollectionUtils.isEmpty(ids)){
|
|
|
+ throw new XiaoShiException("需要删除的id集合不能为空");
|
|
|
+ }
|
|
|
+ if(type == null){
|
|
|
+ throw new XiaoShiException("删除类型不能为空");
|
|
|
+ }
|
|
|
+ //有逻辑删除和物理删除两种,需要进行判定,传入类型为0时,物理删除;传入类型为1时,逻辑删除
|
|
|
+ //逻辑删除(更新isDelete字段为1)
|
|
|
+ if(type.equals(1)){
|
|
|
+ //遍历传入的id集合,获取需要更新的对象,赋值给实体类
|
|
|
+ for(int i = 0; i < ids.size(); i++){
|
|
|
+ SystemFileVO systemFileVO = systemFileMapper.query(ids.get(i));
|
|
|
+ systemFileVO.setIsDelete(1);
|
|
|
+ //将查询出来的vo赋值给实体类
|
|
|
+ SystemFile systemFile = new SystemFile();
|
|
|
+ BeanUtils.copyProperties(systemFileVO, systemFile);
|
|
|
+ //更新表
|
|
|
+ int row = systemFileMapper.update(systemFile);
|
|
|
+ if(row != 1){
|
|
|
+ String mes = "逻辑删除系统文件第" + i + "条失败";
|
|
|
+ log.info("逻辑删除失败,{}", mes);
|
|
|
+ throw new XiaoShiException(mes);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //物理删除(删除服务器文件,删除数据库中记录)
|
|
|
+ //sftp删除文件
|
|
|
+ if(type.equals(2)){
|
|
|
+ for(int i = 0; i < ids.size(); i++){
|
|
|
+ //根据id到表中查询该文件记录的数据
|
|
|
+ SystemFileVO systemFileVO = systemFileService.query(ids.get(i));
|
|
|
+ //pType判断是服务器还是阿里云OSS
|
|
|
+ int pType = systemFileVO.getPType();
|
|
|
+ String filePath = systemFileVO.getFilePath();
|
|
|
+ fileFactoryService.delete(filePath, pType);
|
|
|
+ int row = systemFileMapper.deleteById(ids.get(i));
|
|
|
+ if(row != 1){
|
|
|
+ throw new XiaoShiException("删除异常");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
//系统文件是否存在
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|