diff --git a/src/main/java/com/gis/xian/mapper/XianInferenceResultFileMapper.java b/src/main/java/com/gis/xian/mapper/XianInferenceResultFileMapper.java index 65e2d1d..1406700 100644 --- a/src/main/java/com/gis/xian/mapper/XianInferenceResultFileMapper.java +++ b/src/main/java/com/gis/xian/mapper/XianInferenceResultFileMapper.java @@ -16,4 +16,11 @@ public interface XianInferenceResultFileMapper { * 根据推理结果id获取文件列表 */ List selectByInferenceId(@Param("inferenceId") Long inferenceId); + + /** + * 插入或更新(按 inference_id + file_name 唯一约束 upsert) + */ + int upsert(@Param("inferenceId") Long inferenceId, + @Param("filePath") String filePath, + @Param("fileName") String fileName); } diff --git a/src/main/java/com/gis/xian/service/impl/IReportOutputServiceImpl.java b/src/main/java/com/gis/xian/service/impl/IReportOutputServiceImpl.java index 318098b..ecc0ee5 100644 --- a/src/main/java/com/gis/xian/service/impl/IReportOutputServiceImpl.java +++ b/src/main/java/com/gis/xian/service/impl/IReportOutputServiceImpl.java @@ -116,12 +116,21 @@ public class IReportOutputServiceImpl implements ReportOutputService { allDistricts, top3Districts, riskCount, hiddenCount, predictPointNum); // 渲染输出 - return renderReport( - reportProperties.getDisasterCausingFactors().getRainfall().getTemplatePath(), - Path.of(localPath, reportProperties.getDisasterCausingFactors().getRainfall().getOutputPath().replace("{id}", id.toString())).toString(), - reportProperties.getDisasterCausingFactors().getRainfall().getOutputName().replace("{currentTime}", System.currentTimeMillis() + ""), - model - ); + String templatePath = reportProperties.getDisasterCausingFactors().getRainfall().getTemplatePath(); + String outputDir = Path.of(localPath, + reportProperties.getDisasterCausingFactors().getRainfall().getOutputPath() + .replace("{id}", id.toString())).toString(); + String outputName = reportProperties.getDisasterCausingFactors().getRainfall().getOutputName() + .replace("{currentTime}", String.valueOf(System.currentTimeMillis())); + String fullPath = renderReport(templatePath, outputDir, outputName, model); + + // 写入文件记录 + String baseName = outputName.replaceAll("_\\d+(\\.\\w+)$", "$1"); + String relativePath = fullPath.substring(localPath.length()).replace("\\", "/").replaceAll("^/+", ""); + inferenceResultFileMapper.upsert(id, relativePath, baseName); + log.info("文件记录已写入: inference_id={}, file_name={}, file_path={}", id, baseName, relativePath); + + return fileServerPath.replaceAll("/+$", "") + "/" + relativePath; } /** diff --git a/src/main/resources/com/gis/xian/mapper/XianInferenceResultFileMapper.xml b/src/main/resources/com/gis/xian/mapper/XianInferenceResultFileMapper.xml index eaec324..094b161 100644 --- a/src/main/resources/com/gis/xian/mapper/XianInferenceResultFileMapper.xml +++ b/src/main/resources/com/gis/xian/mapper/XianInferenceResultFileMapper.xml @@ -21,4 +21,11 @@ ORDER BY create_time + + INSERT INTO xian_inference_result_file (inference_id, file_path, file_name, create_time, is_delete) + VALUES (#{inferenceId}, #{filePath}, #{fileName}, NOW(), 0) + ON CONFLICT (inference_id, file_name) + DO UPDATE SET file_path = #{filePath}, create_time = NOW() + +