保誠-保戶業務員媒合平台
wayne
2022-03-01 68343c0e409d7f02f29c5a832a6a1e24e9690f06
pamapi/src/main/java/com/pollex/pam/service/ScheduleTaskService.java
@@ -6,6 +6,7 @@
import com.pollex.pam.enums.AppointmentStatusEnum;
import com.pollex.pam.enums.ContactStatusEnum;
import com.pollex.pam.enums.SatisfactionStatusEnum;
import com.pollex.pam.enums.SatisfactionTypeEnum;
import com.pollex.pam.repository.AppointmentCustomerViewRepository;
import com.pollex.pam.repository.AppointmentExpiringNotifyRecordRepository;
import org.slf4j.Logger;
@@ -76,10 +77,11 @@
            Optional<String> optionalPhone = Optional.ofNullable(consultant.getPhoneNumber()).filter(StringUtils::hasText);
            Optional<String> optionalEmail = Optional.ofNullable(consultant.getEmail()).filter(StringUtils::hasText);
            String emailContent = getAppointmentPendingNotifyEmailContent(pendingAppointmentsSum);
            String emailContent = getAppointmentPendingNotifyEmailContent(pendingAppointmentsSum, getAppointmentPendingNotifyUrl());
            optionalPhone.ifPresent(phone -> {
                sendMsgService.sendMsgBySMS(phone, String.format("您有%s則預約單未進行聯繫,請盡速處理", pendingAppointmentsSum));
                sendMsgService.sendMsgBySMS(phone, String.format("您有%s則預約單未進行聯繫,請盡速處理,點擊網址:%s"
                    , pendingAppointmentsSum, getAppointmentPendingNotifyUrl()));
            });
            optionalEmail.ifPresent(email -> {
                sendMsgService.sendMsgByEmail(email, NOT_CONTACTED_NOTIFY_SUBJECT, emailContent, true);
@@ -125,18 +127,17 @@
        log.info("Sending appointment expiring notify to customer finish");
    }
    // todo 需確認該時間, otis todo=134497
    @Scheduled(cron = "0 30 8 * * *")
    public void sendNotFillSatisfactionToPersonalNotification() {
        Map<Long, List<Satisfaction>> customerNotFillSatisfactions = satisfactionService.getByStatus(SatisfactionStatusEnum.UNFILLED)
    public void sendNotFillAppointmentSatisfactionToPersonalNotification() {
        Map<Long, List<Satisfaction>> customerNotFillSatisfactions =
            satisfactionService.getByStatusAndType(SatisfactionStatusEnum.UNFILLED, SatisfactionTypeEnum.APPOINTMENT)
                .stream()
                .collect(Collectors.groupingBy(Satisfaction::getCustomerId));
        customerNotFillSatisfactions.forEach((customerId, notFillSatisfactions) ->
            personalNotificationService.createNotFillSatisfactionSumToCustomer(customerId, notFillSatisfactions.size())
            personalNotificationService.createNotFillAppointmentSatisfactionNumberToCustomer(customerId, notFillSatisfactions.size())
        );
    }
    private boolean isAppointmentExpiringNotifyNotOnLimit(AppointmentCustomerView appointment) {
        int sendNotifyToCustomerRecordSum =
            appointmentExpiringNotifyRecordRepository.findAllByAppointmentId(appointment.getId()).size();
@@ -144,13 +145,18 @@
        return sendNotifyToCustomerRecordSum < Constants.SEND_EXPIRING_NOTIFY_LIMIT;
    }
    private String getAppointmentPendingNotifyUrl() {
        return applicationProperties.getFrontEndDomain() + "/consultantLogin";
    }
    private String getAppointmentExpiringNotifyUrl(Long appointmentId) {
        return applicationProperties.getFrontEndDomain() + "?notContactAppointmentId=" + appointmentId;
    }
    private String getAppointmentPendingNotifyEmailContent(int sum) {
    private String getAppointmentPendingNotifyEmailContent(int sum, String notifyUrl) {
        Context context = new Context();
        context.setVariable("pendingAppointmentSum", sum);
        context.setVariable("notifyUrl", notifyUrl);
        return springTemplateEngine.process("mail/appointmentPendingNotifyEmail", context);
    }