From 546d3fcba73b772446b4cf4654c3b3a995244bce Mon Sep 17 00:00:00 2001
From: liusheng <337615773@qq.com>
Date: 星期三, 26 十一月 2025 09:09:24 +0800
Subject: [PATCH] 新增访问路径

---
 jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/controller/admin/freemark/TemplateCreateController.java |   41 ++++++++++++++++++++++++++++++++---------
 1 files changed, 32 insertions(+), 9 deletions(-)

diff --git a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/controller/admin/freemark/TemplateCreateController.java b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/controller/admin/freemark/TemplateCreateController.java
index cad5cc2..d5d668a 100644
--- a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/controller/admin/freemark/TemplateCreateController.java
+++ b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/controller/admin/freemark/TemplateCreateController.java
@@ -2,6 +2,8 @@
 
 import cn.lihu.jh.module.ecg.dal.dataobject.appointment.AppointmentDO;
 import cn.lihu.jh.module.ecg.service.appointment.AppointmentService;
+import cn.lihu.jh.module.infra.dal.dataobject.config.ConfigDO;
+import cn.lihu.jh.module.infra.service.config.ConfigService;
 import freemarker.template.Configuration;
 import freemarker.template.Template;
 import io.swagger.v3.oas.annotations.Operation;
@@ -17,7 +19,6 @@
 import java.io.*;
 import java.time.LocalDate;
 import java.time.Period;
-import java.util.Calendar;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -30,6 +31,8 @@
     @Resource
     private AppointmentService appointmentService;
 
+    @Resource
+    private ConfigService configService;
 
     private static Configuration configuration = null;
 
@@ -54,17 +57,19 @@
             //鎹愮尞琛�.ftl涓鸿瑁呰浇鐨勬ā鏉�
             t = configuration.getTemplate("鐭ユ儏鍚屾剰杩愬姩璇曢獙.ftl");
 
-            String year = String.valueOf(Calendar.getInstance().get(Calendar.YEAR));
-            String name = "鐭ユ儏鍚屾剰杩愬姩璇曢獙-" + appointment.getPatName() + "-" + year;
+            String time = String.valueOf(System.currentTimeMillis());
+            String name = "骞虫澘杩愬姩蹇冪數鍥剧煡鎯呭悓鎰忎功-" + appointment.getPatName() + "-" + time;
 
             //杈撳嚭鏂囨。璺緞鍙婂悕绉�
-            File outFile = new File("D:/" + name + ".doc");
+            ConfigDO configByKey = configService.getConfigByKey("file.upload.path");
+            createPath(configByKey.getValue());
+            File outFile = new File(configByKey.getValue() + name + ".doc");
             Writer out = null;
             out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile), "utf-8"));
             t.process(dataMap, out);
 
             Map<String, Object> map = new HashMap<>();
-            map.put("downloadUrl", "D:/" + name + ".doc");
+            map.put("downloadUrl", "profile/" + name + ".doc");
             map.put("downloadName", name + ".doc");
             return map;
         } catch (Exception e) {
@@ -90,17 +95,19 @@
             //鎹愮尞琛�.ftl涓鸿瑁呰浇鐨勬ā鏉�
             t = configuration.getTemplate("椋熺蹇冭剰鐢电敓鐞嗙煡鎯呭悓鎰忎功.ftl");
 
-            String year = String.valueOf(Calendar.getInstance().get(Calendar.YEAR));
-            String name = "椋熺蹇冭剰鐢电敓鐞嗙煡鎯呭悓鎰忎功-" + appointment.getPatName() + "-" + year;
+            String time = String.valueOf(System.currentTimeMillis());
+            String name = "椋熺蹇冭剰鐢电敓鐞嗙煡鎯呭悓鎰忎功-" + appointment.getPatName() + "-" + time;
 
             //杈撳嚭鏂囨。璺緞鍙婂悕绉�
-            File outFile = new File("D:/" + name + ".doc");
+            ConfigDO configByKey = configService.getConfigByKey("file.upload.path");
+            createPath(configByKey.getValue());
+            File outFile = new File(configByKey.getValue() + name + ".doc");
             Writer out = null;
             out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile), "utf-8"));
             t.process(dataMap, out);
 
             Map<String, Object> map = new HashMap<>();
-            map.put("downloadUrl", "D:/" + name + ".doc");
+            map.put("downloadUrl", "profile/" + name + ".doc");
             map.put("downloadName", name + ".doc");
             return map;
         } catch (Exception e) {
@@ -127,4 +134,20 @@
         return Period.between(birthdayStr, LocalDate.now()).getYears();
     }
 
+    public void createPath(String uploadPath) {
+        // 纭繚璺緞浠ユ枩鏉犵粨灏�
+        if (!uploadPath.endsWith("/") && !uploadPath.endsWith("\\")) {
+            uploadPath += "/";
+        }
+
+        // 鍒涘缓鐩綍锛堝鏋滀笉瀛樺湪锛�
+        File uploadDir = new File(uploadPath);
+        if (!uploadDir.exists()) {
+            boolean created = uploadDir.mkdirs();
+            if (created) {
+                log.info("鍒涘缓鐩綍鎴愬姛: {}", uploadPath);
+            }
+        }
+    }
+
 }

--
Gitblit v1.9.3