瀏覽代碼

适配需求响应审核短信模板变量组装

Co-authored-by: Cursor <cursoragent@cursor.com>
fuyuchuan 3 天之前
父節點
當前提交
4a4f715c8e

+ 1 - 1
service-vpp/service-vpp-biz/src/main/java/com/usky/vpp/service/VppAliyunSmsService.java

@@ -10,7 +10,7 @@ public interface VppAliyunSmsService {
      *
      * @param phone        手机号
      * @param templateCode 模板 CODE
-     * @param templateParam JSON 模板变量,如 {"meet":"夏季削峰","time":"2026-07-08 14:00:00","room":"某某公司"}
+     * @param templateParam JSON 模板变量,如 {"name":"某某公司","responsetype":"日前","time":"2026-07-08 14:00:00~2026-07-08 15:00:00","number":"100","operationtype":"参与削峰"}
      */
     void sendTemplateSms(String phone, String templateCode, String templateParam);
 }

+ 69 - 13
service-vpp/service-vpp-biz/src/main/java/com/usky/vpp/util/VppSmsTemplateHelper.java

@@ -5,12 +5,17 @@ import com.usky.vpp.domain.VppCustomerContact;
 import com.usky.vpp.domain.VppDrEvent;
 import com.usky.vpp.domain.VppDrInvitation;
 
+import java.math.BigDecimal;
 import java.time.format.DateTimeFormatter;
 
 /**
  * 邀约短信模板参数构建
  * <p>
- * 阿里云模板变量需与控制台一致,默认使用:meet、time、room(SMS_465362899)
+ * 阿里云模板变量需与控制台一致:name、responsetype、time、number、operationtype
+ * <pre>
+ * 尊敬的${name},您已通过电力需求响应审核。 响应类型:${responsetype} 响应时间:${time}
+ * 邀约规模: ${number}kW 请在规定时段内${operationtype}
+ * </pre>
  */
 public final class VppSmsTemplateHelper {
 
@@ -23,21 +28,72 @@ public final class VppSmsTemplateHelper {
                                             VppDrEvent event,
                                             VppCustomer customer,
                                             VppCustomerContact contact) {
-        String meet = event != null && event.getEventName() != null
-                ? event.getEventName()
-                : (event != null ? event.getEventId() : "");
-        String time = "";
-        if (event != null && event.getStartTime() != null) {
-            time = TIME_FORMAT.format(event.getStartTime());
-        } else if (invitation.getReplyDeadline() != null) {
-            time = TIME_FORMAT.format(invitation.getReplyDeadline());
-        }
-        String room = customer != null && customer.getCustomerName() != null
+        String name = customer != null && customer.getCustomerName() != null
                 ? customer.getCustomerName()
                 : "";
-        return "{\"meet\":\"" + escapeJson(meet)
+
+        Integer responseType = invitation != null && invitation.getResponseType() != null
+                ? invitation.getResponseType()
+                : (event != null ? event.getResponseType() : null);
+        String responsetype = VppCapabilityEvalHelper.responseTypeLabel(responseType);
+
+        String time = buildResponseTime(invitation, event);
+
+        BigDecimal capacity = invitation != null && invitation.getDemandCapacityKw() != null
+                ? invitation.getDemandCapacityKw()
+                : (event != null ? event.getTargetCapacityKw() : null);
+        String number = formatNumber(capacity);
+
+        Integer eventType = invitation != null && invitation.getTransactionType() != null
+                ? invitation.getTransactionType()
+                : (event != null ? event.getEventType() : null);
+        String operationtype = buildOperationType(eventType);
+
+        return "{\"name\":\"" + escapeJson(name)
+                + "\",\"responsetype\":\"" + escapeJson(responsetype)
                 + "\",\"time\":\"" + escapeJson(time)
-                + "\",\"room\":\"" + escapeJson(room) + "\"}";
+                + "\",\"number\":\"" + escapeJson(number)
+                + "\",\"operationtype\":\"" + escapeJson(operationtype) + "\"}";
+    }
+
+    private static String buildResponseTime(VppDrInvitation invitation, VppDrEvent event) {
+        if (event != null && event.getStartTime() != null) {
+            if (event.getEndTime() != null) {
+                return TIME_FORMAT.format(event.getStartTime()) + "~" + TIME_FORMAT.format(event.getEndTime());
+            }
+            return TIME_FORMAT.format(event.getStartTime());
+        }
+        if (invitation != null && invitation.getExecuteStartDate() != null) {
+            if (invitation.getExecuteEndDate() != null
+                    && !invitation.getExecuteStartDate().equals(invitation.getExecuteEndDate())) {
+                return invitation.getExecuteStartDate() + "~" + invitation.getExecuteEndDate();
+            }
+            return invitation.getExecuteStartDate().toString();
+        }
+        if (invitation != null && invitation.getReplyDeadline() != null) {
+            return TIME_FORMAT.format(invitation.getReplyDeadline());
+        }
+        return "";
+    }
+
+    private static String buildOperationType(Integer eventType) {
+        if (eventType == null) {
+            return "完成响应";
+        }
+        if (eventType == 1) {
+            return "参与削峰";
+        }
+        if (eventType == 2) {
+            return "参与填谷";
+        }
+        return "完成响应";
+    }
+
+    private static String formatNumber(BigDecimal value) {
+        if (value == null) {
+            return "0";
+        }
+        return value.stripTrailingZeros().toPlainString();
     }
 
     private static String escapeJson(String value) {