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
@@ -20,22 +20,22 @@ @Service @Transactional public class PersonalNotificationService { @Autowired PersonalNotificationRepository personalNotificationRepository; @Autowired ConsultantService consultantService; @Autowired AppointmentService appointmentService; @Autowired CustomerService customerService; @Autowired CustomerRepository customerRepository; @Autowired SatisfactionService satisfactionService; @@ -68,6 +68,18 @@ 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(); String content = "您的個人帳號設定已進行更新"; pamapi/src/main/java/com/pollex/pam/service/SatisfactionService.java
@@ -40,13 +40,13 @@ @Autowired CustomerRepository customerRepository; @Autowired ConsultantRepository consultantRepository; @Autowired ConsultantService consultantService; @Autowired PersonalNotificationService personalNotificationService; @@ -55,7 +55,7 @@ consultantService.setConsultantAvgScore(satisfaction); return satisfaction; } public Satisfaction scorefaction(SatisfactionCustomerScoreDTO scoreDTO) { Optional<Satisfaction> satisfactionOP = getByAppointmentId(scoreDTO.getAppointmentId()); Satisfaction satisfaction = satisfactionOP.orElseThrow(SatisfactionNotFoundException::new); @@ -65,7 +65,7 @@ personalNotificationService.createScorefactionToConsultant(satisfaction); return satisfaction; } public Satisfaction createSatisfaction(Appointment appointment) { boolean isexist = getByAppointmentId(appointment.getId()).isPresent(); if(isexist) { @@ -94,6 +94,10 @@ return satisfactionRepository.findOneByAppointmentId(appointmentId); } public List<Satisfaction> getByStatus(SatisfactionStatusEnum status) { return satisfactionRepository.findAllByStatus(status); } public List<Satisfaction> scoreAllfaction(List<SatisfactionCustomerScoreDTO> scoreDTO) { List<Satisfaction> satisfactionList = new ArrayList<>(); scoreDTO.stream().forEach(dto ->{ 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());