修复SonarQube:Logger格式化、System.out替换、删除注释代码

main
SLMS Development Team 5 months ago
parent 6ce1e3fefc
commit f12b0b31d0

@ -4,6 +4,7 @@ import com.smartlibrary.observer.BookStatusObserver;
import com.smartlibrary.observer.BookEventType;
import com.smartlibrary.model.Book;
import com.smartlibrary.model.Loan;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Pattern;
@ -29,20 +30,20 @@ public class SMSNotification implements Notification, BookStatusObserver {
@Override
public boolean sendNotification(String recipient, String subject, String message) {
if (!validateRecipient(recipient)) {
LOGGER.warning("无效的手机号码: " + recipient);
LOGGER.log(Level.WARNING, "无效的手机号码: {0}", recipient);
return false;
}
try {
// 模拟发送短信
LOGGER.info("正在发送短信...");
LOGGER.info("服务提供商: " + serviceProvider);
LOGGER.info("收件人: " + recipient);
LOGGER.info("内容: " + message);
LOGGER.log(Level.INFO, "服务提供商: {0}", serviceProvider);
LOGGER.log(Level.INFO, "收件人: {0}", recipient);
LOGGER.log(Level.INFO, "内容: {0}", message);
LOGGER.info("短信发送成功!");
return true;
} catch (Exception e) {
LOGGER.severe("短信发送失败: " + e.getMessage());
LOGGER.log(Level.SEVERE, "短信发送失败: {0}", e.getMessage());
return false;
}
}

@ -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);
}
}
Loading…
Cancel
Save