| | |
| | | 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.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 |
| | |
| | | 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); |
| | | }); |
| | | } |
| | | } |