|
@@ -1,24 +1,14 @@
|
|
|
-package com.example.fms.service.impl;
|
|
|
+package com.example.fms.service;
|
|
|
|
|
|
-import com.example.fms.common.model.dto.DownloadFileDTO;
|
|
|
import com.example.fms.common.model.dto.DownloadSysFileDTO;
|
|
|
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.common.utils.Response;
|
|
|
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.context.annotation.Bean;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
@@ -26,17 +16,15 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
|
- * service层实现类
|
|
|
- *
|
|
|
* @Author xiexiang
|
|
|
- * @Date 2023/6/7
|
|
|
+ * @Date 2023/8/9
|
|
|
*/
|
|
|
+@RequiredArgsConstructor
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
-@RequiredArgsConstructor
|
|
|
-public class FileManagerServiceImpl implements IFileManagerService {
|
|
|
+public class FileMangerService {
|
|
|
private final FileFactoryService fileFactoryService;
|
|
|
- private final ISystemFileService systemFileService;
|
|
|
+ private final SystemFileService systemFileService;
|
|
|
private final SystemFileMapper systemFileMapper;
|
|
|
|
|
|
/**
|
|
@@ -45,14 +33,14 @@ public class FileManagerServiceImpl implements IFileManagerService {
|
|
|
* @param files
|
|
|
* @param sourceId
|
|
|
*/
|
|
|
- @Override
|
|
|
- public void add(List<MultipartFile> files, Integer sourceId){
|
|
|
+ public List<Integer> add(List<MultipartFile> files, Integer sourceId){
|
|
|
if(files != null && files.size() != 0){
|
|
|
//1.获取文件上传到服务器,调用FileFactory的uploadFile
|
|
|
List<SystemFileDTO> systemFileDTOS = fileFactoryService.uploadFiles(files, sourceId);
|
|
|
//2.根据上传后的返回实体类信息,将实体类信息入库,调用systemFileService add
|
|
|
if(systemFileDTOS != null && systemFileDTOS.size() != 0 ) {
|
|
|
- systemFileService.add(systemFileDTOS);
|
|
|
+ List<Integer> insertIds = systemFileService.add(systemFileDTOS);
|
|
|
+ return insertIds;
|
|
|
} else {
|
|
|
throw new XiaoShiException("入表信息为空");
|
|
|
}
|
|
@@ -62,58 +50,27 @@ public class FileManagerServiceImpl implements IFileManagerService {
|
|
|
}
|
|
|
|
|
|
//取系统文件
|
|
|
- @Override
|
|
|
- public String download(DownloadFileDTO downloadFileDTO) throws Exception {
|
|
|
- Integer fileId = downloadFileDTO.getFileId();
|
|
|
- String fileName = downloadFileDTO.getFileName();
|
|
|
- Integer sourceId = downloadFileDTO.getSourceId();
|
|
|
+ public byte[] download(Integer fileId) throws Exception {
|
|
|
DownloadSysFileDTO downloadSysFileDTO = new DownloadSysFileDTO();
|
|
|
- SystemFileVO systemFileVO = new SystemFileVO();
|
|
|
- if(fileId != null && fileName == null){
|
|
|
- systemFileVO = systemFileService.query(fileId);
|
|
|
- if(systemFileVO.getIsDelete().equals(1)){
|
|
|
- return Response.error("文件已被删除");
|
|
|
- } else {
|
|
|
- BeanUtils.copyProperties(systemFileVO,downloadSysFileDTO);
|
|
|
- downloadSysFileDTO.setSourceId(sourceId);
|
|
|
- fileFactoryService.download(downloadSysFileDTO);
|
|
|
- return Response.success("下载成功");
|
|
|
- }
|
|
|
- } else if(fileId == null && fileName != null) {
|
|
|
- systemFileVO = systemFileMapper.getSystemFile(fileName);
|
|
|
+ if(fileId != null){
|
|
|
+ SystemFileVO systemFileVO = systemFileService.query(fileId);
|
|
|
if(systemFileVO.getIsDelete().equals(1)){
|
|
|
- return Response.error("文件已被删除");
|
|
|
+ return null;
|
|
|
} else {
|
|
|
BeanUtils.copyProperties(systemFileVO,downloadSysFileDTO);
|
|
|
- downloadSysFileDTO.setSourceId(sourceId);
|
|
|
- fileFactoryService.download(downloadSysFileDTO);
|
|
|
- return Response.success("下载成功");
|
|
|
- }
|
|
|
- } else if(fileId != null && fileName != null){
|
|
|
- systemFileVO = systemFileService.query(fileId);
|
|
|
- if(fileName.equals(systemFileVO.getFileName())){
|
|
|
- if(systemFileVO.getIsDelete().equals(1)){
|
|
|
- return Response.error("文件已被删除");
|
|
|
- } else {
|
|
|
- BeanUtils.copyProperties(systemFileVO,downloadSysFileDTO);
|
|
|
- downloadSysFileDTO.setSourceId(sourceId);
|
|
|
- fileFactoryService.download(downloadSysFileDTO);
|
|
|
- return Response.success("下载成功");
|
|
|
- }
|
|
|
- } else {
|
|
|
- return Response.error("错误数据");
|
|
|
+ downloadSysFileDTO.setSourceId(systemFileVO.getPType());
|
|
|
+ return fileFactoryService.download(downloadSysFileDTO);
|
|
|
}
|
|
|
- } else {
|
|
|
- return Response.error("参数错误");
|
|
|
}
|
|
|
+ return null;
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 删除系统文件
|
|
|
*
|
|
|
* @param ids
|
|
|
* @param type
|
|
|
*/
|
|
|
- @Override
|
|
|
public void delete(List<Integer> ids, Integer type){
|
|
|
//首先判断传入的需要删除的id集合不能为空
|
|
|
if(CollectionUtils.isEmpty(ids)){
|
|
@@ -160,8 +117,4 @@ public class FileManagerServiceImpl implements IFileManagerService {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- //系统文件是否存在
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|