保誠-保戶業務員媒合平台
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.service.mapper;
 
import static java.util.stream.Collectors.toList;
 
import java.util.List;
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.AppointmentClosedInfo;
import com.pollex.pam.domain.AppointmentCustomerView;
import com.pollex.pam.domain.AppointmentNoticeLog;
import com.pollex.pam.repository.AppointmentClosedInfoRepository;
import com.pollex.pam.service.AppointmentClosedInfoService;
import com.pollex.pam.service.AppointmentNoticeLogService;
import com.pollex.pam.service.AppointmentService;
import com.pollex.pam.service.dto.AppointmentCustomerViewDTO;
 
@Service
public class AppointmentCustomerViewMapper {
    
    @Autowired
    AppointmentService appointmentService;
    
    @Autowired
    AppointmentNoticeLogService appointmentNoticeLogService;
    
    @Autowired
    AppointmentClosedInfoRepository appointmentClosedInfoRepository;
    
    @Transactional
    public AppointmentCustomerViewDTO toAppointmentCustomerViewDTO(AppointmentCustomerView source) {
        AppointmentCustomerViewDTO target = new AppointmentCustomerViewDTO();
        BeanUtils.copyProperties(source, target);
        target.setAppointmentMemoList(source.getAppointmentMemoList());
        appointmentService.setInterviewRecordDTO(target);
        List<AppointmentNoticeLog> noticeLogs = appointmentNoticeLogService.findByAppointmentId(source.getId());
        target.setAppointmentNoticeLogs(noticeLogs);
        Optional<AppointmentClosedInfo> appointmentClosedInfoOP = appointmentClosedInfoRepository
                .findByAppointmentId(source.getId());
        if(appointmentClosedInfoOP.isPresent()) {
            target.setAppointmentClosedInfo(appointmentClosedInfoOP.get());
        }
        appointmentService.setSatisfactionScore(target, source.getId());
        
        return target;
    }
 
    public List<AppointmentCustomerViewDTO> toAppointmentCustomerViewDTO(
            List<AppointmentCustomerView> source) {
        return source.stream().map(s -> toAppointmentCustomerViewDTO(s))
                .collect(toList());
    }
}