From 3e1d9a15ec902447f566e7b0dea9d0503230288c Mon Sep 17 00:00:00 2001
From: wayne <wayne8692wayne8692@gmail.com>
Date: 星期三, 01 十二月 2021 16:48:42 +0800
Subject: [PATCH] [ADD]【todo 131457, 131458】預約單瀏覽與查看時間紀錄API

---
 pamapi/src/main/java/com/pollex/pam/service/ConsultantService.java |   18 ++++++++++++++++++
 1 files changed, 18 insertions(+), 0 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 76af3d3..acc8f33 100644
--- a/pamapi/src/main/java/com/pollex/pam/service/ConsultantService.java
+++ b/pamapi/src/main/java/com/pollex/pam/service/ConsultantService.java
@@ -1,10 +1,12 @@
 package com.pollex.pam.service;
 
+import com.pollex.pam.domain.Appointment;
 import com.pollex.pam.domain.AppointmentCustomerView;
 import com.pollex.pam.domain.Consultant;
 import com.pollex.pam.domain.CustomerFavoriteConsultant;
 import com.pollex.pam.enums.LoginResult;
 import com.pollex.pam.repository.AppointmentCustomerViewRepository;
+import com.pollex.pam.repository.AppointmentRepository;
 import com.pollex.pam.repository.ConsultantRepository;
 import com.pollex.pam.repository.CustomerFavoriteConsultantRepository;
 import com.pollex.pam.security.SecurityUtils;
@@ -18,7 +20,9 @@
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.time.Instant;
 import java.util.List;
+import java.util.Objects;
 import java.util.stream.Collectors;
 
 @Service
@@ -37,6 +41,9 @@
 
     @Autowired
     AppointmentService appointmentService;
+
+    @Autowired
+    AppointmentRepository appointmentRepository;
 
     @Autowired
     AppointmentCustomerViewRepository appointmentCustomerViewRepository;
@@ -127,4 +134,15 @@
             log.info("this consultant is not in customer list! agentNo = {}, customId = {}", agentNo, customId);
         }
     }
+
+    public void recordAllAppointmentsView() {
+        String agentNo = SecurityUtils.getAgentNo();
+        List<Appointment> consultantNotViewAppointments = appointmentService.findByAgentNo(agentNo)
+            .stream()
+            .filter(appointment -> Objects.isNull(appointment.getConsultantViewTime()))
+            .collect(Collectors.toList());
+
+        consultantNotViewAppointments.forEach(appointment -> appointment.setConsultantViewTime(Instant.now()));
+        appointmentRepository.saveAll(consultantNotViewAppointments);
+    }
 }

--
Gitblit v1.8.0