|
|
@@ -36,6 +36,7 @@ import com.etotem.cfc.service.NutritionDeficiencyService;
|
|
|
import com.etotem.cfc.service.PdfParseService;
|
|
|
import com.etotem.cfc.service.ReportBlockAssembler;
|
|
|
import com.etotem.cfc.service.ReportBlockService;
|
|
|
+import com.etotem.cfc.service.StorageService;
|
|
|
import com.etotem.cfc.service.TongueDiagnosisService;
|
|
|
import com.etotem.cfc.service.api.WechatServiceInterface;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
@@ -142,6 +143,9 @@ public class HealthReportController {
|
|
|
@Resource
|
|
|
private ReportBlockService reportBlockService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private StorageService storageService;
|
|
|
+
|
|
|
@Resource
|
|
|
private ReportBlockAssembler reportBlockAssembler;
|
|
|
|
|
|
@@ -403,7 +407,7 @@ public class HealthReportController {
|
|
|
return Result.error("无法解析PDF文件,请确认是募极生物肠道菌群报告");
|
|
|
}
|
|
|
|
|
|
- String fileUrl = saveUploadFile(file, userId);
|
|
|
+ String fileUrl = storageService.storeFile(file, "health-reports");
|
|
|
|
|
|
ParsedReportPayload.Payload payload = convertToPayload(parsed);
|
|
|
String payloadJson = objectMapper.writeValueAsString(payload);
|
|
|
@@ -512,7 +516,7 @@ public class HealthReportController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- String fileUrl = saveUploadFile(file, userId);
|
|
|
+ String fileUrl = storageService.storeFile(file, "health-reports");
|
|
|
String reportType = familyId != null && !("pdf".equals(type) || "auto".equals(type))
|
|
|
? "physical_exam" : "gut_flora";
|
|
|
|
|
|
@@ -562,18 +566,14 @@ public class HealthReportController {
|
|
|
|
|
|
String fileUrl = draft.getFileUrl();
|
|
|
String originalFilename = draft.getOriginalFilename();
|
|
|
- String absolutePath = resolveUploadFilePath(fileUrl);
|
|
|
|
|
|
try {
|
|
|
- java.io.File localFile = new java.io.File(absolutePath);
|
|
|
- if (!localFile.exists()) {
|
|
|
- return Result.error("文件不存在或已过期: " + originalFilename);
|
|
|
- }
|
|
|
-
|
|
|
- // 尝试 LangGraph 远程解析
|
|
|
+ // LangGraph 优先:远程 OSS URL 直接传 URL(LangGraph 自行下载),本地路径传共享卷路径
|
|
|
try {
|
|
|
+ String lgPath = (fileUrl != null && fileUrl.startsWith("http"))
|
|
|
+ ? fileUrl : storageService.getFilePath(fileUrl);
|
|
|
Map<String, Object> lgRequest = new HashMap<>();
|
|
|
- lgRequest.put("file_path", absolutePath);
|
|
|
+ lgRequest.put("file_path", lgPath);
|
|
|
lgRequest.put("user_id", userId);
|
|
|
if (familyId != null) {
|
|
|
lgRequest.put("family_id", familyId);
|
|
|
@@ -592,7 +592,12 @@ public class HealthReportController {
|
|
|
log.warn("LangGraph 解析失败,回退到本地 Java 解析: {}", e.getMessage());
|
|
|
}
|
|
|
|
|
|
- // Fallback: 本地 Java 解析
|
|
|
+ // Fallback: 本地 Java 解析(下载 OSS 文件到本地临时目录,或直接读共享卷)
|
|
|
+ String absolutePath = storageService.getFilePath(fileUrl);
|
|
|
+ java.io.File localFile = new java.io.File(absolutePath);
|
|
|
+ if (!localFile.exists()) {
|
|
|
+ return Result.error("文件不存在或已过期: " + originalFilename);
|
|
|
+ }
|
|
|
return parseLocalFallback(absolutePath, draft, familyId, userId);
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
@@ -718,7 +723,7 @@ public class HealthReportController {
|
|
|
return Result.error("图片读取失败: " + e.getMessage());
|
|
|
}
|
|
|
|
|
|
- String fileUrl = saveUploadFile(file, userId);
|
|
|
+ String fileUrl = storageService.storeFile(file, "health-reports");
|
|
|
String reportType = familyId != null ? "physical_exam" : "gut_flora";
|
|
|
|
|
|
// 创建空载荷草稿,后续由 confirm 阶段用户补充
|
|
|
@@ -743,14 +748,14 @@ public class HealthReportController {
|
|
|
return Result.error("仅支持PDF文件");
|
|
|
}
|
|
|
|
|
|
- // 保存文件到磁盘(LangGraph 和本地解析共用)
|
|
|
- String fileUrl = saveUploadFile(file, userId);
|
|
|
- String absolutePath = resolveUploadFilePath(fileUrl);
|
|
|
+ // 保存文件(通过 StorageService 支持本地磁盘或京东云 OSS)
|
|
|
+ String fileUrl = storageService.storeFile(file, "health-reports");
|
|
|
+ boolean isRemote = fileUrl != null && fileUrl.startsWith("http");
|
|
|
|
|
|
- // 尝试 LangGraph 远程解析
|
|
|
+ // 尝试 LangGraph 远程解析(远程 OSS URL 直接传 URL,LangGraph 自行下载)
|
|
|
try {
|
|
|
Map<String, Object> lgRequest = new HashMap<>();
|
|
|
- lgRequest.put("file_path", absolutePath);
|
|
|
+ lgRequest.put("file_path", isRemote ? fileUrl : storageService.getFilePath(fileUrl));
|
|
|
lgRequest.put("user_id", userId);
|
|
|
if (familyId != null) {
|
|
|
lgRequest.put("family_id", familyId);
|
|
|
@@ -1794,57 +1799,6 @@ public class HealthReportController {
|
|
|
log.info(summary);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 解析草稿文件在服务器上的绝对路径。
|
|
|
- * 兼容两种存储格式:
|
|
|
- * - 当前格式:saveUploadFile 返回的绝对路径(已含 uploadBaseDir 前缀)
|
|
|
- * - 历史格式:相对路径(如 uploads/health-reports/...)
|
|
|
- * 修复:parse/parse-preview 曾对绝对路径再次拼接 uploadBaseDir 导致文件找不到。
|
|
|
- */
|
|
|
- private String resolveUploadFilePath(String fileUrl) {
|
|
|
- if (fileUrl == null || fileUrl.isEmpty()) {
|
|
|
- return null;
|
|
|
- }
|
|
|
- String normalized = fileUrl.replace("\\", "/");
|
|
|
- if (normalized.startsWith("/") || normalized.matches("^[A-Za-z]:.*")) {
|
|
|
- // 已是绝对路径,直接使用
|
|
|
- return normalized;
|
|
|
- }
|
|
|
- // 相对路径,拼接上传根目录
|
|
|
- return uploadBaseDir + "/" + normalized;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 保存上传文件到本地存储
|
|
|
- */
|
|
|
- private String saveUploadFile(MultipartFile file, Long ownerId) throws IOException {
|
|
|
- String uploadDir = uploadBaseDir + File.separator + "uploads" + File.separator + "health-reports" + File.separator + ownerId;
|
|
|
- File dir = new File(uploadDir);
|
|
|
- if (!dir.exists()) {
|
|
|
- dir.mkdirs();
|
|
|
- }
|
|
|
-
|
|
|
- String originalFilename = file.getOriginalFilename();
|
|
|
- if (originalFilename == null) {
|
|
|
- originalFilename = "report.pdf";
|
|
|
- }
|
|
|
-
|
|
|
- // 文件名:timestamp_uuid.extension
|
|
|
- String extension = "";
|
|
|
- int dotIdx = originalFilename.lastIndexOf('.');
|
|
|
- if (dotIdx > 0) {
|
|
|
- extension = originalFilename.substring(dotIdx);
|
|
|
- }
|
|
|
- String savedFilename = System.currentTimeMillis() + "_" + UUID.randomUUID().toString().substring(0, 8) + extension;
|
|
|
- Path filePath = Paths.get(uploadDir, savedFilename);
|
|
|
-
|
|
|
- Files.copy(file.getInputStream(), filePath);
|
|
|
-
|
|
|
- String relativePath = uploadDir.replace("\\", "/") + "/" + savedFilename;
|
|
|
- log.info("报告文件已保存: {}", relativePath);
|
|
|
- return relativePath;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 检查是否为授权代上传角色
|
|
|
*/
|