feat: 通用带文件导出(是用OssFile表)
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package com.jero.modules.oss.entity;
|
package com.jero.modules.oss.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
@@ -34,6 +35,9 @@ public class OSSFile extends JeroEntity {
|
|||||||
@ApiModelProperty(value = "标准id")
|
@ApiModelProperty(value = "标准id")
|
||||||
private String standardId;
|
private String standardId;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "标准编号")
|
||||||
|
private String standardNo;
|
||||||
|
|
||||||
@ApiModelProperty(value = "创建人登录名称")
|
@ApiModelProperty(value = "创建人登录名称")
|
||||||
private String createBy;
|
private String createBy;
|
||||||
|
|
||||||
@@ -51,4 +55,12 @@ public class OSSFile extends JeroEntity {
|
|||||||
@ApiModelProperty(value = "所属部门")
|
@ApiModelProperty(value = "所属部门")
|
||||||
private String sysOrgCode;
|
private String sysOrgCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 带文件下载之后展示的名字
|
||||||
|
*/
|
||||||
|
@TableField(exist = false)
|
||||||
|
@ApiModelProperty(value = "带文件下载之后展示的名字")
|
||||||
|
private String fileDisplayName;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-11
@@ -899,7 +899,7 @@ public class LawsCommonServiceImpl implements ILawsCommonService {
|
|||||||
.collect(Collectors.toMap(LawsTag::getDbFieldName, LawsTag::getDbFieldTxt));
|
.collect(Collectors.toMap(LawsTag::getDbFieldName, LawsTag::getDbFieldTxt));
|
||||||
|
|
||||||
// 获取所有文件
|
// 获取所有文件
|
||||||
Map<String, List<LawsStandardFile>> fileMap = lawsStandardFileService.getAllFiles(standardNos);
|
Map<String, List<OSSFile>> fileMap = lawsStandardFileService.getAllFiles(standardNos);
|
||||||
|
|
||||||
// 设置文件字段
|
// 设置文件字段
|
||||||
lawsStandardFileService.setRecordFile(records, standardNos, fileHeaders);
|
lawsStandardFileService.setRecordFile(records, standardNos, fileHeaders);
|
||||||
@@ -946,13 +946,13 @@ public class LawsCommonServiceImpl implements ILawsCommonService {
|
|||||||
zipOut.closeEntry();
|
zipOut.closeEntry();
|
||||||
|
|
||||||
// 将文件和文件夹加入ZIP
|
// 将文件和文件夹加入ZIP
|
||||||
for (Map.Entry<String, List<LawsStandardFile>> entry : fileMap.entrySet()) {
|
for (Map.Entry<String, List<OSSFile>> entry : fileMap.entrySet()) {
|
||||||
String folderName = entry.getKey();
|
String folderName = entry.getKey();
|
||||||
List<LawsStandardFile> files = entry.getValue();
|
List<OSSFile> files = entry.getValue();
|
||||||
|
|
||||||
// 收集所有文件id
|
// 收集所有文件id
|
||||||
List<String> fileIds = files.stream()
|
List<String> fileIds = files.stream()
|
||||||
.map(LawsStandardFile::getFileId)
|
.map(OSSFile::getId)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
// 找到所有文件记录
|
// 找到所有文件记录
|
||||||
@@ -963,8 +963,8 @@ public class LawsCommonServiceImpl implements ILawsCommonService {
|
|||||||
List<String> filePathList = new ArrayList<>();
|
List<String> filePathList = new ArrayList<>();
|
||||||
Map<String, Integer> nameCountMap = new HashMap<>();
|
Map<String, Integer> nameCountMap = new HashMap<>();
|
||||||
|
|
||||||
for (LawsStandardFile file : files) {
|
for (OSSFile file : files) {
|
||||||
String fileNameByType = fileNameByTypeMap.get(file.getFileType());
|
String fileNameByType = fileNameByTypeMap.get(file.getStandardFileType());
|
||||||
String baseFilePath = folderName + "/" + fileNameByType;
|
String baseFilePath = folderName + "/" + fileNameByType;
|
||||||
String currentFilePath = baseFilePath;
|
String currentFilePath = baseFilePath;
|
||||||
|
|
||||||
@@ -991,17 +991,18 @@ public class LawsCommonServiceImpl implements ILawsCommonService {
|
|||||||
|
|
||||||
Iterator<String> iterator = filePathList.iterator();
|
Iterator<String> iterator = filePathList.iterator();
|
||||||
|
|
||||||
for (LawsStandardFile file : files) {
|
for (OSSFile file : files) {
|
||||||
if (iterator.hasNext()) {
|
if (iterator.hasNext()) {
|
||||||
String updatedFilePath = iterator.next();
|
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 fileExtension = FileUtil.extName(ossFile.getFileName());
|
||||||
String filePath = file.getFileName() + "." + fileExtension;
|
String filePath = file.getFileDisplayName() + "." + fileExtension;
|
||||||
ZipEntry fileEntry = new ZipEntry(filePath);
|
ZipEntry fileEntry = new ZipEntry(filePath);
|
||||||
zipOut.putNextEntry(fileEntry);
|
zipOut.putNextEntry(fileEntry);
|
||||||
|
|
||||||
|
|||||||
-22
@@ -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<LawsStandardFile> {
|
|
||||||
|
|
||||||
List<LawsStandardFile> getFilesByStandardNos(@Param("standardNos") List<String> standardNos);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-42
@@ -1,42 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!DOCTYPE mapper
|
|
||||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|
||||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
|
||||||
<mapper namespace="com.jero.modules.laws.standard.mapper.LawsStandardFileMapper">
|
|
||||||
|
|
||||||
<resultMap id="BaseResultMap" type="com.jero.modules.laws.standard.entity.LawsStandardFile">
|
|
||||||
<id property="id" column="id" jdbcType="VARCHAR"/>
|
|
||||||
<result property="createBy" column="create_by" jdbcType="VARCHAR"/>
|
|
||||||
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
|
|
||||||
<result property="updateBy" column="update_by" jdbcType="VARCHAR"/>
|
|
||||||
<result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
|
|
||||||
<result property="orgCode" column="org_code" jdbcType="VARCHAR"/>
|
|
||||||
<result property="standardNo" column="standard_no" jdbcType="VARCHAR"/>
|
|
||||||
<result property="fileId" column="file_id" jdbcType="VARCHAR"/>
|
|
||||||
<result property="fileType" column="file_type" jdbcType="VARCHAR"/>
|
|
||||||
<result property="moduleCode" column="module_code" jdbcType="VARCHAR"/>
|
|
||||||
</resultMap>
|
|
||||||
|
|
||||||
<sql id="Base_Column_List">
|
|
||||||
id,create_by,create_time,
|
|
||||||
update_by,update_time,org_code,
|
|
||||||
standard_no,file_id,file_type,
|
|
||||||
module_code
|
|
||||||
</sql>
|
|
||||||
|
|
||||||
<select id="getFilesByStandardNos" resultType="com.jero.modules.laws.standard.entity.LawsStandardFile">
|
|
||||||
SELECT
|
|
||||||
sf.id,
|
|
||||||
sf.standard_no,
|
|
||||||
o.id AS fileId,
|
|
||||||
sf.file_type,
|
|
||||||
sf.module_code,
|
|
||||||
o.file_name AS fileDiskName
|
|
||||||
FROM laws_standard_file AS sf
|
|
||||||
LEFT JOIN oss_file AS O ON sf.file_id = O.id
|
|
||||||
WHERE sf.standard_no IN
|
|
||||||
<foreach item="item" index="index" collection="standardNos" open="(" separator="," close=")">
|
|
||||||
#{item}
|
|
||||||
</foreach>
|
|
||||||
</select>
|
|
||||||
</mapper>
|
|
||||||
+10
-2
@@ -2,6 +2,7 @@ package com.jero.modules.laws.standard.service;
|
|||||||
|
|
||||||
import com.jero.modules.laws.standard.entity.LawsStandardFile;
|
import com.jero.modules.laws.standard.entity.LawsStandardFile;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.jero.modules.oss.entity.OSSFile;
|
||||||
import com.jero.modules.tag.entity.LawsTag;
|
import com.jero.modules.tag.entity.LawsTag;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -12,14 +13,21 @@ import java.util.Map;
|
|||||||
* @description 针对表【laws_standard_file】的数据库操作Service
|
* @description 针对表【laws_standard_file】的数据库操作Service
|
||||||
* @createDate 2023-09-20 10:45:16
|
* @createDate 2023-09-20 10:45:16
|
||||||
*/
|
*/
|
||||||
public interface ILawsStandardFileService extends IService<LawsStandardFile> {
|
public interface ILawsStandardFileService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据标准编号集合获取文件列表
|
* 根据标准编号集合获取文件列表
|
||||||
|
*
|
||||||
* @param standardNos
|
* @param standardNos
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
Map<String, List<LawsStandardFile>> getAllFiles(List<String> standardNos);
|
Map<String, List<OSSFile>> getAllFiles(List<String> standardNos);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置对象中的文件路径
|
||||||
|
* @param records
|
||||||
|
* @param standardNos
|
||||||
|
* @param fileHeaders
|
||||||
|
*/
|
||||||
void setRecordFile(List<Map<String, Object>> records, List<String> standardNos, List<LawsTag> fileHeaders);
|
void setRecordFile(List<Map<String, Object>> records, List<String> standardNos, List<LawsTag> fileHeaders);
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-22
@@ -2,19 +2,15 @@ package com.jero.modules.laws.standard.service.impl;
|
|||||||
|
|
||||||
import cn.hutool.core.io.FileUtil;
|
import cn.hutool.core.io.FileUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
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.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.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 com.jero.modules.tag.entity.LawsTag;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@@ -26,34 +22,33 @@ import java.util.stream.Collectors;
|
|||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
@Transactional(rollbackFor = JeroBootException.class)
|
@Transactional(rollbackFor = JeroBootException.class)
|
||||||
public class LawsStandardFileServiceImpl extends ServiceImpl<LawsStandardFileMapper, LawsStandardFile>
|
public class LawsStandardFileServiceImpl implements ILawsStandardFileService {
|
||||||
implements ILawsStandardFileService {
|
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private LawsStandardFileMapper standardFileMapper;
|
private IOSSFileService ossFileService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, List<LawsStandardFile>> getAllFiles(List<String> standardNos) {
|
public Map<String, List<OSSFile>> getAllFiles(List<String> standardNos) {
|
||||||
// 找到所有相关文件
|
// 找到所有相关文件
|
||||||
LambdaQueryWrapper<LawsStandardFile> queryWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<OSSFile> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
queryWrapper.in(LawsStandardFile::getStandardNo, standardNos);
|
queryWrapper.in(OSSFile::getStandardNo, standardNos);
|
||||||
List<LawsStandardFile> list = list(queryWrapper);
|
List<OSSFile> list = ossFileService.list(queryWrapper);
|
||||||
|
|
||||||
// 将List转成Map
|
// 将List转成Map
|
||||||
return list.stream()
|
return list.stream()
|
||||||
.collect(Collectors.groupingBy(LawsStandardFile::getStandardNo));
|
.collect(Collectors.groupingBy(OSSFile::getStandardNo));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setRecordFile(List<Map<String, Object>> records, List<String> standardNos, List<LawsTag> fileHeaders) {
|
public void setRecordFile(List<Map<String, Object>> records, List<String> standardNos, List<LawsTag> fileHeaders) {
|
||||||
// 找到所有相关文件
|
// 找到所有相关文件
|
||||||
LambdaQueryWrapper<LawsStandardFile> queryWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<OSSFile> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
queryWrapper.in(LawsStandardFile::getStandardNo, standardNos);
|
queryWrapper.in(OSSFile::getStandardNo, standardNos);
|
||||||
List<LawsStandardFile> list = standardFileMapper.getFilesByStandardNos(standardNos);
|
List<OSSFile> list = ossFileService.list(queryWrapper);
|
||||||
// 按照标准编号和文件类型分组
|
// 按照标准编号和文件类型分组
|
||||||
Map<String, List<LawsStandardFile>> groupMap = list.stream()
|
Map<String, List<OSSFile>> groupMap = list.stream()
|
||||||
.collect(Collectors.groupingBy(
|
.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<LawsStandardFileMap
|
|||||||
for (LawsTag tag : fileHeaders) {
|
for (LawsTag tag : fileHeaders) {
|
||||||
String fileName = tag.getDbFieldTxt();
|
String fileName = tag.getDbFieldTxt();
|
||||||
String key = standardNo + "-" + tag.getDbFieldName();
|
String key = standardNo + "-" + tag.getDbFieldName();
|
||||||
List<LawsStandardFile> lawsStandardFiles = groupMap.get(key);
|
List<OSSFile> lawsStandardFiles = groupMap.get(key);
|
||||||
if (lawsStandardFiles == null) {
|
if (lawsStandardFiles == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
StringBuilder allFileName = new StringBuilder();
|
StringBuilder allFileName = new StringBuilder();
|
||||||
// 遍历找到的结果
|
// 遍历找到的结果
|
||||||
if (lawsStandardFiles.size() == 1) {
|
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);
|
allFileName = new StringBuilder(standardNo + "/" + fileName + fileExtension);
|
||||||
} else {
|
} else {
|
||||||
for (int i = 1; i <= lawsStandardFiles.size(); i++) {
|
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(",");
|
allFileName.append(standardNo).append("/").append(fileName).append(i).append(fileExtension).append(",");
|
||||||
}
|
}
|
||||||
// 去除最后一个,
|
// 去除最后一个,
|
||||||
|
|||||||
Reference in New Issue
Block a user