保誠-保戶業務員媒合平台
wayne
2022-01-22 a6b0be5d9e6e21b050d1d46c30aa0200d82ec4d5
pamapi/src/main/java/com/pollex/pam/service/PersonalNotificationService.java
@@ -6,19 +6,129 @@
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
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 createNotFillSatisfactionSumToCustomer(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("客戶滿意度");
        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);
   }
}