|
|
@ -296,10 +296,132 @@ public class DocumentTaskResultsServiceImpl implements IDocumentTaskResultsServi |
|
|
|
List<DocumentTaskResults> list = baseMapper.selectList(lqw); |
|
|
|
|
|
|
|
if (list.isEmpty()) { |
|
|
|
throw new RuntimeException("未找到相关文件"); |
|
|
|
} |
|
|
|
|
|
|
|
if (list.size() > 1) { |
|
|
|
// 使用新的导出逻辑,基于getDetailResultsByTaskId获取结果
|
|
|
|
if (ids.length > 0) { |
|
|
|
if (ids.length > 1) { |
|
|
|
// 多文件压缩下载
|
|
|
|
String tempDir = System.getProperty("java.io.tmpdir"); |
|
|
|
String zipFileName = "results_export.zip"; |
|
|
|
String zipFilePath = tempDir + File.separator + zipFileName; |
|
|
|
|
|
|
|
try (ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipFilePath))) { |
|
|
|
for (Long taskId : ids) { |
|
|
|
DocumentTasksVo documentTasksVo = documentTasksService.queryById(taskId); |
|
|
|
if (documentTasksVo == null) continue; |
|
|
|
|
|
|
|
String documentName = documentTasksVo.getDocumentName(); |
|
|
|
String taskName = documentTasksVo.getTaskName(); |
|
|
|
String taskType = documentTasksVo.getTaskType(); |
|
|
|
String label = dictTypeService.getDictLabel(taskType, taskName); |
|
|
|
|
|
|
|
// 获取详细的任务结果
|
|
|
|
List<DocumentTaskResultVO> resultDetails = getDetailResultsByTaskId(String.valueOf(taskId)); |
|
|
|
if (resultDetails != null && !resultDetails.isEmpty()) { |
|
|
|
// 第一个是"全部"分类
|
|
|
|
DocumentTaskResultVO allCategory = resultDetails.get(0); |
|
|
|
if (allCategory.getResults() != null && !allCategory.getResults().isEmpty()) { |
|
|
|
// 获取任务类型对应的字段配置
|
|
|
|
List<FieldConfig> fieldConfigs = getFieldConfigsByTaskType(taskName); |
|
|
|
|
|
|
|
// 将结果转换为Markdown
|
|
|
|
StringBuilder markdown = new StringBuilder(); |
|
|
|
for (DocumentTaskResultVO.ResultItem item : allCategory.getResults()) { |
|
|
|
markdown.append("## ").append(item.getSerialNumber()).append(". ").append(item.getExistingIssues()).append("\n\n"); |
|
|
|
|
|
|
|
// 根据配置添加各字段内容
|
|
|
|
for (FieldConfig config : fieldConfigs) { |
|
|
|
String fieldValue = getFieldValue(item, config.getField()); |
|
|
|
if (StringUtils.isNotBlank(fieldValue)) { |
|
|
|
markdown.append("### ").append(config.getTitle()).append("\n\n").append(fieldValue).append("\n\n"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 添加分隔线
|
|
|
|
markdown.append("---\n\n"); |
|
|
|
} |
|
|
|
|
|
|
|
// 为每个结果创建PDF文件
|
|
|
|
String pdfFileName = label + "_" + documentName + "_" + ".pdf"; |
|
|
|
String pdfPath = tempDir + File.separator + pdfFileName; |
|
|
|
|
|
|
|
// 转换Markdown为PDF
|
|
|
|
convertMarkdownToPdf(markdown.toString(), pdfPath); |
|
|
|
|
|
|
|
// 添加到ZIP
|
|
|
|
addToZip(pdfPath, pdfFileName, zos); |
|
|
|
|
|
|
|
// 删除临时PDF文件
|
|
|
|
new File(pdfPath).delete(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 下载ZIP文件
|
|
|
|
downloadFile(response, zipFilePath, zipFileName); |
|
|
|
|
|
|
|
// 删除临时ZIP文件
|
|
|
|
new File(zipFilePath).delete(); |
|
|
|
} else { |
|
|
|
// 单文件下载
|
|
|
|
Long taskId = ids[0]; |
|
|
|
DocumentTasksVo documentTasksVo = documentTasksService.queryById(taskId); |
|
|
|
if (documentTasksVo == null) { |
|
|
|
throw new RuntimeException("未找到相关任务"); |
|
|
|
} |
|
|
|
|
|
|
|
String documentName = documentTasksVo.getDocumentName(); |
|
|
|
String taskName = documentTasksVo.getTaskName(); |
|
|
|
String taskType = documentTasksVo.getTaskType(); |
|
|
|
String label = dictTypeService.getDictLabel(taskType, taskName); |
|
|
|
|
|
|
|
// 获取详细的任务结果
|
|
|
|
List<DocumentTaskResultVO> resultDetails = getDetailResultsByTaskId(String.valueOf(taskId)); |
|
|
|
if (resultDetails == null || resultDetails.isEmpty() || |
|
|
|
resultDetails.get(0).getResults() == null || resultDetails.get(0).getResults().isEmpty()) { |
|
|
|
throw new RuntimeException("未找到相关结果"); |
|
|
|
} |
|
|
|
|
|
|
|
// 第一个是"全部"分类
|
|
|
|
DocumentTaskResultVO allCategory = resultDetails.get(0); |
|
|
|
|
|
|
|
// 获取任务类型对应的字段配置
|
|
|
|
List<FieldConfig> fieldConfigs = getFieldConfigsByTaskType(taskName); |
|
|
|
|
|
|
|
// 将结果转换为Markdown
|
|
|
|
StringBuilder markdown = new StringBuilder(); |
|
|
|
for (DocumentTaskResultVO.ResultItem item : allCategory.getResults()) { |
|
|
|
markdown.append("## ").append(item.getSerialNumber()).append(". ").append(item.getExistingIssues()).append("\n\n"); |
|
|
|
|
|
|
|
// 根据配置添加各字段内容
|
|
|
|
for (FieldConfig config : fieldConfigs) { |
|
|
|
String fieldValue = getFieldValue(item, config.getField()); |
|
|
|
if (StringUtils.isNotBlank(fieldValue)) { |
|
|
|
markdown.append("### ").append(config.getTitle()).append("\n\n").append(fieldValue).append("\n\n"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 添加分隔线
|
|
|
|
markdown.append("---\n\n"); |
|
|
|
} |
|
|
|
|
|
|
|
String pdfFileName = label + "_" + documentName + "_" + ".pdf"; |
|
|
|
String tempDir = System.getProperty("java.io.tmpdir"); |
|
|
|
String pdfPath = tempDir + File.separator + pdfFileName; |
|
|
|
|
|
|
|
// 转换Markdown为PDF
|
|
|
|
convertMarkdownToPdf(markdown.toString(), pdfPath); |
|
|
|
|
|
|
|
// 下载PDF文件
|
|
|
|
downloadFile(response, pdfPath, pdfFileName); |
|
|
|
|
|
|
|
// 删除临时PDF文件
|
|
|
|
new File(pdfPath).delete(); |
|
|
|
} |
|
|
|
} else { |
|
|
|
throw new RuntimeException("未找到相关文件"); |
|
|
|
} |
|
|
|
} else if (list.size() > 1) { |
|
|
|
// 多文件压缩下载
|
|
|
|
DocumentTasksVo documentTasksVo = documentTasksService.queryById(list.get(0).getDocumentTaskId()); |
|
|
|
String documentName = documentTasksVo.getDocumentName(); |
|
|
@ -641,4 +763,86 @@ public class DocumentTaskResultsServiceImpl implements IDocumentTaskResultsServi |
|
|
|
throw new RuntimeException("获取PDF文件流失败: " + e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 定义字段配置类,用于存储字段名和标题 |
|
|
|
*/ |
|
|
|
private static class FieldConfig { |
|
|
|
private String field; |
|
|
|
private String title; |
|
|
|
|
|
|
|
public FieldConfig(String field, String title) { |
|
|
|
this.field = field; |
|
|
|
this.title = title; |
|
|
|
} |
|
|
|
|
|
|
|
public String getField() { |
|
|
|
return field; |
|
|
|
} |
|
|
|
|
|
|
|
public String getTitle() { |
|
|
|
return title; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 根据任务类型获取对应的字段配置 |
|
|
|
* |
|
|
|
* @param taskName 任务类型名称 |
|
|
|
* @return 字段配置列表 |
|
|
|
*/ |
|
|
|
private List<FieldConfig> getFieldConfigsByTaskType(String taskName) { |
|
|
|
List<FieldConfig> configs = new java.util.ArrayList<>(); |
|
|
|
|
|
|
|
// 根据任务类型返回不同的字段配置
|
|
|
|
switch (taskName) { |
|
|
|
case "checkCompanyName": |
|
|
|
case "checkTitleName": |
|
|
|
case "checkPlaceName": |
|
|
|
configs.add(new FieldConfig("modificationDisplay", "相关原文")); |
|
|
|
break; |
|
|
|
case "checkRepeatText": |
|
|
|
configs.add(new FieldConfig("originalText", "第一段原文")); |
|
|
|
configs.add(new FieldConfig("comparedText", "第二段原文")); |
|
|
|
configs.add(new FieldConfig("modificationDisplay", "相似情况")); |
|
|
|
break; |
|
|
|
case "allCheckRepeatText": |
|
|
|
configs.add(new FieldConfig("originalText", "第一段原文")); |
|
|
|
configs.add(new FieldConfig("comparedText", "第二段原文")); |
|
|
|
configs.add(new FieldConfig("modificationDisplay", "相似情况")); |
|
|
|
break; |
|
|
|
case "checkDocumentError": |
|
|
|
configs.add(new FieldConfig("originalText", "原文")); |
|
|
|
configs.add(new FieldConfig("modifiedContent", "修改建议")); |
|
|
|
configs.add(new FieldConfig("modificationDisplay", "修改情况")); |
|
|
|
break; |
|
|
|
default: |
|
|
|
// 默认配置
|
|
|
|
configs.add(new FieldConfig("originalText", "原文")); |
|
|
|
configs.add(new FieldConfig("comparedText", "比对原文")); |
|
|
|
configs.add(new FieldConfig("modifiedContent", "修改后内容")); |
|
|
|
configs.add(new FieldConfig("modificationDisplay", "修改情况")); |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
return configs; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取对象的字段值 |
|
|
|
* |
|
|
|
* @param item 结果项对象 |
|
|
|
* @param fieldName 字段名 |
|
|
|
* @return 字段值 |
|
|
|
*/ |
|
|
|
private String getFieldValue(DocumentTaskResultVO.ResultItem item, String fieldName) { |
|
|
|
try { |
|
|
|
java.lang.reflect.Method method = item.getClass().getMethod("get" + StringUtils.capitalize(fieldName)); |
|
|
|
Object value = method.invoke(item); |
|
|
|
return value != null ? value.toString() : ""; |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("获取字段值失败: {}", e.getMessage()); |
|
|
|
return ""; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|