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
6fb95cc5
Commit
6fb95cc5
authored
Jul 03, 2025
by
wujipeng
Browse files
增加月初运维
parent
c2a85dbc
Changes
5
Show whitespace changes
Inline
Side-by-side
src/main/java/com/ruzhoukj/sms/entity/SmsInformEntity.java
View file @
6fb95cc5
package
com.ruzhoukj.sms.entity
;
import
com.baomidou.mybatisplus.annotation.IdType
;
import
com.baomidou.mybatisplus.annotation.TableField
;
import
com.baomidou.mybatisplus.annotation.TableId
;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
com.fasterxml.jackson.annotation.JsonFormat
;
...
...
@@ -32,4 +33,6 @@ public class SmsInformEntity {
private
Date
date
;
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
,
timezone
=
"GMT+8"
)
private
Date
createTime
;
@TableField
(
value
=
"is_delete"
)
private
Integer
isDelete
;
}
src/main/java/com/ruzhoukj/sms/task/DingTask.java
View file @
6fb95cc5
...
...
@@ -21,7 +21,6 @@ import org.springframework.scheduling.annotation.Scheduled;
import
org.springframework.stereotype.Component
;
import
javax.annotation.Resource
;
import
java.math.BigDecimal
;
import
java.time.LocalDate
;
import
java.time.LocalDateTime
;
import
java.time.ZoneId
;
...
...
src/main/java/com/ruzhoukj/sms/task/InTheEarlyTask.java
0 → 100644
View file @
6fb95cc5
package
com.ruzhoukj.sms.task
;
import
cn.hutool.core.bean.BeanUtil
;
import
com.ruzhoukj.sms.entity.EmailRecordEntity
;
import
com.ruzhoukj.sms.entity.ScheduleEntity
;
import
com.ruzhoukj.sms.entity.SmsInformEntity
;
import
com.ruzhoukj.sms.service.EmailRecordService
;
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
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.Resource
;
import
java.util.Date
;
/**
* @author : wujipeng
* @date : 2025/7/3 15:55
* @Version: 1.0
* @Desc : 月初运维通知
*/
@Component
@Slf4j
public
class
InTheEarlyTask
{
@Resource
private
ScheduleService
scheduleService
;
@Resource
private
EmailRecordService
emailRecordService
;
@Resource
private
SmsInformService
smsInformService
;
//邮箱通知
// @Scheduled(cron = "0/10 * * * * ?")
@Scheduled
(
cron
=
"0 0 9 1 * ?"
)
public
void
inTheEarlyEmail
()
{
Date
[]
dates
=
DateUtils
.
getStartAndEndDateOfCurrentMonth
();
//查询本月维护人的信息
ScheduleEntity
scheduleEntity
=
scheduleService
.
getUser
(
dates
[
0
],
dates
[
1
]);
if
(
BeanUtil
.
isNotEmpty
(
scheduleEntity
))
{
//发送邮件
EmailUtil
.
sendInTheEarlyEmail
(
scheduleEntity
.
getName
(),
scheduleEntity
.
getEmail
());
//保存历史记录
emailRecordService
.
save
(
EmailRecordEntity
.
builder
()
.
name
(
scheduleEntity
.
getName
())
.
email
(
scheduleEntity
.
getEmail
())
.
info
(
"月初通知"
)
.
createTime
(
new
Date
())
.
build
());
//保存短信信息
smsInformService
.
save
(
SmsInformEntity
.
builder
()
.
date
(
new
Date
())
.
name
(
scheduleEntity
.
getName
())
.
num
(
0
)
.
phone
(
scheduleEntity
.
getPhone
())
.
serviceName
(
"月初通知"
)
.
build
());
}
}
}
src/main/java/com/ruzhoukj/sms/task/SmsTask.java
View file @
6fb95cc5
...
...
@@ -27,12 +27,14 @@ public class SmsTask {
/**
* 每十五分钟执行一次
*/
@Scheduled
(
cron
=
"0 */15 * * * ?"
)
//
@Scheduled(fixedRate = 10000)
//
@Scheduled(cron = "0 */15 * * * ?")
@Scheduled
(
fixedRate
=
10000
)
public
void
projectRemind
()
{
//查询最新的一条数据
SmsInformEntity
smsInformEntity
=
smsInformService
.
getOne
(
new
LambdaQueryWrapper
<
SmsInformEntity
>().
orderByAsc
(
SmsInformEntity:
:
getCreateTime
),
false
);
.
getOne
(
new
LambdaQueryWrapper
<
SmsInformEntity
>()
.
eq
(
SmsInformEntity:
:
getIsDelete
,
0
)
.
orderByAsc
(
SmsInformEntity:
:
getCreateTime
),
false
);
if
(
BeanUtil
.
isNotEmpty
(
smsInformEntity
))
{
Map
<
String
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
"name"
,
smsInformEntity
.
getName
());
...
...
@@ -42,7 +44,8 @@ public class SmsTask {
if
(
smsInformEntity
.
getNum
()
>
0
){
SmsUtil
.
sendMsg
(
smsInformEntity
.
getPhone
(),
"SMS_472285139"
,
map
);
}
smsInformService
.
removeById
(
smsInformEntity
.
getId
());
smsInformEntity
.
setIsDelete
(
1
);
smsInformService
.
updateById
(
smsInformEntity
);
}
}
}
src/main/java/com/ruzhoukj/sms/util/EmailUtil.java
View file @
6fb95cc5
...
...
@@ -165,12 +165,9 @@ public class EmailUtil {
stringJoiner
.
add
(
"备注:"
+
projectEntity
.
getDescribe
());
stringJoiner
.
add
(
"请您及时进行处理,以确保服务的连续性。"
);
stringJoiner
.
add
(
"From:研发部"
);
message
.
setText
(
stringJoiner
.
toString
());
Transport
.
send
(
message
);
log
.
info
(
"Email sent successfully"
);
}
catch
(
MessagingException
e
)
{
...
...
@@ -201,12 +198,10 @@ public class EmailUtil {
Message
message
=
new
MimeMessage
(
session
);
message
.
setSubject
(
"项目到期提醒"
);
message
.
setFrom
(
new
InternetAddress
(
username
));
// 添加多个收件人
String
[]
toAddresses
=
{
email
};
message
.
setRecipients
(
Message
.
RecipientType
.
TO
,
InternetAddress
.
parse
(
String
.
join
(
", "
,
toAddresses
)));
StringJoiner
stringJoiner
=
new
StringJoiner
(
"\n"
);
stringJoiner
.
add
(
"尊敬的"
+
name
+
","
);
stringJoiner
.
add
(
"您和"
+
contractVO
.
getClient
()
+
"签订的:"
+
contractVO
.
getCode
()
+
"合同即将到期。"
);
...
...
@@ -215,14 +210,50 @@ public class EmailUtil {
stringJoiner
.
add
(
"距今还有:"
+
(
int
)
DateUtils
.
daysBetween
(
new
Date
(),
contractVO
.
getEndTime
())
+
"天"
);
stringJoiner
.
add
(
"请您及时进行处理,以确保合同的连续性。"
);
stringJoiner
.
add
(
"From:研发部"
);
message
.
setText
(
stringJoiner
.
toString
());
Transport
.
send
(
message
);
log
.
info
(
"Email sent successfully"
);
}
catch
(
MessagingException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
public
static
void
sendInTheEarlyEmail
(
String
name
,
String
email
)
{
final
String
username
=
"2404263178@qq.com"
;
final
String
password
=
"eryzvsveckiudiee"
;
log
.
info
(
"Email sent successfully"
);
// QQ Mail SMTP server information
Properties
props
=
new
Properties
();
props
.
put
(
"mail.smtp.auth"
,
"true"
);
props
.
put
(
"mail.smtp.starttls.enable"
,
"true"
);
props
.
put
(
"mail.smtp.host"
,
"smtp.qq.com"
);
props
.
put
(
"mail.smtp.port"
,
"587"
);
Session
session
=
Session
.
getInstance
(
props
,
new
javax
.
mail
.
Authenticator
()
{
@Override
protected
javax
.
mail
.
PasswordAuthentication
getPasswordAuthentication
()
{
return
new
javax
.
mail
.
PasswordAuthentication
(
username
,
password
);
}
});
try
{
Message
message
=
new
MimeMessage
(
session
);
message
.
setSubject
(
"项目到期提醒"
);
message
.
setFrom
(
new
InternetAddress
(
username
));
// 添加多个收件人
String
[]
toAddresses
=
{
email
};
message
.
setRecipients
(
Message
.
RecipientType
.
TO
,
InternetAddress
.
parse
(
String
.
join
(
", "
,
toAddresses
)));
StringJoiner
stringJoiner
=
new
StringJoiner
(
"\n"
);
stringJoiner
.
add
(
"尊敬的"
+
name
+
","
);
stringJoiner
.
add
(
"本月由你负责公司的项目运维"
);
stringJoiner
.
add
(
"请检查是否有运维工作待完成"
);
stringJoiner
.
add
(
"From:研发部"
);
message
.
setText
(
stringJoiner
.
toString
());
Transport
.
send
(
message
);
log
.
info
(
"Email sent successfully"
);
}
catch
(
MessagingException
e
)
{
throw
new
RuntimeException
(
e
);
}
...
...
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