From 07ad8699440e269e56d7411f43fa74315664bae5 Mon Sep 17 00:00:00 2001
From: wayne <wayne8692wayne8692@gmail.com>
Date: 星期三, 29 十二月 2021 12:00:49 +0800
Subject: [PATCH] [update] 若顧問沒有手機號碼及email時會拋出例外,不發送給service

---
 pamapi/src/main/java/com/pollex/pam/service/AppointmentService.java |   17 +++++++++++++----
 1 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/pamapi/src/main/java/com/pollex/pam/service/AppointmentService.java b/pamapi/src/main/java/com/pollex/pam/service/AppointmentService.java
index ad552b0..06b9eb0 100644
--- a/pamapi/src/main/java/com/pollex/pam/service/AppointmentService.java
+++ b/pamapi/src/main/java/com/pollex/pam/service/AppointmentService.java
@@ -9,6 +9,7 @@
 import com.pollex.pam.config.ApplicationProperties;
 import com.pollex.pam.service.dto.AppointmentUpdateDTO;
 import com.pollex.pam.web.rest.errors.SendEmailFailException;
+import com.pollex.pam.web.rest.errors.SendSMSFailException;
 import io.jsonwebtoken.lang.Assert;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -188,8 +189,12 @@
         String consultantMobile = consultantService.findByAgentNo(appointment.getAgentNo()).getPhoneNumber();
 
         try {
-            sendMsgService.sendMsgBySMS(consultantMobile, msg);
-        } catch (Exception e) {
+            if(StringUtils.hasText(consultantMobile)) {
+                sendMsgService.sendMsgBySMS(consultantMobile, msg);
+            }
+
+            throw new SendEmailFailException("the consultant does not have mobile!");
+        } catch (SendSMSFailException e) {
             log.warn("send appointment notify by sms was fail, appointment Id = {}", appointment.getId(), e);
         }
     }
@@ -226,9 +231,13 @@
         String content = springTemplateEngine.process("mail/appointmentNotifyEmail", context);
 
         try {
-            sendMsgService.sendMsgByEmail(senderEmail, consultantEmail, NOTIFY_EMAIL_SUBJECT, content, true);
+            if(StringUtils.hasText(consultantEmail)) {
+                sendMsgService.sendMsgByEmail(senderEmail, consultantEmail, NOTIFY_EMAIL_SUBJECT, content, true);
+            }
+
+            throw new SendEmailFailException("the consultant does not have email!");
         } catch (SendEmailFailException e) {
-            log.warn("send email failed, appointment Id = {}", appointment.getId(), e);
+            log.warn("send appointment notify by email was fail, appointment Id = {}", appointment.getId(), e);
         }
     }
 

--
Gitblit v1.8.0