保誠-保戶業務員媒合平台
wayne
2022-01-26 6fa4bba623713c396432ba8b863846883d6a1906
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package com.pollex.pam.appointment.process;
 
import java.time.Instant;
import java.util.List;
import java.util.Optional;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import com.pollex.pam.domain.Appointment;
import com.pollex.pam.domain.AppointmentClosedInfo;
import com.pollex.pam.enums.ContactStatusEnum;
import com.pollex.pam.repository.AppointmentClosedInfoRepository;
import com.pollex.pam.repository.AppointmentRepository;
import com.pollex.pam.service.AppointmentClosedInfoService;
import com.pollex.pam.service.AppointmentService;
import com.pollex.pam.service.dto.AbstractAppointmentProcessDTO;
import com.pollex.pam.service.dto.DoneProcessDTO;
 
@Service
public class AppointmentProcess{
    
    @Autowired
    List<AppointmentProcessInterface> processList;
    
    @Autowired
    AppointmentService appointmentService;
    
    @Autowired
    AppointmentRepository appointmentRepository;
    
    @Autowired
    AppointmentClosedInfoRepository appointmentClosedInfoRepository;
    
    public void process(AbstractAppointmentProcessDTO dto) {
        
        processList.stream().forEach(process ->{
            if(process.getProcessType() == dto.getContactStatus()) {
                Optional<AppointmentClosedInfo> closedInfoOP = appointmentClosedInfoRepository.findByAppointmentId(dto.getAppointmentId());
                if(closedInfoOP.isPresent()) {
                    process.editClosedInfo(dto, closedInfoOP.get());
                }else {
                    process.create(dto);
                }
            }
        });
        
        changeAppointmentCommunicateStatus(dto.getAppointmentId(), dto.getContactStatus());
    }
 
    private void changeAppointmentCommunicateStatus(Long appointmentId, ContactStatusEnum contactStatus) {
        Appointment appointment = appointmentService.findById(appointmentId);
        appointment.setCommunicateStatus(contactStatus);
        appointmentRepository.save(appointment);
    }
    
}