From bdae23a40c461c2c6b6ee614f661eac731c949c8 Mon Sep 17 00:00:00 2001 From: Mila <Mila@pollex.com.tw> Date: 星期三, 22 十二月 2021 14:12:05 +0800 Subject: [PATCH] Merge branch 'master' of https://192.168.0.10:8443/r/pcalife/PAM --- pamapi/src/main/java/com/pollex/pam/service/ConsultantService.java | 50 ++++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 42 insertions(+), 8 deletions(-) diff --git a/pamapi/src/main/java/com/pollex/pam/service/ConsultantService.java b/pamapi/src/main/java/com/pollex/pam/service/ConsultantService.java index adbb6ab..8c109fe 100644 --- a/pamapi/src/main/java/com/pollex/pam/service/ConsultantService.java +++ b/pamapi/src/main/java/com/pollex/pam/service/ConsultantService.java @@ -3,6 +3,7 @@ import com.pollex.pam.domain.AppointmentCustomerView; import com.pollex.pam.domain.Consultant; import com.pollex.pam.domain.CustomerFavoriteConsultant; +import com.pollex.pam.enums.AppointmentStatusEnum; import com.pollex.pam.enums.ContactStatusEnum; import com.pollex.pam.enums.LoginResult; import com.pollex.pam.repository.ConsultantRepository; @@ -18,9 +19,13 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.time.Instant; import java.util.Comparator; import java.util.List; +import java.util.Objects; import java.util.stream.Collectors; + +import static com.pollex.pam.enums.ContactStatusEnum.*; @Service public class ConsultantService { @@ -53,24 +58,35 @@ return customerFavoriteConsultantRepository.findAllByCustomerId(customerId) .stream() - .map(customerFavoriteConsultantRelation -> { - Consultant consultant = customerFavoriteConsultantRelation.getConsultant(); + .map(relation -> { + Consultant consultant = relation.getConsultant(); CustomerFavoriteConsultantDTO dto = consultantMapper.toCustomerFavoriteConsultantDto(consultant); dto.setContactStatus(ContactStatusEnum.PICKED); - dto.setCreateTime(customerFavoriteConsultantRelation.getCreatedDate()); + dto.setCreateTime(relation.getCreatedDate()); + dto.setUpdateTime(relation.getCreatedDate()); + dto.setCustomerViewTime(relation.getViewTime()); - setAppointmentInfo( + setAvailableAppointmentInfo( dto, appointmentService.findAvailableByAgentNoAndCustomerId(consultant.getAgentNo(), customerId) ); + + appointmentService.findLatestAppointmentByAgentNoAndCustomerId(consultant.getAgentNo(), customerId) + .ifPresent(latestAppointment -> { + dto.setUpdateTime(latestAppointment.getLastModifiedDate()); + }); + + if(dto.getUpdateTime().isBefore(relation.getCreatedDate())) { + dto.setUpdateTime(relation.getCreatedDate()); + } return dto; }).collect(Collectors.toList()); } - private void setAppointmentInfo(CustomerFavoriteConsultantDTO customerFavoriteConsultantDTO, List<AppointmentCustomerView> appointmentList) { + private void setAvailableAppointmentInfo(CustomerFavoriteConsultantDTO customerFavoriteConsultantDTO, List<AppointmentCustomerView> appointmentList) { List<AppointmentCustomerView> appointments = appointmentList.stream() .sorted(Comparator.comparing(AppointmentCustomerView::getAppointmentDate).reversed()) .collect(Collectors.toList()); @@ -82,9 +98,12 @@ customerFavoriteConsultantDTO.setAppointments(appointmentCustomerViewDTOS); if (!appointments.isEmpty()) { - AppointmentCustomerView latestAppointment = appointments.get(0); - customerFavoriteConsultantDTO.setContactStatus(latestAppointment.getCommunicateStatus()); - customerFavoriteConsultantDTO.setUpdateTime(latestAppointment.getLastModifiedDate()); + AppointmentCustomerView latestAvailableAppointment = appointments.get(0); + + if(latestAvailableAppointment.getCommunicateStatus() == RESERVED) + customerFavoriteConsultantDTO.setContactStatus(RESERVED); + else + customerFavoriteConsultantDTO.setContactStatus(PICKED); } } @@ -164,4 +183,19 @@ String agentNo = SecurityUtils.getAgentNo(); appointmentService.recordAllAppointmentsView(agentNo); } + + public void recordMyConsultantListView() { + Long customerId = SecurityUtils.getCustomerDBId(); + List<CustomerFavoriteConsultant> notViewRelation = customerFavoriteConsultantRepository + .findAllByCustomerId(customerId) + .stream() + .filter(relation -> Objects.isNull(relation.getViewTime())) + .collect(Collectors.toList()); + + notViewRelation.forEach(relation -> { + relation.setViewTime(Instant.now()); + }); + + customerFavoriteConsultantRepository.saveAll(notViewRelation); + } } -- Gitblit v1.8.0