| | |
| | | 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 |
| | |
| | | |
| | | @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()+"客戶已取消您的預約"; |
| | | 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()+"客戶已更新您的預約資訊"; |
| | | 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()+"客戶已對您進行滿意度評比"; |
| | | entity.setContent(content); |
| | | entity.setNotificationType(NotificationTypeEnum.ACTIVITY); |
| | | entity.setOwnerId(consultant.getId()); |
| | | entity.setOwnerRole(PersonalNotificationRoleEnum.CONSULTANT); |
| | | entity.setTitle("客戶滿意度"); |
| | | personalNotificationRepository.save(entity); |
| | | } |
| | | |
| | | } |