Compare commits
2 Commits
64ce923631
...
b8981ffc98
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b8981ffc98 | ||
|
|
9e69230948 |
@@ -116,11 +116,44 @@ public class ErpProductController extends BaseController
|
||||
{
|
||||
try {
|
||||
int count = erpProductService.pullAndSaveProductList(appid, pageNo, pageSize, productStatus);
|
||||
return success("成功拉取并保存 " + count + " 个商品");
|
||||
if (count > 0) {
|
||||
return success("成功拉取并保存 " + count + " 个商品");
|
||||
} else {
|
||||
String statusText = getStatusText(productStatus);
|
||||
String message = "拉取完成,但没有获取到商品数据";
|
||||
if (productStatus != null) {
|
||||
message += "(筛选条件:状态=" + statusText + ")";
|
||||
}
|
||||
message += "。建议:1.尝试不选择状态拉取全部商品;2.尝试其他状态(下架、已售等)";
|
||||
return success(message);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return error("拉取商品列表失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取状态文本(用于提示信息)
|
||||
*/
|
||||
private String getStatusText(Integer status) {
|
||||
if (status == null) {
|
||||
return "全部";
|
||||
}
|
||||
switch (status) {
|
||||
case 1:
|
||||
return "上架";
|
||||
case 2:
|
||||
return "下架";
|
||||
case 3:
|
||||
return "已售";
|
||||
case 22:
|
||||
return "草稿";
|
||||
case 23:
|
||||
return "审核中";
|
||||
default:
|
||||
return String.valueOf(status);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量上架商品
|
||||
|
||||
@@ -146,8 +146,10 @@ public class ErpProductServiceImpl implements IErpProductService
|
||||
JSONObject response = JSONObject.parseObject(responseBody);
|
||||
|
||||
if (response == null || response.getInteger("code") == null || response.getInteger("code") != 0) {
|
||||
log.error("拉取商品列表失败: {}", responseBody);
|
||||
return 0;
|
||||
String errorMsg = response != null ? response.getString("msg") : "未知错误";
|
||||
log.error("拉取商品列表失败: code={}, msg={}, response={}",
|
||||
response != null ? response.getInteger("code") : null, errorMsg, responseBody);
|
||||
throw new RuntimeException("拉取商品列表失败: " + errorMsg);
|
||||
}
|
||||
|
||||
// 解析商品列表
|
||||
@@ -158,11 +160,20 @@ public class ErpProductServiceImpl implements IErpProductService
|
||||
}
|
||||
|
||||
JSONArray productList = data.getJSONArray("list");
|
||||
Integer totalCount = data.getInteger("count");
|
||||
|
||||
if (productList == null || productList.isEmpty()) {
|
||||
log.info("拉取商品列表为空");
|
||||
String statusMsg = productStatus != null ? "(状态:" + productStatus + ")" : "";
|
||||
if (totalCount != null && totalCount > 0) {
|
||||
log.info("拉取商品列表为空,但总数显示为 {},可能是分页问题", totalCount);
|
||||
} else {
|
||||
log.info("拉取商品列表为空{},该账号下没有符合条件的商品", statusMsg);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
log.info("拉取到 {} 个商品,开始保存", productList.size());
|
||||
|
||||
// 转换为实体对象并保存
|
||||
List<ErpProduct> erpProducts = new ArrayList<>();
|
||||
for (int i = 0; i < productList.size(); i++) {
|
||||
|
||||
Reference in New Issue
Block a user