opt:任务完成取消与ACS确认是否可行
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
package cn.code.nl.framework.common.pojo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 基础DTO对象
|
||||
* @Author: liyongde
|
||||
* @Date: 2026/7/24 8:49
|
||||
*/
|
||||
@Data
|
||||
public class AcsBaseReqDTO {
|
||||
/**
|
||||
* 请求号: traceId
|
||||
*/
|
||||
private String traceId;
|
||||
|
||||
/**
|
||||
*
|
||||
* 时间
|
||||
*/
|
||||
private Long timestamp;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package cn.code.nl.framework.common.pojo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* acs返回基础对象
|
||||
* @Author: liyongde
|
||||
* @Date: 2026/7/24 10:27
|
||||
*/
|
||||
@Data
|
||||
public class AcsBaseRespDTO {
|
||||
/**
|
||||
* 是否整体成功
|
||||
*/
|
||||
private Boolean success;
|
||||
|
||||
/**
|
||||
* 响应编码
|
||||
*/
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 响应消息
|
||||
*/
|
||||
private String msg;
|
||||
}
|
||||
@@ -1,8 +1,15 @@
|
||||
package cn.code.nl.framework.common.util.http;
|
||||
|
||||
import cn.code.nl.framework.common.exception.ServerException;
|
||||
import cn.code.nl.framework.common.exception.ServiceException;
|
||||
import cn.code.nl.framework.common.util.json.JsonUtils;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
||||
import java.net.ConnectException;
|
||||
import java.net.NoRouteToHostException;
|
||||
import java.net.SocketException;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -22,7 +29,15 @@ public class AcsUtil {
|
||||
*/
|
||||
public static <T> T post(String serverAddress, String api, Object request, Class<T> responseType) {
|
||||
String url = buildUrl(serverAddress, api);
|
||||
String response = HttpUtils.post(url, headers(), JsonUtils.toJsonString(request));
|
||||
String response;
|
||||
try {
|
||||
response = HttpUtils.post(url, headers(), JsonUtils.toJsonString(request));
|
||||
} catch (RuntimeException ex) {
|
||||
if (isNetworkException(ex)) {
|
||||
throw new ServerException(500, "ACS服务网络不通");
|
||||
}
|
||||
throw ex;
|
||||
}
|
||||
return JsonUtils.parseObject(response, responseType);
|
||||
}
|
||||
|
||||
@@ -42,4 +57,22 @@ public class AcsUtil {
|
||||
return Collections.singletonMap("Content-Type", "application/json;charset=UTF-8");
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为 ACS 网络连接异常
|
||||
*/
|
||||
private static boolean isNetworkException(Throwable ex) {
|
||||
Throwable cause = ex;
|
||||
while (cause != null) {
|
||||
if (cause instanceof ConnectException
|
||||
|| cause instanceof SocketTimeoutException
|
||||
|| cause instanceof UnknownHostException
|
||||
|| cause instanceof NoRouteToHostException
|
||||
|| cause instanceof SocketException) {
|
||||
return true;
|
||||
}
|
||||
cause = cause.getCause();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user