From cefc2c5ad32eddb94998f8ffc759f1fd8806e56e Mon Sep 17 00:00:00 2001
From: wayne <wayne8692wayne8692@gmail.com>
Date: 星期四, 10 二月 2022 12:33:31 +0800
Subject: [PATCH] [update] 因應需求並不會有全台選項,因此移除其資料,並將嚴選配對的搜尋修正

---
 pamapi/src/main/java/com/pollex/pam/service/SatisfactionService.java |   48 +++++++++++++++++++++++++++++++++---------------
 1 files changed, 33 insertions(+), 15 deletions(-)

diff --git a/pamapi/src/main/java/com/pollex/pam/service/SatisfactionService.java b/pamapi/src/main/java/com/pollex/pam/service/SatisfactionService.java
index 569844e..0d8a786 100644
--- a/pamapi/src/main/java/com/pollex/pam/service/SatisfactionService.java
+++ b/pamapi/src/main/java/com/pollex/pam/service/SatisfactionService.java
@@ -4,6 +4,9 @@
 import java.util.List;
 import java.util.Optional;
 
+import com.pollex.pam.enums.SatisfactionTypeEnum;
+import com.pollex.pam.security.SecurityUtils;
+import com.pollex.pam.service.dto.SatisfactionSystemScoreDTO;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -40,13 +43,13 @@
 
 	@Autowired
 	CustomerRepository customerRepository;
-	
+
 	@Autowired
 	ConsultantRepository consultantRepository;
-	
+
 	@Autowired
 	ConsultantService consultantService;
-	
+
 	@Autowired
 	PersonalNotificationService personalNotificationService;
 
@@ -55,23 +58,24 @@
 		consultantService.setConsultantAvgScore(satisfaction);
 		return satisfaction;
 	}
-	
+
 	public Satisfaction scorefaction(SatisfactionCustomerScoreDTO scoreDTO) {
-		Optional<Satisfaction> satisfactionOP = getByAppointmentId(scoreDTO.getAppointmentId());
+		Optional<Satisfaction> satisfactionOP = getByAppointmentIdAndType(scoreDTO.getAppointmentId(), SatisfactionTypeEnum.APPOINTMENT);
 		Satisfaction satisfaction = satisfactionOP.orElseThrow(SatisfactionNotFoundException::new);
 		satisfaction.setScore(scoreDTO.getScore());
 		satisfaction.setStatus(SatisfactionStatusEnum.FILLED);
+        satisfaction.setType(SatisfactionTypeEnum.APPOINTMENT);
 		save(satisfaction);
 		personalNotificationService.createScorefactionToConsultant(satisfaction);
 		return satisfaction;
 	}
-	
-	public Satisfaction createSatisfaction(Appointment appointment) {
-		boolean isexist = getByAppointmentId(appointment.getId()).isPresent();
+
+	public Satisfaction createAppointmentSatisfaction(Appointment appointment) {
+		boolean isexist = getByAppointmentIdAndType(appointment.getId(), SatisfactionTypeEnum.APPOINTMENT).isPresent();
 		if(isexist) {
 			throw new SatisfactionAlreadyExistException();
 		}
-		Satisfaction satisfaction = appointmentMapper.toSatisfaction(appointment);
+		Satisfaction satisfaction = appointmentMapper.toAppointmentSatisfaction(appointment);
 		return save(satisfaction);
 	}
 //
@@ -80,18 +84,22 @@
 //		return save(satisfaction);
 //	}
 
-	public List<SatisfactionDTO> getByAgentNo(String agentNo) {
-		List<Satisfaction> satisfactionList = satisfactionRepository.findByAgentNo(agentNo);
+	public List<SatisfactionDTO> getByAgentNoAndType(String agentNo, SatisfactionTypeEnum type) {
+		List<Satisfaction> satisfactionList = satisfactionRepository.findByAgentNoAndType(agentNo, type);
 		return satisfactionMapper.toDTO(satisfactionList);
 	}
 
-	public List<SatisfactionDTO> getByCustomerId(Long customerDBId) {
-		List<Satisfaction> satisfactionList = satisfactionRepository.findByCustomerId(customerDBId);
+	public List<SatisfactionDTO> getByCustomerIdAndType(Long customerDBId, SatisfactionTypeEnum type) {
+		List<Satisfaction> satisfactionList = satisfactionRepository.findByCustomerIdAndType(customerDBId, type);
 		return satisfactionMapper.toDTO(satisfactionList);
 	}
 
-    public Optional<Satisfaction> getByAppointmentId(Long appointmentId) {
-        return satisfactionRepository.findOneByAppointmentId(appointmentId);
+    public Optional<Satisfaction> getByAppointmentIdAndType(Long appointmentId, SatisfactionTypeEnum type) {
+        return satisfactionRepository.findOneByAppointmentIdAndType(appointmentId, type);
+    }
+
+    public List<Satisfaction> getByStatusAndType(SatisfactionStatusEnum status, SatisfactionTypeEnum type) {
+        return satisfactionRepository.findAllByStatusAndType(status, type);
     }
 
 	public List<Satisfaction> scoreAllfaction(List<SatisfactionCustomerScoreDTO> scoreDTO) {
@@ -101,4 +109,14 @@
 		});
 		return satisfactionList;
 	}
+
+    public Satisfaction createSystemSatisfaction(SatisfactionSystemScoreDTO scoreDTO) {
+        Satisfaction satisfaction = new Satisfaction();
+        satisfaction.setCustomerId(SecurityUtils.getCustomerDBId());
+        satisfaction.setAppointmentId(scoreDTO.getAppointmentId());
+        satisfaction.setStatus(SatisfactionStatusEnum.FILLED);
+        satisfaction.setScore(scoreDTO.getScore());
+        satisfaction.setType(SatisfactionTypeEnum.SYSTEM);
+        return satisfactionRepository.save(satisfaction);
+    }
 }

--
Gitblit v1.8.0