From 8a73ac17d717c32aa8fd97f4c682094d7b1c0654 Mon Sep 17 00:00:00 2001
From: 陈昶聿 <chychen@nbjetron.com>
Date: 星期二, 17 十一月 2026 17:59:54 +0800
Subject: [PATCH] fix: 支持妇幼随访短信微信内容占位符

---
 smartor/src/main/java/com/smartor/service/mch/MchFollowupMessageSender.java |   39 ++++++++++++++++++-
 smartor/src/test/java/com/smartor/service/mch/MchFollowupLogicCheck.java    |   17 ++++++++
 docs/妇幼随访按周期发送测试报告_20261117.md                                              |   11 +++--
 docs/妇幼随访按周期发送功能说明_20261117.md                                              |   14 +++++++
 4 files changed, 73 insertions(+), 8 deletions(-)

diff --git "a/docs/\345\246\207\345\271\274\351\232\217\350\256\277\346\214\211\345\221\250\346\234\237\345\217\221\351\200\201\345\212\237\350\203\275\350\257\264\346\230\216_20261117.md" "b/docs/\345\246\207\345\271\274\351\232\217\350\256\277\346\214\211\345\221\250\346\234\237\345\217\221\351\200\201\345\212\237\350\203\275\350\257\264\346\230\216_20261117.md"
index 300c92f..4141c96 100644
--- "a/docs/\345\246\207\345\271\274\351\232\217\350\256\277\346\214\211\345\221\250\346\234\237\345\217\221\351\200\201\345\212\237\350\203\275\350\257\264\346\230\216_20261117.md"
+++ "b/docs/\345\246\207\345\271\274\351\232\217\350\256\277\346\214\211\345\221\250\346\234\237\345\217\221\351\200\201\345\212\237\350\203\275\350\257\264\346\230\216_20261117.md"
@@ -120,6 +120,20 @@
 
 鐭俊鑺傜偣濡傛灉 `content` 涓虹┖浼氳В鏋愬け璐ワ紝璁″垝杩涘叆鈥滃緟琛ュ厖/閰嶇疆寮傚父鈥濈姸鎬併��
 
+`content` 鍜� `titleName` 鏀寔鍗犱綅绗︼細
+
+```text
+${patname}            鎮h�呭鍚�
+${patid}              鎮h�匢D
+${phone}              鑱旂郴鐢佃瘽
+${idcardno}           璇佷欢鍙风爜
+${plannedFollowTime}  鍛ㄦ湡鍩哄噯鏃ワ紙yyyy-MM-dd HH:mm:ss锛�
+${sourceBizNo}        闂ㄨ瘖鍙�/浣忛櫌鍙�
+${archiveType}        妗f绫诲瀷锛�1濡囦繚 2鍎夸繚
+${orgid}              鏈烘瀯ID
+${seq}                鑺傜偣椤哄簭
+```
+
 ### 3.2 闂撮殧 + 娆℃暟
 
 ```json
diff --git "a/docs/\345\246\207\345\271\274\351\232\217\350\256\277\346\214\211\345\221\250\346\234\237\345\217\221\351\200\201\346\265\213\350\257\225\346\212\245\345\221\212_20261117.md" "b/docs/\345\246\207\345\271\274\351\232\217\350\256\277\346\214\211\345\221\250\346\234\237\345\217\221\351\200\201\346\265\213\350\257\225\346\212\245\345\221\212_20261117.md"
index 796c7d8..a53e467 100644
--- "a/docs/\345\246\207\345\271\274\351\232\217\350\256\277\346\214\211\345\221\250\346\234\237\345\217\221\351\200\201\346\265\213\350\257\225\346\212\245\345\221\212_20261117.md"
+++ "b/docs/\345\246\207\345\271\274\351\232\217\350\256\277\346\214\211\345\221\250\346\234\237\345\217\221\351\200\201\346\265\213\350\257\225\346\212\245\345\221\212_20261117.md"
@@ -11,10 +11,10 @@
 
 | 娴嬭瘯濂椾欢 | 鐢ㄤ緥鏁� | 閫氳繃 | 澶辫触 |
 |---|---:|---:|---:|
-| `MchFollowupLogicCheck` | 40 | 40 | 0 |
+| `MchFollowupLogicCheck` | 41 | 41 | 0 |
 | `MchFollowupPlanServiceCheck` | 19 | 19 | 0 |
 | `MchFollowupSendServiceCheck` | 18 | 18 | 0 |
-| **鍚堣** | **77** | **77** | **0** |
+| **鍚堣** | **78** | **78** | **0** |
 
 缁撹锛�**鏍稿績閫昏緫娴嬭瘯鍏ㄩ儴閫氳繃銆�**
 
@@ -53,8 +53,9 @@
    - 鎭板ソ 24 灏忔椂琛ュ彂锛�
    - 瓒呰繃 24 灏忔椂杩囨湡锛�
 8. 鑺傜偣缁勮锛�
-9. 3 涓柊澧� Mapper XML 鍙В鏋愶紱
-10. DDL 鑴氭湰瀛樺湪銆�
+9. 鍐呭鍗犱綅绗︽覆鏌擄紙`${patname}`銆乣${patid}`銆乣${phone}`銆乣${plannedFollowTime}`銆乣${seq}`銆乣${orgid}`锛夛紱
+10. 3 涓柊澧� Mapper XML 鍙В鏋愶紱
+11. DDL 鑴氭湰瀛樺湪銆�
 
 ### 2.2 `MchFollowupPlanServiceCheck`
 
