From 2f0e71d3d73b71cba5a0caebfdb9ba79722989c0 Mon Sep 17 00:00:00 2001
From: wayne <wayne8692wayne8692@gmail.com>
Date: 星期四, 27 一月 2022 14:54:38 +0800
Subject: [PATCH] [update] [todo 134826, 134662] 調整顧問資料格式、棄用搜尋並改將其功能改到前端算匹配度

---
 pamapi/src/main/java/com/pollex/pam/service/PersonalNotificationService.java |   25 +++++++++++++++++++++++++
 1 files changed, 25 insertions(+), 0 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 cad80e9..5a4d09a 100644
--- a/pamapi/src/main/java/com/pollex/pam/service/PersonalNotificationService.java
+++ b/pamapi/src/main/java/com/pollex/pam/service/PersonalNotificationService.java
@@ -1,10 +1,14 @@
 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;
@@ -15,6 +19,7 @@
 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
@@ -131,4 +136,24 @@
 		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