From 8f45c5915850bdfd9be7578e62ed250eee9c56b4 Mon Sep 17 00:00:00 2001 From: caihaohan Date: Fri, 22 Sep 2023 09:58:20 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=80=9A=E7=94=A8=E5=B8=A6=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=AF=BC=E5=87=BA=EF=BC=88=E6=98=AF=E7=94=A8OssFile?= =?UTF-8?q?=E8=A1=A8=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/jero/modules/oss/entity/OSSFile.java | 12 ++++++ .../service/impl/LawsCommonServiceImpl.java | 23 +++++----- .../mapper/LawsStandardFileMapper.java | 22 ---------- .../mapper/xml/LawsStandardFileMapper.xml | 42 ------------------- .../service/ILawsStandardFileService.java | 12 +++++- .../impl/LawsStandardFileServiceImpl.java | 39 ++++++++--------- 6 files changed, 51 insertions(+), 99 deletions(-) delete mode 100644 laws-modules/src/main/java/com/jero/modules/laws/standard/mapper/LawsStandardFileMapper.java delete mode 100644 laws-modules/src/main/java/com/jero/modules/laws/standard/mapper/xml/LawsStandardFileMapper.xml diff --git a/laws-module-system/src/main/java/com/jero/modules/oss/entity/OSSFile.java b/laws-module-system/src/main/java/com/jero/modules/oss/entity/OSSFile.java index 1bd55c0d..ad6601ea 100644 --- a/laws-module-system/src/main/java/com/jero/modules/oss/entity/OSSFile.java +++ b/laws-module-system/src/main/java/com/jero/modules/oss/entity/OSSFile.java @@ -1,5 +1,6 @@ package com.jero.modules.oss.entity; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.annotations.ApiModelProperty; @@ -34,6 +35,9 @@ public class OSSFile extends JeroEntity { @ApiModelProperty(value = "标准id") private String standardId; + @ApiModelProperty(value = "标准编号") + private String standardNo; + @ApiModelProperty(value = "创建人登录名称") private String createBy; @@ -51,4 +55,12 @@ public class OSSFile extends JeroEntity { @ApiModelProperty(value = "所属部门") private String sysOrgCode; + /** + * 带文件下载之后展示的名字 + */ + @TableField(exist = false) + @ApiModelProperty(value = "带文件下载之后展示的名字") + private String fileDisplayName; + + } diff --git a/laws-modules/src/main/java/com/jero/modules/laws/common/service/impl/LawsCommonServiceImpl.java b/laws-modules/src/main/java/com/jero/modules/laws/common/service/impl/LawsCommonServiceImpl.java index b55ec7e6..eff4e241 100644 --- a/laws-modules/src/main/java/com/jero/modules/laws/common/service/impl/LawsCommonServiceImpl.java +++ b/laws-modules/src/main/java/com/jero/modules/laws/common/service/impl/LawsCommonServiceImpl.java @@ -899,7 +899,7 @@ public class LawsCommonServiceImpl implements ILawsCommonService { .collect(Collectors.toMap(LawsTag::getDbFieldName, LawsTag::getDbFieldTxt)); // 获取所有文件 - Map> fileMap = lawsStandardFileService.getAllFiles(standardNos); + Map> fileMap = lawsStandardFileService.getAllFiles(standardNos); // 设置文件字段 lawsStandardFileService.setRecordFile(records, standardNos, fileHeaders); @@ -946,13 +946,13 @@ public class LawsCommonServiceImpl implements ILawsCommonService { zipOut.closeEntry(); // 将文件和文件夹加入ZIP - for (Map.Entry> entry : fileMap.entrySet()) { + for (Map.Entry> entry : fileMap.entrySet()) { String folderName = entry.getKey(); - List files = entry.getValue(); + List files = entry.getValue(); // 收集所有文件id List fileIds = files.stream() - .map(LawsStandardFile::getFileId) + .map(OSSFile::getId) .collect(Collectors.toList()); // 找到所有文件记录 @@ -963,8 +963,8 @@ public class LawsCommonServiceImpl implements ILawsCommonService { List filePathList = new ArrayList<>(); Map nameCountMap = new HashMap<>(); - for (LawsStandardFile file : files) { - String fileNameByType = fileNameByTypeMap.get(file.getFileType()); + for (OSSFile file : files) { + String fileNameByType = fileNameByTypeMap.get(file.getStandardFileType()); String baseFilePath = folderName + "/" + fileNameByType; String currentFilePath = baseFilePath; @@ -991,17 +991,18 @@ public class LawsCommonServiceImpl implements ILawsCommonService { Iterator iterator = filePathList.iterator(); - for (LawsStandardFile file : files) { + for (OSSFile file : files) { if (iterator.hasNext()) { String updatedFilePath = iterator.next(); - file.setFileName(updatedFilePath); + file.setFileDisplayName(updatedFilePath); } } - for (LawsStandardFile file : files) { - OSSFile ossFile = ossFileMap.get(file.getFileId()); + + for (OSSFile file : files) { + OSSFile ossFile = ossFileMap.get(file.getId()); String fileExtension = FileUtil.extName(ossFile.getFileName()); - String filePath = file.getFileName() + "." + fileExtension; + String filePath = file.getFileDisplayName() + "." + fileExtension; ZipEntry fileEntry = new ZipEntry(filePath); zipOut.putNextEntry(fileEntry); diff --git a/laws-modules/src/main/java/com/jero/modules/laws/standard/mapper/LawsStandardFileMapper.java b/laws-modules/src/main/java/com/jero/modules/laws/standard/mapper/LawsStandardFileMapper.java deleted file mode 100644 index c1f4ca14..00000000 --- a/laws-modules/src/main/java/com/jero/modules/laws/standard/mapper/LawsStandardFileMapper.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.jero.modules.laws.standard.mapper; - -import com.jero.modules.laws.standard.entity.LawsStandardFile; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import org.apache.ibatis.annotations.Param; - -import java.util.List; - -/** -* @author ThinkBook -* @description 针对表【laws_standard_file】的数据库操作Mapper -* @createDate 2023-09-20 10:45:16 -* @Entity com.jero.modules.laws.standard.entity.StandardFile -*/ -public interface LawsStandardFileMapper extends BaseMapper { - - List getFilesByStandardNos(@Param("standardNos") List standardNos); -} - - - - diff --git a/laws-modules/src/main/java/com/jero/modules/laws/standard/mapper/xml/LawsStandardFileMapper.xml b/laws-modules/src/main/java/com/jero/modules/laws/standard/mapper/xml/LawsStandardFileMapper.xml deleted file mode 100644 index 4e517859..00000000 --- a/laws-modules/src/main/java/com/jero/modules/laws/standard/mapper/xml/LawsStandardFileMapper.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - - - - - - - - - - - - - - id,create_by,create_time, - update_by,update_time,org_code, - standard_no,file_id,file_type, - module_code - - - - diff --git a/laws-modules/src/main/java/com/jero/modules/laws/standard/service/ILawsStandardFileService.java b/laws-modules/src/main/java/com/jero/modules/laws/standard/service/ILawsStandardFileService.java index 7355f893..83d18919 100644 --- a/laws-modules/src/main/java/com/jero/modules/laws/standard/service/ILawsStandardFileService.java +++ b/laws-modules/src/main/java/com/jero/modules/laws/standard/service/ILawsStandardFileService.java @@ -2,6 +2,7 @@ package com.jero.modules.laws.standard.service; import com.jero.modules.laws.standard.entity.LawsStandardFile; import com.baomidou.mybatisplus.extension.service.IService; +import com.jero.modules.oss.entity.OSSFile; import com.jero.modules.tag.entity.LawsTag; import java.util.List; @@ -12,14 +13,21 @@ import java.util.Map; * @description 针对表【laws_standard_file】的数据库操作Service * @createDate 2023-09-20 10:45:16 */ -public interface ILawsStandardFileService extends IService { +public interface ILawsStandardFileService { /** * 根据标准编号集合获取文件列表 + * * @param standardNos * @return */ - Map> getAllFiles(List standardNos); + Map> getAllFiles(List standardNos); + /** + * 设置对象中的文件路径 + * @param records + * @param standardNos + * @param fileHeaders + */ void setRecordFile(List> records, List standardNos, List fileHeaders); } diff --git a/laws-modules/src/main/java/com/jero/modules/laws/standard/service/impl/LawsStandardFileServiceImpl.java b/laws-modules/src/main/java/com/jero/modules/laws/standard/service/impl/LawsStandardFileServiceImpl.java index bfc75243..1d3e5e8a 100644 --- a/laws-modules/src/main/java/com/jero/modules/laws/standard/service/impl/LawsStandardFileServiceImpl.java +++ b/laws-modules/src/main/java/com/jero/modules/laws/standard/service/impl/LawsStandardFileServiceImpl.java @@ -2,19 +2,15 @@ package com.jero.modules.laws.standard.service.impl; import cn.hutool.core.io.FileUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.jero.common.exception.JeroBootException; -import com.jero.common.system.api.ISysBaseAPI; -import com.jero.modules.laws.standard.entity.LawsStandardFile; import com.jero.modules.laws.standard.service.ILawsStandardFileService; -import com.jero.modules.laws.standard.mapper.LawsStandardFileMapper; +import com.jero.modules.oss.entity.OSSFile; +import com.jero.modules.oss.service.IOSSFileService; import com.jero.modules.tag.entity.LawsTag; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; -import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -26,34 +22,33 @@ import java.util.stream.Collectors; */ @Service @Transactional(rollbackFor = JeroBootException.class) -public class LawsStandardFileServiceImpl extends ServiceImpl - implements ILawsStandardFileService { +public class LawsStandardFileServiceImpl implements ILawsStandardFileService { @Resource - private LawsStandardFileMapper standardFileMapper; + private IOSSFileService ossFileService; @Override - public Map> getAllFiles(List standardNos) { + public Map> getAllFiles(List standardNos) { // 找到所有相关文件 - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper.in(LawsStandardFile::getStandardNo, standardNos); - List list = list(queryWrapper); + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.in(OSSFile::getStandardNo, standardNos); + List list = ossFileService.list(queryWrapper); // 将List转成Map return list.stream() - .collect(Collectors.groupingBy(LawsStandardFile::getStandardNo)); + .collect(Collectors.groupingBy(OSSFile::getStandardNo)); } @Override public void setRecordFile(List> records, List standardNos, List fileHeaders) { // 找到所有相关文件 - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper.in(LawsStandardFile::getStandardNo, standardNos); - List list = standardFileMapper.getFilesByStandardNos(standardNos); + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.in(OSSFile::getStandardNo, standardNos); + List list = ossFileService.list(queryWrapper); // 按照标准编号和文件类型分组 - Map> groupMap = list.stream() + Map> groupMap = list.stream() .collect(Collectors.groupingBy( - sf -> sf.getStandardNo() + "-" + sf.getFileType() // Key: standardNo-fileType + sf -> sf.getStandardNo() + "-" + sf.getStandardFileType() // Key: standardNo-fileType )); // 遍历每个记录 @@ -62,18 +57,18 @@ public class LawsStandardFileServiceImpl extends ServiceImpl lawsStandardFiles = groupMap.get(key); + List lawsStandardFiles = groupMap.get(key); if (lawsStandardFiles == null) { continue; } StringBuilder allFileName = new StringBuilder(); // 遍历找到的结果 if (lawsStandardFiles.size() == 1) { - String fileExtension = "." + FileUtil.extName(lawsStandardFiles.get(0).getFileDiskName()); + String fileExtension = "." + FileUtil.extName(lawsStandardFiles.get(0).getFileName()); allFileName = new StringBuilder(standardNo + "/" + fileName + fileExtension); } else { for (int i = 1; i <= lawsStandardFiles.size(); i++) { - String fileExtension = "." + FileUtil.extName(lawsStandardFiles.get(0).getFileDiskName()); + String fileExtension = "." + FileUtil.extName(lawsStandardFiles.get(0).getFileName()); allFileName.append(standardNo).append("/").append(fileName).append(i).append(fileExtension).append(","); } // 去除最后一个,