From c7d4211b02f5931382fed6e9d1009074256d6003 Mon Sep 17 00:00:00 2001 From: 劉鈞霖 <benson@gmail.com> Date: 星期一, 13 十二月 2021 14:23:44 +0800 Subject: [PATCH] [ Update ] : 修正 http header 統一由攔截器去加入以及回傳資料改為 response.data --- pamapi/src/main/java/com/pollex/pam/service/ConsultantService.java | 66 ++++++++++++++++++-------------- 1 files changed, 37 insertions(+), 29 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 7a9c552..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,7 +3,7 @@ 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.AppointmentStatusEnum; import com.pollex.pam.enums.ContactStatusEnum; import com.pollex.pam.enums.LoginResult; import com.pollex.pam.repository.ConsultantRepository; @@ -19,9 +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.Optional; +import java.util.Objects; import java.util.stream.Collectors; @Service @@ -55,52 +56,44 @@ 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.setLatestAppointmentId(null); - dto.setLatestAppointmentDate(null); - dto.setLatestAppointmentScore(null); - dto.setCreateTime(customerFavoriteConsultantRelation.getLastModifiedDate()); + 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 dto, 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()); - 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()); } } @@ -160,7 +153,7 @@ public List<AppointmentCustomerViewDTO> getMyAppointment() { String agentNo = SecurityUtils.getAgentNo(); - return appointmentService.getConsultantAppointments(agentNo); + return appointmentService.getConsultantAvailableAppointments(agentNo); } public void removeConsultantFromCustomList(String agentNo) { @@ -180,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