[UPDATE] 更新預約單狀態新增新的狀態
[UPDATE] 取消預約時一併更新預約單的狀態為cancel
[REF] 針對發送email和簡訊當設定檔為開發環境時不會實際連線
¤ñ¹ï·sÀÉ®× |
| | |
| | | http post : |
| | | |
| | | http://localhost:8080/api/notice/send |
| | | |
| | | message: ç¼éçæåå
§å®¹ |
| | | appointmentId : ç´è¨ªéç¥çé ç´å®id |
| | | |
| | | request body: |
| | | |
| | | { |
| | | "message":"notice customer invterview time", |
| | | "email":"pollex@gmail.com", |
| | | "phone":"0912345678", |
| | | "appointmentId": 385 |
| | | } |
¤ñ¹ï·sÀÉ®× |
| | |
| | | package com.pollex.pam.domain; |
| | | |
| | | import java.io.Serializable; |
| | | import java.time.Instant; |
| | | |
| | | import javax.persistence.Column; |
| | | import javax.persistence.Entity; |
| | | import javax.persistence.GeneratedValue; |
| | | import javax.persistence.GenerationType; |
| | | import javax.persistence.Id; |
| | | import javax.persistence.Table; |
| | | |
| | | import org.springframework.data.annotation.CreatedBy; |
| | | import org.springframework.data.annotation.CreatedDate; |
| | | |
| | | import com.fasterxml.jackson.annotation.JsonIgnore; |
| | | |
| | | @Entity |
| | | @Table(name = "appointment_notice_log") |
| | | public class AppointmentNoticeLog implements Serializable { |
| | | |
| | | /** |
| | | * |
| | | */ |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | @Id |
| | | @GeneratedValue(strategy = GenerationType.IDENTITY) |
| | | private Long id; |
| | | |
| | | @Column(name = "phone") |
| | | private String phone; |
| | | |
| | | @Column(name = "email") |
| | | private String email; |
| | | |
| | | @Column(name = "appointment_id") |
| | | private Long appointmentId; |
| | | |
| | | // @Column(name = "type") |
| | | // private String type; |
| | | |
| | | @Column(name = "content") |
| | | private String content; |
| | | |
| | | // @CreatedBy |
| | | // @Column(name = "created_by", nullable = false, length = 50, updatable = false) |
| | | // @JsonIgnore |
| | | // private String createdBy; |
| | | |
| | | @CreatedDate |
| | | @Column(name = "created_date", updatable = false) |
| | | @JsonIgnore |
| | | private Instant createdDate = Instant.now(); |
| | | |
| | | public Long getId() { |
| | | return id; |
| | | } |
| | | |
| | | public void setId(Long id) { |
| | | this.id = id; |
| | | } |
| | | |
| | | public String getPhone() { |
| | | return phone; |
| | | } |
| | | |
| | | public void setPhone(String phone) { |
| | | this.phone = phone; |
| | | } |
| | | |
| | | public String getEmail() { |
| | | return email; |
| | | } |
| | | |
| | | public void setEmail(String email) { |
| | | this.email = email; |
| | | } |
| | | |
| | | public Long getAppointmentId() { |
| | | return appointmentId; |
| | | } |
| | | |
| | | public void setAppointmentId(Long appointmentId) { |
| | | this.appointmentId = appointmentId; |
| | | } |
| | | |
| | | // public String getType() { |
| | | // return type; |
| | | // } |
| | | // |
| | | // public void setType(String type) { |
| | | // this.type = type; |
| | | // } |
| | | |
| | | public String getContent() { |
| | | return content; |
| | | } |
| | | |
| | | public void setContent(String content) { |
| | | this.content = content; |
| | | } |
| | | |
| | | // public String getCreatedBy() { |
| | | // return createdBy; |
| | | // } |
| | | // |
| | | // public void setCreatedBy(String createdBy) { |
| | | // this.createdBy = createdBy; |
| | | // } |
| | | |
| | | public Instant getCreatedDate() { |
| | | return createdDate; |
| | | } |
| | | |
| | | public void setCreatedDate(Instant createdDate) { |
| | | this.createdDate = createdDate; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | |
| | | RESERVED, |
| | | |
| | | @JsonProperty("contacted") |
| | | CONTACTED |
| | | CONTACTED, |
| | | |
| | | @JsonProperty("done") |
| | | DONE, |
| | | |
| | | @JsonProperty("closed") |
| | | CLOSED, |
| | | |
| | | @JsonProperty("cancel") |
| | | CANCEL |
| | | } |
¤ñ¹ï·sÀÉ®× |
| | |
| | | package com.pollex.pam.repository; |
| | | |
| | | import org.springframework.data.jpa.repository.JpaRepository; |
| | | import org.springframework.stereotype.Repository; |
| | | |
| | | import com.pollex.pam.domain.AppointmentNoticeLog; |
| | | |
| | | @Repository |
| | | public interface AppointmentNoticeLogRepository extends JpaRepository<AppointmentNoticeLog, Long>{ |
| | | |
| | | } |
| | |
| | | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import com.pollex.pam.domain.Appointment; |
| | | import com.pollex.pam.domain.AppointmentMemo; |
| | |
| | | import com.pollex.pam.web.rest.errors.AppointmentNotFoundException; |
| | | |
| | | @Service |
| | | @Transactional |
| | | public class AppointmentMemoService { |
| | | |
| | | @Autowired |
¤ñ¹ï·sÀÉ®× |
| | |
| | | package com.pollex.pam.service; |
| | | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import com.pollex.pam.domain.AppointmentNoticeLog; |
| | | import com.pollex.pam.repository.AppointmentNoticeLogRepository; |
| | | import com.pollex.pam.service.dto.AppointmentNoticeSendDTO; |
| | | import com.pollex.pam.service.mapper.AppointmentNoticeSendMapper; |
| | | |
| | | @Service |
| | | @Transactional |
| | | public class AppointmentNoticeLogService { |
| | | |
| | | @Autowired |
| | | AppointmentNoticeLogRepository appointmentNoticeLogRepository; |
| | | |
| | | @Autowired |
| | | AppointmentNoticeSendMapper appointmentNoticeSendMapper; |
| | | |
| | | public AppointmentNoticeLog create(AppointmentNoticeSendDTO noticeSendDTO) { |
| | | AppointmentNoticeLog appointmentNoticeLog = |
| | | appointmentNoticeSendMapper.toAppointmentNoticeLog(noticeSendDTO); |
| | | return appointmentNoticeLogRepository.save(appointmentNoticeLog); |
| | | } |
| | | } |
| | |
| | | Appointment appointment = appointmentRepository.findById(appointmentId).get(); |
| | | appointment.setStatus(DELETED); |
| | | appointment.setLastModifiedDate(Instant.now()); |
| | | appointment.setCommunicateStatus(ContactStatusEnum.CANCEL); |
| | | appointmentRepository.save(appointment); |
| | | } |
| | | |
| | |
| | | Assert.notNull(appointment, "appointment entity cannot be null"); |
| | | |
| | | log.debug("is need send appointment notify msg? = {}", applicationProperties.isSendNotifyMsg()); |
| | | if(applicationProperties.isSendNotifyMsg()) { |
| | | log.debug("sending appointment notify, appointmentId = {}", appointment.getId()); |
| | | sendAppointmentNotifyBySMS(appointment); |
| | | sendAppointmentNotifyByHtmlEmail(appointment); |
| | | } |
| | | |
| | | log.debug("sending appointment notify, appointmentId = {}", appointment.getId()); |
| | | sendAppointmentNotifyBySMS(appointment); |
| | | sendAppointmentNotifyByHtmlEmail(appointment); |
| | | } |
| | | |
| | | private void sendAppointmentNotifyBySMS(Appointment appointment) { |
| | |
| | | } |
| | | |
| | | private void sendAppointmentNotifyByHtmlEmail(Appointment appointment) { |
| | | String senderEmail = applicationProperties.getEmail().getSenderEmail(); |
| | | String consultantEmail = consultantService.findByAgentNo(appointment.getAgentNo()).getEmail(); |
| | | String consultantEmail = consultantService.findByAgentNo(appointment.getAgentNo()).getEmail(); |
| | | String customerMobile = appointment.getPhone(); |
| | | String normalContent; |
| | | |
| | |
| | | throw new SendEmailFailException("the consultant does not have email!"); |
| | | } |
| | | |
| | | sendMsgService.sendMsgByEmail(senderEmail, consultantEmail, NOTIFY_EMAIL_SUBJECT, content, true); |
| | | sendMsgService.sendMsgByEmail(consultantEmail, NOTIFY_EMAIL_SUBJECT, content, true); |
| | | } catch (SendEmailFailException e) { |
| | | log.warn("send appointment notify by email was fail, appointment Id = {}", appointment.getId(), e); |
| | | } |
| | |
| | | import org.hibernate.boot.model.naming.IllegalIdentifierException; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import com.pollex.pam.domain.Appointment; |
| | | import com.pollex.pam.domain.InterviewRecord; |
| | |
| | | import com.pollex.pam.web.rest.errors.InterviewRecordNotFoundException; |
| | | |
| | | @Service |
| | | @Transactional |
| | | public class InterviewRecordService { |
| | | |
| | | @Autowired |
¤ñ¹ï·sÀÉ®× |
| | |
| | | package com.pollex.pam.service; |
| | | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.StringUtils; |
| | | |
| | | import com.pollex.pam.domain.Appointment; |
| | | import com.pollex.pam.service.dto.AppointmentNoticeSendDTO; |
| | | |
| | | @Service |
| | | @Transactional |
| | | public class NoticeService { |
| | | |
| | | @Autowired |
| | | AppointmentService appointmentService; |
| | | |
| | | @Autowired |
| | | SendMsgService sendMsgService; |
| | | |
| | | @Autowired |
| | | AppointmentNoticeLogService appointmentNoticeLogService; |
| | | |
| | | public void sendNotice(AppointmentNoticeSendDTO dto) { |
| | | String subject = "ä¿èª åªåå¹³å°ç³»çµ±éç¥ï¼é ç´éç¥"; |
| | | |
| | | // Appointment appointment = appointmentService.findById(dto.getAppointmentId()); |
| | | if(StringUtils.hasText(dto.getEmail())) { |
| | | sendMsgService.sendMsgByEmail(dto.getEmail(), subject, dto.getMessage(), true); |
| | | }if(StringUtils.hasText(dto.getPhone())) { |
| | | sendMsgService.sendMsgBySMS(dto.getPhone(), dto.getMessage()); |
| | | } |
| | | |
| | | appointmentNoticeLogService.create(dto); |
| | | } |
| | | |
| | | } |
| | |
| | | SpringTemplateEngine springTemplateEngine; |
| | | |
| | | public SendSMSResponse sendMsgBySMS(String toMobile, String content) throws SendSMSFailException { |
| | | SMS smsProperties = applicationProperties.getSms(); |
| | | if(!applicationProperties.isSendNotifyMsg()) { |
| | | // return getMockSMSResponse(); |
| | | return null; |
| | | } |
| | | |
| | | SMS smsProperties = applicationProperties.getSms(); |
| | | |
| | | SendSMSRequest sendSMSRequest = new SendSMSRequest(); |
| | | sendSMSRequest.setpKey(UUID.randomUUID().toString()); |
| | |
| | | } |
| | | } |
| | | |
| | | public String sendMsgByEmail(String from, String to, String subject, String content, boolean htmlFormat) throws SendEmailFailException{ |
| | | return sendMsgByEmail(from, to, subject, content, htmlFormat, Collections.emptyList(), Collections.emptyList()); |
| | | // private SendSMSResponse getMockSMSResponse() { |
| | | // SendSMSResponse mock = new SendSMSResponse(); |
| | | // mock.set |
| | | // return null; |
| | | // } |
| | | |
| | | public String sendMsgByEmail(String to, String subject, String content, boolean htmlFormat) throws SendEmailFailException{ |
| | | return sendMsgByEmail(to, subject, content, htmlFormat, Collections.emptyList(), Collections.emptyList()); |
| | | } |
| | | |
| | | public String sendMsgByEmail( |
| | | String fromAddress, String toAddress, String subject, String content, boolean htmlFormat, List<String> toCCAddress, |
| | | List<String> attachments) throws SendEmailFailException |
| | | { |
| | | public String sendMsgByEmail(String toAddress, String subject, String content, boolean htmlFormat, List<String> toCCAddress, |
| | | List<String> attachments) throws SendEmailFailException { |
| | | String fromAddress = applicationProperties.getEmail().getSenderEmail(); |
| | | |
| | | SendMailRequest sendMailRequest = new SendMailRequest(); |
| | | sendMailRequest.setSendMailAddresses(Collections.singletonList(toAddress)); |
| | | sendMailRequest.setFrom(fromAddress); |
| | |
| | | } |
| | | |
| | | public String sendMsgByEmail(SendMailRequest sendMailRequest) throws SendEmailFailException{ |
| | | try { |
| | | if(!applicationProperties.isSendNotifyMsg()) { |
| | | return null; |
| | | } |
| | | try { |
| | | ResponseEntity<String> responseEntity = |
| | | HttpRequestUtil.postWithJson( applicationProperties.getEmail().getUrl(), sendMailRequest, String.class); |
| | | log.debug("responseEntity = {}", responseEntity); |
¤ñ¹ï·sÀÉ®× |
| | |
| | | package com.pollex.pam.service.dto; |
| | | |
| | | public class AppointmentNoticeSendDTO { |
| | | |
| | | private String message; |
| | | private Long appointmentId; |
| | | private String email; |
| | | private String phone; |
| | | // private String noticeType; |
| | | |
| | | public String getMessage() { |
| | | return message; |
| | | } |
| | | public void setMessage(String message) { |
| | | this.message = message; |
| | | } |
| | | public Long getAppointmentId() { |
| | | return appointmentId; |
| | | } |
| | | public void setAppointmentId(Long appointmentId) { |
| | | this.appointmentId = appointmentId; |
| | | } |
| | | // public String getNoticeType() { |
| | | // return noticeType; |
| | | // } |
| | | // public void setNoticeType(String noticeType) { |
| | | // this.noticeType = noticeType; |
| | | // } |
| | | public String getEmail() { |
| | | return email; |
| | | } |
| | | public void setEmail(String email) { |
| | | this.email = email; |
| | | } |
| | | public String getPhone() { |
| | | return phone; |
| | | } |
| | | public void setPhone(String phone) { |
| | | this.phone = phone; |
| | | } |
| | | |
| | | |
| | | |
| | | } |
¤ñ¹ï·sÀÉ®× |
| | |
| | | package com.pollex.pam.service.mapper; |
| | | |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import com.pollex.pam.domain.AppointmentNoticeLog; |
| | | import com.pollex.pam.service.dto.AppointmentNoticeSendDTO; |
| | | |
| | | @Service |
| | | public class AppointmentNoticeSendMapper { |
| | | |
| | | public AppointmentNoticeLog toAppointmentNoticeLog(AppointmentNoticeSendDTO source) { |
| | | AppointmentNoticeLog target = new AppointmentNoticeLog(); |
| | | target.setAppointmentId(source.getAppointmentId()); |
| | | target.setContent(source.getMessage()); |
| | | target.setEmail(source.getEmail()); |
| | | target.setPhone(source.getPhone()); |
| | | return target; |
| | | } |
| | | } |
¤ñ¹ï·sÀÉ®× |
| | |
| | | package com.pollex.pam.web.rest; |
| | | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import com.pollex.pam.domain.Appointment; |
| | | import com.pollex.pam.security.SecurityUtils; |
| | | import com.pollex.pam.service.AppointmentService; |
| | | import com.pollex.pam.service.NoticeService; |
| | | import com.pollex.pam.service.dto.AppointmentNoticeSendDTO; |
| | | |
| | | @RestController |
| | | @RequestMapping("/api/notice") |
| | | public class NoticeResource { |
| | | |
| | | @Autowired |
| | | NoticeService noticeService; |
| | | |
| | | @Autowired |
| | | AppointmentService appointmentService; |
| | | |
| | | @PostMapping("/send") |
| | | public void sendNotice(@RequestBody AppointmentNoticeSendDTO dto) { |
| | | Appointment appointment = appointmentService.findById(dto.getAppointmentId()); |
| | | if(!appointment.getAgentNo().equals(SecurityUtils.getAgentNo())) { |
| | | throw new IllegalAccessError("The user do not have access permission"); |
| | | } |
| | | noticeService.sendNotice(dto); |
| | | } |
| | | } |
| | |
| | | return ResponseEntity.ok(sendMsgService.sendMsgBySMS(toMobile, content)); |
| | | } |
| | | |
| | | @GetMapping("/byEmail") |
| | | public ResponseEntity<String> byEmail( |
| | | @RequestParam String from, |
| | | @RequestParam String to, |
| | | @RequestParam String subject, |
| | | @RequestParam String content, |
| | | @RequestParam boolean htmlFormat |
| | | ) { |
| | | return ResponseEntity.ok(sendMsgService.sendMsgByEmail(from, to, subject, content, htmlFormat)); |
| | | } |
| | | // @GetMapping("/byEmail") |
| | | // public ResponseEntity<String> byEmail( |
| | | // @RequestParam String from, |
| | | // @RequestParam String to, |
| | | // @RequestParam String subject, |
| | | // @RequestParam String content, |
| | | // @RequestParam boolean htmlFormat |
| | | // ) { |
| | | // return ResponseEntity.ok(sendMsgService.sendMsgByEmail(from, to, subject, content, htmlFormat)); |
| | | // } |
| | | // |
| | | // @GetMapping("/byHtmlEmail") |
| | | // public ResponseEntity<String> byHtmlEmail( |
| | | // @RequestParam String from, |
| | | // @RequestParam String to |
| | | // ) { |
| | | // return ResponseEntity.ok(testSendMsgByHtmlTemplateEmail(from, to)); |
| | | // } |
| | | |
| | | @GetMapping("/byHtmlEmail") |
| | | public ResponseEntity<String> byHtmlEmail( |
| | | @RequestParam String from, |
| | | @RequestParam String to |
| | | ) { |
| | | return ResponseEntity.ok(testSendMsgByHtmlTemplateEmail(from, to)); |
| | | } |
| | | |
| | | private String testSendMsgByHtmlTemplateEmail(String from, String to) { |
| | | Context context = new Context(); |
| | | context.setVariable("content", "親æçé¡§åæ¨å¥½ï¼æ¨æä¸çä¾èªä¿èª åªåå¹³å°çæ°é ç´å®\n"); |
| | | context.setVariable("urlHint", appointmentService.getAppointmentDetailUrl(0L)); |
| | | |
| | | String content = springTemplateEngine.process("mail/appointmentNotifyEmail", context); |
| | | return sendMsgService.sendMsgByEmail(from, to, NOTIFY_EMAIL_SUBJECT, content, true); |
| | | } |
| | | // private String testSendMsgByHtmlTemplateEmail(String from, String to) { |
| | | // Context context = new Context(); |
| | | // context.setVariable("content", "親æçé¡§åæ¨å¥½ï¼æ¨æä¸çä¾èªä¿èª åªåå¹³å°çæ°é ç´å®\n"); |
| | | // context.setVariable("urlHint", appointmentService.getAppointmentDetailUrl(0L)); |
| | | // |
| | | // String content = springTemplateEngine.process("mail/appointmentNotifyEmail", context); |
| | | // return sendMsgService.sendMsgByEmail(from, to, NOTIFY_EMAIL_SUBJECT, content, true); |
| | | // } |
| | | } |