From 6f394b0027019d4d014cf0b8ec13fa43e47c27c9 Mon Sep 17 00:00:00 2001
From: wayne <wayne8692wayne8692@gmail.com>
Date: 星期五, 24 十二月 2021 10:39:39 +0800
Subject: [PATCH] Merge branch '簡訊與email測通'

---
 pamapi/src/main/java/com/pollex/pam/service/SendMsgService.java |   77 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 77 insertions(+), 0 deletions(-)

diff --git a/pamapi/src/main/java/com/pollex/pam/service/SendMsgService.java b/pamapi/src/main/java/com/pollex/pam/service/SendMsgService.java
index 343b767..d630ba6 100644
--- a/pamapi/src/main/java/com/pollex/pam/service/SendMsgService.java
+++ b/pamapi/src/main/java/com/pollex/pam/service/SendMsgService.java
@@ -45,6 +45,83 @@
     @Autowired
     SpringTemplateEngine springTemplateEngine;
 
+    public void sendAppointmentNotify(Appointment appointment) {
+        Assert.notNull(appointment);
+
+        log.debug("is need sending notify msg = {}", applicationProperties.isSendNotifyMsg());
+        if(applicationProperties.isSendNotifyMsg()) {
+            log.debug("sending appointment notify, appointmentId = {}", appointment.getId());
+            sendAppointmentNotifyBySMS(appointment);
+            sendAppointmentNotifyByEmail(appointment);
+
+            // todo ��蝣箄�������瘙蝙�html mail
+            // sendAppointmentNotifyByHtmlEmail(appointment);
+        }
+    }
+
+    private void sendAppointmentNotifyBySMS(Appointment appointment) throws SendSMSFailException {
+        String msg = getAppointmentNotifyWording(appointment);
+        String consultantMobile = consultantRepository.findOneByAgentNo(appointment.getAgentNo()).get().getPhoneNumber();
+
+        try {
+            sendMsgBySMS(consultantMobile, msg);
+        } catch (SendSMSFailException e) {
+            log.debug("send sms failed, appointment Id = {}", appointment.getId(), e);
+        }
+    }
+
+    private void sendAppointmentNotifyByEmail(Appointment appointment) {
+        // todo ��敺靽�頂蝯勗�辣靽∠拳 (銝行�閮剖��葉)
+        String senderEmail = applicationProperties.getEmail().getSenderEmail();
+        String consultantEmail = consultantRepository.findOneByAgentNo(appointment.getAgentNo()).get().getEmail();
+        String content = getAppointmentNotifyWording(appointment);
+
+        try {
+            sendMsgByEmail(senderEmail, consultantEmail, EMAIL_SUBJECT, content, false);
+        } catch (SendEmailFailException e) {
+            log.debug("send email failed, appointment Id = {}", appointment.getId(), e);
+        }
+    }
+
+    private void sendAppointmentNotifyByHtmlEmail(Appointment appointment) {
+        // todo ��敺靽�頂蝯勗�辣靽∠拳 (銝行�閮剖��葉)
+        String senderEmail = applicationProperties.getEmail().getSenderEmail();
+        String consultantEmail = consultantRepository.findOneByAgentNo(appointment.getAgentNo()).get().getEmail();
+        String customerMobile = appointment.getPhone();
+        String normalContent;
+
+        if(StringUtils.hasText(customerMobile)) {
+            normalContent = "閬芣��“��憟踝����蝑�靽���像������嚗府摰X����Ⅳ�" + customerMobile + "\n";
+        }
+        else {
+            normalContent = "閬芣��“��憟踝����蝑�靽���像������\n";
+        }
+
+        Context context = new Context();
+        context.setVariable("content", normalContent);
+        context.setVariable("urlHint", getAppointmentDetailUrl(appointment.getId()));
+        String content = springTemplateEngine.process("mail/appointmentNotifyEmail", context);
+
+        try {
+            sendMsgByEmail(senderEmail, consultantEmail, EMAIL_SUBJECT, content, true);
+        } catch (SendEmailFailException e) {
+            log.debug("send email failed, appointment Id = {}", appointment.getId(), e);
+        }
+    }
+
+    private String getAppointmentNotifyWording(Appointment appointment) {
+        String normalContent;
+        if(StringUtils.hasText(appointment.getPhone())) {
+            normalContent = "閬芣��“��憟踝����蝑�靽���像������嚗府摰X����Ⅳ�" + appointment.getPhone() + "\n";
+        }
+        else {
+            normalContent = "閬芣��“��憟踝����蝑�靽���像������\n";
+        }
+
+        String urlContent = "暺�雯��嚗�" + getAppointmentDetailUrl(appointment.getId()) + " �����像������";
+        return normalContent + urlContent;
+    }
+
     public SendSMSResponse sendMsgBySMS(String toMobile, String content) throws SendSMSFailException {
         SMS smsProperties = applicationProperties.getSms();
 

--
Gitblit v1.8.0