| | |
| | | import com.pollex.pam.domain.AppointmentCustomerView; |
| | | import com.pollex.pam.domain.Consultant; |
| | | import com.pollex.pam.domain.CustomerFavoriteConsultant; |
| | | import com.pollex.pam.domain.Satisfaction; |
| | | import com.pollex.pam.enums.ContactStatusEnum; |
| | | import com.pollex.pam.enums.LoginResult; |
| | | import com.pollex.pam.repository.ConsultantRepository; |
| | |
| | | |
| | | import java.util.Comparator; |
| | | import java.util.List; |
| | | import java.util.Optional; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | |
| | | CustomerFavoriteConsultantDTO dto = consultantMapper.toCustomerFavoriteConsultantDto(consultant); |
| | | |
| | | dto.setContactStatus(ContactStatusEnum.PICKED); |
| | | dto.setLatestAppointmentId(null); |
| | | dto.setLatestAppointmentDate(null); |
| | | dto.setLatestAppointmentScore(null); |
| | | dto.setCreateTime(customerFavoriteConsultantRelation.getLastModifiedDate()); |
| | | dto.setCreateTime(customerFavoriteConsultantRelation.getCreatedDate()); |
| | | |
| | | setAppointmentInfo( |
| | | dto, |
| | |
| | | }).collect(Collectors.toList()); |
| | | } |
| | | |
| | | private void setAppointmentInfo(CustomerFavoriteConsultantDTO dto, List<AppointmentCustomerView> appointmentList) { |
| | | private void setAppointmentInfo(CustomerFavoriteConsultantDTO customerFavoriteConsultantDTO, List<AppointmentCustomerView> appointmentList) { |
| | | List<AppointmentCustomerView> appointments = appointmentList.stream() |
| | | .sorted(Comparator.comparing(AppointmentCustomerView::getAppointmentDate).reversed()) |
| | | .collect(Collectors.toList()); |
| | | |
| | | dto.setAppointments(appointmentCustomerViewMapper.toAppointmentCustomerViewDTO(appointments)); |
| | | List<AppointmentCustomerViewDTO> appointmentCustomerViewDTOS = appointmentCustomerViewMapper.toAppointmentCustomerViewDTO(appointments); |
| | | appointmentCustomerViewDTOS.forEach(appointmentCustomerViewDTO -> { |
| | | appointmentService.setSatisfactionScore(appointmentCustomerViewDTO, appointmentCustomerViewDTO.getId()); |
| | | }); |
| | | customerFavoriteConsultantDTO.setAppointments(appointmentCustomerViewDTOS); |
| | | |
| | | if (!appointments.isEmpty()) { |
| | | AppointmentCustomerView latestAppointment = appointments.get(0); |
| | | dto.setContactStatus(latestAppointment.getCommunicateStatus()); |
| | | dto.setLatestAppointmentId(latestAppointment.getId()); |
| | | dto.setLatestAppointmentDate(latestAppointment.getAppointmentDate()); |
| | | dto.setUpdateTime(latestAppointment.getLastModifiedDate()); |
| | | |
| | | setLatestAppointmentScore(dto, latestAppointment); |
| | | } |
| | | } |
| | | |
| | | private void setLatestAppointmentScore(CustomerFavoriteConsultantDTO dto, AppointmentCustomerView latestAppointment) { |
| | | Optional<Satisfaction> satisfactionOptional = satisfactionService.getByAppointmentId(latestAppointment.getId()); |
| | | if(satisfactionOptional.isPresent()) { |
| | | Satisfaction satisfaction = satisfactionOptional.get(); |
| | | dto.setLatestAppointmentScore(satisfaction.getScore()); |
| | | } |
| | | else { |
| | | dto.setLatestAppointmentScore(null); |
| | | customerFavoriteConsultantDTO.setContactStatus(latestAppointment.getCommunicateStatus()); |
| | | customerFavoriteConsultantDTO.setUpdateTime(latestAppointment.getLastModifiedDate()); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | public List<AppointmentCustomerViewDTO> getMyAppointment() { |
| | | String agentNo = SecurityUtils.getAgentNo(); |
| | | return appointmentService.getConsultantAppointments(agentNo); |
| | | return appointmentService.getConsultantAvailableAppointments(agentNo); |
| | | } |
| | | |
| | | public void removeConsultantFromCustomList(String agentNo) { |