1
This commit is contained in:
@@ -59,6 +59,28 @@ public class BatchPublishServiceImpl implements IBatchPublishService
|
||||
@Autowired
|
||||
private IOuterIdGeneratorService outerIdGeneratorService;
|
||||
|
||||
/**
|
||||
* 清理文本中的所有URL链接
|
||||
*
|
||||
* @param text 原始文本
|
||||
* @return 清理后的文本
|
||||
*/
|
||||
private String cleanUrlsFromText(String text) {
|
||||
if (text == null || text.isEmpty()) {
|
||||
return text;
|
||||
}
|
||||
|
||||
// 匹配所有URL(包括http、https)
|
||||
// 匹配到空格、换行或中文字符为止
|
||||
String cleaned = text.replaceAll("https?://[^\\s\\u4e00-\\u9fa5]+", "");
|
||||
|
||||
// 清理可能留下的多余空白和换行
|
||||
cleaned = cleaned.replaceAll("\\s+", " ");
|
||||
cleaned = cleaned.replaceAll("^\\s+|\\s+$", "");
|
||||
|
||||
return cleaned;
|
||||
}
|
||||
|
||||
/**
|
||||
* 调用京东接口生成推广内容
|
||||
*/
|
||||
@@ -80,14 +102,33 @@ public class BatchPublishServiceImpl implements IBatchPublishService
|
||||
com.alibaba.fastjson2.JSONArray array = (com.alibaba.fastjson2.JSONArray) parsed;
|
||||
for (int i = 0; i < array.size(); i++) {
|
||||
JSONObject item = array.getJSONObject(i);
|
||||
|
||||
// 提取 price 字段
|
||||
if (item.containsKey("priceInfo") && item.getJSONObject("priceInfo").containsKey("price")) {
|
||||
item.put("price", item.getJSONObject("priceInfo").get("price"));
|
||||
}
|
||||
// 清理文案中的URL
|
||||
|
||||
// 清理 content 字段中的URL
|
||||
if (item.containsKey("content")) {
|
||||
String content = item.getString("content");
|
||||
content = content.replaceAll("https?://[\\S]+", "");
|
||||
item.put("content", content.trim());
|
||||
content = cleanUrlsFromText(content);
|
||||
item.put("content", content);
|
||||
}
|
||||
|
||||
// 【新增】清理 wenan 数组中每个文案的 URL
|
||||
if (item.containsKey("wenan")) {
|
||||
Object wenanObj = item.get("wenan");
|
||||
if (wenanObj instanceof com.alibaba.fastjson2.JSONArray) {
|
||||
com.alibaba.fastjson2.JSONArray wenanArray = (com.alibaba.fastjson2.JSONArray) wenanObj;
|
||||
for (int j = 0; j < wenanArray.size(); j++) {
|
||||
JSONObject wenanItem = wenanArray.getJSONObject(j);
|
||||
if (wenanItem != null && wenanItem.containsKey("content")) {
|
||||
String wenanContent = wenanItem.getString("content");
|
||||
wenanContent = cleanUrlsFromText(wenanContent);
|
||||
wenanItem.put("content", wenanContent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
result = array.toJSONString();
|
||||
|
||||
Reference in New Issue
Block a user