1
This commit is contained in:
@@ -61,150 +61,7 @@ public class JDProductService {
|
|||||||
this.xbMessageRepository = xbMessageRepository;
|
this.xbMessageRepository = xbMessageRepository;
|
||||||
this.xbMessageItemRepository = xbMessageItemRepository;
|
this.xbMessageItemRepository = xbMessageItemRepository;
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* 生成转链和方案的方法
|
|
||||||
*
|
|
||||||
* @param message 方案内容,包含商品链接
|
|
||||||
* @param fromWxid
|
|
||||||
* @return 处理后的方案,附带商品信息
|
|
||||||
*/
|
|
||||||
public synchronized HashMap<String, List<String>> generatePromotionContent(String message) {
|
|
||||||
HashMap<String, List<String>> finallyMessage = new HashMap<>();
|
|
||||||
List<String> textList = new ArrayList<>();
|
|
||||||
List<String> imagesList = new ArrayList<>();
|
|
||||||
List<String> dataList = new ArrayList<>();
|
|
||||||
// 最终的方案
|
|
||||||
List<String> finalWenAn = new ArrayList<>();
|
|
||||||
// 提取方案中的所有 u.jd.com 链接
|
|
||||||
List<String> urlList = new ArrayList<>();
|
|
||||||
List<String> priceList = new ArrayList<>();
|
|
||||||
|
|
||||||
// 提取方案中的所有 u.jd.com 链接
|
|
||||||
List<String> urls = extractUJDUrls(message);
|
|
||||||
if (urls.isEmpty()) {
|
|
||||||
textList.add("方案中未找到有效的商品链接,请检查格式是否正确。");
|
|
||||||
finallyMessage.put("text", textList);
|
|
||||||
return finallyMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// 如果需要图片和SKU名称,则代表要把图片下载发过去,还有对应的skuName
|
|
||||||
StringBuilder couponInfo = null;
|
|
||||||
ArrayList<HashMap<String, String>> resultList = new ArrayList<>();
|
|
||||||
|
|
||||||
String format = null;
|
|
||||||
DateFormat dateFormat = new SimpleDateFormat("yyyy年MM月dd日HH时mm分ss秒");
|
|
||||||
|
|
||||||
for (String url : urls) {
|
|
||||||
try {
|
|
||||||
// 重置。不然会一直追加文本内容
|
|
||||||
couponInfo = new StringBuilder();
|
|
||||||
// 新建格式好日期
|
|
||||||
format = dateFormat.format(new Date());
|
|
||||||
// 查询商品信息
|
|
||||||
GoodsQueryResult productInfo = queryProductInfoByUJDUrl(url);
|
|
||||||
if (productInfo == null || productInfo.getCode() != 200) {
|
|
||||||
couponInfo.append("链接查询失败:").append(url).append("\n");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
long totalCount = productInfo.getTotalCount();
|
|
||||||
if (totalCount == 0) {
|
|
||||||
//couponInfo.append("链接类型:优惠券\n\n");
|
|
||||||
} else {
|
|
||||||
couponInfo.append(url).append("\n");
|
|
||||||
urlList.add(url);
|
|
||||||
couponInfo.append("链接类型:商品\n\n");
|
|
||||||
JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(productInfo.getData()[0]));
|
|
||||||
jsonObject.put("url", url);
|
|
||||||
dataList.add(jsonObject.toString());
|
|
||||||
|
|
||||||
HashMap<String, String> itemMap = new HashMap<>();
|
|
||||||
itemMap.put("url", url);
|
|
||||||
itemMap.put("materialUrl", productInfo.getData()[0].getMaterialUrl());
|
|
||||||
itemMap.put("oriItemId", productInfo.getData()[0].getOriItemId());
|
|
||||||
itemMap.put("owner", productInfo.getData()[0].getOwner());
|
|
||||||
itemMap.put("shopId", String.valueOf(productInfo.getData()[0].getShopInfo().getShopId()));
|
|
||||||
itemMap.put("shopName", productInfo.getData()[0].getShopInfo().getShopName());
|
|
||||||
itemMap.put("skuName", productInfo.getData()[0].getSkuName());
|
|
||||||
String replaceAll = itemMap.get("skuName").replaceAll("以旧|政府|换新|领取|国家|补贴|15%|20%|国补|立减|【|】", "");
|
|
||||||
itemMap.put("spuid", String.valueOf(productInfo.getData()[0].getSpuid()));
|
|
||||||
itemMap.put("commission", String.valueOf(productInfo.getData()[0].getCommissionInfo().getCommission()));
|
|
||||||
itemMap.put("commissionShare", String.valueOf(productInfo.getData()[0].getCommissionInfo().getCommissionShare()));
|
|
||||||
|
|
||||||
couponInfo.append("店铺: ").append(itemMap.get("shopName")).append("\n").append("标题: ").append(replaceAll).append("\n").append("自营 POP: ").append(itemMap.get("owner").equals("g") ? " 自营 " : " POP ").append("\n").append("佣金比例: ").append(itemMap.get("commissionShare")).append("\n").append("佣金: ").append(itemMap.get("commission")).append("\n");
|
|
||||||
|
|
||||||
resultList.add(itemMap);
|
|
||||||
String title = "";
|
|
||||||
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (!message.equals(url)) {
|
|
||||||
String[] lines = message.split("\\r?\\n");
|
|
||||||
if (lines.length > 0) {
|
|
||||||
title = lines[0];
|
|
||||||
// 有的换行了
|
|
||||||
if (lines[1].length() > 3 && !lines[1].contains("u.jd")) {
|
|
||||||
title = title + lines[1];
|
|
||||||
}
|
|
||||||
logger.info("文案首行 {}", title);
|
|
||||||
title = title.replaceAll("@|所有人", "");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.error("文案首行异常", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*直接生成闲鱼的商品文案*/
|
|
||||||
StringBuilder sb1 = new StringBuilder();
|
|
||||||
|
|
||||||
sb1.append("(标价到手) ").append(title).append(replaceAll).append("\n").append(WENAN_FANAN_LQD.replaceAll("更新", format + "更新"));
|
|
||||||
//textList.add("闲鱼方案的文案:\n");
|
|
||||||
textList.add(String.valueOf(sb1));
|
|
||||||
StringBuilder sb2 = new StringBuilder();
|
|
||||||
sb2.append("(一键代下) ").append(title).append(replaceAll).append("\n").append(WENAN_ZCXS);
|
|
||||||
//textList.add("闲鱼正常销售:\n");
|
|
||||||
textList.add(String.valueOf(sb2));
|
|
||||||
StringBuilder sb3 = new StringBuilder();
|
|
||||||
sb3.append("(标价到手) ").append(title).append(replaceAll).append("\n").append(WENAN_FANAN_HG.replaceAll("更新", format + "更新"));
|
|
||||||
textList.add(String.valueOf(sb3));
|
|
||||||
|
|
||||||
StringBuilder sb4 = new StringBuilder();
|
|
||||||
sb4.append("【教你下单】 ").append(title).append(replaceAll).append("\n").append(WENAN_FANAN_BX.replaceAll("信息更新日期:", "信息更新日期:" + format));
|
|
||||||
textList.add(String.valueOf(sb4));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
textList.add(String.valueOf(couponInfo));
|
|
||||||
finallyMessage.put("data", dataList);
|
|
||||||
finallyMessage.put("urlList", urlList);
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("处理商品链接时发生异常:{}", url, e);
|
|
||||||
couponInfo.append(" 处理商品链接时发生异常:").append(url).append("\n");
|
|
||||||
textList.add(String.valueOf(couponInfo));
|
|
||||||
finallyMessage.put("text", textList);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* 因为在这里转链返回,没有什么意义,后面走转链不转链,会重新发方案
|
|
||||||
* */
|
|
||||||
StringBuilder wenan = new StringBuilder();
|
|
||||||
|
|
||||||
wenan = new StringBuilder().append(format).append(FANAN_COMMON).append(message);
|
|
||||||
|
|
||||||
|
|
||||||
finalWenAn.add(String.valueOf(wenan));
|
|
||||||
|
|
||||||
finallyMessage.put("text", textList);
|
|
||||||
finallyMessage.put("images", imagesList);
|
|
||||||
finallyMessage.put("finalWenAn", finalWenAn);
|
|
||||||
|
|
||||||
return finallyMessage;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成转链和方案的方法(JSON数组格式)
|
* 生成转链和方案的方法(JSON数组格式)
|
||||||
@@ -555,7 +412,7 @@ public class JDProductService {
|
|||||||
|
|
||||||
// 计算优惠金额
|
// 计算优惠金额
|
||||||
if (priceInfo.getPrice() != null && priceInfo.getLowestCouponPrice() != null) {
|
if (priceInfo.getPrice() != null && priceInfo.getLowestCouponPrice() != null) {
|
||||||
long discount = priceInfo.getPrice() - priceInfo.getLowestCouponPrice();
|
double discount = priceInfo.getPrice() - priceInfo.getLowestCouponPrice();
|
||||||
priceMap.put("discount", discount); // 优惠金额
|
priceMap.put("discount", discount); // 优惠金额
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user