Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
邬吉朋
ops
Commits
e38063fa
Commit
e38063fa
authored
Sep 03, 2024
by
wujipeng
Browse files
运维提醒添加短信
parent
c40771c1
Changes
3
Show whitespace changes
Inline
Side-by-side
src/main/java/com/ruzhoukj/sms/entity/ScheduleEntity.java
View file @
e38063fa
...
...
@@ -23,4 +23,5 @@ public class ScheduleEntity {
private
String
email
;
@JsonFormat
(
pattern
=
"yyyy-MM-dd"
,
timezone
=
"GMT+8"
)
private
Date
time
;
private
String
phone
;
}
src/main/java/com/ruzhoukj/sms/task/OpsTask.java
View file @
e38063fa
...
...
@@ -3,8 +3,10 @@ package com.ruzhoukj.sms.task;
import
cn.hutool.core.bean.BeanUtil
;
import
com.ruzhoukj.sms.entity.SSLEntity
;
import
com.ruzhoukj.sms.entity.ScheduleEntity
;
import
com.ruzhoukj.sms.entity.SmsInformEntity
;
import
com.ruzhoukj.sms.service.SSLService
;
import
com.ruzhoukj.sms.service.ScheduleService
;
import
com.ruzhoukj.sms.service.SmsInformService
;
import
com.ruzhoukj.sms.util.DateUtils
;
import
com.ruzhoukj.sms.util.EmailUtil
;
import
lombok.extern.slf4j.Slf4j
;
...
...
@@ -28,6 +30,8 @@ public class OpsTask {
private
ScheduleService
scheduleService
;
@Resource
private
SSLService
sslService
;
@Resource
private
SmsInformService
smsInformService
;
//每个月一号执行一次,本月要到期的证书
@Scheduled
(
cron
=
"0 10 1 * * ?"
)
...
...
@@ -43,6 +47,17 @@ public class OpsTask {
if
(
BeanUtil
.
isNotEmpty
(
scheduleEntity
))
{
//发送邮件
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 {
if
(
BeanUtil
.
isNotEmpty
(
scheduleEntity
))
{
//发送邮件
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
());
}
}
}
}
...
...
src/main/java/com/ruzhoukj/sms/util/DateUtils.java
View file @
e38063fa
...
...
@@ -68,6 +68,20 @@ public class DateUtils {
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
)
{
Date
[]
dates
=
getStartAndEndDateOfCurrentMonth
();
System
.
out
.
println
(
"Start date of this month: "
+
dates
[
0
]);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment