1
This commit is contained in:
@@ -600,6 +600,7 @@ public class JDOrderController extends BaseController {
|
||||
String originalUrl = urls.get(i);
|
||||
logger.info("处理第{}/{}个URL: {}", i + 1, urls.size(), originalUrl);
|
||||
|
||||
JSONObject product = null; // 在try外部声明,以便在catch中使用
|
||||
try {
|
||||
// 1. 查询该URL的商品信息
|
||||
String queryUrl = requestUrl + "generatePromotionContent";
|
||||
@@ -611,7 +612,6 @@ public class JDOrderController extends BaseController {
|
||||
logger.debug("商品查询响应: {}", queryResult);
|
||||
|
||||
Object parsed = JSON.parse(queryResult);
|
||||
JSONObject product = null;
|
||||
|
||||
// 解析商品信息
|
||||
if (parsed instanceof JSONArray) {
|
||||
@@ -633,13 +633,23 @@ public class JDOrderController extends BaseController {
|
||||
}
|
||||
|
||||
if (product == null || product.containsKey("error")) {
|
||||
logger.warn("URL{}商品信息查询失败: {}", originalUrl, product != null ? product.getString("error") : "无数据");
|
||||
String errorMsg = "商品信息查询失败";
|
||||
if (product != null) {
|
||||
String apiError = product.getString("error");
|
||||
String apiMessage = product.getString("message");
|
||||
if (apiMessage != null && !apiMessage.trim().isEmpty()) {
|
||||
errorMsg = apiMessage;
|
||||
} else if (apiError != null && !apiError.trim().isEmpty()) {
|
||||
errorMsg = apiError;
|
||||
}
|
||||
}
|
||||
logger.warn("URL{}商品信息查询失败: {}", originalUrl, errorMsg);
|
||||
JSONObject info = new JSONObject();
|
||||
info.put("index", i + 1);
|
||||
info.put("originalUrl", originalUrl);
|
||||
info.put("newUrl", originalUrl);
|
||||
info.put("success", false);
|
||||
info.put("error", "商品信息查询失败");
|
||||
info.put("error", errorMsg);
|
||||
replacementInfo.add(info);
|
||||
continue;
|
||||
}
|
||||
@@ -729,13 +739,26 @@ public class JDOrderController extends BaseController {
|
||||
if (createData == null || createData.containsKey("error") ||
|
||||
createData.getString("giftCouponKey") == null ||
|
||||
createData.getString("giftCouponKey").trim().isEmpty()) {
|
||||
logger.warn("URL{}礼金创建失败: {}", originalUrl, createData != null ? createData.getString("error") : "giftCouponKey为空");
|
||||
String errorMsg = "礼金创建失败";
|
||||
if (createData != null) {
|
||||
String apiError = createData.getString("error");
|
||||
String apiMessage = createData.getString("message");
|
||||
if (apiMessage != null && !apiMessage.trim().isEmpty()) {
|
||||
errorMsg = apiMessage;
|
||||
} else if (apiError != null && !apiError.trim().isEmpty()) {
|
||||
errorMsg = apiError;
|
||||
}
|
||||
}
|
||||
logger.warn("URL{}礼金创建失败: {}", originalUrl, errorMsg);
|
||||
JSONObject info = new JSONObject();
|
||||
info.put("index", i + 1);
|
||||
info.put("originalUrl", originalUrl);
|
||||
info.put("newUrl", originalUrl);
|
||||
info.put("success", false);
|
||||
info.put("error", "礼金创建失败");
|
||||
info.put("error", errorMsg);
|
||||
if (product != null && product.getString("skuName") != null) {
|
||||
info.put("skuName", product.getString("skuName"));
|
||||
}
|
||||
replacementInfo.add(info);
|
||||
continue;
|
||||
}
|
||||
@@ -756,14 +779,27 @@ public class JDOrderController extends BaseController {
|
||||
if (transferData == null || transferData.containsKey("error") ||
|
||||
transferData.getString("shortURL") == null ||
|
||||
transferData.getString("shortURL").trim().isEmpty()) {
|
||||
logger.warn("URL{}转链失败: {}", originalUrl, transferData != null ? transferData.getString("error") : "shortURL为空");
|
||||
String errorMsg = "转链失败";
|
||||
if (transferData != null) {
|
||||
String apiError = transferData.getString("error");
|
||||
String apiMessage = transferData.getString("message");
|
||||
if (apiMessage != null && !apiMessage.trim().isEmpty()) {
|
||||
errorMsg = apiMessage;
|
||||
} else if (apiError != null && !apiError.trim().isEmpty()) {
|
||||
errorMsg = apiError;
|
||||
}
|
||||
}
|
||||
logger.warn("URL{}转链失败: {}", originalUrl, errorMsg);
|
||||
JSONObject info = new JSONObject();
|
||||
info.put("index", i + 1);
|
||||
info.put("originalUrl", originalUrl);
|
||||
info.put("newUrl", originalUrl);
|
||||
info.put("success", false);
|
||||
info.put("giftCouponKey", giftCouponKey);
|
||||
info.put("error", "转链失败");
|
||||
info.put("error", errorMsg);
|
||||
if (product != null && product.getString("skuName") != null) {
|
||||
info.put("skuName", product.getString("skuName"));
|
||||
}
|
||||
replacementInfo.add(info);
|
||||
continue;
|
||||
}
|
||||
@@ -787,12 +823,19 @@ public class JDOrderController extends BaseController {
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("处理URL{}失败: {}", originalUrl, e.getMessage(), e);
|
||||
String errorMsg = e.getMessage();
|
||||
if (errorMsg == null || errorMsg.trim().isEmpty()) {
|
||||
errorMsg = "处理失败: " + e.getClass().getSimpleName();
|
||||
}
|
||||
JSONObject info = new JSONObject();
|
||||
info.put("index", i + 1);
|
||||
info.put("originalUrl", originalUrl);
|
||||
info.put("newUrl", originalUrl);
|
||||
info.put("success", false);
|
||||
info.put("error", e.getMessage());
|
||||
info.put("error", errorMsg);
|
||||
if (product != null && product.getString("skuName") != null) {
|
||||
info.put("skuName", product.getString("skuName"));
|
||||
}
|
||||
replacementInfo.add(info);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user