|
|
|
|
@ -7,12 +7,16 @@ import com.smartlibrary.notification.InAppNotification;
|
|
|
|
|
import com.smartlibrary.notification.Notification;
|
|
|
|
|
import com.smartlibrary.notification.SMSNotification;
|
|
|
|
|
|
|
|
|
|
import java.util.logging.Logger;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 图书状态通知观察者 - 实现观察者模式
|
|
|
|
|
* 负责在图书状态变更时发送通知
|
|
|
|
|
*/
|
|
|
|
|
@SuppressWarnings("unused") // 预留字段,用于多渠道通知功能扩展
|
|
|
|
|
public class BookNotificationObserver implements BookStatusObserver {
|
|
|
|
|
private static final Logger LOGGER = Logger.getLogger(BookNotificationObserver.class.getName());
|
|
|
|
|
|
|
|
|
|
private Notification emailNotification;
|
|
|
|
|
private Notification smsNotification;
|
|
|
|
|
private Notification inAppNotification;
|
|
|
|
|
@ -45,7 +49,7 @@ public class BookNotificationObserver implements BookStatusObserver {
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
// 其他事件记录日志
|
|
|
|
|
System.out.println("图书事件: " + eventType.getDescription() + " - " + message);
|
|
|
|
|
LOGGER.info("图书事件: " + eventType.getDescription() + " - " + message);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -68,7 +72,7 @@ public class BookNotificationObserver implements BookStatusObserver {
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
// 其他借阅事件记录日志
|
|
|
|
|
System.out.println("借阅事件: " + eventType.getDescription() + " - " + message);
|
|
|
|
|
LOGGER.info("借阅事件: " + eventType.getDescription() + " - " + message);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -109,8 +113,7 @@ public class BookNotificationObserver implements BookStatusObserver {
|
|
|
|
|
* 发送通知给所有用户
|
|
|
|
|
*/
|
|
|
|
|
private void sendNotificationToAllUsers(String subject, String message) {
|
|
|
|
|
// 模拟发送给所有用户
|
|
|
|
|
System.out.println("发送通知给所有用户:");
|
|
|
|
|
LOGGER.info("发送通知给所有用户");
|
|
|
|
|
inAppNotification.sendNotification("all_users", subject, message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -118,8 +121,7 @@ public class BookNotificationObserver implements BookStatusObserver {
|
|
|
|
|
* 发送通知给预约用户
|
|
|
|
|
*/
|
|
|
|
|
private void sendNotificationToReservedUsers(Book book, String subject, String message) {
|
|
|
|
|
// 模拟发送给预约用户
|
|
|
|
|
System.out.println("发送通知给预约用户:");
|
|
|
|
|
LOGGER.info("发送通知给预约用户");
|
|
|
|
|
inAppNotification.sendNotification("reserved_users_" + book.getId(), subject, message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -127,8 +129,7 @@ public class BookNotificationObserver implements BookStatusObserver {
|
|
|
|
|
* 发送通知给管理员
|
|
|
|
|
*/
|
|
|
|
|
private void sendNotificationToAdmin(String subject, String message) {
|
|
|
|
|
// 模拟发送给管理员
|
|
|
|
|
System.out.println("发送通知给管理员:");
|
|
|
|
|
LOGGER.info("发送通知给管理员");
|
|
|
|
|
emailNotification.sendNotification("admin@library.com", subject, message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -136,11 +137,7 @@ public class BookNotificationObserver implements BookStatusObserver {
|
|
|
|
|
* 发送通知给特定用户
|
|
|
|
|
*/
|
|
|
|
|
private void sendNotificationToUser(String userId, String subject, String message) {
|
|
|
|
|
// 模拟发送给特定用户
|
|
|
|
|
System.out.println("发送通知给用户 " + userId + ":");
|
|
|
|
|
LOGGER.info("发送通知给用户: " + userId);
|
|
|
|
|
inAppNotification.sendNotification(userId, subject, message);
|
|
|
|
|
// 也可以同时发送邮件或短信
|
|
|
|
|
// emailNotification.sendNotification(getUserEmail(userId), subject, message);
|
|
|
|
|
// smsNotification.sendNotification(getUserPhone(userId), subject, message);
|
|
|
|
|
}
|
|
|
|
|
}
|