From 296632415043a56e27da67f23e9d801e2afe5ec6 Mon Sep 17 00:00:00 2001 From: wayne <wayne8692wayne8692@gmail.com> Date: 星期三, 29 十二月 2021 13:58:05 +0800 Subject: [PATCH] [fix] 微調訊息文案的換行處理 --- pamapi/src/main/java/com/pollex/pam/service/ConsultantService.java | 53 +++++++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 45 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..5f8232c 100644 --- a/pamapi/src/main/java/com/pollex/pam/service/ConsultantService.java +++ b/pamapi/src/main/java/com/pollex/pam/service/ConsultantService.java @@ -18,9 +18,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 +57,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 +97,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 +182,23 @@ 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); + } + + public Consultant findByAgentNo(String agentNo) { + return consultantRepository.findOneByAgentNo(agentNo).get(); + } } -- Gitblit v1.8.0