From 86e79681da9c98bd08bd1f2be0c6dbd3f3dd3159 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期六, 07 三月 2026 13:47:31 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/asrs/service/NotifyAsyncService.java | 32 ++++++++++++++++++++++----------
1 files changed, 22 insertions(+), 10 deletions(-)
diff --git a/src/main/java/com/zy/asrs/service/NotifyAsyncService.java b/src/main/java/com/zy/asrs/service/NotifyAsyncService.java
index e2ac52c..7bde6e2 100644
--- a/src/main/java/com/zy/asrs/service/NotifyAsyncService.java
+++ b/src/main/java/com/zy/asrs/service/NotifyAsyncService.java
@@ -3,6 +3,7 @@
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.zy.asrs.domain.NotifyDto;
+import com.zy.asrs.domain.NotifySendResult;
import com.zy.asrs.entity.HttpRequestLog;
import com.zy.common.utils.HttpHandler;
import com.zy.common.utils.RedisUtil;
@@ -36,40 +37,51 @@
*/
@Async
public void sendNotifyAsync(String notifyUri, String notifyUriPath, String key, NotifyDto notifyDto) {
+ sendNotifyNow(notifyUri, notifyUriPath, key, notifyDto, true, true);
+ }
+
+ public NotifySendResult sendNotifyNow(String notifyUri, String notifyUriPath, String key, NotifyDto notifyDto,
+ boolean deleteOnSuccess, boolean updateRetryState) {
HttpRequestLog httpRequestLog = new HttpRequestLog();
httpRequestLog.setName(notifyUri + notifyUriPath);
httpRequestLog.setRequest(JSON.toJSONString(notifyDto));
httpRequestLog.setCreateTime(new Date());
- boolean success = false;
+ NotifySendResult result = new NotifySendResult();
+ result.setSuccess(false);
try {
- // 瑙﹀彂閫氱煡
String response = new HttpHandler.Builder()
.setUri(notifyUri)
.setPath(notifyUriPath)
.setJson(JSON.toJSONString(notifyDto))
.build()
.doPost();
+ result.setResponse(response);
httpRequestLog.setResponse(response);
JSONObject jsonObject = JSON.parseObject(response);
- Integer code = jsonObject.getInteger("code");
- if (code == 200) {
- // 閫氱煡鎴愬姛
- redisUtil.del(key);
- success = true;
+ Integer code = jsonObject == null ? null : jsonObject.getInteger("code");
+ if (code != null && code == 200) {
+ if (deleteOnSuccess && key != null) {
+ redisUtil.del(key);
+ }
+ result.setSuccess(true);
+ result.setMessage("閫氱煡鎴愬姛");
+ } else {
+ result.setMessage("閫氱煡鎺ュ彛杩斿洖澶辫触");
}
} catch (Exception e) {
log.error("寮傛閫氱煡澶辫触, key={}", key, e);
+ result.setMessage("閫氱煡寮傚父: " + e.getMessage());
} finally {
- // 淇濆瓨璁板綍
+ httpRequestLog.setResult(result.isSuccess() ? 1 : 0);
httpRequestLogService.insert(httpRequestLog);
}
- if (!success) {
- // 閫氱煡澶辫触锛屾洿鏂伴噸璇曟鏁�
+ if (!result.isSuccess() && updateRetryState && key != null) {
handleNotifyFailure(key, notifyDto);
}
+ return result;
}
/**
--
Gitblit v1.9.1