#
Junjie
昨天 86e79681da9c98bd08bd1f2be0c6dbd3f3dd3159
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;
    }
    /**