From a3716f72066d25d745f4d5103ff23a553c3e102b Mon Sep 17 00:00:00 2001
From: wayne <wayne8692wayne8692@gmail.com>
Date: 星期四, 17 二月 2022 11:41:19 +0800
Subject: [PATCH] Merge branch 'sit' into uat

---
 pamapi/src/main/java/com/pollex/pam/service/SatisfactionService.java |   44 ++++++++++++++++++++++++++++----------------
 1 files changed, 28 insertions(+), 16 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 0fa1b91..1bf3c20 100644
--- a/pamapi/src/main/java/com/pollex/pam/service/SatisfactionService.java
+++ b/pamapi/src/main/java/com/pollex/pam/service/SatisfactionService.java
@@ -6,7 +6,8 @@
 
 import com.pollex.pam.enums.SatisfactionTypeEnum;
 import com.pollex.pam.security.SecurityUtils;
-import com.pollex.pam.service.dto.SatisfactionSystemScoreDTO;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -24,10 +25,13 @@
 import com.pollex.pam.service.mapper.SatisfactionMapper;
 import com.pollex.pam.web.rest.errors.SatisfactionAlreadyExistException;
 import com.pollex.pam.web.rest.errors.SatisfactionNotFoundException;
+import org.springframework.util.Assert;
 
 @Service
 @Transactional
 public class SatisfactionService {
+
+    private static final Logger log = LoggerFactory.getLogger(SatisfactionService.class);
 
 	@Autowired
 	SatisfactionRepository satisfactionRepository;
@@ -55,23 +59,31 @@
 
 	public Satisfaction save(Satisfaction satisfaction) {
 		satisfaction = satisfactionRepository.save(satisfaction);
-		consultantService.setConsultantAvgScore(satisfaction);
+        if(satisfaction.getType() == SatisfactionTypeEnum.APPOINTMENT) {
+            consultantService.setConsultantAvgScore(satisfaction);
+        }
 		return satisfaction;
 	}
 
 	public Satisfaction scorefaction(SatisfactionCustomerScoreDTO scoreDTO) {
-		Optional<Satisfaction> satisfactionOP = getByAppointmentId(scoreDTO.getAppointmentId());
+		Optional<Satisfaction> satisfactionOP = satisfactionRepository.findOneByAppointmentIdAndType(scoreDTO.getAppointmentId(), scoreDTO.getType());
 		Satisfaction satisfaction = satisfactionOP.orElseThrow(SatisfactionNotFoundException::new);
+
+        boolean isSameCustomer = satisfaction.getCustomerId().equals(SecurityUtils.getCustomerDBId());
+        Assert.isTrue(isSameCustomer, "The currently logged in customer has a different ID than the customer on Satisfaction");
+
 		satisfaction.setScore(scoreDTO.getScore());
 		satisfaction.setStatus(SatisfactionStatusEnum.FILLED);
-        satisfaction.setType(SatisfactionTypeEnum.APPOINTMENT);
 		save(satisfaction);
-		personalNotificationService.createScorefactionToConsultant(satisfaction);
-		return satisfaction;
+
+        if(satisfaction.getType() == SatisfactionTypeEnum.APPOINTMENT) {
+            personalNotificationService.createScorefactionToConsultant(satisfaction);
+        }
+        return satisfaction;
 	}
 
 	public Satisfaction createAppointmentSatisfaction(Appointment appointment) {
-		boolean isexist = getByAppointmentId(appointment.getId()).isPresent();
+		boolean isexist = getByAppointmentIdAndType(appointment.getId(), SatisfactionTypeEnum.APPOINTMENT).isPresent();
 		if(isexist) {
 			throw new SatisfactionAlreadyExistException();
 		}
@@ -89,13 +101,13 @@
 		return satisfactionMapper.toDTO(satisfactionList);
 	}
 
-	public List<SatisfactionDTO> getByCustomerIdAndType(Long customerDBId, SatisfactionTypeEnum type) {
-		List<Satisfaction> satisfactionList = satisfactionRepository.findByCustomerIdAndType(customerDBId, type);
+	public List<SatisfactionDTO> getByCustomerId(Long customerDBId) {
+		List<Satisfaction> satisfactionList = satisfactionRepository.findByCustomerId(customerDBId);
 		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) {
@@ -110,13 +122,13 @@
 		return satisfactionList;
 	}
 
-    public Satisfaction createSystemSatisfaction(SatisfactionSystemScoreDTO scoreDTO) {
+    public void createUnfilledSystemSatisfaction(Appointment appointment) {
         Satisfaction satisfaction = new Satisfaction();
+        satisfaction.setAppointmentId(appointment.getId());
         satisfaction.setCustomerId(SecurityUtils.getCustomerDBId());
-        satisfaction.setAppointmentId(scoreDTO.getAppointmentId());
-        satisfaction.setStatus(SatisfactionStatusEnum.FILLED);
-        satisfaction.setScore(scoreDTO.getScore());
+        satisfaction.setStatus(SatisfactionStatusEnum.UNFILLED);
         satisfaction.setType(SatisfactionTypeEnum.SYSTEM);
-        return satisfactionRepository.save(satisfaction);
+
+        satisfactionRepository.save(satisfaction);
     }
 }

--
Gitblit v1.8.0