fix(notice): 修复商户回调和通知的延迟逻辑

- 在 MerchantCallbackSendService 和 MerchantNotifySendService 中修改了延迟次数的初始值和计算方式
- 修复了可能导致无限延迟的问题
This commit is contained in:
DaxPay
2024-11-20 15:54:12 +08:00
parent a10ae1d1c0
commit 42d6b6a447
2 changed files with 8 additions and 5 deletions

View File

@@ -73,6 +73,7 @@ public class MerchantCallbackSendService {
// 如果响应值等于SUCCESS, 说明发送成功, 进行成功处理
if (StrUtil.equalsIgnoreCase(body, "SUCCESS")){
task.setSendCount(task.getSendCount() + 1)
.setDelayCount(0)
.setLatestTime(sendTime)
.setSuccess(true);
record.setSuccess(true);
@@ -103,7 +104,7 @@ public class MerchantCallbackSendService {
if (Objects.isNull(task)){
return;
}
// 次数+1
// 发送次数+1
task.setSendCount(task.getSendCount() + 1).setLatestTime(sendTime);
// 任务完成了也不进行处理
if (task.isSuccess()){
@@ -111,14 +112,14 @@ public class MerchantCallbackSendService {
}
// 如果延迟次数为空, 先设置为-1
if (autoSend && Objects.isNull(task.getDelayCount())){
task.setDelayCount(-1);
task.setDelayCount(0);
}
// 判断延迟次数是否未超过15次, 注册任务到redis中
if (autoSend && task.getDelayCount() < 16){
// 添加延迟次数
task.setDelayCount(task.getDelayCount() + 1);
// 下次偏移毫秒数
int delay = merchantNoticeAssistService.getDelayTime(task.getDelayCount()+1);
int delay = merchantNoticeAssistService.getDelayTime(task.getDelayCount());
// 根据当前延迟次数和计算出下次执行时间
task.setNextTime(sendTime.plusSeconds(delay/1000L));
// 注册延时任务

View File

@@ -47,6 +47,7 @@ public class MerchantNotifySendService {
private final PaymentAssistService paymentAssistService;
private final DelayJobService delayJobService;
private final MerchantNotifyConfigService notifyConfigService;
@@ -82,6 +83,7 @@ public class MerchantNotifySendService {
if (StrUtil.equalsIgnoreCase(body, "SUCCESS")){
record.setSuccess(true);
task.setSendCount(task.getSendCount() + 1)
.setDelayCount(0)
.setLatestTime(sendTime)
.setSuccess(true);
// 如果为自动发送且延迟次数, 延迟次数也+1
@@ -119,14 +121,14 @@ public class MerchantNotifySendService {
}
// 如果延迟次数为空, 先设置为-1
if (autoSend && Objects.isNull(task.getDelayCount())){
task.setDelayCount(-1);
task.setDelayCount(0);
}
// 判断延迟次数是否未超过15次, 注册任务到redis中
if (autoSend && task.getDelayCount() < 16){
// 添加延迟次数
task.setDelayCount(task.getDelayCount() + 1);
// 下次偏移毫秒数
int delay = merchantNoticeAssistService.getDelayTime(task.getDelayCount()+1);
int delay = merchantNoticeAssistService.getDelayTime(task.getDelayCount());
// 根据当前延迟次数和计算出下次执行时间
task.setNextTime(sendTime.plusSeconds(delay/1000));
// 注册延时任务