From 2ad11fa39ac42b17dc1b34b01788322855fa2e3e Mon Sep 17 00:00:00 2001 From: wayne <wayne8692wayne8692@gmail.com> Date: 星期一, 13 十二月 2021 12:16:11 +0800 Subject: [PATCH] [update] 【todo 132231】修正顧問清單的更新時間在有預約單刪除後應為刪除時間 --- pamapi/src/main/java/com/pollex/pam/service/ConsultantService.java | 36 ++++++++++++++++++++++++++++++------ 1 files changed, 30 insertions(+), 6 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..da2ee4f 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,8 +19,10 @@ 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; @Service @@ -53,24 +56,31 @@ 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.getLastModifiedDate()); + dto.setCustomerViewTime(relation.getViewTime()); - setAppointmentInfo( + setAvaliableAppointmentInfo( dto, appointmentService.findAvailableByAgentNoAndCustomerId(consultant.getAgentNo(), customerId) ); + + appointmentService.findLatestAppointmentByAgentNoAndCustomerId(consultant.getAgentNo(), customerId) + .ifPresent(latestAppointment -> { + dto.setUpdateTime(latestAppointment.getLastModifiedDate()); + }); return dto; }).collect(Collectors.toList()); } - private void setAppointmentInfo(CustomerFavoriteConsultantDTO customerFavoriteConsultantDTO, List<AppointmentCustomerView> appointmentList) { + private void setAvaliableAppointmentInfo(CustomerFavoriteConsultantDTO customerFavoriteConsultantDTO, List<AppointmentCustomerView> appointmentList) { List<AppointmentCustomerView> appointments = appointmentList.stream() .sorted(Comparator.comparing(AppointmentCustomerView::getAppointmentDate).reversed()) .collect(Collectors.toList()); @@ -84,7 +94,6 @@ if (!appointments.isEmpty()) { AppointmentCustomerView latestAppointment = appointments.get(0); customerFavoriteConsultantDTO.setContactStatus(latestAppointment.getCommunicateStatus()); - customerFavoriteConsultantDTO.setUpdateTime(latestAppointment.getLastModifiedDate()); } } @@ -164,4 +173,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