| | |
| | | @Autowired |
| | | SpringTemplateEngine springTemplateEngine; |
| | | |
| | | public void sendAppointmentNotify(Appointment appointment) { |
| | | Assert.notNull(appointment); |
| | | |
| | | log.debug("is need sending notify msg = {}", applicationProperties.isSendNotifyMsg()); |
| | | if(applicationProperties.isSendNotifyMsg()) { |
| | | log.debug("sending appointment notify, appointmentId = {}", appointment.getId()); |
| | | sendAppointmentNotifyBySMS(appointment); |
| | | sendAppointmentNotifyByEmail(appointment); |
| | | |
| | | // todo 需確認保誠是否有需求使用html mail |
| | | // sendAppointmentNotifyByHtmlEmail(appointment); |
| | | } |
| | | } |
| | | |
| | | private void sendAppointmentNotifyBySMS(Appointment appointment) throws SendSMSFailException { |
| | | String msg = getAppointmentNotifyWording(appointment); |
| | | String consultantMobile = consultantRepository.findOneByAgentNo(appointment.getAgentNo()).get().getPhoneNumber(); |
| | | |
| | | try { |
| | | sendMsgBySMS(consultantMobile, msg); |
| | | } catch (SendSMSFailException e) { |
| | | log.debug("send sms failed, appointment Id = {}", appointment.getId(), e); |
| | | } |
| | | } |
| | | |
| | | private void sendAppointmentNotifyByEmail(Appointment appointment) { |
| | | // todo 需得知保誠系統寄件信箱 (並改於設定檔中) |
| | | String senderEmail = applicationProperties.getEmail().getSenderEmail(); |
| | | String consultantEmail = consultantRepository.findOneByAgentNo(appointment.getAgentNo()).get().getEmail(); |
| | | String content = getAppointmentNotifyWording(appointment); |
| | | |
| | | try { |
| | | sendMsgByEmail(senderEmail, consultantEmail, EMAIL_SUBJECT, content, false); |
| | | } catch (SendEmailFailException e) { |
| | | log.debug("send email failed, appointment Id = {}", appointment.getId(), e); |
| | | } |
| | | } |
| | | |
| | | private void sendAppointmentNotifyByHtmlEmail(Appointment appointment) { |
| | | // todo 需得知保誠系統寄件信箱 (並改於設定檔中) |
| | | String senderEmail = applicationProperties.getEmail().getSenderEmail(); |
| | | String consultantEmail = consultantRepository.findOneByAgentNo(appointment.getAgentNo()).get().getEmail(); |
| | | String customerMobile = appointment.getPhone(); |
| | | String normalContent; |
| | | |
| | | if(StringUtils.hasText(customerMobile)) { |
| | | normalContent = "親愛的顧問您好,您有一筆來自保誠媒合平台的新預約單,該客戶手機號碼為" + customerMobile + "\n"; |
| | | } |
| | | else { |
| | | normalContent = "親愛的顧問您好,您有一筆來自保誠媒合平台的新預約單\n"; |
| | | } |
| | | |
| | | Context context = new Context(); |
| | | context.setVariable("content", normalContent); |
| | | context.setVariable("urlHint", getAppointmentDetailUrl(appointment.getId())); |
| | | String content = springTemplateEngine.process("mail/appointmentNotifyEmail", context); |
| | | |
| | | try { |
| | | sendMsgByEmail(senderEmail, consultantEmail, EMAIL_SUBJECT, content, true); |
| | | } catch (SendEmailFailException e) { |
| | | log.debug("send email failed, appointment Id = {}", appointment.getId(), e); |
| | | } |
| | | } |
| | | |
| | | private String getAppointmentNotifyWording(Appointment appointment) { |
| | | String normalContent; |
| | | if(StringUtils.hasText(appointment.getPhone())) { |
| | | normalContent = "親愛的顧問您好,您有一筆來自保誠媒合平台的新預約單,該客戶手機號碼為" + appointment.getPhone() + "\n"; |
| | | } |
| | | else { |
| | | normalContent = "親愛的顧問您好,您有一筆來自保誠媒合平台的新預約單\n"; |
| | | } |
| | | |
| | | String urlContent = "點擊網址:" + getAppointmentDetailUrl(appointment.getId()) + " 開啟媒合平台查看。"; |
| | | return normalContent + urlContent; |
| | | } |
| | | |
| | | public SendSMSResponse sendMsgBySMS(String toMobile, String content) throws SendSMSFailException { |
| | | SMS smsProperties = applicationProperties.getSms(); |
| | | |