Commit 65c2c187 hc

代码优化

1 个父辈 4bb60a70
......@@ -1023,7 +1023,7 @@ public class LuxsanApi extends DefaultSmfApiListener {
}
public static List<GetBoxNGResult> getBoxNGsnListWithStrategyPattern(GetBoxNGsnListRequest request) throws ApiException {
return RequestURLUtil.INSTANCE.request(BusinessConst.DATA_RESULT_TYPE, request, BusinessConst.POST_METHOD, getBoxNGsnListUrl, GetBoxNGResult.class);
return RequestURLUtil.request(BusinessConst.DATA_RESULT_TYPE, request, BusinessConst.POST_METHOD, getBoxNGsnListUrl, GetBoxNGResult.class);
}
......
......@@ -2,8 +2,8 @@ package com.neotel.smfcore.custom.luxsan.common.constants;
public class BusinessConst {
/*================ HTTP类型 ==========================*/
public static String GET_METHOD = "GET";
public static String POST_METHOD = "POST";
public static final String GET_METHOD = "GET";
public static final String POST_METHOD = "POST";
/*================ 解析外部接口类型规则 ==========================*/
/**
......@@ -48,6 +48,6 @@ public class BusinessConst {
* "executeTime": 20
* }
*/
public static String DATA_RESULT_TYPE = "DataResult";
public static final String DATA_RESULT_TYPE = "DataResult";
}
......@@ -11,5 +11,5 @@ import java.util.Map;
public interface IJsonRule<T> {
String getType();
List request(T request, String httpMethod, String url, Class<?> returnType) throws ApiException;
List request(Object request, String httpMethod, String url, Class<?> returnType) throws ApiException;
}
......@@ -26,7 +26,7 @@ public class DataResultJsonRule<T> implements IJsonRule<T> {
}
@Override
public List request(T request, String httpMethod, String url, Class<?> returnType) throws ApiException {
public List request(Object request, String httpMethod, String url, Class<?> returnType) throws ApiException {
log.info(String.format("[%s]接口请求参数为:" + JSON.toJSONString(request), url));
String resultStr = null;
// 调用外部接口
......
......@@ -13,25 +13,14 @@ import java.util.List;
import java.util.Map;
@Component
public class RequestURLUtil<T> implements ApplicationContextAware{
public static RequestURLUtil INSTANCE;
public class RequestURLUtil<T> {
private static Map<String, IJsonRule> iJsonRuleMap = new HashMap<>();
private static final Map<String, IJsonRule> iJsonRuleMap = new HashMap<>();
public RequestURLUtil(List<IJsonRule> iJsonRules) {
for (IJsonRule iJsonRule : iJsonRules) {
iJsonRuleMap.put(iJsonRule.getType(), iJsonRule);
}
}
public List request(String type, T request, String httpMethod, String url, Class<?> returnType) throws ApiException {
public static List request(String type, Object request, String httpMethod, String url, Class<?> returnType) throws ApiException {
IJsonRule iJsonRule = iJsonRuleMap.get(type);
List res = iJsonRule.request(request, httpMethod, url, returnType);
return res;
}
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
INSTANCE = applicationContext.getBean(RequestURLUtil.class);
}
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!