Commit 45d27156 hc

代码优化

1 个父辈 980761b1
...@@ -1004,48 +1004,6 @@ public class LuxsanApi extends DefaultSmfApiListener { ...@@ -1004,48 +1004,6 @@ public class LuxsanApi extends DefaultSmfApiListener {
} }
} }
public static List<GetBoxNGResult> getBoxNGsnList(Map request) throws ApiException {
return RequestURLUtil.request(BusinessConst.DATA_RESULT_TYPE, request, BusinessConst.POST_METHOD, getBoxNGsnListUrl, GetBoxNGResult.class);
}
public static List<GetBoxNGResult> getBoxNGsnList(GetBoxNGsnListRequest request) throws ApiException {
log.info("getBoxNGsnList接口请求参数为:" + JSON.toJSONString(request));
String resultStr = null;
// 调用外部接口
try {
resultStr = HttpHelper.postJson(getBoxNGsnListUrl, request);
}catch (Exception e) {
log.error(String.format("接口请求失败[%s]", getBoxNGsnListUrl));
throw new ValidateException("smfcore.api.error", "接口请求失败[{0}]", new String[]{getBoxNGsnListUrl});
}
log.info("getBoxNGsnList接口返回结果为:" + resultStr);
JSONObject resultJson = JsonUtil.toObj(resultStr, JSONObject.class);
String data = resultJson.getString("data");
if (StringUtils.isEmpty(data)) {
throw new ApiException(String.format("接口返回内容有误[%s]", getBoxNGsnListUrl));
}
JSONObject dataJson = resultJson.getJSONObject("data");
// 远程接口返回的数据错误
if (dataJson.get("result") != null && !dataJson.getBoolean("result")) {
String errorMessage = (String) dataJson.get("message");
if (StringUtils.isEmpty(errorMessage)) {
errorMessage = "";
}
log.error(String.format("接口请求失败[%s],失败原因[%s]", getBoxNGsnListUrl, errorMessage));
throw new ApiException(String.format("smfcore.api.error 接口请求失败[%s],失败原因[%s]", getBoxNGsnListUrl, errorMessage));
} else {
JSONArray arrayData = dataJson.getJSONArray("data");
System.out.println(arrayData);
List<GetBoxNGResult> resultList = JSONObject.parseArray(JSONArray.toJSONString(arrayData), GetBoxNGResult.class);
if (resultList != null && !resultList.isEmpty()) {
return resultList;
}else {
return new ArrayList<>();
}
}
}
public static void ticketPick(TicketPickRequest request) { public static void ticketPick(TicketPickRequest request) {
log.info("ticketPick接口请求参数为:" + JSON.toJSONString(request)+",地址为:"+ticketPickUrl); log.info("ticketPick接口请求参数为:" + JSON.toJSONString(request)+",地址为:"+ticketPickUrl);
try { try {
...@@ -1062,6 +1020,10 @@ public class LuxsanApi extends DefaultSmfApiListener { ...@@ -1062,6 +1020,10 @@ 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);
}
@Override @Override
public void outTaskStatusChange(String outNotifyUrl, DataLog task) { public void outTaskStatusChange(String outNotifyUrl, DataLog task) {
......
...@@ -8,8 +8,8 @@ import java.util.Map; ...@@ -8,8 +8,8 @@ import java.util.Map;
/** /**
* 解析外部接口返回的json规则 * 解析外部接口返回的json规则
*/ */
public interface IJsonRule { public interface IJsonRule<T> {
String getType(); String getType();
List request(Map request, String httpMethod, String url, Class<?> returnType) throws ApiException; List request(T request, String httpMethod, String url, Class<?> returnType) throws ApiException;
} }
...@@ -19,14 +19,14 @@ import java.util.Map; ...@@ -19,14 +19,14 @@ import java.util.Map;
@Slf4j @Slf4j
@Service @Service
public class DataResultJsonRule implements IJsonRule { public class DataResultJsonRule<T> implements IJsonRule<T> {
@Override @Override
public String getType() { public String getType() {
return BusinessConst.DATA_RESULT_TYPE; return BusinessConst.DATA_RESULT_TYPE;
} }
@Override @Override
public List request(Map request, String httpMethod, String url, Class<?> returnType) throws ApiException { public List request(T request, String httpMethod, String url, Class<?> returnType) throws ApiException {
log.info(String.format("[%s]接口请求参数为:" + JSON.toJSONString(request), url)); log.info(String.format("[%s]接口请求参数为:" + JSON.toJSONString(request), url));
String resultStr = null; String resultStr = null;
// 调用外部接口 // 调用外部接口
......
...@@ -2,6 +2,10 @@ package com.neotel.smfcore.custom.luxsan.common.util; ...@@ -2,6 +2,10 @@ package com.neotel.smfcore.custom.luxsan.common.util;
import com.neotel.smfcore.common.exception.ApiException; import com.neotel.smfcore.common.exception.ApiException;
import com.neotel.smfcore.custom.luxsan.common.json.IJsonRule; import com.neotel.smfcore.custom.luxsan.common.json.IJsonRule;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.HashMap; import java.util.HashMap;
...@@ -9,7 +13,9 @@ import java.util.List; ...@@ -9,7 +13,9 @@ import java.util.List;
import java.util.Map; import java.util.Map;
@Component @Component
public class RequestURLUtil { public class RequestURLUtil<T> implements ApplicationContextAware{
public static RequestURLUtil INSTANCE;
private static Map<String, IJsonRule> iJsonRuleMap = new HashMap<>(); private static Map<String, IJsonRule> iJsonRuleMap = new HashMap<>();
public RequestURLUtil(List<IJsonRule> iJsonRules) { public RequestURLUtil(List<IJsonRule> iJsonRules) {
...@@ -18,10 +24,14 @@ public class RequestURLUtil { ...@@ -18,10 +24,14 @@ public class RequestURLUtil {
} }
} }
public static List request(String type, Map request, String httpMethod, String url, Class<?> returnType) throws ApiException { public List request(String type, T request, String httpMethod, String url, Class<?> returnType) throws ApiException {
IJsonRule iJsonRule = iJsonRuleMap.get(type); IJsonRule iJsonRule = iJsonRuleMap.get(type);
List res = iJsonRule.request(request, httpMethod, url, returnType); List res = iJsonRule.request(request, httpMethod, url, returnType);
return res; return res;
} }
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
INSTANCE = applicationContext.getBean(RequestURLUtil.class);
}
} }
...@@ -355,8 +355,7 @@ public class LineController { ...@@ -355,8 +355,7 @@ public class LineController {
Map<String, String> map = new HashMap<>(); Map<String, String> map = new HashMap<>();
map.put("model", result.getModel()); map.put("model", result.getModel());
map.put("carton_id", result.getCarton_id()); map.put("carton_id", result.getCarton_id());
List<GetBoxNGResult> boxNGsnList = LuxsanApi.getBoxNGsnList(map); return ResultBean.newOkResult(LuxsanApi.getBoxNGsnListWithStrategyPattern(result));
return ResultBean.newOkResult(boxNGsnList);
} }
@ApiOperation("手动完成入库任务") @ApiOperation("手动完成入库任务")
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!