fix: 是否启用acs连接
This commit is contained in:
@@ -18,6 +18,12 @@
|
||||
<artifactId>nl-common</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.nl.cloud</groupId>
|
||||
<artifactId>nl-module-infra-api</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Spring 核心 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
||||
@@ -2,6 +2,7 @@ package cn.code.nl.framework.execute.config;
|
||||
|
||||
import cn.code.nl.framework.execute.biz.api.lms.LmsTaskCommonApi;
|
||||
import cn.code.nl.framework.execute.biz.api.wms.WmsTaskCommonApi;
|
||||
import cn.code.nl.module.infra.api.config.ConfigApi;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
|
||||
@@ -13,6 +14,6 @@ import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
* @Date: 2026/7/15
|
||||
*/
|
||||
@AutoConfiguration
|
||||
@EnableFeignClients(clients = {LmsTaskCommonApi.class, WmsTaskCommonApi.class})
|
||||
@EnableFeignClients(clients = {LmsTaskCommonApi.class, WmsTaskCommonApi.class, ConfigApi.class})
|
||||
public class NlExecuteRpcAutoConfiguration {
|
||||
}
|
||||
|
||||
@@ -1,26 +1,24 @@
|
||||
package cn.code.nl.framework.common.util.http;
|
||||
package cn.code.nl.framework.execute.util.http;
|
||||
|
||||
import cn.code.nl.framework.common.exception.ServerException;
|
||||
import cn.code.nl.framework.common.exception.ServiceException;
|
||||
import cn.code.nl.framework.common.pojo.AcsBaseRespDTO;
|
||||
import cn.code.nl.framework.common.pojo.CommonResult;
|
||||
import cn.code.nl.framework.common.util.http.HttpUtils;
|
||||
import cn.code.nl.framework.common.util.json.JsonUtils;
|
||||
import cn.code.nl.framework.common.util.spring.SpringUtils;
|
||||
import cn.code.nl.module.infra.api.config.ConfigApi;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.ConnectException;
|
||||
import java.net.NoRouteToHostException;
|
||||
import java.net.SocketException;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.net.*;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* ACS 调用工具
|
||||
*/
|
||||
@Slf4j
|
||||
public class AcsUtil {
|
||||
|
||||
/**
|
||||
@@ -37,9 +35,9 @@ public class AcsUtil {
|
||||
* 发送 POST 请求并解析响应
|
||||
*
|
||||
* @param serverAddress ACS 服务地址
|
||||
* @param api API 路径
|
||||
* @param request 请求参数
|
||||
* @param responseType 响应类型
|
||||
* @param api API 路径
|
||||
* @param request 请求参数
|
||||
* @param responseType 响应类型
|
||||
* @return 响应对象
|
||||
*/
|
||||
public static <T> T post(String serverAddress, String api, Object request, Class<T> responseType) {
|
||||
@@ -71,29 +69,13 @@ public class AcsUtil {
|
||||
* 获取 ACS 开关配置
|
||||
*/
|
||||
private static String getAcsSwitchConfigValue() {
|
||||
Object configApi;
|
||||
try {
|
||||
configApi = SpringUtils.getBean("configApi");
|
||||
} catch (RuntimeException ex) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
Object result = configApi.getClass()
|
||||
.getMethod("getConfigValueByKey", String.class)
|
||||
.invoke(configApi, ACS_SWITCH_CONFIG_KEY);
|
||||
if (result instanceof CommonResult<?> commonResult) {
|
||||
Object data = commonResult.getCheckedData();
|
||||
return data instanceof String value ? value : null;
|
||||
}
|
||||
return null;
|
||||
} catch (InvocationTargetException ex) {
|
||||
Throwable targetException = ex.getTargetException();
|
||||
if (targetException instanceof RuntimeException runtimeException) {
|
||||
throw runtimeException;
|
||||
}
|
||||
throw new ServerException(500, "获取 ACS 开关配置失败");
|
||||
} catch (ReflectiveOperationException ex) {
|
||||
throw new ServerException(500, "获取 ACS 开关配置失败");
|
||||
ConfigApi configApi = SpringUtils.getBean("configApi");
|
||||
String checkedData = configApi.getConfigValueByKey(ACS_SWITCH_CONFIG_KEY).getCheckedData();
|
||||
return ObjectUtil.isEmpty(checkedData) ? ACS_DISABLED : checkedData;
|
||||
} catch (Exception ex) {
|
||||
log.error("获取 ACS 开关配置失败", ex);
|
||||
return ACS_DISABLED;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user