| | |
| | | package com.pollex.pam.service.mapper; |
| | | |
| | | import com.pollex.pam.domain.Appointment; |
| | | import com.pollex.pam.domain.Consultant; |
| | | import com.pollex.pam.domain.CustomFavoriteConsultant; |
| | | import com.pollex.pam.enums.ContactStatusEnum; |
| | | import com.pollex.pam.service.AppointmentService; |
| | | import com.pollex.pam.service.dto.ConsultantDTO; |
| | | import com.pollex.pam.service.dto.ConsultantDetailDTO; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.time.Instant; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | | public class ConsultantMapper { |
| | | |
| | | private final static Character SPLIT_MASK = ','; |
| | | |
| | | private final AppointmentService appointmentService; |
| | | |
| | | public ConsultantMapper(AppointmentService appointmentService) { |
| | | this.appointmentService = appointmentService; |
| | | } |
| | | |
| | | public ConsultantDTO toDto(Consultant source) { |
| | | ConsultantDTO consultantDTO = new ConsultantDTO(); |
| | |
| | | |
| | | consultantDTO.setContactStatus(null); |
| | | consultantDTO.setUpdateTime(null); |
| | | consultantDTO.setLatestAppointmentId(null); |
| | | |
| | | return consultantDTO; |
| | | } |
| | |
| | | Consultant consultant = customFavoriteConsultant.getConsultant(); |
| | | ConsultantDTO dto = toDto(consultant); |
| | | |
| | | Instant updateTime = customFavoriteConsultant.getLastModifiedDate(); |
| | | dto.setContactStatus(customFavoriteConsultant.getContactStatus()); |
| | | dto.setUpdateTime(updateTime); |
| | | final Optional<Appointment> latestAppointmentOptional = appointmentService.findByAgentNoAndCustomerId(consultant.getAgentNo(), customFavoriteConsultant.getCustomerId()) |
| | | .stream() |
| | | .max(Comparator.comparing(Appointment::getAppointmentDate)); |
| | | |
| | | if(latestAppointmentOptional.isPresent()) { |
| | | Appointment latestAppointment = latestAppointmentOptional.get(); |
| | | dto.setContactStatus(latestAppointment.getCommunicateStatus()); |
| | | dto.setLatestAppointmentId(latestAppointment.getId()); |
| | | dto.setUpdateTime(latestAppointment.getAppointmentDate()); |
| | | } |
| | | else { |
| | | dto.setContactStatus(ContactStatusEnum.PICKED); |
| | | dto.setLatestAppointmentId(null); |
| | | dto.setUpdateTime(customFavoriteConsultant.getLastModifiedDate()); |
| | | } |
| | | |
| | | return dto; |
| | | } |