Browse Source

新增删除,下载 和优化相关功能

ai_300
zhouhaibin 3 weeks ago
parent
commit
bfd77f494a
  1. 4
      ruoyi-admin/src/main/resources/application-dev.yml
  2. 1
      zaojiaManagement/zaojia-productManagement/src/main/java/org/dromara/productManagement/common/service/BaseTaskService.java
  3. 7
      zaojiaManagement/zaojia-productManagement/src/main/java/org/dromara/productManagement/controller/DocumentTasksController.java
  4. 1
      zaojiaManagement/zaojia-productManagement/src/main/java/org/dromara/productManagement/domain/DocumentTaskGroup.java
  5. 2
      zaojiaManagement/zaojia-productManagement/src/main/java/org/dromara/productManagement/domain/DocumentTasks.java
  6. 3
      zaojiaManagement/zaojia-productManagement/src/main/java/org/dromara/productManagement/domain/bo/DocumentTasksBo.java
  7. 3
      zaojiaManagement/zaojia-productManagement/src/main/java/org/dromara/productManagement/domain/vo/DocumentTasksVo.java
  8. 2
      zaojiaManagement/zaojia-productManagement/src/main/java/org/dromara/productManagement/service/IDocumentTasksService.java
  9. 212
      zaojiaManagement/zaojia-productManagement/src/main/java/org/dromara/productManagement/service/impl/DocumentTaskResultsServiceImpl.java
  10. 16
      zaojiaManagement/zaojia-productManagement/src/main/java/org/dromara/productManagement/service/impl/DocumentTasksServiceImpl.java
  11. 2
      zaojiaManagement/zaojia-productManagement/src/main/resources/mapper/productManagement/DocumentTasksMapper.xml

4
ruoyi-admin/src/main/resources/application-dev.yml

@ -52,8 +52,8 @@ spring:
# url: jdbc:mysql://localhost:3306/zaojia?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
# username: root
# password: root
url: jdbc:mysql://10.1.21.250:3306/aitable?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
# url: jdbc:mysql://218.0.1.42:53306/aitable?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
# url: jdbc:mysql://10.1.21.250:3306/aitable?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
url: jdbc:mysql://218.0.1.42:53306/aitable?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
username: root
password: 'HXj-6nR|D8xy*h#!I&:('
# 从库数据源

1
zaojiaManagement/zaojia-productManagement/src/main/java/org/dromara/productManagement/common/service/BaseTaskService.java

@ -35,6 +35,7 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.UUID;
/**
* 任务处理抽象基类

7
zaojiaManagement/zaojia-productManagement/src/main/java/org/dromara/productManagement/controller/DocumentTasksController.java

@ -123,4 +123,11 @@ public class DocumentTasksController extends BaseController {
uploadVo.setOssId(oss.getOssId().toString());
return R.ok(uploadVo);
}
@DeleteMapping("/ossRemoveById/{ossid}")
public R<Void> ossRemoveById(@NotEmpty(message = "主键不能为空")
@PathVariable String ossid) {
return toAjax(documentTasksService.ossRemoveById(ossid, true));
}
}

1
zaojiaManagement/zaojia-productManagement/src/main/java/org/dromara/productManagement/domain/DocumentTaskGroup.java

@ -15,5 +15,6 @@ public class DocumentTaskGroup {
private Date createTime;
private String createUser;
private String progress;
private String delFile;
private List<DocumentTaskChild> childrenTasks;
}

2
zaojiaManagement/zaojia-productManagement/src/main/java/org/dromara/productManagement/domain/DocumentTasks.java

@ -81,5 +81,7 @@ public class DocumentTasks extends TenantEntity {
private String taskIndustry;
private String pdfPath;
private String groupId;
private String delFile;
}

3
zaojiaManagement/zaojia-productManagement/src/main/java/org/dromara/productManagement/domain/bo/DocumentTasksBo.java

@ -32,6 +32,7 @@ public class DocumentTasksBo extends BaseTaskBo {
private String pdfPath;
private String groupId;
private String delFile;
}

3
zaojiaManagement/zaojia-productManagement/src/main/java/org/dromara/productManagement/domain/vo/DocumentTasksVo.java

@ -32,5 +32,6 @@ public class DocumentTasksVo extends BaseTaskVo implements Serializable {
@ExcelProperty(value = "主键")
private String id;
private String pdfPath;
private String groupId;
private String delFile;
}

2
zaojiaManagement/zaojia-productManagement/src/main/java/org/dromara/productManagement/service/IDocumentTasksService.java

@ -72,4 +72,6 @@ public interface IDocumentTasksService {
int stopTask(Long id);
SysOssVo uploadFile(MultipartFile file) throws IOException, InterruptedException;
Boolean ossRemoveById(String ossId, boolean b);
}

212
zaojiaManagement/zaojia-productManagement/src/main/java/org/dromara/productManagement/service/impl/DocumentTaskResultsServiceImpl.java

@ -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 "";
}
}
}

16
zaojiaManagement/zaojia-productManagement/src/main/java/org/dromara/productManagement/service/impl/DocumentTasksServiceImpl.java

@ -3,6 +3,7 @@ package org.dromara.productManagement.service.impl;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.io.FileUtil;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import lombok.Data;
import okhttp3.*;
import org.dromara.common.core.service.DictService;
@ -37,6 +38,7 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Collection;
@ -128,7 +130,8 @@ public class DocumentTasksServiceImpl extends BaseTaskService implements IDocume
DocumentTasks::getCreateBy,
DocumentTasks::getTaskIndustry,
DocumentTasks::getTaskRegion,
DocumentTasks::getCreateTime);
DocumentTasks::getCreateTime,
DocumentTasks::getDelFile);
return lqw;
}
@ -260,6 +263,17 @@ public class DocumentTasksServiceImpl extends BaseTaskService implements IDocume
return upload;
}
@Override
public Boolean ossRemoveById(String ossId, boolean b) {
ossService.deleteWithValidByIds(Collections.singletonList(Long.valueOf(ossId)), true);
LambdaUpdateWrapper<DocumentTasks> queryWrapper = new LambdaUpdateWrapper<>();
queryWrapper.eq(DocumentTasks::getOssId, ossId);
queryWrapper.set(DocumentTasks::getDelFile, "Y");
baseMapper.update(null, queryWrapper);
return true;
}
// @Override
// protected Boolean processTaskItems(List<String> taskNames, BaseTaskBo bo, FileProcessResult fileResult, String taskType) {
// boolean flag = false;

2
zaojiaManagement/zaojia-productManagement/src/main/resources/mapper/productManagement/DocumentTasksMapper.xml

@ -11,6 +11,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="taskRegion" column="task_region"/>
<result property="createTime" column="group_create_time"/>
<result property="progress" column="progress"/>
<result property="delFile" column="del_file"/>
<!-- 使用collection标签正确映射子任务列表 -->
<collection property="childrenTasks"
column="{documentName=document_name,
@ -29,6 +30,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
task_industry,
task_region,
create_time as group_create_time,
del_file,
CASE
WHEN (SUM(CASE WHEN progress_status IN ('SUCCESS', 'FAILURE') THEN 1 ELSE 0 END) * 100.0) / COUNT(*) = 100
THEN

Loading…
Cancel
Save