Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jiedao-api-boot-master
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lanbaoming
jiedao-api-boot-master
Commits
babf89dc
Commit
babf89dc
authored
Nov 21, 2024
by
honghy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
短信接收 Job
parent
9452b7e6
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
55 additions
and
15 deletions
+55
-15
SmsLogMapper.java
...coder/yudao/module/system/dal/mysql/sms/SmsLogMapper.java
+2
-2
SmsReceiveJob.java
...cn/iocoder/yudao/module/system/job/sms/SmsReceiveJob.java
+32
-0
SmsLogService.java
...ocoder/yudao/module/system/service/sms/SmsLogService.java
+1
-1
SmsLogServiceImpl.java
...er/yudao/module/system/service/sms/SmsLogServiceImpl.java
+2
-2
SmsNodeService.java
...coder/yudao/module/system/service/sms/SmsNodeService.java
+5
-0
SmsNodeServiceImpl.java
...r/yudao/module/system/service/sms/SmsNodeServiceImpl.java
+13
-10
No files found.
yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/sms/SmsLogMapper.java
View file @
babf89dc
...
@@ -48,9 +48,9 @@ public interface SmsLogMapper extends BaseMapperX<SmsLogDO> {
...
@@ -48,9 +48,9 @@ public interface SmsLogMapper extends BaseMapperX<SmsLogDO> {
"DELETE FROM system_sms_log WHERE date(create_time) <= date(date_sub(now(), interval 90 day))"
"DELETE FROM system_sms_log WHERE date(create_time) <= date(date_sub(now(), interval 90 day))"
})
})
int
clearLog
(
Integer
day
);
int
clearLog
(
Integer
day
);
default
List
<
SmsLogDO
>
selectReceiveList
()
{
default
List
<
SmsLogDO
>
selectReceiveList
(
Integer
time
)
{
return
selectList
(
new
QueryWrapperX
<
SmsLogDO
>()
return
selectList
(
new
QueryWrapperX
<
SmsLogDO
>()
.
apply
(
"create_time >= NOW() - INTERVAL 20 HOUR"
)
.
apply
(
String
.
format
(
"create_time >= NOW() - INTERVAL %d HOUR"
,
time
)
)
.
eq
(
"template_type"
,
2
)
.
eq
(
"template_type"
,
2
)
.
lt
(
"num"
,
1
)
.
lt
(
"num"
,
1
)
.
ne
(
"receive_status"
,
10
));
.
ne
(
"receive_status"
,
10
));
...
...
yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/job/sms/SmsReceiveJob.java
0 → 100644
View file @
babf89dc
package
cn
.
iocoder
.
yudao
.
module
.
system
.
job
.
sms
;
import
cn.iocoder.yudao.framework.quartz.core.handler.JobHandler
;
import
cn.iocoder.yudao.module.system.service.sms.SmsNodeService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
/**
* 短信接收 Job
*
* @author Jayden
* @date 2024/11/21
*/
@Component
@Slf4j
public
class
SmsReceiveJob
implements
JobHandler
{
@Autowired
private
SmsNodeService
smsNodeService
;
@Override
public
String
execute
(
String
time
)
{
if
(
StringUtils
.
isBlank
(
time
))
{
log
.
error
(
"短信接收参数错误:{},此参数不能为空"
,
time
);
return
"短信接收参数错误,此参数不能为空"
;
}
smsNodeService
.
scheduleReceiveRefresh
(
Integer
.
valueOf
(
time
));
return
"短信接收 Job 执行成功"
;
}
}
yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsLogService.java
View file @
babf89dc
...
@@ -112,7 +112,7 @@ public interface SmsLogService {
...
@@ -112,7 +112,7 @@ public interface SmsLogService {
void
updateBatchSmsLog
(
List
<
SmsLogDO
>
resendSmsLogList
);
void
updateBatchSmsLog
(
List
<
SmsLogDO
>
resendSmsLogList
);
List
<
SmsLogDO
>
selectReceiveList
();
List
<
SmsLogDO
>
selectReceiveList
(
Integer
time
);
/**
/**
* 更新sendchamp回调状态
* 更新sendchamp回调状态
...
...
yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsLogServiceImpl.java
View file @
babf89dc
...
@@ -155,8 +155,8 @@ public class SmsLogServiceImpl implements SmsLogService {
...
@@ -155,8 +155,8 @@ public class SmsLogServiceImpl implements SmsLogService {
}
}
@Override
@Override
public
List
<
SmsLogDO
>
selectReceiveList
()
{
public
List
<
SmsLogDO
>
selectReceiveList
(
Integer
time
)
{
return
smsLogMapper
.
selectReceiveList
();
return
smsLogMapper
.
selectReceiveList
(
time
);
}
}
@Override
@Override
...
...
yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsNodeService.java
View file @
babf89dc
...
@@ -81,4 +81,9 @@ public interface SmsNodeService extends IService<SmsNodeDO> {
...
@@ -81,4 +81,9 @@ public interface SmsNodeService extends IService<SmsNodeDO> {
* @return 缓存键
* @return 缓存键
*/
*/
String
buildCacheKey
(
SmsNodeDO
smsNodeDO
);
String
buildCacheKey
(
SmsNodeDO
smsNodeDO
);
/**
* 短信重发定时任务
*/
public
void
scheduleReceiveRefresh
(
Integer
time
);
}
}
yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsNodeServiceImpl.java
View file @
babf89dc
...
@@ -18,7 +18,6 @@ import cn.iocoder.yudao.module.system.dal.mysql.sms.SmsNodeMapper;
...
@@ -18,7 +18,6 @@ import cn.iocoder.yudao.module.system.dal.mysql.sms.SmsNodeMapper;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.validation.annotation.Validated
;
...
@@ -112,14 +111,12 @@ public class SmsNodeServiceImpl extends AbstractService<SmsNodeMapper, SmsNodeDO
...
@@ -112,14 +111,12 @@ public class SmsNodeServiceImpl extends AbstractService<SmsNodeMapper, SmsNodeDO
}
}
/**
/**
* 每半小时执行一次
* 短信重发定时任务
* 短信重发定时任务
*/
*/
@Scheduled
(
cron
=
"0 0/30 * * * ?"
)
public
void
scheduleReceiveRefresh
(
Integer
time
)
{
public
void
scheduleReceiveRefresh
()
{
try
{
try
{
// 获取需要重发短信的日志列表
// 获取需要重发短信的日志列表
List
<
SmsLogDO
>
smsLogs
=
smsLogService
.
selectReceiveList
();
List
<
SmsLogDO
>
smsLogs
=
smsLogService
.
selectReceiveList
(
time
);
if
(
smsLogs
!=
null
)
{
if
(
smsLogs
!=
null
)
{
for
(
SmsLogDO
smsLog
:
smsLogs
)
{
for
(
SmsLogDO
smsLog
:
smsLogs
)
{
try
{
try
{
...
@@ -144,12 +141,18 @@ public class SmsNodeServiceImpl extends AbstractService<SmsNodeMapper, SmsNodeDO
...
@@ -144,12 +141,18 @@ public class SmsNodeServiceImpl extends AbstractService<SmsNodeMapper, SmsNodeDO
private
void
processSmsLog
(
SmsLogDO
smsLog
)
{
private
void
processSmsLog
(
SmsLogDO
smsLog
)
{
// 根据渠道ID获取短信客户端
// 根据渠道ID获取短信客户端
SmsClient
smsClient
=
smsClientFactory
.
getSmsClient
(
smsLog
.
getChannelId
());
SmsClient
smsClient
=
smsClientFactory
.
getSmsClient
(
smsLog
.
getChannelId
());
try
{
// 获取短信接收状态
// 获取短信接收状态
SmsLogDTO
receiveStatus
=
smsClient
.
getReceiveStatus
(
SmsLogConvert
.
INSTANCE
.
toDto
(
smsLog
));
SmsLogDTO
receiveStatus
=
smsClient
.
getReceiveStatus
(
SmsLogConvert
.
INSTANCE
.
toDto
(
smsLog
));
smsLog
.
setReceiveStatus
(
receiveStatus
.
getReceiveStatus
());
smsLog
.
setReceiveStatus
(
receiveStatus
.
getReceiveStatus
());
}
catch
(
Exception
e
)
{
smsLog
.
setReceiveStatus
(
ReceiveStatusEnum
.
Receive_STATUS_20
.
getValue
());
log
.
error
(
"获取短信接收状态失败: {}"
,
smsLog
,
e
);
}
// 接收失败,则重发
// 接收失败,则重发
if
(
ReceiveStatusEnum
.
Receive_STATUS_20
.
getValue
()
==
receiveStatus
.
getReceiveStatus
())
{
if
(
ReceiveStatusEnum
.
Receive_STATUS_20
.
getValue
()
==
smsLog
.
getReceiveStatus
())
{
smsLog
.
setReceiveTime
(
receiveStatus
.
getReceiveTime
());
smsLog
.
setReceiveTime
(
smsLog
.
getReceiveTime
());
smsLog
.
setNum
(
1
);
smsLog
.
setNum
(
1
);
// 从Redis中获取短信节点信息
// 从Redis中获取短信节点信息
String
node
=
redisHelper
.
get
(
SYSTEM_SMS_NODE_KEY
+
smsLog
.
getNodeId
());
String
node
=
redisHelper
.
get
(
SYSTEM_SMS_NODE_KEY
+
smsLog
.
getNodeId
());
...
...
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