保誠-保戶業務員媒合平台
wayne
2021-12-08 783f227a8d6962b290ef4a8bc0d0d5e12fc88e4c
pamapi/src/main/java/com/pollex/pam/service/ConsultantService.java
@@ -3,7 +3,6 @@
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;
@@ -21,7 +20,6 @@
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
@Service
@@ -60,10 +58,7 @@
                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,
@@ -75,32 +70,21 @@
            }).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());
        }
    }
@@ -160,7 +144,7 @@
   public List<AppointmentCustomerViewDTO> getMyAppointment() {
      String agentNo = SecurityUtils.getAgentNo();
      return appointmentService.getConsultantAppointments(agentNo);
      return appointmentService.getConsultantAvailableAppointments(agentNo);
   }
    public void removeConsultantFromCustomList(String agentNo) {