From 925f8b4ffca99f07c629660d42c48f531b4f77a0 Mon Sep 17 00:00:00 2001 From: wayne <wayne8692wayne8692@gmail.com> Date: 星期一, 21 二月 2022 18:17:14 +0800 Subject: [PATCH] [update] 移除login_record欄位,改統一放之後 將新開的稽核欄位"audit_logging",並在顧問欄位加開最後上線時間 --- pamapi/src/main/java/com/pollex/pam/service/PersonalNotificationService.java | 137 +++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 136 insertions(+), 1 deletions(-) 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..3fa7b67 100644 --- a/pamapi/src/main/java/com/pollex/pam/service/PersonalNotificationService.java +++ b/pamapi/src/main/java/com/pollex/pam/service/PersonalNotificationService.java @@ -1,24 +1,159 @@ package com.pollex.pam.service; +import java.time.Instant; import java.util.List; + +import javax.management.Notification; 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.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.security.SecurityUtils; +import com.pollex.pam.service.dto.AppointmentUpdateDTO; @Service @Transactional public class PersonalNotificationService { - + @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 createNotFillAppointmentSatisfactionNumberToCustomer(Long customerId, int notFillSatisfactionSum) { + PersonalNotification entity = new PersonalNotification(); + + String content = "���� "+notFillSatisfactionSum+" 蝑“���遛��漲��閬‵撖�"; + entity.setContent(content); + entity.setNotificationType(NotificationTypeEnum.ACTIVITY); + entity.setOwnerId(customerId); + entity.setOwnerRole(PersonalNotificationRoleEnum.CUSTOMER); + entity.setTitle("摰X皛踵�漲"); + 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); + } + + public void readAllMyNotification() { + if(StringUtils.hasText(SecurityUtils.getAgentNo())) { + Long consultantId = consultantService.findByAgentNo(SecurityUtils.getAgentNo()).getId(); + readAllNotification(PersonalNotificationRoleEnum.CONSULTANT, consultantId); + }else if(SecurityUtils.getCustomerDBId()!=null){ + readAllNotification(PersonalNotificationRoleEnum.CUSTOMER, SecurityUtils.getCustomerDBId()); + } + } + + public void readAllNotification(PersonalNotificationRoleEnum ownerRole + , Long ownerId) { + List<PersonalNotification> allNotification = personalNotificationRepository.findAllByOwnerRoleAndOwnerId(ownerRole, ownerId); + Instant today = Instant.now(); + allNotification.stream() + .filter(notification -> notification.getReadDate()==null) + .forEach(notification ->{ + notification.setReadDate(today); + personalNotificationRepository.saveAll(allNotification); + }); + } } -- Gitblit v1.8.0