@@ -124,7 +125,7 @@
 ### 3.4 缁撴灉鎽樿
 
 ```text
-MchFollowupLogicCheck        PASS=40锛孎AIL=0
+MchFollowupLogicCheck        PASS=41锛孎AIL=0
 MchFollowupPlanServiceCheck  PASS=19锛孎AIL=0
 MchFollowupSendServiceCheck  PASS=18锛孎AIL=0
 ```
diff --git a/smartor/src/main/java/com/smartor/service/mch/MchFollowupMessageSender.java b/smartor/src/main/java/com/smartor/service/mch/MchFollowupMessageSender.java
index 8784bfd..4f20367 100644
--- a/smartor/src/main/java/com/smartor/service/mch/MchFollowupMessageSender.java
+++ b/smartor/src/main/java/com/smartor/service/mch/MchFollowupMessageSender.java
@@ -12,6 +12,8 @@
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
+import java.text.SimpleDateFormat;
+
 /**
  * 濡囧辜闅忚娑堟伅鍙戦�佸櫒銆�
  *
@@ -28,7 +30,7 @@
 
     public MchFollowupSendOutcome sendSms(MchFollowupPlan plan, MchFollowupPlanItem item) {
         String phone = plan == null ? null : plan.getPhone();
-        String content = item == null ? null : item.getContent();
+        String content = item == null ? null : renderContent(item.getContent(), plan, item);
         if (StringUtils.isBlank(phone)) {
             return MchFollowupSendOutcome.skip("鎵嬫満鍙蜂负绌�");
         }
@@ -71,8 +73,8 @@
             message.setIdCard(plan.getIdcardno());
             message.setMobile(phone);
             message.setMedCardNo(plan.getSourceBizNo());
-            message.setTitleName(item.getTitleName());
-            message.setContent(item.getContent());
+            message.setTitleName(renderContent(item.getTitleName(), plan, item));
+            message.setContent(renderContent(item.getContent(), plan, item));
             message.setUrl(item.getUrl());
 
             String requestBody = requestSummary("wechat", phone, item.getTemplateId());
@@ -118,6 +120,37 @@
         }
     }
 
+    /**
+     * 娓叉煋濡囧辜闅忚鍐呭鍗犱綅绗︺�傚綋鍓嶆敮鎸侊細
+     * ${patname}銆�${patid}銆�${phone}銆�${idcardno}銆�${plannedFollowTime}銆�
+     * ${sourceBizNo}銆�${archiveType}銆�${orgid}銆�${seq}銆�
+     */
+    String renderContent(String text, MchFollowupPlan plan, MchFollowupPlanItem item) {
+        if (StringUtils.isBlank(text) || plan == null) {
+            return text;
+        }
+        String result = text;
+        result = result.replace("${patname}", nvl(plan.getPatname()));
+        result = result.replace("${patid}", plan.getPatid() == null ? "" : String.valueOf(plan.getPatid()));
+        result = result.replace("${phone}", nvl(plan.getPhone()));
+        result = result.replace("${idcardno}", nvl(plan.getIdcardno()));
+        result = result.replace("${sourceBizNo}", nvl(plan.getSourceBizNo()));
+        result = result.replace("${archiveType}", nvl(plan.getArchiveType()));
+        result = result.replace("${orgid}", nvl(plan.getOrgid()));
+        result = result.replace("${seq}", item == null || item.getSeq() == null ? "" : String.valueOf(item.getSeq()));
+        if (plan.getPlannedFollowTime() != null) {
+            result = result.replace("${plannedFollowTime}",
+                    new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(plan.getPlannedFollowTime()));
+        } else {
+            result = result.replace("${plannedFollowTime}", "");
+        }
+        return result;
+    }
+
+    private String nvl(String value) {
+        return value == null ? "" : value;
+    }
+
     private String requestSummary(String sendType, String phone, Long templateId) {
         return "sendType=" + sendType
                 + "锛沺hone=" + maskPhone(phone)
diff --git a/smartor/src/test/java/com/smartor/service/mch/MchFollowupLogicCheck.java b/smartor/src/test/java/com/smartor/service/mch/MchFollowupLogicCheck.java
index d6deec2..25688c7 100644
--- a/smartor/src/test/java/com/smartor/service/mch/MchFollowupLogicCheck.java
+++ b/smartor/src/test/java/com/smartor/service/mch/MchFollowupLogicCheck.java
@@ -2,6 +2,7 @@
 
 import com.smartor.common.MchFollowupConstants;
 import com.smartor.domain.MchFollowupNode;
+import com.smartor.domain.MchFollowupPlan;
 import com.smartor.domain.MchFollowupPlanItem;
 
 import javax.xml.parsers.DocumentBuilderFactory;
@@ -155,6 +156,22 @@
         check("缁勮鏃堕棿1", "2026-11-20 09:00:00", DATE_TIME.format(items.get(0).getSendTime()));
         check("缁勮鏃堕棿3娌跨敤鍩哄噯鏃�14:30", "2026-11-27 14:30:00", DATE_TIME.format(items.get(2).getSendTime()));
 
+        System.out.println("-- 8.1) 鍐呭鍗犱綅绗︽覆鏌� --");
+        MchFollowupPlan plan = new MchFollowupPlan();
+        plan.setPatid(100L);
+        plan.setPatname("寮犱笁");
+        plan.setPhone("13800000000");
+        plan.setOrgid("47226079133110211G1001");
+        plan.setPlannedFollowTime(baseline);
+        MchFollowupPlanItem seqItem = new MchFollowupPlanItem();
+        seqItem.setSeq(2);
+        MchFollowupMessageSender messageSender = new MchFollowupMessageSender();
+        check("鍗犱綅绗︽覆鏌�",
+                "鎮ㄥソ寮犱笁锛孖D=100锛岀數璇�=13800000000锛屽熀鍑�=2026-11-20 14:30:00锛屽簭鍙�=2锛屾満鏋�=47226079133110211G1001",
+                messageSender.renderContent(
+                        "鎮ㄥソ${patname}锛孖D=${patid}锛岀數璇�=${phone}锛屽熀鍑�=${plannedFollowTime}锛屽簭鍙�=${seq}锛屾満鏋�=${orgid}",
+                        plan, seqItem));
+
         System.out.println("-- 9) Mapper XML 鍙В鏋愭�� --");
         String[] xmlFiles = new String[]{
                 "smartor/src/main/resources/mapper/smartor/MchFollowupPlanMapper.xml",

--
Gitblit v1.9.3