From beeee55db98ec9028a3fcc6a05b844b04ba0c229 Mon Sep 17 00:00:00 2001 From: Jack <jack.su@pollex.com.tw> Date: 星期六, 22 一月 2022 10:39:16 +0800 Subject: [PATCH] [ADD] 新增小鈴鐺通知的紀錄( * 顧問主動發送滿意度給客戶的通知後,系統立即通知客戶需要填寫滿意度通知 * 顧問發送約訪通知後,系統通知客戶有約訪 * 顧問更新個人帳號通知 * 客戶取消預約單通知 * 客戶更新預約單通知 * 客戶進行滿意度評比通知) --- pamapi/src/main/java/com/pollex/pam/service/PersonalNotificationService.java | 98 ++++++++++++++++++++++++++++++++ pamapi/src/main/java/com/pollex/pam/service/SatisfactionService.java | 7 ++ pamapi/src/main/java/com/pollex/pam/service/AppointmentService.java | 11 ++- pamapi/src/main/java/com/pollex/pam/web/rest/AppointmentResource.java | 9 ++ pamapi/src/main/java/com/pollex/pam/service/ConsultantService.java | 9 ++ pamapi/src/main/java/com/pollex/pam/service/NoticeService.java | 5 + 6 files changed, 132 insertions(+), 7 deletions(-) diff --git a/pamapi/src/main/java/com/pollex/pam/service/AppointmentService.java b/pamapi/src/main/java/com/pollex/pam/service/AppointmentService.java index 8cc1a69..dcac303 100644 --- a/pamapi/src/main/java/com/pollex/pam/service/AppointmentService.java +++ b/pamapi/src/main/java/com/pollex/pam/service/AppointmentService.java @@ -83,6 +83,9 @@ @Autowired AppointmentProcess abstractAppointmentProcess; + + @Autowired + PersonalNotificationService personalNotificationService; public Appointment customerCreateAppointment(AppointmentCreateDTO appointmentCreateDTO) { Appointment appointment = appointmentDTOMapper.toAppointment(appointmentCreateDTO); @@ -92,9 +95,9 @@ return appointmentRepository.save(appointment); } - public void updateAppointment(AppointmentUpdateDTO updateAppointmentDTO) { + public Appointment updateAppointment(AppointmentUpdateDTO updateAppointmentDTO) { Appointment appointment = appointmentRepository.findById(updateAppointmentDTO.getId()).get(); - + BeanUtils.copyProperties(updateAppointmentDTO, appointment); appointment.setPhone(updateAppointmentDTO.getPhone()); appointment.setEmail(updateAppointmentDTO.getEmail()); appointment.setContactType(updateAppointmentDTO.getContactType()); @@ -106,7 +109,7 @@ appointment.setOtherRequirement(updateAppointmentDTO.getOtherRequirement()); appointment.setLastModifiedDate(Instant.now()); - appointmentRepository.save(appointment); + return appointmentRepository.save(appointment); } public void markAppointmentDeleted(Long appointmentId) { @@ -115,6 +118,8 @@ appointment.setLastModifiedDate(Instant.now()); appointment.setCommunicateStatus(ContactStatusEnum.CANCEL); appointmentRepository.save(appointment); + personalNotificationService.createMarkAppointmentDeletedToConsultant(appointment); + } public List<Appointment> findByAgentNo(String agentNo) { diff --git a/pamapi/src/main/java/com/pollex/pam/service/ConsultantService.java b/pamapi/src/main/java/com/pollex/pam/service/ConsultantService.java index 91e1ba3..d78a39f 100644 --- a/pamapi/src/main/java/com/pollex/pam/service/ConsultantService.java +++ b/pamapi/src/main/java/com/pollex/pam/service/ConsultantService.java @@ -88,6 +88,9 @@ @Autowired SatisfactionRepository satisfactionRepository; + + @Autowired + PersonalNotificationService personalNotificationService; public List<CustomerFavoriteConsultantDTO> getMyConsultantList() { Long customerId = SecurityUtils.getCustomerDBId(); @@ -248,7 +251,9 @@ .orElseThrow(ConsultantNotFoundException::new); consultantDTOMapper.copyToConsultant(editDTO, consultant); FileUtil.base64ToFile(editDTO.getPhotoBase64(), editDTO.getPhotoFileName(), applicationProperty.getFileFolderPath()); - return consultantRepository.save(consultant); + consultantRepository.save(consultant); + personalNotificationService.createEditConsultantToConsultant(consultant); + return consultant; } public InputStream getAvatarImage(String agentNo) { @@ -275,6 +280,8 @@ String content = genSendSatisfactionSMSContent(appointment); sendMsgService.sendMsgBySMS(appointment.getPhone(), content); } + + personalNotificationService.createSendSatisfactionToClientToCustomer(appointment); } private String genSendSatisfactionSMSContent(Appointment appointment) { diff --git a/pamapi/src/main/java/com/pollex/pam/service/NoticeService.java b/pamapi/src/main/java/com/pollex/pam/service/NoticeService.java index 5dd8984..5d9a908 100644 --- a/pamapi/src/main/java/com/pollex/pam/service/NoticeService.java +++ b/pamapi/src/main/java/com/pollex/pam/service/NoticeService.java @@ -29,6 +29,9 @@ @Autowired AppointmentRepository appointmentRepository; + @Autowired + PersonalNotificationService personalNotificationService; + public void sendNotice(AppointmentNoticeSendDTO dto) { String subject = "靽���像�蝟餌絞�嚗���"; @@ -38,6 +41,7 @@ }if(StringUtils.hasText(dto.getPhone())) { sendMsgService.sendMsgBySMS(dto.getPhone(), dto.getMessage()); } + List<AppointmentNoticeLog> noticeLogs = appointmentNoticeLogService.findByAppointmentId(dto.getAppointmentId()); if(noticeLogs.size()==0) { @@ -47,6 +51,7 @@ } appointmentNoticeLogService.create(dto); + personalNotificationService.createSendNoticeToCustomer(dto.getAppointmentId()); } } diff --git a/pamapi/src/main/java/com/pollex/pam/service/PersonalNotificationService.java b/pamapi/src/main/java/com/pollex/pam/service/PersonalNotificationService.java index 5cf50ae..b6426cd 100644 --- a/pamapi/src/main/java/com/pollex/pam/service/PersonalNotificationService.java +++ b/pamapi/src/main/java/com/pollex/pam/service/PersonalNotificationService.java @@ -6,9 +6,16 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import com.pollex.pam.domain.Appointment; +import com.pollex.pam.domain.Consultant; +import com.pollex.pam.domain.Customer; import com.pollex.pam.domain.PersonalNotification; +import com.pollex.pam.domain.Satisfaction; +import com.pollex.pam.enums.NotificationTypeEnum; import com.pollex.pam.enums.PersonalNotificationRoleEnum; +import com.pollex.pam.repository.CustomerRepository; import com.pollex.pam.repository.PersonalNotificationRepository; +import com.pollex.pam.service.dto.AppointmentUpdateDTO; @Service @Transactional @@ -16,9 +23,100 @@ @Autowired PersonalNotificationRepository personalNotificationRepository; + + @Autowired + ConsultantService consultantService; + + @Autowired + AppointmentService appointmentService; + + @Autowired + CustomerService customerService; + + @Autowired + CustomerRepository customerRepository; + + @Autowired + SatisfactionService satisfactionService; public List<PersonalNotification> getMyPersonalNotification(Long ownerId, PersonalNotificationRoleEnum role) { return personalNotificationRepository.findAllByOwnerRoleAndOwnerId(role, ownerId); } + public void createSendSatisfactionToClientToCustomer(Appointment appointment) { + PersonalNotification entity = new PersonalNotification(); + Consultant consultant = consultantService.findByAgentNo(appointment.getAgentNo()); + String content = consultant.getName()+"憿批��憛怠神皛踵�漲閰��"; + entity.setContent(content); + entity.setNotificationType(NotificationTypeEnum.ACTIVITY); + entity.setOwnerId(appointment.getCustomerId()); + entity.setOwnerRole(PersonalNotificationRoleEnum.CUSTOMER); + entity.setTitle("憛怠神皛踵�漲"); + personalNotificationRepository.save(entity); + } + + public void createSendNoticeToCustomer(Long appointmentId) { + Appointment appointment = appointmentService.findById(appointmentId); + PersonalNotification entity = new PersonalNotification(); + Consultant consultant = consultantService.findByAgentNo(appointment.getAgentNo()); + String content = "���� "+consultant.getName()+"憿批���赤�"; + entity.setContent(content); + entity.setNotificationType(NotificationTypeEnum.ACTIVITY); + entity.setOwnerId(appointment.getCustomerId()); + entity.setOwnerRole(PersonalNotificationRoleEnum.CUSTOMER); + entity.setTitle("憿批��赤�"); + personalNotificationRepository.save(entity); + } + + public void createEditConsultantToConsultant(Consultant consultant) { + PersonalNotification entity = new PersonalNotification(); + String content = "����犖撣唾�身摰歇�脰��"; + entity.setContent(content); + entity.setNotificationType(NotificationTypeEnum.ACTIVITY); + entity.setOwnerId(consultant.getId()); + entity.setOwnerRole(PersonalNotificationRoleEnum.CONSULTANT); + entity.setTitle("霈撣唾����"); + personalNotificationRepository.save(entity); + } + + public void createMarkAppointmentDeletedToConsultant(Appointment appointment) { + PersonalNotification entity = new PersonalNotification(); + Customer customer = customerRepository.findById(appointment.getCustomerId()).get(); + Consultant consultant = consultantService.findByAgentNo(appointment.getAgentNo()); + String content = customer.getName()+"摰X撌脣�������"; + entity.setContent(content); + entity.setNotificationType(NotificationTypeEnum.ACTIVITY); + entity.setOwnerId(consultant.getId()); + entity.setOwnerRole(PersonalNotificationRoleEnum.CONSULTANT); + entity.setTitle("��������"); + personalNotificationRepository.save(entity); + } + + public void createUpdateAppointmentToConsultant(Appointment appointment) { + PersonalNotification entity = new PersonalNotification(); + Customer customer = customerRepository.findById(appointment.getCustomerId()).get(); + Consultant consultant = consultantService.findByAgentNo(appointment.getAgentNo()); + String content = customer.getName()+"摰X撌脫���������"; + entity.setContent(content); + entity.setNotificationType(NotificationTypeEnum.ACTIVITY); + entity.setOwnerId(consultant.getId()); + entity.setOwnerRole(PersonalNotificationRoleEnum.CONSULTANT); + entity.setTitle("��������"); + personalNotificationRepository.save(entity); + } + + public void createScorefactionToConsultant(Satisfaction satisfaction) { + PersonalNotification entity = new PersonalNotification(); + Appointment appointment = appointmentService.findById(satisfaction.getAppointmentId()); + Customer customer = customerRepository.findById(appointment.getCustomerId()).get(); + Consultant consultant = consultantService.findByAgentNo(appointment.getAgentNo()); + String content = customer.getName()+"摰X撌脣��脰�遛��漲閰��"; + entity.setContent(content); + entity.setNotificationType(NotificationTypeEnum.ACTIVITY); + entity.setOwnerId(consultant.getId()); + entity.setOwnerRole(PersonalNotificationRoleEnum.CONSULTANT); + entity.setTitle("摰X皛踵�漲"); + personalNotificationRepository.save(entity); + } + } diff --git a/pamapi/src/main/java/com/pollex/pam/service/SatisfactionService.java b/pamapi/src/main/java/com/pollex/pam/service/SatisfactionService.java index 9f59e61..569844e 100644 --- a/pamapi/src/main/java/com/pollex/pam/service/SatisfactionService.java +++ b/pamapi/src/main/java/com/pollex/pam/service/SatisfactionService.java @@ -46,6 +46,9 @@ @Autowired ConsultantService consultantService; + + @Autowired + PersonalNotificationService personalNotificationService; public Satisfaction save(Satisfaction satisfaction) { satisfaction = satisfactionRepository.save(satisfaction); @@ -58,7 +61,9 @@ Satisfaction satisfaction = satisfactionOP.orElseThrow(SatisfactionNotFoundException::new); satisfaction.setScore(scoreDTO.getScore()); satisfaction.setStatus(SatisfactionStatusEnum.FILLED); - return save(satisfaction); + save(satisfaction); + personalNotificationService.createScorefactionToConsultant(satisfaction); + return satisfaction; } public Satisfaction createSatisfaction(Appointment appointment) { diff --git a/pamapi/src/main/java/com/pollex/pam/web/rest/AppointmentResource.java b/pamapi/src/main/java/com/pollex/pam/web/rest/AppointmentResource.java index a2f280e..ca378b3 100644 --- a/pamapi/src/main/java/com/pollex/pam/web/rest/AppointmentResource.java +++ b/pamapi/src/main/java/com/pollex/pam/web/rest/AppointmentResource.java @@ -15,6 +15,7 @@ import org.springframework.web.bind.annotation.*; import com.pollex.pam.service.AppointmentService; +import com.pollex.pam.service.PersonalNotificationService; import com.pollex.pam.service.SatisfactionService; import com.pollex.pam.service.dto.AppointmentCloseDTO; import com.pollex.pam.service.dto.AppointmentCreateDTO; @@ -35,10 +36,14 @@ @Autowired AppointmentProcess abstractAppointmentProcess; + + @Autowired + PersonalNotificationService personalNotificationService; @PutMapping("") - public ResponseEntity<Void> updateAppointment(@RequestBody AppointmentUpdateDTO appointment) { - appointmentService.updateAppointment(appointment); + public ResponseEntity<Void> updateAppointment(@RequestBody AppointmentUpdateDTO dto) { + Appointment appointment = appointmentService.updateAppointment(dto); + personalNotificationService.createUpdateAppointmentToConsultant(appointment); return ResponseEntity.noContent().build(); } -- Gitblit v1.8.0