From 210abe8695707b725f093eea2f95cfc49980c59f Mon Sep 17 00:00:00 2001
From: wayne <wayne8692wayne8692@gmail.com>
Date: 星期五, 03 十二月 2021 16:16:43 +0800
Subject: [PATCH] [update] 預約單dto加上預約單對應的滿意度分數

---
 pamapi/src/main/java/com/pollex/pam/service/AppointmentService.java |   30 ++++++++++++++++++++++--------
 1 files changed, 22 insertions(+), 8 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 8108fc9..0730d6d 100644
--- a/pamapi/src/main/java/com/pollex/pam/service/AppointmentService.java
+++ b/pamapi/src/main/java/com/pollex/pam/service/AppointmentService.java
@@ -5,6 +5,7 @@
 import java.util.Objects;
 import java.util.stream.Collectors;
 
+import com.pollex.pam.domain.Satisfaction;
 import com.pollex.pam.service.dto.AppointmentUpdateDTO;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -96,8 +97,28 @@
 	public AppointmentCustomerViewDTO getAppointmentDetail(Long appointmentId) {
 		AppointmentCustomerView appointment = appointmentCustomerViewRepository.findById(appointmentId)
 				.orElseThrow(AppointmentNotFoundException::new);
-		return appointmentCustomerViewMapper.toAppointmentCustomerViewDTO(appointment);
+
+        AppointmentCustomerViewDTO dto = appointmentCustomerViewMapper.toAppointmentCustomerViewDTO(appointment);
+        setSatisfactionScore(dto, appointmentId);
+		return dto;
 	}
+
+    public List<AppointmentCustomerViewDTO> getConsultantAvailableAppointments(String agentNo) {
+        return appointmentCustomerViewRepository.findByAgentNo(agentNo).stream()
+            .filter(appointment -> appointment.getStatus() == AVAILABLE)
+            .map(appointmentCustomerView -> {
+                AppointmentCustomerViewDTO dto = appointmentCustomerViewMapper.toAppointmentCustomerViewDTO(appointmentCustomerView);
+                setSatisfactionScore(dto, appointmentCustomerView.getId());
+                return dto;
+            })
+            .collect(Collectors.toList());
+    }
+
+    public void setSatisfactionScore(AppointmentCustomerViewDTO dto, Long appointmentId) {
+        satisfactionService.getByAppointmentId(appointmentId).ifPresent(satisfaction -> {
+            dto.setSatisfactionScore(satisfaction.getScore());
+        });
+    }
 
     public List<AppointmentCustomerView> findAvailableByAgentNoAndCustomerId(String agentNo, Long customerId) {
         return appointmentCustomerViewRepository.findByAgentNoAndCustomerId(agentNo, customerId)
@@ -126,12 +147,5 @@
 
         consultantNotViewAppointments.forEach(appointment -> appointment.setConsultantViewTime(Instant.now()));
         appointmentRepository.saveAll(consultantNotViewAppointments);
-    }
-
-    public List<AppointmentCustomerViewDTO> getConsultantAppointments(String agentNo) {
-        return appointmentCustomerViewRepository.findByAgentNo(agentNo).stream()
-            .filter(appointment -> appointment.getStatus() != DELETED)
-            .map(appointmentCustomerViewMapper::toAppointmentCustomerViewDTO)
-            .collect(Collectors.toList());
     }
 }

--
Gitblit v1.8.0