From e8a53c081980ce1a5a9e1a36c822edab15ea42e0 Mon Sep 17 00:00:00 2001 From: wayne <wayne8692wayne8692@gmail.com> Date: 星期四, 02 十二月 2021 14:54:05 +0800 Subject: [PATCH] [update] 標記為已聯繫時紀錄已聯繫時間 --- pamapi/src/main/java/com/pollex/pam/service/ConsultantService.java | 29 ++++++++++++++++++++++++++++- 1 files changed, 28 insertions(+), 1 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 f59f84b..acc8f33 100644 --- a/pamapi/src/main/java/com/pollex/pam/service/ConsultantService.java +++ b/pamapi/src/main/java/com/pollex/pam/service/ConsultantService.java @@ -1,9 +1,12 @@ package com.pollex.pam.service; +import com.pollex.pam.domain.Appointment; import com.pollex.pam.domain.AppointmentCustomerView; import com.pollex.pam.domain.Consultant; import com.pollex.pam.domain.CustomerFavoriteConsultant; +import com.pollex.pam.enums.LoginResult; import com.pollex.pam.repository.AppointmentCustomerViewRepository; +import com.pollex.pam.repository.AppointmentRepository; import com.pollex.pam.repository.ConsultantRepository; import com.pollex.pam.repository.CustomerFavoriteConsultantRepository; import com.pollex.pam.security.SecurityUtils; @@ -17,7 +20,9 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.time.Instant; import java.util.List; +import java.util.Objects; import java.util.stream.Collectors; @Service @@ -38,10 +43,16 @@ AppointmentService appointmentService; @Autowired + AppointmentRepository appointmentRepository; + + @Autowired AppointmentCustomerViewRepository appointmentCustomerViewRepository; @Autowired AppointmentCustomerViewMapper appointmentCustomerViewMapper; + + @Autowired + LoginRecordService loginRecordService; public List<ConsultantDTO> getMyConsultantList() { Long userId = SecurityUtils.getCustomerDBId(); @@ -74,7 +85,12 @@ public ConsultantDetailDTO getConsultantDetail(String agentNo) { Consultant consultant = consultantRepository.findOneByAgentNo(agentNo).orElseThrow(ConsultantNotFoundException::new); - return consultantMapper.toDetailDto(consultant); + ConsultantDetailDTO consultantDetailDTO = consultantMapper.toDetailDto(consultant); + + loginRecordService.findLatestLoginRecord(agentNo, LoginResult.SUCCESS) + .ifPresent(loginRecord -> consultantDetailDTO.setLatestLoginTime(loginRecord.getLoginDate())); + + return consultantDetailDTO; } @Transactional @@ -118,4 +134,15 @@ log.info("this consultant is not in customer list! agentNo = {}, customId = {}", agentNo, customId); } } + + public void recordAllAppointmentsView() { + String agentNo = SecurityUtils.getAgentNo(); + List<Appointment> consultantNotViewAppointments = appointmentService.findByAgentNo(agentNo) + .stream() + .filter(appointment -> Objects.isNull(appointment.getConsultantViewTime())) + .collect(Collectors.toList()); + + consultantNotViewAppointments.forEach(appointment -> appointment.setConsultantViewTime(Instant.now())); + appointmentRepository.saveAll(consultantNotViewAppointments); + } } -- Gitblit v1.8.0