Commit e38063fa authored by wujipeng's avatar wujipeng
Browse files

运维提醒添加短信

parent c40771c1
...@@ -23,4 +23,5 @@ public class ScheduleEntity { ...@@ -23,4 +23,5 @@ public class ScheduleEntity {
private String email; private String email;
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
private Date time; private Date time;
private String phone;
} }
...@@ -3,8 +3,10 @@ package com.ruzhoukj.sms.task; ...@@ -3,8 +3,10 @@ package com.ruzhoukj.sms.task;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import com.ruzhoukj.sms.entity.SSLEntity; import com.ruzhoukj.sms.entity.SSLEntity;
import com.ruzhoukj.sms.entity.ScheduleEntity; import com.ruzhoukj.sms.entity.ScheduleEntity;
import com.ruzhoukj.sms.entity.SmsInformEntity;
import com.ruzhoukj.sms.service.SSLService; import com.ruzhoukj.sms.service.SSLService;
import com.ruzhoukj.sms.service.ScheduleService; import com.ruzhoukj.sms.service.ScheduleService;
import com.ruzhoukj.sms.service.SmsInformService;
import com.ruzhoukj.sms.util.DateUtils; import com.ruzhoukj.sms.util.DateUtils;
import com.ruzhoukj.sms.util.EmailUtil; import com.ruzhoukj.sms.util.EmailUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -28,6 +30,8 @@ public class OpsTask { ...@@ -28,6 +30,8 @@ public class OpsTask {
private ScheduleService scheduleService; private ScheduleService scheduleService;
@Resource @Resource
private SSLService sslService; private SSLService sslService;
@Resource
private SmsInformService smsInformService;
//每个月一号执行一次,本月要到期的证书 //每个月一号执行一次,本月要到期的证书
@Scheduled(cron = "0 10 1 * * ?") @Scheduled(cron = "0 10 1 * * ?")
...@@ -43,6 +47,17 @@ public class OpsTask { ...@@ -43,6 +47,17 @@ public class OpsTask {
if (BeanUtil.isNotEmpty(scheduleEntity)) { if (BeanUtil.isNotEmpty(scheduleEntity)) {
//发送邮件 //发送邮件
EmailUtil.sendOperationsEmail(scheduleEntity.getName(), scheduleEntity.getEmail(), sslEntities); EmailUtil.sendOperationsEmail(scheduleEntity.getName(), scheduleEntity.getEmail(), sslEntities);
//保存短信信息
for (SSLEntity sslEntity : sslEntities) {
int num = (int) DateUtils.daysBetween(new Date(), DateUtils.convertLocalDateToDate(sslEntity.getTime()));
smsInformService.save(SmsInformEntity.builder()
.date(DateUtils.convertLocalDateToDate(sslEntity.getTime()))
.name(scheduleEntity.getName())
.num(num)
.phone(scheduleEntity.getPhone())
.serviceName(sslEntity.getName())
.build());
}
} }
} }
} }
...@@ -61,6 +76,17 @@ public class OpsTask { ...@@ -61,6 +76,17 @@ public class OpsTask {
if (BeanUtil.isNotEmpty(scheduleEntity)) { if (BeanUtil.isNotEmpty(scheduleEntity)) {
//发送邮件 //发送邮件
EmailUtil.sendOperationsExigencyEmail(scheduleEntity.getName(), scheduleEntity.getEmail(), sslEntities); EmailUtil.sendOperationsExigencyEmail(scheduleEntity.getName(), scheduleEntity.getEmail(), sslEntities);
//保存短信信息
for (SSLEntity sslEntity : sslEntities) {
int num = (int) DateUtils.daysBetween(new Date(), DateUtils.convertLocalDateToDate(sslEntity.getTime()));
smsInformService.save(SmsInformEntity.builder()
.date(DateUtils.convertLocalDateToDate(sslEntity.getTime()))
.name(scheduleEntity.getName())
.num(num)
.phone(scheduleEntity.getPhone())
.serviceName(sslEntity.getName())
.build());
}
} }
} }
} }
......
...@@ -68,6 +68,20 @@ public class DateUtils { ...@@ -68,6 +68,20 @@ public class DateUtils {
return Math.abs(ChronoUnit.DAYS.between(localDate1, localDate2)); return Math.abs(ChronoUnit.DAYS.between(localDate1, localDate2));
} }
/**
* 将 LocalDate 转换为 Date
*
* @param localDate 要转换的 LocalDate 对象
* @return 转换后的 Date 对象
*/
public static Date convertLocalDateToDate(LocalDate localDate) {
if (localDate == null) {
return null; // 处理 null 值
}
return Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
}
public static void main(String[] args) { public static void main(String[] args) {
Date[] dates = getStartAndEndDateOfCurrentMonth(); Date[] dates = getStartAndEndDateOfCurrentMonth();
System.out.println("Start date of this month: " + dates[0]); System.out.println("Start date of this month: " + dates[0]);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment