fix[project]: 同步待办时,下载待办的报告文件

This commit is contained in:
2026-03-23 16:41:08 +08:00
parent 54b4467ef3
commit 6418c89d3a
5 changed files with 237 additions and 0 deletions

View File

@@ -6,6 +6,8 @@ import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.MappedByteBuffer;
import java.nio.charset.StandardCharsets;
import java.nio.file.*;
@@ -582,4 +584,115 @@ public class FilesUtil {
}
}
/**
* 从指定URL下载文件到本地
* @param fileUrl 远程文件的URL地址
* @param savePath 本地保存路径(包含文件名,例如:/opt/demand/report/有限元仿真结果报告.pdf
* @throws IOException 处理IO异常
*/
public static void downloadFile(String fileUrl, String savePath) throws IOException {
createDirectoryIfNotExists(savePath);
// 声明连接和流对象
HttpURLConnection connection = null;
BufferedInputStream in = null;
BufferedOutputStream out = null;
try {
// 1. 创建URL对象
URL url = new URL(fileUrl);
// 2. 打开连接并设置属性
connection = (HttpURLConnection) url.openConnection();
// 设置连接超时时间5秒
connection.setConnectTimeout(5000);
// 设置读取超时时间10秒
connection.setReadTimeout(10000);
// 设置请求方法
connection.setRequestMethod("GET");
// 允许输入流
connection.setDoInput(true);
// 3. 检查响应码200表示成功
int responseCode = connection.getResponseCode();
if (responseCode != HttpURLConnection.HTTP_OK) {
throw new IOException("下载失败HTTP响应码" + responseCode);
}
// 4. 获取文件大小(用于进度显示)
long fileSize = connection.getContentLengthLong();
log.info("文件大小:{}", formatFileSize(fileSize));
// 5. 创建输入输出流
in = new BufferedInputStream(connection.getInputStream());
out = new BufferedOutputStream(new FileOutputStream(savePath));
// 6. 缓冲区读写数据
byte[] buffer = new byte[4096]; // 4KB缓冲区
int bytesRead;
while ((bytesRead = in.read(buffer)) != -1) {
out.write(buffer, 0, bytesRead);
}
log.info("文件下载完成!保存路径:{}",savePath);
} finally {
// 7. 关闭所有流和连接,确保资源释放
if (out != null) {
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (in != null) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (connection != null) {
connection.disconnect();
}
}
}
/**
* 格式化文件大小显示字节转KB/MB
* @param size 字节数
* @return 格式化后的大小字符串
*/
private static String formatFileSize(long size) {
if (size < 1024) {
return size + " B";
} else if (size < 1024 * 1024) {
return String.format("%.2f KB", size / 1024.0);
} else {
return String.format("%.2f MB", size / (1024.0 * 1024.0));
}
}
/**
* 解析保存路径,创建不存在的目录
* @param savePath 完整的文件保存路径
*/
private static void createDirectoryIfNotExists(String savePath) {
// 1. 创建File对象
File file = new File(savePath);
// 2. 获取文件所在的目录(去掉文件名部分)
File parentDir = file.getParentFile();
// 3. 如果目录不为空且不存在则创建mkdirs会创建多级目录
if (parentDir != null && !parentDir.exists()) {
boolean isCreated = parentDir.mkdirs();
if (isCreated) {
log.info("目录不存在,已自动创建:" + parentDir.getAbsolutePath());
} else {
log.error("创建目录失败:" + parentDir.getAbsolutePath());
}
}
}
}

View File

