From 7fcdb8eab75295661e4450614474e3c5a35bec94 Mon Sep 17 00:00:00 2001
From: Mila <Mila@pollex.com.tw>
Date: 星期四, 20 一月 2022 14:56:05 +0800
Subject: [PATCH] Merge branch 'Phase3' of https://192.168.0.10:8443/r/pcalife/PAM into Phase3

---
 pamapi/src/main/java/com/pollex/pam/appointment/process/ClosedProcess.java |   33 ++++++++++++++-------------------
 1 files changed, 14 insertions(+), 19 deletions(-)

diff --git a/pamapi/src/main/java/com/pollex/pam/appointment/process/ClosedProcess.java b/pamapi/src/main/java/com/pollex/pam/appointment/process/ClosedProcess.java
index 2e75575..b6c70ce 100644
--- a/pamapi/src/main/java/com/pollex/pam/appointment/process/ClosedProcess.java
+++ b/pamapi/src/main/java/com/pollex/pam/appointment/process/ClosedProcess.java
@@ -1,10 +1,9 @@
 package com.pollex.pam.appointment.process;
 
-import java.util.Optional;
-
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import com.pollex.pam.domain.Appointment;
 import com.pollex.pam.domain.AppointmentClosedInfo;
@@ -12,12 +11,12 @@
 import com.pollex.pam.repository.AppointmentClosedInfoRepository;
 import com.pollex.pam.service.AppointmentClosedInfoService;
 import com.pollex.pam.service.AppointmentService;
+import com.pollex.pam.service.SatisfactionService;
 import com.pollex.pam.service.dto.AbstractAppointmentProcessDTO;
 import com.pollex.pam.service.dto.ClosedProcessDTO;
-import com.pollex.pam.service.dto.DoneProcessDTO;
-import com.pollex.pam.web.rest.errors.AppointmentClosedInfoNotFoundException;
 
 @Service
+@Transactional
 public class ClosedProcess implements AppointmentProcessInterface{
 	
 	@Autowired
@@ -29,14 +28,17 @@
 	@Autowired
 	AppointmentClosedInfoService appointmentClosedInfoService;
 	
+	@Autowired
+	SatisfactionService satisfactionService;
+	
 	@Override
-	public void createProcess(AbstractAppointmentProcessDTO processDTO) {
-		checkClosedInfo(processDTO.getAppointmentId());
+	public AppointmentClosedInfo create(AbstractAppointmentProcessDTO processDTO) {
 		ClosedProcessDTO closeProcess = toClosedProcessDTO(processDTO);
 		AppointmentClosedInfo closedInfo = new AppointmentClosedInfo();
 		BeanUtils.copyProperties(closeProcess, closedInfo);
-		appointmentClosedInfoRepository.save(closedInfo);
-		
+		Appointment appointment = appointmentService.findById(processDTO.getAppointmentId());
+		satisfactionService.createSatisfaction(appointment);
+		return appointmentClosedInfoRepository.save(closedInfo);
 	}
 	
 	private ClosedProcessDTO toClosedProcessDTO(AbstractAppointmentProcessDTO processDTO) {
@@ -45,23 +47,16 @@
 		return closeProcess;
 	}
 
-	private void checkClosedInfo(Long appointmentId) {
-		Optional<AppointmentClosedInfo> closedInfo = appointmentClosedInfoRepository.findByAppointmentId(appointmentId);
-		if(closedInfo.isPresent()) {
-			throw new IllegalArgumentException("appointment closed info exist");
-		}
-	}
-
 	@Override
 	public ContactStatusEnum getProcessType() {
 		return ContactStatusEnum.CLOSED;
 	}
-
+	
 	@Override
-	public AppointmentClosedInfo editClosedInfo(AbstractAppointmentProcessDTO abstractDTO) {
+	public AppointmentClosedInfo editClosedInfo(
+			AbstractAppointmentProcessDTO abstractDTO
+			, AppointmentClosedInfo closedInfo) {
 		ClosedProcessDTO closeProcess =  toClosedProcessDTO(abstractDTO);
-		AppointmentClosedInfo closedInfo = appointmentClosedInfoService.findByAppointmentId(abstractDTO.getAppointmentId());
-		
 		BeanUtils.copyProperties(closeProcess, closedInfo);
 		return appointmentClosedInfoRepository.save(closedInfo);
 	}

--
Gitblit v1.8.0