fix(sms): 调整生日和主题日短信日志级别

- 将调试日志升级为信息日志以提高可见性-优化日志记录逻辑确保关键操作被正确跟踪- 统一异常处理中的日志输出格式
- 改进定时任务执行时的日志记录准确性
-修正线程安全状态检查时的日志描述
- 更新方法注释以符合实际实现逻辑
master
李一帆 2025-09-28 10:16:24 +08:00
parent 0b18a1147e
commit 0f94998144
2 changed files with 17 additions and 19 deletions

View File

@ -180,6 +180,7 @@ public class SmsBirthdayServiceImpl extends ServiceImpl<SmsBirthdayMapper, SmsBi
public void resetFlagBirthdaySentToday() { public void resetFlagBirthdaySentToday() {
specialistMapper.resetFlagBirthdaySentToday(); specialistMapper.resetFlagBirthdaySentToday();
} }
/** /**
* *
* *
@ -190,7 +191,7 @@ public class SmsBirthdayServiceImpl extends ServiceImpl<SmsBirthdayMapper, SmsBi
// 获取生日短信配置 // 获取生日短信配置
SmsBirthday smsBirthday = this.getById(1L); SmsBirthday smsBirthday = this.getById(1L);
if (smsBirthday == null || smsBirthday.getStatus() != 1) { if (smsBirthday == null || smsBirthday.getStatus() != 1) {
log.debug("生日短信功能未启用"); log.info("生日短信功能未启用");
return; return;
} }
@ -203,7 +204,7 @@ public class SmsBirthdayServiceImpl extends ServiceImpl<SmsBirthdayMapper, SmsBi
// 如果已经发送过,不再重复发送 // 如果已经发送过,不再重复发送
if (sending.get()) { if (sending.get()) {
log.debug("其他线程正在执行生日短信发送任务"); log.info("其他线程正在执行生日短信发送任务");
return; return;
} }
@ -224,29 +225,26 @@ public class SmsBirthdayServiceImpl extends ServiceImpl<SmsBirthdayMapper, SmsBi
if (now.isEqual(scheduledTime) || now.isAfter(scheduledTime)) { if (now.isEqual(scheduledTime) || now.isAfter(scheduledTime)) {
// 原子性检查和设置发送状态 // 原子性检查和设置发送状态
if (sending.compareAndSet(false, true)) { if (sending.compareAndSet(false, true)) {
try {
log.info("到达生日短信发送时间: {}, 开始执行发送任务", executionTime); log.info("到达生日短信发送时间: {}, 开始执行发送任务", executionTime);
// 查询今天过生日的专家 // 查询今天过生日的专家
List<SmsSpecialist> birthdaySpecialists = listBirthdayToday(); List<SmsSpecialist> birthdaySpecialists = listBirthdayToday();
if (birthdaySpecialists.isEmpty()) { if (birthdaySpecialists.isEmpty()) {
log.info("今天没有专家过生日,无需发送生日短信"); log.info("今天没有专家过生日,无需发送生日短信");
} else { } else {
log.info("今天有{}位专家过生日,开始发送生日短信", birthdaySpecialists.size()); log.info("今天有{}位专家过生日,开始发送生日短信", birthdaySpecialists.size());
try {
// 发送生日短信 // 发送生日短信
sendBirthdaySms(birthdaySpecialists); sendBirthdaySms(birthdaySpecialists);
log.info("生日短信发送任务完成");
}
} finally { } finally {
sending.set(false); sending.set(false);
} }
log.info("生日短信发送任务完成"); } else {
log.info("其他线程正在执行生日短信发送任务");
} }
} else { } else {
log.debug("其他线程正在执行生日短信发送任务"); log.info("当前时间{}未到执行时间{}", now.format(DateTimeFormatter.ofPattern("HH:mm:ss")), executionTime);
}
} else {
log.debug("当前时间{}未到执行时间{}", now.format(DateTimeFormatter.ofPattern("HH:mm:ss")), executionTime);
} }
} catch (Exception e) { } catch (Exception e) {

View File

@ -273,7 +273,7 @@ public class SmsHolidayServiceImpl extends ServiceImpl<SmsHolidayMapper, SmsHoli
List<SmsHoliday> todayTasks = listTodayTasks(); List<SmsHoliday> todayTasks = listTodayTasks();
if (todayTasks.isEmpty()) { if (todayTasks.isEmpty()) {
log.debug("今日没有需要执行的主题日短信任务"); log.info("今日没有需要执行的主题日短信任务");
return; return;
} }