保誠-保戶業務員媒合平台
wayne
2021-12-02 e8a53c081980ce1a5a9e1a36c822edab15ea42e0
pamapi/src/main/java/com/pollex/pam/service/ConsultantService.java
@@ -1,10 +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;
@@ -18,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
@@ -37,6 +41,9 @@
    @Autowired
    AppointmentService appointmentService;
    @Autowired
    AppointmentRepository appointmentRepository;
    @Autowired
    AppointmentCustomerViewRepository appointmentCustomerViewRepository;
@@ -127,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);
    }
}