From 9afbe6e5183fbc3dbccb74169e0079d600169f25 Mon Sep 17 00:00:00 2001
From: rain <1679827795@qq.com>
Date: Fri, 23 Jan 2026 17:29:38 +0800
Subject: [PATCH] 附件上传优化

---
 drone-service/drone-gd/src/main/java/org/sxkj/gd/workorder/service/impl/GdPatrolTaskServiceImpl.java |   32 ++++++++++++++++++++------------
 1 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/drone-service/drone-gd/src/main/java/org/sxkj/gd/workorder/service/impl/GdPatrolTaskServiceImpl.java b/drone-service/drone-gd/src/main/java/org/sxkj/gd/workorder/service/impl/GdPatrolTaskServiceImpl.java
index 98cef1a..b55d756 100644
--- a/drone-service/drone-gd/src/main/java/org/sxkj/gd/workorder/service/impl/GdPatrolTaskServiceImpl.java
+++ b/drone-service/drone-gd/src/main/java/org/sxkj/gd/workorder/service/impl/GdPatrolTaskServiceImpl.java
@@ -362,7 +362,7 @@
     }
 
 	@Override
-	public File exportPatrolReport(Long patrolTaskId) {
+	public boolean exportPatrolReport(Long patrolTaskId) {
 		if (patrolTaskId == null) {
 			throw new RuntimeException("巡查任务主键不能为空");
 		}
@@ -377,8 +377,7 @@
 		String deptName = getDeptName(taskEntity.getCreateDept());
 		try {
 			File reportFile = GdPatrolReportWordUtil.generateReportFile(taskEntity, resultList, creatorName, deptName);
-			saveAttachFile(reportFile, taskEntity);
-			return reportFile;
+			return saveAttachFile(reportFile, taskEntity);
 		} catch (Exception e) {
 			throw new RuntimeException("生成巡查报告失败", e);
 		}
@@ -486,34 +485,35 @@
 		return StringUtil.isBlank(realName) ? "/" : realName;
 	}
 
-	private BladeFile saveAttachFile(File reportFile, GdPatrolTaskEntity taskEntity) throws IOException {
+	private boolean saveAttachFile(File reportFile, GdPatrolTaskEntity taskEntity) throws IOException {
 		if (reportFile == null || !reportFile.exists()) {
 			throw new RuntimeException("巡查报告文件不存在");
 		}
-		String fileName = reportFile.getName();
+		String desiredName = buildReportAttachName(taskEntity, reportFile.getName());
 		BladeFile bladeFile = attachClient.putFile(
 			GdMultipartFileUtil.fromFile(reportFile,
 				"application/vnd.openxmlformats-officedocument.wordprocessingml.document"),
-			fileName
+			desiredName
 		);
 		if (bladeFile == null || StringUtil.isBlank(bladeFile.getLink())) {
 			throw new RuntimeException("附件上传失败");
 		}
 		Integer resultType = parseResultType(taskEntity != null ? taskEntity.getPatrolTaskType() : null);
-		Attach attach = buildAttachInfo(taskEntity, reportFile, bladeFile, resultType);
+		Attach attach = buildAttachInfo(taskEntity, reportFile, bladeFile, resultType, desiredName);
 		Boolean saved = attachClient.saveAttachInfo(attach);
 		if (!Boolean.TRUE.equals(saved)) {
-			log.error("附件信息保存失败,报告文件:"+fileName);
+			log.error("附件信息保存失败,报告文件:" + desiredName);
+			return false;
 		}
-		return bladeFile;
+		return true;
 	}
 
-	private Attach buildAttachInfo(GdPatrolTaskEntity taskEntity, File reportFile, BladeFile bladeFile, Integer resultType) {
+	private Attach buildAttachInfo(GdPatrolTaskEntity taskEntity, File reportFile, BladeFile bladeFile, Integer resultType, String desiredName) {
 		Attach attach = new Attach();
 		attach.setDomainUrl(bladeFile.getDomain());
 		attach.setLink(bladeFile.getLink());
-		attach.setName(bladeFile.getName());
-		attach.setOriginalName(StringUtil.isBlank(bladeFile.getOriginalName()) ? reportFile.getName() : bladeFile.getOriginalName());
+		attach.setName(desiredName);
+		attach.setOriginalName(desiredName);
 		attach.setAttachSize(reportFile.length());
 		attach.setExtension(FileUtil.getFileExtension(reportFile.getName()));
 		attach.setResultType(resultType);
@@ -538,6 +538,14 @@
 		return attach;
 	}
 
+	private String buildReportAttachName(GdPatrolTaskEntity taskEntity, String fallbackName) {
+		String taskNo = taskEntity != null ? taskEntity.getTaskNo() : null;
+		if (StringUtil.isBlank(taskNo)) {
+			return fallbackName;
+		}
+		return taskNo + ".docx";
+	}
+
 	private Integer parseResultType(String patrolTaskType) {
 		if (StringUtil.isBlank(patrolTaskType)) {
 			return null;

--
Gitblit v1.9.3