feat: 导出文件放在单独的文件夹并且维护超链接
This commit is contained in:
+1
@@ -138,6 +138,7 @@ public class ProcessStandardComplianceCheckDetail implements Serializable {
|
||||
/**
|
||||
* 评估日期
|
||||
*/
|
||||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@ApiModelProperty(value = "评估日期")
|
||||
private Date valuationTime;
|
||||
|
||||
|
||||
+5
-5
@@ -516,7 +516,7 @@ public class ProcessStandardComplianceCheckServiceImpl extends ServiceImpl<Proce
|
||||
}
|
||||
try (FileOutputStream fos = new FileOutputStream(url + File.separator + fileName + ".xls")) {
|
||||
// 获取数据
|
||||
excelExportUtilPro.settleDocuments(url, detailInfoList,
|
||||
excelExportUtilPro.settleDocuments(url, "附件", detailInfoList,
|
||||
ProcessStandardComplianceCheckDetail::obtainFileIds,
|
||||
ProcessStandardComplianceCheckDetail::setFileList);
|
||||
// 生成excel
|
||||
@@ -534,8 +534,8 @@ public class ProcessStandardComplianceCheckServiceImpl extends ServiceImpl<Proce
|
||||
Workbook workbook = ExcelExportUtil
|
||||
.exportExcel(exportParams, ProcessStandardComplianceCheckDetail.class, detailInfoList);
|
||||
// 生成超链接
|
||||
excelExportUtilPro.generateHyperlink(newRecordsExport, workbook,
|
||||
ProcessStandardComplianceCheckDetail::getFileList, 15);
|
||||
excelExportUtilPro.generateHyperlink("附件", newRecordsExport, workbook,
|
||||
ProcessStandardComplianceCheckDetail::getFileList, 16);
|
||||
// 导出excel
|
||||
workbook.write(fos);
|
||||
// 生成并导出zip
|
||||
@@ -573,7 +573,7 @@ public class ProcessStandardComplianceCheckServiceImpl extends ServiceImpl<Proce
|
||||
}
|
||||
try (FileOutputStream fos = new FileOutputStream(url + File.separator + fileName + ".xls")) {
|
||||
// 获取数据
|
||||
excelExportUtilPro.settleDocuments(url, detailInfoList,
|
||||
excelExportUtilPro.settleDocuments(url, "佐证材料", detailInfoList,
|
||||
ProcessStandardComplianceCheckDetail::obtainFileIds,
|
||||
ProcessStandardComplianceCheckDetail::setFileList);
|
||||
|
||||
@@ -594,7 +594,7 @@ public class ProcessStandardComplianceCheckServiceImpl extends ServiceImpl<Proce
|
||||
// 翻译评估结果和佐证材料字段
|
||||
data.parallelStream().forEach(item -> {
|
||||
item.setResult(excelUtils.translateDict("evaluation_result", item.getResult(), listDict));
|
||||
item.setMaterial(excelUtils.translateDictValue("id", "file_name", "oss_file", item.getMaterial(), listDict));
|
||||
item.setMaterial("佐证材料/" + excelUtils.translateDictValue("id", "file_name", "oss_file", item.getMaterial(), listDict));
|
||||
});
|
||||
Workbook workbook = ExcelExportUtil
|
||||
.exportExcel(exportParams, WithoutDistributeExcelTemplate.class, data);
|
||||
|
||||
+19
-8
@@ -173,7 +173,7 @@ public class LawsConformityAssessmentLibraryServiceImpl extends ServiceImpl<Laws
|
||||
recordsExport.addAll(vos);
|
||||
});
|
||||
|
||||
this.settleDocuments(url, recordsExport);
|
||||
this.settleDocuments(url, "佐证材料", recordsExport);
|
||||
|
||||
// 去除文本的<p>
|
||||
String regex = "<[^>]*>";
|
||||
@@ -191,7 +191,7 @@ public class LawsConformityAssessmentLibraryServiceImpl extends ServiceImpl<Laws
|
||||
List<LawsConformityAssessmentLibraryExportVO> newRecordsExport = new ArrayList<>(recordsExport);
|
||||
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, LawsConformityAssessmentLibraryExportVO.class, recordsExport);
|
||||
// 生成超链接
|
||||
generateHyperlink(newRecordsExport, workbook);
|
||||
generateHyperlink("佐证材料", newRecordsExport, workbook);
|
||||
// 导出excel
|
||||
workbook.write(fos);
|
||||
// 生成并导出zip
|
||||
@@ -227,7 +227,7 @@ public class LawsConformityAssessmentLibraryServiceImpl extends ServiceImpl<Laws
|
||||
}
|
||||
}
|
||||
|
||||
private static void generateHyperlink(List<LawsConformityAssessmentLibraryExportVO> vos, Workbook workbook) {
|
||||
private static void generateHyperlink(String folderName, List<LawsConformityAssessmentLibraryExportVO> vos, Workbook workbook) {
|
||||
Sheet sheet = workbook.getSheetAt(0);
|
||||
// 设置字体颜色、下划线
|
||||
CellStyle cellStyle = workbook.createCellStyle();
|
||||
@@ -242,7 +242,9 @@ public class LawsConformityAssessmentLibraryServiceImpl extends ServiceImpl<Laws
|
||||
for (MaterialFile materialFile : vo.getMaterialFileList()) {
|
||||
Row row = sheet.getRow(i);
|
||||
Cell cell = row.getCell(18);
|
||||
cell.setCellFormula("HYPERLINK(\"" + materialFile.getFileName() + "\", \"" + materialFile.getFileName() + "\")");
|
||||
// 构建完整的超链接路径,包括文件夹名称
|
||||
String hyperlinkPath = folderName + "/" + materialFile.getFileName();
|
||||
cell.setCellFormula("HYPERLINK(\"" + hyperlinkPath + "\", \"" + materialFile.getFileName() + "\")");
|
||||
cell.setCellStyle(cellStyle);
|
||||
i += 1;
|
||||
}
|
||||
@@ -252,8 +254,16 @@ public class LawsConformityAssessmentLibraryServiceImpl extends ServiceImpl<Laws
|
||||
}
|
||||
}
|
||||
|
||||
private void settleDocuments(String url, List<LawsConformityAssessmentLibraryExportVO> excelVos) throws
|
||||
IOException {
|
||||
private void settleDocuments(String url, String folderName, List<LawsConformityAssessmentLibraryExportVO> excelVos) throws IOException {
|
||||
// 构建完整的文件夹路径
|
||||
String directoryPath = url + File.separator + folderName;
|
||||
|
||||
// 检查文件夹是否存在,如果不存在则创建
|
||||
File directory = new File(directoryPath);
|
||||
if (!directory.exists()) {
|
||||
directory.mkdirs(); // 使用mkdirs()而不是mkdir(),因为mkdirs()会创建所有必需的父目录
|
||||
}
|
||||
|
||||
for (LawsConformityAssessmentLibraryExportVO vo : excelVos) {
|
||||
// 查询文件
|
||||
if (StringUtils.isNotBlank(vo.getMaterial())) {
|
||||
@@ -270,8 +280,8 @@ public class LawsConformityAssessmentLibraryServiceImpl extends ServiceImpl<Laws
|
||||
if (StringUtils.endsWithIgnoreCase(ossFile.getFileName(), ".pdf")) {
|
||||
inputStream = sysWaterMarkUtil.addWatermarkToPdf(inputStream);
|
||||
}
|
||||
// 导出文件
|
||||
String filePath = url + File.separator + ossFile.getFileName();
|
||||
// 构建文件保存路径,将文件保存在指定文件夹下
|
||||
String filePath = url + File.separator + folderName + File.separator + ossFile.getFileName();
|
||||
writeToLocal(filePath, inputStream);
|
||||
}
|
||||
}
|
||||
@@ -279,6 +289,7 @@ public class LawsConformityAssessmentLibraryServiceImpl extends ServiceImpl<Laws
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 将InputStream写入本地文件
|
||||
*
|
||||
|
||||
+2
-2
@@ -117,7 +117,7 @@ public class LawsEvaluationNotMetLibraryServiceImpl extends ServiceImpl<LawsEval
|
||||
IPage<LawsEvaluationNotMetLibrary> lawsEvaluationNotMets = this.queryPage(lawsEvaluationNotMet, 1, Integer.MAX_VALUE, req);
|
||||
List<LawsEvaluationNotMetLibrary> records = lawsEvaluationNotMets.getRecords();
|
||||
|
||||
excelExportUtilPro.settleDocuments(url, records, LawsEvaluationNotMetLibrary::obtainFileIds, LawsEvaluationNotMetLibrary::setFileList);
|
||||
excelExportUtilPro.settleDocuments(url, "附件", records, LawsEvaluationNotMetLibrary::obtainFileIds, LawsEvaluationNotMetLibrary::setFileList);
|
||||
|
||||
// 去除文本的<p>
|
||||
String regex = "<[^>]*>";
|
||||
@@ -135,7 +135,7 @@ public class LawsEvaluationNotMetLibraryServiceImpl extends ServiceImpl<LawsEval
|
||||
List<LawsEvaluationNotMetLibrary> newRecordsExport = new ArrayList<>(records);
|
||||
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, LawsEvaluationNotMetLibrary.class, records);
|
||||
// 生成超链接
|
||||
excelExportUtilPro.generateHyperlink(newRecordsExport, workbook, LawsEvaluationNotMetLibrary::getFileList, 12);
|
||||
excelExportUtilPro.generateHyperlink("附件", newRecordsExport, workbook, LawsEvaluationNotMetLibrary::getFileList, 12);
|
||||
// 导出excel
|
||||
workbook.write(fos);
|
||||
// 生成并导出zip
|
||||
|
||||
@@ -44,7 +44,7 @@ public class ExcelExportUtilPro {
|
||||
private String fileName;
|
||||
}
|
||||
|
||||
public <T> void generateHyperlink(List<T> items, Workbook workbook,
|
||||
public <T> void generateHyperlink(String folderName, List<T> items, Workbook workbook,
|
||||
Function<T, List<FileDetails>> fileDetailsProvider,
|
||||
Integer cellNum) {
|
||||
Sheet sheet = workbook.getSheetAt(0);
|
||||
@@ -56,7 +56,9 @@ public class ExcelExportUtilPro {
|
||||
for (FileDetails fileDetails : fileDetailsList) {
|
||||
Row row = sheet.getRow(rowIndex);
|
||||
Cell cell = row.getCell(cellNum);
|
||||
cell.setCellFormula("HYPERLINK(\"" + fileDetails.getFileName() + "\", \"" + fileDetails.getFileName() + "\")");
|
||||
// 构建完整的超链接路径,包括文件夹名称
|
||||
String hyperlinkPath = folderName + "/" + fileDetails.getFileName();
|
||||
cell.setCellFormula("HYPERLINK(\"" + hyperlinkPath + "\", \"" + fileDetails.getFileName() + "\")");
|
||||
cell.setCellStyle(cellStyle);
|
||||
rowIndex++;
|
||||
}
|
||||
@@ -76,9 +78,18 @@ public class ExcelExportUtilPro {
|
||||
return cellStyle;
|
||||
}
|
||||
|
||||
public <T> void settleDocuments(String url, List<T> items,
|
||||
public <T> void settleDocuments(String url, String folderName, List<T> items,
|
||||
Function<T, List<String>> fileIdProvider,
|
||||
BiConsumer<T, List<FileDetails>> fileDetailsConsumer) throws IOException {
|
||||
// 构建完整的文件夹路径
|
||||
String directoryPath = url + File.separator + folderName;
|
||||
|
||||
// 检查文件夹是否存在,如果不存在则创建
|
||||
File directory = new File(directoryPath);
|
||||
if (!directory.exists()) {
|
||||
directory.mkdirs(); // 使用mkdirs()而不是mkdir(),因为mkdirs()会创建所有必需的父目录
|
||||
}
|
||||
|
||||
for (T item : items) {
|
||||
List<String> fileIdList = fileIdProvider.apply(item);
|
||||
if (fileIdList != null && !fileIdList.isEmpty()) {
|
||||
@@ -91,7 +102,7 @@ public class ExcelExportUtilPro {
|
||||
if (StringUtils.endsWithIgnoreCase(ossFile.getFileName(), ".pdf")) {
|
||||
inputStream = sysWaterMarkUtil.addWatermarkToPdf(inputStream);
|
||||
}
|
||||
String filePath = url + File.separator + ossFile.getFileName();
|
||||
String filePath = url + File.separator + folderName + File.separator + ossFile.getFileName();
|
||||
writeToLocal(filePath, inputStream);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user