修改导出功能

This commit is contained in:
wzy-warehouse
2026-06-28 17:01:22 +08:00
parent c9cad1e366
commit 9390c5dc85
3 changed files with 29 additions and 6 deletions
@@ -16,4 +16,11 @@ public interface XianInferenceResultFileMapper {
* 根据推理结果id获取文件列表
*/
List<XianInferenceResultFile> selectByInferenceId(@Param("inferenceId") Long inferenceId);
/**
* 插入或更新(按 inference_id + file_name 唯一约束 upsert
*/
int upsert(@Param("inferenceId") Long inferenceId,
@Param("filePath") String filePath,
@Param("fileName") String fileName);
}
@@ -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;
}
/**
@@ -21,4 +21,11 @@
ORDER BY create_time
</select>
<insert id="upsert">
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()
</insert>
</mapper>