Commit 32ef4b1d hc

fix:正式环境接口请求路径修改以及报错信息修改

1 个父辈 c26858b4
......@@ -19,6 +19,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
......@@ -50,11 +51,12 @@ public class LuxsanSpApi extends DefaultSmfApiListener {
// 备品仓退库查询接口的GET方法
public static List<GetReturnInventoryResult> getReturnInventory(GetReturnInventoryRequest request) {
String url = null;
try {
// 记录请求日志
log.info("备品仓退库查询接口请求为: " + JSON.toJSONString(request));
// 构造请求URL,附加查询参数
String url = GetReturnInventory + getQueryStr(request);
url = GetReturnInventory + getQueryStr(request);
// 发送GET请求并获取JSON格式的响应字符串
String resJsonStr = HttpHelper.sendGet(url);
log.info("备品仓退库查询接口返回为:" + resJsonStr);
......@@ -63,45 +65,49 @@ public class LuxsanSpApi extends DefaultSmfApiListener {
// 检查API调用是否成功,并返回结果对象
if (ObjectUtil.isNotNull(lizhenApiResult)) {
if (lizhenApiResult.getCode() != 200) {
throw new Exception(String.format("备品仓退库查询接口请求失败, 错误代码[%d],错误原因[%s]",
lizhenApiResult.getCode(), lizhenApiResult.getMsg()));
throw new Exception(String.format("备品仓退库查询接口[%s]请求失败, 错误代码[%d],错误原因[%s]",
url, lizhenApiResult.getCode(), lizhenApiResult.getMsg()));
}
List<GetReturnInventoryResult> resultList = JSONObject.parseArray(lizhenApiResult.getData(), GetReturnInventoryResult.class);
if (resultList != null && !resultList.isEmpty()){
if (resultList != null && !resultList.isEmpty()) {
return resultList;
} else {
return new ArrayList<>();
}
}
} catch (Exception e) {
// 记录异常日志
log.error("备品仓退库查询接口请求失败: " + e.getMessage(), e);
log.error("备品仓退库查询接口[{0}]请求失败: " + e.getMessage(), url);
// 抛出自定义异常
throw new ValidateException("smfcore.api.error", "接口请求失败[{0}]", new String[]{e.getMessage()});
throw new ValidateException("smfcore.api.error", "接口[{0}]请求失败[{1}]", new String[]{url, e.getMessage()});
}
// 如果没有成功返回结果,抛出异常
throw new ValidateException("smfcore.api.error", "接口请求失败[{0}]", new String[]{"未找到对应的退库单信息"});
}
public static List<GetUnclaimedResult> getUnclaimedDetails(GetUnclaimedRequest request) {
String url = null;
try {
log.info("预约待领取接口请求为:" + JSON.toJSONString(request));
String url = GetUnclaimedUrl + getQueryStr(request);
url = GetUnclaimedUrl + getQueryStr(request);
String resJsonStr = HttpHelper.sendGet(url);
log.info("预约待领取接口请求返回:" + resJsonStr);
LuxsanSpApiResult lizhenApiResult = JSONObject.parseObject(resJsonStr, LuxsanSpApiResult.class);
if (lizhenApiResult.getCode() != 200) {
throw new Exception(String.format("预约待领取接口接口请求失败, 错误代码[%d],错误原因[%s]",
lizhenApiResult.getCode(), lizhenApiResult.getMsg()));
throw new Exception(String.format("预约待领取接口接口[%s]请求失败, 错误代码[%d],错误原因[%s]",
url, lizhenApiResult.getCode(), lizhenApiResult.getMsg()));
}
String data = lizhenApiResult.getData();
List<GetUnclaimedResult> resultList = JSONObject.parseArray(data, GetUnclaimedResult.class);
if (resultList != null && !resultList.isEmpty()){
if (resultList != null && !resultList.isEmpty()) {
return resultList;
}else{
return new ArrayList<>();
}
} catch (Exception e) {
log.info("getUnclaimedDetails请求失败:" + e.getMessage());
throw new ValidateException("smfcore.api.error", "接口请求失败[{0}]", new String[]{e.getMessage()});
throw new ValidateException("smfcore.api.error", "接口请求失败[{0}],错误信息[{1}]", new String[]{url, e.getMessage()});
}
throw new ValidateException("smfcore.api.error", "接口请求失败[{0}]", new String[]{"未找到对应的预约单接口"});
}
......@@ -112,28 +118,29 @@ public class LuxsanSpApi extends DefaultSmfApiListener {
log.info("备品仓入库接口返回:" + resJsonStr);
LuxsanSpApiResult lizhenApiResult = JSONObject.parseObject(resJsonStr, LuxsanSpApiResult.class);
if (lizhenApiResult.getCode() != 200) {
throw new ApiException(String.format("备品仓入库接口请求失败, 错误代码[%d],错误原因[%s]",
lizhenApiResult.getCode(), lizhenApiResult.getMsg()));
throw new ApiException(String.format("备品仓入库接口[%s]请求失败, 错误代码[%d],错误原因[%s]",
SpareInHourseUrl, lizhenApiResult.getCode(), lizhenApiResult.getMsg()));
}
} catch (ApiException e) {
log.info("备品仓入库接口请求失败:" + e.getMessage());
throw new ValidateException("smfcore.api.error", "接口请求失败[{0}]", new String[]{e.getMessage()});
throw new ValidateException("smfcore.api.error", "接口[{0}]请求失败[{1}]", new String[]{SpareInHourseUrl, e.getMessage()});
}
//throw new ValidateException("smfcore.api.error", "接口请求失败[{0}]", new String[]{SpareInHourseUrl});
}
public static List<GetSpareNoResult> getSpareNo(GetSpareNoRequest request) {
String url = null;
try {
String url = GetSpareNoUrl + getQueryStr(request);
url = GetSpareNoUrl + getQueryStr(request);
log.info("获取入库单号请求为:" + request);
String resJsonStr = HttpHelper.sendGet(url);
// String resJsonStr = HttpHelper.sendGet(url);
log.info("获取入库单号返回:" + resJsonStr);
LuxsanSpApiResult lizhenApiResult = JSONObject.parseObject(resJsonStr, LuxsanSpApiResult.class);
if (lizhenApiResult.getCode() != 200) {
throw new Exception(String.format("获取入库单号接口请求失败, 错误代码[%d],错误原因[%s]",
lizhenApiResult.getCode(), lizhenApiResult.getMsg()));
throw new Exception(String.format("获取入库单号接口请[{%s}]求失败, 错误代码[%d],错误原因[%s]",
url, lizhenApiResult.getCode(), lizhenApiResult.getMsg()));
}
List<GetSpareNoResult> resultList = JSONObject.parseArray(lizhenApiResult.getData(), GetSpareNoResult.class);
if (resultList != null && !resultList.isEmpty()) {
......@@ -141,7 +148,7 @@ public class LuxsanSpApi extends DefaultSmfApiListener {
}
} catch (Exception e) {
log.info("getSpareNo请求失败:" + e.getMessage());
throw new ValidateException("smfcore.api.error", "接口请求失败[{0}]", new String[]{e.getMessage()});
throw new ValidateException("smfcore.api.error", "接口[{0}]请求失败[{1}]", new String[]{url, e.getMessage()});
}
throw new ValidateException("smfcore.api.error", "接口请求失败[{0}]", new String[]{"未找到入库单信息"});
}
......
api:
name: Luxsan_sp
getSpareNo: http://lxkjgw.api.luxsan-ict.com:8000/iams-api/getSpareNo
getSpareNo: http://lxkjgw.api.luxsan-ict.com:8000/iamsprdapi/getSpareNo
spareInhourse: http://lxkjgw.api.luxsan-ict.com:8000/iamsprdapi/spareInhourse
getUnclaimed: http://lxkjgw.api.luxsan-ict.com:8000/iamsprdapi/getUnclaimed
getReturnInventory: http://lxkjgw.api.luxsan-ict.com:8000/iamsprdapi/getReturnInventory
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!