From c8d79abfc012de3d5cd6749866067b04613276c8 Mon Sep 17 00:00:00 2001
From: liyj <1003249715@qq.com>
Date: Mon, 02 Sep 2024 19:50:36 +0800
Subject: [PATCH] 1、新增sys服务删除附件接口
---
dyh-service/dyh-sys/src/main/java/cn/huge/module/file/service/FileInfoService.java | 153 +++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 148 insertions(+), 5 deletions(-)
diff --git a/dyh-service/dyh-sys/src/main/java/cn/huge/module/file/service/FileInfoService.java b/dyh-service/dyh-sys/src/main/java/cn/huge/module/file/service/FileInfoService.java
index a8018fd..659a334 100644
--- a/dyh-service/dyh-sys/src/main/java/cn/huge/module/file/service/FileInfoService.java
+++ b/dyh-service/dyh-sys/src/main/java/cn/huge/module/file/service/FileInfoService.java
@@ -3,23 +3,31 @@
import cn.huge.base.common.exception.ServiceException;
import cn.huge.base.common.utils.DateUtils;
import cn.huge.base.common.utils.IdUtils;
+import cn.huge.base.common.utils.ObjectUtils;
import cn.huge.module.client.api.impl.UtilsClientImpl;
+import cn.huge.module.constant.BaseConsts;
import cn.huge.module.file.dao.mapper.FileInfoMapper;
+import cn.huge.module.file.domain.dto.FileForCatDTO;
+import cn.huge.module.file.domain.dto.FileForCatListDTO;
+import cn.huge.module.file.domain.dto.UploaderDTO;
import cn.huge.module.file.domain.po.FileInfo;
+import cn.huge.module.file.domain.po.FileRelate;
+import cn.huge.module.file.utils.FtpUtils;
+import cn.huge.module.file.utils.FtpMultipartFileWrapper;
+import cn.huge.module.sys.constant.FileOwnerTypeBaseEnum;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.multipart.MultipartFile;
-import javax.annotation.PostConstruct;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
/**
* @title: 附件信息表业务逻辑处理
@@ -36,6 +44,8 @@
@Autowired
private FileInfoMapper mapper;
+ @Autowired
+ private FileRelateService fileRelateService;
@Autowired
private UtilsClientImpl utilsClient;
@@ -130,4 +140,137 @@
}
}
+ /**
+ * web端上传附件,保存附件信息和业务关系
+ * @param file 附件
+ * @param ownerId 所属业务编号
+ * @param ownerType 所属业务名称
+ * @param fileCount 第几份附件
+ * @param uploaderDTO 上传人信息
+ * @return
+ */
+ public FileInfo webUploadFile(MultipartFile file, String mainId, String ownerId, String ownerType, int fileCount, UploaderDTO uploaderDTO) {
+ try {
+ String fileId = utilsClient.getNewTimeId();
+ // 创建附件信息
+ FileInfo fileInfo = new FtpMultipartFileWrapper(file).toWebFileInfo(fileId);
+ // 上传到ftp服务器
+ FtpUtils ftpUtils = new FtpUtils();
+ ftpUtils.upload(fileInfo.getPath(), fileInfo.getFileName(), file.getInputStream());
+ // 保存附件信息
+ fileInfo.setName(FileOwnerTypeBaseEnum.getDes(ownerType) + BaseConsts.UNDER + fileCount);
+ fileInfo.setMainId(mainId);
+ fileInfo.setOwnerId(ownerId);
+ fileInfo.setOwnerCat(FileOwnerTypeBaseEnum.getCat(ownerType));
+ fileInfo.setOwnerCatName(FileOwnerTypeBaseEnum.getDes(fileInfo.getOwnerCat()));
+ fileInfo.setOwnerType(ownerType);
+ fileInfo.setOwnerTypeName(FileOwnerTypeBaseEnum.getDes(ownerType));
+ fileInfo.setUploaderId(uploaderDTO.getUploaderId());
+ fileInfo.setUploaderName(uploaderDTO.getUploaderName());
+ fileInfo.setUploaderType(uploaderDTO.getUploaderType());
+ fileInfo.setCustId(uploaderDTO.getCustId());
+ mapper.insert(fileInfo);
+ // 保存业务关系
+ fileRelateService.saveByFileInfo(fileInfo);
+ return fileInfo;
+ } catch (Exception e) {
+ log.error("service方法[FileInfoService.uploadFile]调用失败,异常信息:"+e, e);
+ throw new ServiceException("FileInfoService.uploadFile", e);
+ }
+ }
+
+ /**
+ * wechat端上传附件,保存附件信息和业务关系
+ * @param file 附件
+ * @param ownerId 所属业务编号
+ * @param ownerType 所属业务名称
+ * @param fileCount 第几份附件
+ * @param uploaderDTO 上传人信息
+ * @return
+ */
+ public FileInfo wechatUploadFile(MultipartFile file, String mainId, String ownerId, String ownerType, int fileCount, UploaderDTO uploaderDTO) {
+ try {
+ String fileId = utilsClient.getNewTimeId();
+ // 创建附件信息
+ FileInfo fileInfo = new FtpMultipartFileWrapper(file).toWechatFileInfo(fileId);
+ // 上传到ftp服务器
+ FtpUtils ftpUtils = new FtpUtils();
+ ftpUtils.upload(fileInfo.getPath(), fileInfo.getFileName(), file.getInputStream());
+ // 保存附件信息
+ fileInfo.setName(FileOwnerTypeBaseEnum.getDes(ownerType) + BaseConsts.UNDER + fileCount);
+ fileInfo.setMainId(mainId);
+ fileInfo.setOwnerId(ownerId);
+ fileInfo.setOwnerCat(FileOwnerTypeBaseEnum.getCat(ownerType));
+ fileInfo.setOwnerCatName(FileOwnerTypeBaseEnum.getDes(fileInfo.getOwnerCat()));
+ fileInfo.setOwnerType(ownerType);
+ fileInfo.setOwnerTypeName(FileOwnerTypeBaseEnum.getDes(ownerType));
+ fileInfo.setUploaderId(uploaderDTO.getUploaderId());
+ fileInfo.setUploaderName(uploaderDTO.getUploaderName());
+ fileInfo.setUploaderType(uploaderDTO.getUploaderType());
+ fileInfo.setCustId(uploaderDTO.getCustId());
+ mapper.insert(fileInfo);
+ // 保存业务关系
+ fileRelateService.saveByFileInfo(fileInfo);
+ return fileInfo;
+ } catch (Exception e) {
+ log.error("service方法[FileInfoService.uploadFile]调用失败,异常信息:"+e, e);
+ throw new ServiceException("FileInfoService.uploadFile", e);
+ }
+ }
+
+ /**
+ * 查看附件组件-分类查询附件
+ * @param terms
+ * @return
+ */
+ public List<FileForCatListDTO> webListFileByCat(Map<String, Object> terms){
+ List<FileForCatListDTO> fileForCatListDTOList = new ArrayList<>();
+ // 查询附件信息进行封装
+ List<FileForCatDTO> oldFileForCatDTOList = mapper.listFileByCatTerms(terms);
+ if (CollectionUtils.isNotEmpty(oldFileForCatDTOList)) {
+ Set<String> setTmp = new HashSet<>();
+ for (FileForCatDTO fileForCatDTO: oldFileForCatDTOList) {
+ if (ObjectUtils.isNotEmpty(fileForCatDTO.getOwnerCat())) {
+ setTmp.add(fileForCatDTO.getOwnerCat());
+ }
+ }
+ Iterator<String> it = setTmp.iterator();
+ while (it.hasNext()) {
+ String ownerCat = it.next();
+ FileForCatListDTO fileForCatListDTO = new FileForCatListDTO();
+ fileForCatListDTO.setOwnerCat(ownerCat);
+ fileForCatListDTO.setOwnerCatName(FileOwnerTypeBaseEnum.getDes(ownerCat));
+ List<FileForCatDTO> newFileForCatDTOS = new ArrayList<>();
+ for (FileForCatDTO fileForCatDTO : oldFileForCatDTOList) {
+ if (ownerCat.equals(fileForCatDTO.getOwnerCat())) {
+ newFileForCatDTOS.add(fileForCatDTO);
+ }
+ }
+ fileForCatListDTO.setFileList(newFileForCatDTOS);
+ fileForCatListDTO.setFileSize(newFileForCatDTOS.size());
+ fileForCatListDTOList.add(fileForCatListDTO);
+ }
+ }
+ return fileForCatListDTOList;
+ }
+
+ /**
+ * 根据编号删除附件
+ * @param id 附件编号
+ */
+ public void deleteFileById(String id) {
+ try{
+ // 删除关系表
+ QueryWrapper<FileRelate> fileRelateQueryWrapper = new QueryWrapper<>();
+ fileRelateQueryWrapper.eq("file_id", id);
+ fileRelateService.remove(fileRelateQueryWrapper);
+ // 删除附件信息表
+ mapper.deleteById(id);
+ // 删除ftp文件
+ }catch (Exception e){
+ log.error("service方法[FileInfoService.deleteFileById]调用失败,异常信息:"+e, e);
+ throw new ServiceException("FileInfoService.deleteFileById", e);
+ }
+ }
+
}
--
Gitblit v1.8.0