@@ -0,0 +1,82 @@
package com.sdm.outbridge.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.util.Date;
/**
* 附件配置视图实体类
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName(value = "v_attachment_config_to_DM", autoResultMap = true)
@Schema(description = "附件配置视视图")
public class LyricVAttachmentConfigToDM {
@Schema(description = "附件配置视id")
@TableField(value = "id")
private Integer id;
@Schema(description = "文件名")
@TableField(value = "name")
private String name;
@Schema(description = "文件链接地址")
@TableField(value = "project_name")
private String filePath;
@Schema(description = "缩略图地址")
@TableField(value = "thumbnail_Path")
private String thumbnailPath;
@Schema(description = "文件id")
@TableField(value = "file_id")
private Integer fileId;
@Schema(description = "文件大小")
@TableField(value = "file_size")
private Long fileSize;
@Schema(description = "文件类型")
@TableField(value = "file_type")
private String fileType;
@Schema(description = "创建人")
@TableField(value = "create_by")
private String createBy;
@Schema(description = "修改人")
@TableField(value = "modify_by")
private String modifyBy;
@Schema(description = "创建时间")
@TableField(value = "create_time")
private String createTime;
@Schema(description = "修改时间")
@TableField(value = "modify_time")
private String modifyTime;
@Schema(description = "in 内网 out 外网")
@TableField(value = "source")
private String source;
@Schema(description = "内拷外审批流程ID")
@TableField(value = "copy_id")
private String copyId;
@Schema(description = "OA内靠外审批实例ID")
@TableField(value = "oa_process_id")
private String oaProcessId;
@Schema(description = "海葵文件key")
@TableField(value = "hai_kui_file_key")
private String haiKuiFileKey;
}

View File

@@ -219,5 +219,9 @@ public class SimulationTask implements Serializable {
@TableField("reportContent")
private String reportContent;
@Schema(description= "关联的待办的结果文件路径")
@TableField(exist = false)
private String reportFileUrl;
}

View File

@@ -1475,6 +1475,9 @@ public class ProjectServiceImpl extends BaseService implements IProjectService {
projectNode.setTaskCode(projectNode.getNodeCode());
}
projectNode.setAnalyseSoftwares(projectNode.getAnalyseSoftware());
log.info("任务节点为:{}",projectNode);
log.info("tagList为{}",tagList);
log.info("taskIdMap为{}",taskIdMap);
if (CollectionUtils.isNotEmpty(tagList)) {
// List<String> needAddTagList = new ArrayList<>();
// List<String> tags = tagList.stream().map(TaskNodeTag::getValue).toList();
@@ -1593,9 +1596,13 @@ public class ProjectServiceImpl extends BaseService implements IProjectService {
List<String> tag5List = projectNode.getTag5();
log.info("tag5List111为{}",tag5List);
if (CollectionUtils.isNotEmpty(tag5List)) {
if (tag5List.contains(null)) {
log.info("tag5List222为{}",tag5List);
tag5List = tag5List.stream().filter(ObjectUtils::isNotEmpty).collect(Collectors.toList());
log.info("tag5List333为{}",tag5List);
log.info("tag5List tagList为{}",tagList);
for (TaskNodeTag taskNodeTag : tagList) {
if ("tag5".equals(taskNodeTag.getValue())) {
if (CollectionUtils.isNotEmpty(tag5List)) {
@@ -1610,6 +1617,7 @@ public class ProjectServiceImpl extends BaseService implements IProjectService {
}
}
}else {
log.info("tag5List为空tagList为{}taskIdMap为{}",tagList,taskIdMap);
for (TaskNodeTag taskNodeTag : tagList) {
if ("tag5".equals(taskNodeTag.getValue())) {
tag5List = taskIdMap.get(taskNodeTag.getKey());

View File

@@ -10,6 +10,7 @@ import com.sdm.common.entity.enums.FilePermissionEnum;
import com.sdm.common.entity.enums.NodeTypeEnum;
import com.sdm.common.entity.req.data.*;
import com.sdm.common.feign.inter.data.IDataFeignClient;
import com.sdm.common.utils.FilesUtil;
import com.sdm.common.utils.RandomUtil;
import com.sdm.project.common.MemberTypeEnum;
import com.sdm.project.dao.SimulationTaskAttentionMapper;
@@ -32,6 +33,9 @@ import com.sdm.project.model.entity.SimulationDemandMember;
import com.sdm.project.model.entity.SimulationTaskExtra;
import com.sdm.common.enums.DemandMemberTypeEnum;
import lombok.extern.slf4j.Slf4j;
import java.io.IOException;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.collections4.CollectionUtils;
@@ -81,6 +85,8 @@ public class SimulationTaskServiceImpl extends ServiceImpl<SimulationTaskMapper,
@Autowired
private IProjectService projectService;
private static final String REPORT_PATH_PREFIX = "/opt/demand/report/";
@Override
public boolean updateSimulationTask(SpdmTaskOprReq req) {
@@ -218,6 +224,30 @@ public class SimulationTaskServiceImpl extends ServiceImpl<SimulationTaskMapper,
tagReq.setTaskId(task.getUuid());
tagReq.setTaskId(task.getTaskName() );
createTaskDir(task.getUuid(), workspaceId, task.getTaskName(),tagReq);
// 异步下载待办的结果文件到任务文件夹下
// if (StringUtils.isBlank(task.getReportFileUrl())) {
// continue;
// }
// CompletableFuture.runAsync(() -> {
// try {
// FilesUtil.downloadFile(task.getReportFileUrl(), REPORT_PATH_PREFIX + task.getUuid());
// // 上传到minio
// UploadFilesReq fileReq = new UploadFilesReq();
// fileReq.setSourceFiles();
// fileReq.setUploadTaskId();
// fileReq.setType();
// fileReq.setFileType();
// fileReq.setUuid();
// fileReq.setFileTypeDictValue();
// fileReq.setFileTypeDictClass();
// fileReq.setDisciplineDictValue();
// fileReq.setDisciplineTypeDictClass();
// fileReq.setDictTags();
// SdmResponse uploadRespond = dataFeignClient.uploadFiles(fileReq);
// } catch (IOException e) {
// throw new RuntimeException(e);
// }
// });
}
// 批量更新任务权限(使用批量接口)
batchUpdateTaskPermissions(tasksToCreate);