From 847792a08f17d7b2a6c6ef90aa9e956cee671da3 Mon Sep 17 00:00:00 2001
From: Tomas <tomasysh@gmail.com>
Date: 星期三, 22 十二月 2021 10:02:21 +0800
Subject: [PATCH] move ts folder to shared folder

---
 pamapi/src/main/java/com/pollex/pam/service/ConsultantService.java |   26 +++++++++++++++++++++-----
 1 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/pamapi/src/main/java/com/pollex/pam/service/ConsultantService.java b/pamapi/src/main/java/com/pollex/pam/service/ConsultantService.java
index 01c179e..8c109fe 100644
--- a/pamapi/src/main/java/com/pollex/pam/service/ConsultantService.java
+++ b/pamapi/src/main/java/com/pollex/pam/service/ConsultantService.java
@@ -3,6 +3,7 @@
 import com.pollex.pam.domain.AppointmentCustomerView;
 import com.pollex.pam.domain.Consultant;
 import com.pollex.pam.domain.CustomerFavoriteConsultant;
+import com.pollex.pam.enums.AppointmentStatusEnum;
 import com.pollex.pam.enums.ContactStatusEnum;
 import com.pollex.pam.enums.LoginResult;
 import com.pollex.pam.repository.ConsultantRepository;
@@ -23,6 +24,8 @@
 import java.util.List;
 import java.util.Objects;
 import java.util.stream.Collectors;
+
+import static com.pollex.pam.enums.ContactStatusEnum.*;
 
 @Service
 public class ConsultantService {
@@ -61,19 +64,29 @@
 
                 dto.setContactStatus(ContactStatusEnum.PICKED);
                 dto.setCreateTime(relation.getCreatedDate());
+                dto.setUpdateTime(relation.getCreatedDate());
                 dto.setCustomerViewTime(relation.getViewTime());
 
-                setAppointmentInfo(
+                setAvailableAppointmentInfo(
                     dto,
                     appointmentService.findAvailableByAgentNoAndCustomerId(consultant.getAgentNo(), customerId)
                 );
+
+                appointmentService.findLatestAppointmentByAgentNoAndCustomerId(consultant.getAgentNo(), customerId)
+                    .ifPresent(latestAppointment -> {
+                        dto.setUpdateTime(latestAppointment.getLastModifiedDate());
+                    });
+
+                if(dto.getUpdateTime().isBefore(relation.getCreatedDate())) {
+                    dto.setUpdateTime(relation.getCreatedDate());
+                }
 
                 return dto;
 
             }).collect(Collectors.toList());
     }
 
-    private void setAppointmentInfo(CustomerFavoriteConsultantDTO customerFavoriteConsultantDTO, List<AppointmentCustomerView> appointmentList) {
+    private void setAvailableAppointmentInfo(CustomerFavoriteConsultantDTO customerFavoriteConsultantDTO, List<AppointmentCustomerView> appointmentList) {
         List<AppointmentCustomerView> appointments = appointmentList.stream()
             .sorted(Comparator.comparing(AppointmentCustomerView::getAppointmentDate).reversed())
             .collect(Collectors.toList());
@@ -85,9 +98,12 @@
         customerFavoriteConsultantDTO.setAppointments(appointmentCustomerViewDTOS);
 
         if (!appointments.isEmpty()) {
-            AppointmentCustomerView latestAppointment = appointments.get(0);
-            customerFavoriteConsultantDTO.setContactStatus(latestAppointment.getCommunicateStatus());
-            customerFavoriteConsultantDTO.setUpdateTime(latestAppointment.getLastModifiedDate());
+            AppointmentCustomerView latestAvailableAppointment = appointments.get(0);
+
+            if(latestAvailableAppointment.getCommunicateStatus() == RESERVED)
+                customerFavoriteConsultantDTO.setContactStatus(RESERVED);
+            else
+                customerFavoriteConsultantDTO.setContactStatus(PICKED);
         }
     }
 

--
Gitblit v1.8.0