pamapi/src/main/java/com/pollex/pam/repository/SatisfactionRepository.java
@@ -3,6 +3,7 @@ import java.util.List; import java.util.Optional; import com.pollex.pam.enums.SatisfactionStatusEnum; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -19,9 +20,10 @@ Optional<Satisfaction> findOneByAppointmentId(Long appointmentId); List<Satisfaction> findAllByStatus(SatisfactionStatusEnum status); @Query(value = "SELECT avg(score) FROM satisfaction where agent_no=:agent_no" + " and score is not null" , nativeQuery = true) Float getAgentScoreAvg(@Param("agent_no") String agentNo); } pamapi/src/main/java/com/pollex/pam/service/PersonalNotificationService.java
@@ -67,6 +67,18 @@ entity.setTitle("顧問約訪通知"); personalNotificationRepository.save(entity); } public void createNotFillSatisfactionSumToCustomer(Long customerId, int notFillSatisfactionSum) { PersonalNotification entity = new PersonalNotification(); String content = "您有 "+notFillSatisfactionSum+" 筆顧問的滿意度需要填寫"; entity.setContent(content); entity.setNotificationType(NotificationTypeEnum.ACTIVITY); entity.setOwnerId(customerId); entity.setOwnerRole(PersonalNotificationRoleEnum.CUSTOMER); entity.setTitle("客戶滿意度"); personalNotificationRepository.save(entity); } public void createEditConsultantToConsultant(Consultant consultant) { PersonalNotification entity = new PersonalNotification(); pamapi/src/main/java/com/pollex/pam/service/SatisfactionService.java
@@ -92,6 +92,10 @@ public Optional<Satisfaction> getByAppointmentId(Long appointmentId) { return satisfactionRepository.findOneByAppointmentId(appointmentId); } public List<Satisfaction> getByStatus(SatisfactionStatusEnum status) { return satisfactionRepository.findAllByStatus(status); } public List<Satisfaction> scoreAllfaction(List<SatisfactionCustomerScoreDTO> scoreDTO) { pamapi/src/main/java/com/pollex/pam/service/ScheduleTaskService.java
@@ -4,8 +4,10 @@ import com.pollex.pam.domain.Appointment; import com.pollex.pam.domain.AppointmentExpiringNotifyRecord; import com.pollex.pam.domain.Consultant; import com.pollex.pam.domain.Satisfaction; import com.pollex.pam.enums.AppointmentStatusEnum; import com.pollex.pam.enums.ContactStatusEnum; import com.pollex.pam.enums.SatisfactionStatusEnum; import com.pollex.pam.repository.AppointmentExpiringNotifyRecordRepository; import com.pollex.pam.repository.AppointmentRepository; import org.slf4j.Logger; @@ -13,6 +15,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.StringUtils; import org.thymeleaf.context.Context; import org.thymeleaf.spring5.SpringTemplateEngine; @@ -26,6 +29,7 @@ import java.util.stream.Collectors; @Service @Transactional public class ScheduleTaskService { /** @@ -70,6 +74,12 @@ @Autowired AppointmentExpiringNotifyRecordRepository appointmentExpiringNotifyRecordRepository; @Autowired SatisfactionService satisfactionService; @Autowired PersonalNotificationService personalNotificationService; @Scheduled(cron = "0 30 8 * * *") public void sendAppointmentPendingNotifyToConsultant() { @@ -129,6 +139,18 @@ log.info("Sending appointment expiring notify to customer finish"); } // todo 需確認該時間, otis todo=134497 @Scheduled(cron = "0 0 9 * * *") public void sendNotFillSatisfactionToPersonalNotification() { Map<Long, List<Satisfaction>> customerNotFillSatisfactions = satisfactionService.getByStatus(SatisfactionStatusEnum.UNFILLED) .stream() .collect(Collectors.groupingBy(Satisfaction::getCustomerId)); customerNotFillSatisfactions.forEach((customerId, notFillSatisfactions) -> personalNotificationService.createNotFillSatisfactionSumToCustomer(customerId, notFillSatisfactions.size()) ); } private boolean isAppointmentInInterval(Appointment appointment, int phoneInterval, int emailInterval) { final boolean isHavePhone = StringUtils.hasText(appointment.getPhone()); final boolean isHaveEmail = StringUtils.hasText(appointment.getEmail());