1
This commit is contained in:
@@ -75,21 +75,39 @@ public class BatchPublishRequest {
|
||||
/** 商品名称 */
|
||||
private String productName;
|
||||
|
||||
/** 商品价格(元) */
|
||||
/** 京东原价(元) */
|
||||
private Double price;
|
||||
|
||||
/** 商品图片 */
|
||||
/** 发布价格(元) */
|
||||
private Double publishPrice;
|
||||
|
||||
/** 商品主图 */
|
||||
private String productImage;
|
||||
|
||||
/** 商品图片数组 */
|
||||
private List<String> images;
|
||||
|
||||
/** 店铺名称 */
|
||||
private String shopName;
|
||||
|
||||
/** 店铺ID */
|
||||
private String shopId;
|
||||
|
||||
/** 佣金 */
|
||||
private String commission;
|
||||
|
||||
/** 佣金比例 */
|
||||
private String commissionShare;
|
||||
|
||||
/** 佣金信息(兼容旧字段) */
|
||||
private String commissionInfo;
|
||||
|
||||
/** 文案数组 */
|
||||
private List<WenanItem> wenan;
|
||||
|
||||
/** 选中的文案索引 */
|
||||
private Integer selectedWenanIndex;
|
||||
|
||||
public String getSkuid() {
|
||||
return skuid;
|
||||
}
|
||||
@@ -114,6 +132,14 @@ public class BatchPublishRequest {
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
public Double getPublishPrice() {
|
||||
return publishPrice;
|
||||
}
|
||||
|
||||
public void setPublishPrice(Double publishPrice) {
|
||||
this.publishPrice = publishPrice;
|
||||
}
|
||||
|
||||
public String getProductImage() {
|
||||
return productImage;
|
||||
}
|
||||
@@ -122,6 +148,14 @@ public class BatchPublishRequest {
|
||||
this.productImage = productImage;
|
||||
}
|
||||
|
||||
public List<String> getImages() {
|
||||
return images;
|
||||
}
|
||||
|
||||
public void setImages(List<String> images) {
|
||||
this.images = images;
|
||||
}
|
||||
|
||||
public String getShopName() {
|
||||
return shopName;
|
||||
}
|
||||
@@ -138,6 +172,22 @@ public class BatchPublishRequest {
|
||||
this.shopId = shopId;
|
||||
}
|
||||
|
||||
public String getCommission() {
|
||||
return commission;
|
||||
}
|
||||
|
||||
public void setCommission(String commission) {
|
||||
this.commission = commission;
|
||||
}
|
||||
|
||||
public String getCommissionShare() {
|
||||
return commissionShare;
|
||||
}
|
||||
|
||||
public void setCommissionShare(String commissionShare) {
|
||||
this.commissionShare = commissionShare;
|
||||
}
|
||||
|
||||
public String getCommissionInfo() {
|
||||
return commissionInfo;
|
||||
}
|
||||
@@ -145,6 +195,49 @@ public class BatchPublishRequest {
|
||||
public void setCommissionInfo(String commissionInfo) {
|
||||
this.commissionInfo = commissionInfo;
|
||||
}
|
||||
|
||||
public List<WenanItem> getWenan() {
|
||||
return wenan;
|
||||
}
|
||||
|
||||
public void setWenan(List<WenanItem> wenan) {
|
||||
this.wenan = wenan;
|
||||
}
|
||||
|
||||
public Integer getSelectedWenanIndex() {
|
||||
return selectedWenanIndex;
|
||||
}
|
||||
|
||||
public void setSelectedWenanIndex(Integer selectedWenanIndex) {
|
||||
this.selectedWenanIndex = selectedWenanIndex;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 文案项
|
||||
*/
|
||||
public static class WenanItem {
|
||||
/** 文案类型 */
|
||||
private String type;
|
||||
|
||||
/** 文案内容 */
|
||||
private String content;
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
}
|
||||
|
||||
public static class CommonParams {
|
||||
|
||||
@@ -203,14 +203,38 @@ public class BatchPublishServiceImpl implements IBatchPublishService
|
||||
|
||||
// 提取基本信息
|
||||
result.put("skuid", getValueFromMap(productMap, "spuid", "skuId", "sku"));
|
||||
result.put("productName", getValueFromMap(productMap, "skuName", "title", "name"));
|
||||
result.put("productName", getValueFromMap(productMap, "skuName", "cleanSkuName", "title", "name"));
|
||||
result.put("price", getValueFromMap(productMap, "price", "opPrice", "jdPrice"));
|
||||
result.put("productImage", getFirstImage(productMap));
|
||||
result.put("shopName", getValueFromMap(productMap, "shopName"));
|
||||
result.put("shopId", getValueFromMap(productMap, "shopId"));
|
||||
result.put("commission", getValueFromMap(productMap, "commission"));
|
||||
result.put("commissionShare", getValueFromMap(productMap, "commissionShare"));
|
||||
result.put("commissionInfo", getValueFromMap(productMap, "commissionShare", "commission"));
|
||||
result.put("materialUrl", getValueFromMap(productMap, "materialUrl", "url"));
|
||||
|
||||
// 【新增】提取图片数组
|
||||
Object imagesObj = productMap.get("images");
|
||||
if (imagesObj instanceof List) {
|
||||
result.put("images", imagesObj);
|
||||
} else {
|
||||
// 如果没有images数组,则创建只包含主图的列表
|
||||
List<String> imageList = new ArrayList<>();
|
||||
String mainImage = getFirstImage(productMap);
|
||||
if (mainImage != null) {
|
||||
imageList.add(mainImage);
|
||||
}
|
||||
result.put("images", imageList);
|
||||
}
|
||||
|
||||
// 【新增】提取文案数组
|
||||
Object wenanObj = productMap.get("wenan");
|
||||
if (wenanObj instanceof List) {
|
||||
result.put("wenan", wenanObj);
|
||||
} else {
|
||||
result.put("wenan", new ArrayList<>());
|
||||
}
|
||||
|
||||
// 保留原始数据
|
||||
result.put("_raw", productMap);
|
||||
|
||||
@@ -305,7 +329,13 @@ public class BatchPublishServiceImpl implements IBatchPublishService
|
||||
item.setAccountRemark(accountRemark + "-" + subAccount);
|
||||
item.setSubAccount(subAccount); // 设置子账号
|
||||
item.setStatus(0); // 待发布
|
||||
item.setPublishPrice(product.getPrice() != null ? Math.round(product.getPrice() * 100) : null);
|
||||
|
||||
// 【修改】使用发布价格,如果没有则使用京东原价
|
||||
Double priceToSave = product.getPublishPrice() != null ?
|
||||
product.getPublishPrice() :
|
||||
(product.getPrice() != null ? product.getPrice() : 0.0);
|
||||
item.setPublishPrice(Math.round(priceToSave * 100)); // 转分保存
|
||||
|
||||
item.setDelaySeconds(request.getDelaySeconds());
|
||||
item.setCreateTime(new Date());
|
||||
items.add(item);
|
||||
@@ -400,11 +430,11 @@ public class BatchPublishServiceImpl implements IBatchPublishService
|
||||
throw new RuntimeException("未找到ERP账号: " + item.getTargetAccount());
|
||||
}
|
||||
|
||||
// 获取商品详情(从原始数据中获取)
|
||||
Map<String, Object> productDetail = getProductDetail(item.getSkuid());
|
||||
if (productDetail == null) {
|
||||
throw new RuntimeException("无法获取商品详情: " + item.getSkuid());
|
||||
}
|
||||
// 【修改】获取对应的商品配置(包含自定义价格和文案)
|
||||
BatchPublishRequest.ProductItem productConfig = request.getProducts().stream()
|
||||
.filter(p -> p.getSkuid().equals(item.getSkuid()))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new RuntimeException("未找到商品配置: " + item.getSkuid()));
|
||||
|
||||
// 获取通用参数
|
||||
BatchPublishRequest.CommonParams commonParams = request.getCommonParams();
|
||||
@@ -414,7 +444,13 @@ public class BatchPublishServiceImpl implements IBatchPublishService
|
||||
erpShop.setChannelCatid(commonParams.getChannelCatId());
|
||||
erpShop.setItemBizType(commonParams.getItemBizType());
|
||||
erpShop.setSpBizType(commonParams.getSpBizType());
|
||||
erpShop.setPrice(item.getPublishPrice()); // 价格(分)
|
||||
|
||||
// 【修改】使用自定义的发布价格
|
||||
Double publishPrice = productConfig.getPublishPrice() != null ?
|
||||
productConfig.getPublishPrice() :
|
||||
(productConfig.getPrice() != null ? productConfig.getPrice() : 0.0);
|
||||
erpShop.setPrice(Math.round(publishPrice * 100)); // 价格转分
|
||||
|
||||
erpShop.setExpressFee(Math.round(commonParams.getExpressFee() * 100)); // 邮费转分
|
||||
erpShop.setStock(commonParams.getStock());
|
||||
|
||||
@@ -435,14 +471,25 @@ public class BatchPublishServiceImpl implements IBatchPublishService
|
||||
shop.setDistrict(commonParams.getDistrict());
|
||||
shop.setTitle(item.getProductName()); // 使用商品名称
|
||||
|
||||
// 生成商品描述(简单版)
|
||||
String content = "【正品保障】" + item.getProductName() + "\n\n" +
|
||||
"SKUID: " + item.getSkuid() + "\n" +
|
||||
"店铺信息: " + productDetail.getOrDefault("shopName", "京东商城");
|
||||
// 【修改】使用用户选择的文案
|
||||
String content = getSelectedWenanContent(productConfig);
|
||||
if (StringUtils.isEmpty(content)) {
|
||||
// 如果没有选择文案,使用默认描述
|
||||
content = "【正品保障】" + item.getProductName() + "\n\n" +
|
||||
"SKUID: " + item.getSkuid() + "\n" +
|
||||
"店铺信息: " + (productConfig.getShopName() != null ? productConfig.getShopName() : "京东商城");
|
||||
}
|
||||
shop.setContent(content);
|
||||
|
||||
// 商品图片
|
||||
List<String> images = extractImages(productDetail);
|
||||
// 【修改】使用商品配置中的图片数组
|
||||
List<String> images = productConfig.getImages();
|
||||
if (images == null || images.isEmpty()) {
|
||||
// 如果没有图片,使用主图
|
||||
images = new ArrayList<>();
|
||||
if (productConfig.getProductImage() != null) {
|
||||
images.add(productConfig.getProductImage());
|
||||
}
|
||||
}
|
||||
shop.setImages(images);
|
||||
|
||||
shop.setWhiteImages(commonParams.getWhiteImages());
|
||||
@@ -515,66 +562,27 @@ public class BatchPublishServiceImpl implements IBatchPublishService
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商品详情(从缓存或重新查询)
|
||||
* 获取选中的文案内容
|
||||
*/
|
||||
private Map<String, Object> getProductDetail(String skuid) {
|
||||
try {
|
||||
// 调用JD接口查询商品详情
|
||||
Map<String, String> requestBody = new HashMap<>();
|
||||
requestBody.put("promotionContent", skuid);
|
||||
|
||||
String result = generatePromotionContent(requestBody);
|
||||
if (StringUtils.isEmpty(result)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Object resultObj = JSON.parse(result);
|
||||
if (resultObj instanceof List) {
|
||||
List<?> list = (List<?>) resultObj;
|
||||
if (!list.isEmpty() && list.get(0) instanceof Map) {
|
||||
return (Map<String, Object>) list.get(0);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
} catch (Exception e) {
|
||||
log.error("查询商品详情失败: {}", skuid, e);
|
||||
private String getSelectedWenanContent(BatchPublishRequest.ProductItem productConfig) {
|
||||
if (productConfig.getWenan() == null || productConfig.getWenan().isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Integer selectedIndex = productConfig.getSelectedWenanIndex();
|
||||
if (selectedIndex == null) {
|
||||
selectedIndex = 0; // 默认使用第一个
|
||||
}
|
||||
|
||||
if (selectedIndex < 0 || selectedIndex >= productConfig.getWenan().size()) {
|
||||
log.warn("文案索引越界: {}, 文案数量: {}", selectedIndex, productConfig.getWenan().size());
|
||||
selectedIndex = 0;
|
||||
}
|
||||
|
||||
BatchPublishRequest.WenanItem wenanItem = productConfig.getWenan().get(selectedIndex);
|
||||
return wenanItem != null ? wenanItem.getContent() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 提取商品图片
|
||||
*/
|
||||
private List<String> extractImages(Map<String, Object> productDetail) {
|
||||
List<String> images = new ArrayList<>();
|
||||
|
||||
// 从商品详情中提取图片
|
||||
Object imagesObj = productDetail.get("images");
|
||||
if (imagesObj instanceof List) {
|
||||
List<?> imageList = (List<?>) imagesObj;
|
||||
for (Object img : imageList) {
|
||||
if (img != null) {
|
||||
images.add(img.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 如果没有图片,尝试获取主图
|
||||
if (images.isEmpty()) {
|
||||
Object mainImage = productDetail.get("mainImage");
|
||||
if (mainImage != null) {
|
||||
images.add(mainImage.toString());
|
||||
}
|
||||
}
|
||||
|
||||
// 如果还是没有,添加一个占位图
|
||||
if (images.isEmpty()) {
|
||||
images.add("https://placeholder.com/300x300");
|
||||
}
|
||||
|
||||
return images;
|
||||
}
|
||||
|
||||
/**
|
||||
* 延迟上架商品
|
||||
|
||||
Reference in New Issue
Block a user