This commit is contained in:
2025-11-03 19:49:12 +08:00
parent 127a5b71c6
commit 31ecfa6a2f

View File

@@ -174,7 +174,7 @@ public class JDInnerController {
// 准备候选评论列表 // 准备候选评论列表
List<Comment> candidateComments = new ArrayList<>(); List<Comment> candidateComments = new ArrayList<>();
List<String> candidateSources = new ArrayList<>(); // 记录来源,用于标识是京东还是淘宝 List<String> candidateSources = new ArrayList<>(); // 记录来源,用于标识是京东还是淘宝
// 添加已使用过的京东评论 // 添加已使用过的京东评论
if (!usedComments.isEmpty()) { if (!usedComments.isEmpty()) {
Collections.shuffle(usedComments); Collections.shuffle(usedComments);
@@ -182,7 +182,7 @@ public class JDInnerController {
candidateSources.add("JD"); candidateSources.add("JD");
logger.info("已添加已使用过的京东评论到候选列表"); logger.info("已添加已使用过的京东评论到候选列表");
} }
// 添加已使用过的淘宝评论 // 添加已使用过的淘宝评论
String taobaoProductIdMap = tbMap.getOrDefault(productId, null); String taobaoProductIdMap = tbMap.getOrDefault(productId, null);
if (taobaoProductIdMap != null && !taobaoProductIdMap.isEmpty()) { if (taobaoProductIdMap != null && !taobaoProductIdMap.isEmpty()) {
@@ -193,14 +193,14 @@ public class JDInnerController {
logger.info("已添加已使用过的淘宝评论到候选列表"); logger.info("已添加已使用过的淘宝评论到候选列表");
} }
} }
// 如果候选列表不为空,随机选择 // 如果候选列表不为空,随机选择
if (!candidateComments.isEmpty()) { if (!candidateComments.isEmpty()) {
Random random = new Random(); Random random = new Random();
int selectedIndex = random.nextInt(candidateComments.size()); int selectedIndex = random.nextInt(candidateComments.size());
commentToUse = candidateComments.get(selectedIndex); commentToUse = candidateComments.get(selectedIndex);
String selectedSource = candidateSources.get(selectedIndex); String selectedSource = candidateSources.get(selectedIndex);
if ("TB".equals(selectedSource)) { if ("TB".equals(selectedSource)) {
isTb = true; isTb = true;
logger.info("随机选择:使用已使用过的淘宝评论"); logger.info("随机选择:使用已使用过的淘宝评论");
@@ -301,9 +301,9 @@ public class JDInnerController {
// 查询未使用的评论isUse != 1即0或null // 查询未使用的评论isUse != 1即0或null
taobaoComments = taobaoCommentRepository.findByProductIdAndIsUseNotAndPictureUrlsIsNotNull(taobaoProductId, 1); taobaoComments = taobaoCommentRepository.findByProductIdAndIsUseNotAndPictureUrlsIsNotNull(taobaoProductId, 1);
} }
logger.info("taobaoComments.size() {} (includeUsed={})", taobaoComments.size(), includeUsed); logger.info("taobaoComments.size() {} (includeUsed={})", taobaoComments.size(), includeUsed);
if (!taobaoComments.isEmpty()) { if (!taobaoComments.isEmpty()) {
Collections.shuffle(taobaoComments); Collections.shuffle(taobaoComments);
TaobaoComment selected = taobaoComments.get(0); TaobaoComment selected = taobaoComments.get(0);
@@ -319,7 +319,7 @@ public class JDInnerController {
comment.setProductId(product_id); comment.setProductId(product_id);
comment.setUserName(selected.getUserName()); comment.setUserName(selected.getUserName());
comment.setCreatedAt(selected.getCreatedAt()); comment.setCreatedAt(selected.getCreatedAt());
// 只在获取未使用的评论时才标记为已使用 // 只在获取未使用的评论时才标记为已使用
if (!includeUsed) { if (!includeUsed) {
selected.setIsUse(1); selected.setIsUse(1);
@@ -376,19 +376,19 @@ public class JDInnerController {
try { try {
String giftKey = jdProductService.createGiftCoupon(idOrUrl, amount, quantity, owner, skuName); String giftKey = jdProductService.createGiftCoupon(idOrUrl, amount, quantity, owner, skuName);
// 如果giftKey为null返回错误而不是成功响应 // 如果giftKey为null返回错误而不是成功响应
if (giftKey == null || giftKey.trim().isEmpty()) { if (giftKey == null || giftKey.trim().isEmpty()) {
String errorDetail = String.format("礼金创建失败giftCouponKey为null。参数: idOrUrl=%s, amount=%.2f, quantity=%d, owner=%s, skuName=%s。可能原因商品不支持创建礼金、商品类型错误、京东API调用失败。请查看JD项目日志获取详细信息。", String errorDetail = String.format("礼金创建失败giftCouponKey为null。参数: idOrUrl=%s, amount=%.2f, quantity=%d, owner=%s, skuName=%s。可能原因商品不支持创建礼金、商品类型错误、京东API调用失败。请查看JD项目日志获取详细信息。",
idOrUrl, amount, quantity, owner, skuName); idOrUrl, amount, quantity, owner, skuName);
logger.error("礼金创建失败 - giftKey为null, {}", errorDetail); logger.error("礼金创建失败 - giftKey为null, {}", errorDetail);
return error(errorDetail); return error(errorDetail);
} }
// 创建成功保存到Redis // 创建成功保存到Redis
jdProductService.saveGiftCouponToRedis(idOrUrl, giftKey, skuName, owner); jdProductService.saveGiftCouponToRedis(idOrUrl, giftKey, skuName, owner);
logger.info("礼金创建成功 - giftKey={}, idOrUrl={}, owner={}, amount={}, quantity={}", giftKey, idOrUrl, owner, amount, quantity); logger.info("礼金创建成功 - giftKey={}, idOrUrl={}, owner={}, amount={}, quantity={}", giftKey, idOrUrl, owner, amount, quantity);
JSONObject resp = new JSONObject(); JSONObject resp = new JSONObject();
resp.put("giftCouponKey", giftKey); resp.put("giftCouponKey", giftKey);
return resp; return resp;
@@ -431,14 +431,14 @@ public class JDInnerController {
if (checkSkey(skey)) { if (checkSkey(skey)) {
return error("invalid skey"); return error("invalid skey");
} }
String skuId = body.get("skuId") != null ? String.valueOf(body.get("skuId")) : null; String skuId = body.get("skuId") != null ? String.valueOf(body.get("skuId")) : null;
String materialUrl = body.get("materialUrl") != null ? String.valueOf(body.get("materialUrl")) : null; String materialUrl = body.get("materialUrl") != null ? String.valueOf(body.get("materialUrl")) : null;
String owner = body.get("owner") != null ? String.valueOf(body.get("owner")) : "g"; String owner = body.get("owner") != null ? String.valueOf(body.get("owner")) : "g";
String skuName = body.get("skuName") != null ? String.valueOf(body.get("skuName")) : ""; String skuName = body.get("skuName") != null ? String.valueOf(body.get("skuName")) : "";
double amount = parseDouble(body.get("amount"), 1.0); double amount = parseDouble(body.get("amount"), 1.8);
int quantity = parseInt(body.get("quantity"), 1); int quantity = parseInt(body.get("quantity"), 1);
int batchSize = parseInt(body.get("batchSize"), 20); int batchSize = parseInt(body.get("batchSize"), 15);
String idOrUrl = skuId != null && !skuId.trim().isEmpty() ? skuId : materialUrl; String idOrUrl = skuId != null && !skuId.trim().isEmpty() ? skuId : materialUrl;
if (idOrUrl == null || idOrUrl.trim().isEmpty()) { if (idOrUrl == null || idOrUrl.trim().isEmpty()) {
@@ -451,13 +451,13 @@ public class JDInnerController {
return error("batchSize must be between 1 and 100"); return error("batchSize must be between 1 and 100");
} }
logger.info("批量创建礼金券请求 - idOrUrl={}, amount={}, quantity={}, batchSize={}, owner={}, skuName={}", logger.info("批量创建礼金券请求 - idOrUrl={}, amount={}, quantity={}, batchSize={}, owner={}, skuName={}",
idOrUrl, amount, quantity, batchSize, owner, skuName); idOrUrl, amount, quantity, batchSize, owner, skuName);
try { try {
List<Map<String, Object>> results = jdProductService.batchCreateGiftCouponsWithLinks( List<Map<String, Object>> results = jdProductService.batchCreateGiftCouponsWithLinks(
idOrUrl, amount, quantity, batchSize, owner, skuName); idOrUrl, amount, quantity, batchSize, owner, skuName);
int successCount = 0; int successCount = 0;
int failCount = 0; int failCount = 0;
for (Map<String, Object> result : results) { for (Map<String, Object> result : results) {
@@ -467,13 +467,13 @@ public class JDInnerController {
failCount++; failCount++;
} }
} }
JSONObject resp = new JSONObject(); JSONObject resp = new JSONObject();
resp.put("results", results); resp.put("results", results);
resp.put("total", batchSize); resp.put("total", batchSize);
resp.put("successCount", successCount); resp.put("successCount", successCount);
resp.put("failCount", failCount); resp.put("failCount", failCount);
logger.info("批量创建礼金券完成 - 总数={}, 成功={}, 失败={}", batchSize, successCount, failCount); logger.info("批量创建礼金券完成 - 总数={}, 成功={}, 失败={}", batchSize, successCount, failCount);
return resp; return resp;
} catch (Exception e) { } catch (Exception e) {
@@ -497,7 +497,7 @@ public class JDInnerController {
tips.put("tip", "请在Postman的Body标签中选择raw/JSON格式并输入: {\"skey\": \"your_skey_here\"}"); tips.put("tip", "请在Postman的Body标签中选择raw/JSON格式并输入: {\"skey\": \"your_skey_here\"}");
return tips; return tips;
} }
String skey = body.get("skey") != null ? String.valueOf(body.get("skey")) : null; String skey = body.get("skey") != null ? String.valueOf(body.get("skey")) : null;
if (checkSkey(skey)) { if (checkSkey(skey)) {
return error("invalid skey"); return error("invalid skey");