1
This commit is contained in:
@@ -20,6 +20,7 @@ import com.ruoyi.jarvis.service.IBatchPublishService;
|
||||
import com.ruoyi.jarvis.service.IJDOrderService;
|
||||
import com.ruoyi.jarvis.service.IOuterIdGeneratorService;
|
||||
import com.ruoyi.jarvis.util.LineReportParser;
|
||||
import com.ruoyi.common.utils.http.HttpUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -40,7 +41,7 @@ import java.util.concurrent.TimeUnit;
|
||||
@Service
|
||||
public class BatchPublishServiceImpl implements IBatchPublishService
|
||||
{
|
||||
private static final Logger log = LoggerFactory.getLogger(BatchPublishServiceImpl.java);
|
||||
private static final Logger log = LoggerFactory.getLogger(BatchPublishServiceImpl.class);
|
||||
|
||||
@Autowired
|
||||
private BatchPublishTaskMapper taskMapper;
|
||||
@@ -50,10 +51,55 @@ public class BatchPublishServiceImpl implements IBatchPublishService
|
||||
|
||||
@Autowired
|
||||
private IJDOrderService jdOrderService;
|
||||
|
||||
// 京东接口配置
|
||||
private final static String requestUrl = "http://192.168.8.88:6666/jd/";
|
||||
private final static String skey = "your_skey_here";
|
||||
|
||||
@Autowired
|
||||
private IOuterIdGeneratorService outerIdGeneratorService;
|
||||
|
||||
/**
|
||||
* 调用京东接口生成推广内容
|
||||
*/
|
||||
private String generatePromotionContent(Map<String, String> requestBody) {
|
||||
try {
|
||||
String url = requestUrl + "generatePromotionContent";
|
||||
JSONObject param = new JSONObject();
|
||||
param.put("skey", skey);
|
||||
param.put("promotionContent", requestBody.get("promotionContent"));
|
||||
String result = HttpUtils.sendJsonPost(url, param.toJSONString());
|
||||
|
||||
// 尝试将 priceInfo.price 提取为顶层 price 字段,并清理文案中的 URL
|
||||
try {
|
||||
Object parsed = JSON.parse(result);
|
||||
if (parsed instanceof com.alibaba.fastjson2.JSONArray) {
|
||||
com.alibaba.fastjson2.JSONArray array = (com.alibaba.fastjson2.JSONArray) parsed;
|
||||
for (int i = 0; i < array.size(); i++) {
|
||||
JSONObject item = array.getJSONObject(i);
|
||||
if (item.containsKey("priceInfo") && item.getJSONObject("priceInfo").containsKey("price")) {
|
||||
item.put("price", item.getJSONObject("priceInfo").get("price"));
|
||||
}
|
||||
// 清理文案中的URL
|
||||
if (item.containsKey("content")) {
|
||||
String content = item.getString("content");
|
||||
content = content.replaceAll("https?://[\\S]+", "");
|
||||
item.put("content", content.trim());
|
||||
}
|
||||
}
|
||||
result = array.toJSONString();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("处理推广内容响应失败", e);
|
||||
}
|
||||
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
log.error("调用京东推广内容接口失败", e);
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析线报消息,提取商品列表
|
||||
*/
|
||||
@@ -116,7 +162,7 @@ public class BatchPublishServiceImpl implements IBatchPublishService
|
||||
Map<String, String> requestBody = new HashMap<>();
|
||||
requestBody.put("promotionContent", urlOrSkuid);
|
||||
|
||||
String result = jdOrderService.generatePromotionContent(requestBody);
|
||||
String result = generatePromotionContent(requestBody);
|
||||
|
||||
if (StringUtils.isEmpty(result)) {
|
||||
return null;
|
||||
@@ -456,7 +502,7 @@ public class BatchPublishServiceImpl implements IBatchPublishService
|
||||
Map<String, String> requestBody = new HashMap<>();
|
||||
requestBody.put("promotionContent", skuid);
|
||||
|
||||
String result = jdOrderService.generatePromotionContent(requestBody);
|
||||
String result = generatePromotionContent(requestBody);
|
||||
if (StringUtils.isEmpty(result)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user