From 68343c0e409d7f02f29c5a832a6a1e24e9690f06 Mon Sep 17 00:00:00 2001
From: wayne <wayne8692wayne8692@gmail.com>
Date: 星期二, 01 三月 2022 15:49:12 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/Phase3' into Phase3

---
 pamapi/src/main/java/com/pollex/pam/service/ScheduleTaskService.java |   45 ++++++++++++++++++++++++++++-----------------
 1 files changed, 28 insertions(+), 17 deletions(-)

diff --git a/pamapi/src/main/java/com/pollex/pam/service/ScheduleTaskService.java b/pamapi/src/main/java/com/pollex/pam/service/ScheduleTaskService.java
index 604479e..be06791 100644
--- a/pamapi/src/main/java/com/pollex/pam/service/ScheduleTaskService.java
+++ b/pamapi/src/main/java/com/pollex/pam/service/ScheduleTaskService.java
@@ -6,6 +6,7 @@
 import com.pollex.pam.enums.AppointmentStatusEnum;
 import com.pollex.pam.enums.ContactStatusEnum;
 import com.pollex.pam.enums.SatisfactionStatusEnum;
+import com.pollex.pam.enums.SatisfactionTypeEnum;
 import com.pollex.pam.repository.AppointmentCustomerViewRepository;
 import com.pollex.pam.repository.AppointmentExpiringNotifyRecordRepository;
 import org.slf4j.Logger;
@@ -73,12 +74,18 @@
         consultantWithPendingAppointments.forEach((agentNo, pendingAppointments) -> {
             int pendingAppointmentsSum = pendingAppointments.size();
             Consultant consultant = consultantService.findByAgentNo(agentNo);
-            String consultantPhoneNumber = consultant.getPhoneNumber();
-            String consultantEmail = consultant.getEmail();
-            String emailContent = getAppointmentPendingNotifyEmailContent(pendingAppointmentsSum);
+            Optional<String> optionalPhone = Optional.ofNullable(consultant.getPhoneNumber()).filter(StringUtils::hasText);
+            Optional<String> optionalEmail = Optional.ofNullable(consultant.getEmail()).filter(StringUtils::hasText);
 
-            sendMsgService.sendMsgBySMS(consultantPhoneNumber, String.format("����%s������脰�蝜恬������", pendingAppointmentsSum));
-            sendMsgService.sendMsgByEmail(consultantEmail, NOT_CONTACTED_NOTIFY_SUBJECT, emailContent, true);
+            String emailContent = getAppointmentPendingNotifyEmailContent(pendingAppointmentsSum, getAppointmentPendingNotifyUrl());
+
+            optionalPhone.ifPresent(phone -> {
+                sendMsgService.sendMsgBySMS(phone, String.format("����%s������脰�蝜恬��������雯��嚗�%s"
+                    , pendingAppointmentsSum, getAppointmentPendingNotifyUrl()));
+            });
+            optionalEmail.ifPresent(email -> {
+                sendMsgService.sendMsgByEmail(email, NOT_CONTACTED_NOTIFY_SUBJECT, emailContent, true);
+            });
         });
 
         log.info("Sending appointment pending notify to consultant finish");
@@ -94,7 +101,7 @@
                 .filter(appointment ->
                     appointmentService.isAppointmentDateNotInIntervalFromNow(appointment, Constants.APPOINTMENT_EXPIRING_PHONE_INTERVAL, Constants.APPOINTMENT_EXPIRING_EMAIL_INTERVAL)
                 )
-                .filter(this::isAppointmentNotifyNotOnLimit)
+                .filter(this::isAppointmentExpiringNotifyNotOnLimit)
                 .collect(Collectors.toList());
 
         allByCommunicateStatus.forEach(appointment -> {
@@ -104,10 +111,10 @@
 
             optionalPhone.ifPresent(phone ->
                 sendMsgService.sendMsgBySMS(phone, String.format("敺甇�����%s憿批�迤敹�葉嚗������蒂���隞“������雯��嚗�%s"
-                    , consultant.getName(), getAppointmentUrl(appointment.getId())))
+                    , consultant.getName(), getAppointmentExpiringNotifyUrl(appointment.getId())))
             );
             optionalEmail.ifPresent(email ->
-                sendMsgService.sendMsgByEmail(email, NOT_CONTACTED_NOTIFY_SUBJECT, getAppointmentExpiringNotifyEmail(consultant.getName(), getAppointmentUrl(appointment.getId())), true)
+                sendMsgService.sendMsgByEmail(email, NOT_CONTACTED_NOTIFY_SUBJECT, getAppointmentExpiringNotifyEmail(consultant.getName(), getAppointmentExpiringNotifyUrl(appointment.getId())), true)
             );
 
             AppointmentExpiringNotifyRecord record = new AppointmentExpiringNotifyRecord();
@@ -120,32 +127,36 @@
         log.info("Sending appointment expiring notify to customer finish");
     }
 
-    // todo ��蝣箄�府����, otis todo=134497
-    @Scheduled(cron = "0 0 9 * * *")
-    public void sendNotFillSatisfactionToPersonalNotification() {
-        Map<Long, List<Satisfaction>> customerNotFillSatisfactions = satisfactionService.getByStatus(SatisfactionStatusEnum.UNFILLED)
+    @Scheduled(cron = "0 30 8 * * *")
+    public void sendNotFillAppointmentSatisfactionToPersonalNotification() {
+        Map<Long, List<Satisfaction>> customerNotFillSatisfactions =
+            satisfactionService.getByStatusAndType(SatisfactionStatusEnum.UNFILLED, SatisfactionTypeEnum.APPOINTMENT)
                 .stream()
                 .collect(Collectors.groupingBy(Satisfaction::getCustomerId));
 
         customerNotFillSatisfactions.forEach((customerId, notFillSatisfactions) ->
-            personalNotificationService.createNotFillSatisfactionSumToCustomer(customerId, notFillSatisfactions.size())
+            personalNotificationService.createNotFillAppointmentSatisfactionNumberToCustomer(customerId, notFillSatisfactions.size())
         );
     }
-
-    private boolean isAppointmentNotifyNotOnLimit(AppointmentCustomerView appointment) {
+    private boolean isAppointmentExpiringNotifyNotOnLimit(AppointmentCustomerView appointment) {
         int sendNotifyToCustomerRecordSum =
             appointmentExpiringNotifyRecordRepository.findAllByAppointmentId(appointment.getId()).size();
 
         return sendNotifyToCustomerRecordSum < Constants.SEND_EXPIRING_NOTIFY_LIMIT;
     }
 
-    private String getAppointmentUrl(Long appointmentId) {
+    private String getAppointmentPendingNotifyUrl() {
+        return applicationProperties.getFrontEndDomain() + "/consultantLogin";
+    }
+
+    private String getAppointmentExpiringNotifyUrl(Long appointmentId) {
         return applicationProperties.getFrontEndDomain() + "?notContactAppointmentId=" + appointmentId;
     }
 
-    private String getAppointmentPendingNotifyEmailContent(int sum) {
+    private String getAppointmentPendingNotifyEmailContent(int sum, String notifyUrl) {
         Context context = new Context();
         context.setVariable("pendingAppointmentSum", sum);
+        context.setVariable("notifyUrl", notifyUrl);
         return springTemplateEngine.process("mail/appointmentPendingNotifyEmail", context);
     }
 

--
Gitblit v1.8.0