From ee59cafd1de5fe45133e391f3837e8f68e2a6de7 Mon Sep 17 00:00:00 2001
From: wayne <wayne8692wayne8692@gmail.com>
Date: 星期一, 13 十二月 2021 10:43:29 +0800
Subject: [PATCH] [add] 【todo 132301】新增客戶查看顧問清單的時間

---
 pamapi/src/main/java/com/pollex/pam/service/ConsultantService.java |   24 +++++++++++++++++++++---
 1 files changed, 21 insertions(+), 3 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 adbb6ab..01c179e 100644
--- a/pamapi/src/main/java/com/pollex/pam/service/ConsultantService.java
+++ b/pamapi/src/main/java/com/pollex/pam/service/ConsultantService.java
@@ -18,8 +18,10 @@
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.time.Instant;
 import java.util.Comparator;
 import java.util.List;
+import java.util.Objects;
 import java.util.stream.Collectors;
 
 @Service
@@ -53,12 +55,13 @@
 
         return customerFavoriteConsultantRepository.findAllByCustomerId(customerId)
             .stream()
-            .map(customerFavoriteConsultantRelation -> {
-                Consultant consultant = customerFavoriteConsultantRelation.getConsultant();
+            .map(relation -> {
+                Consultant consultant = relation.getConsultant();
                 CustomerFavoriteConsultantDTO dto = consultantMapper.toCustomerFavoriteConsultantDto(consultant);
 
                 dto.setContactStatus(ContactStatusEnum.PICKED);
-                dto.setCreateTime(customerFavoriteConsultantRelation.getCreatedDate());
+                dto.setCreateTime(relation.getCreatedDate());
+                dto.setCustomerViewTime(relation.getViewTime());
 
                 setAppointmentInfo(
                     dto,
@@ -164,4 +167,19 @@
         String agentNo = SecurityUtils.getAgentNo();
         appointmentService.recordAllAppointmentsView(agentNo);
     }
+
+    public void recordMyConsultantListView() {
+        Long customerId = SecurityUtils.getCustomerDBId();
+        List<CustomerFavoriteConsultant> notViewRelation = customerFavoriteConsultantRepository
+            .findAllByCustomerId(customerId)
+            .stream()
+            .filter(relation -> Objects.isNull(relation.getViewTime()))
+            .collect(Collectors.toList());
+
+        notViewRelation.forEach(relation -> {
+            relation.setViewTime(Instant.now());
+        });
+
+        customerFavoriteConsultantRepository.saveAll(notViewRelation);
+    }
 }

--
Gitblit v1.8.0