This commit is contained in:
雷欧(林平凡)
2025-08-08 10:48:16 +08:00
parent d7c08ce505
commit 4708323384
2 changed files with 44 additions and 1 deletions

View File

@@ -32,4 +32,15 @@ public class XbMessage {
@Column(name = "from_wxid", length = 100)
private String fromWxid;
}
@Size(max = 1024)
@Column(name = "first_line", length = 1024)
private String firstLine;
@Size(max = 1024)
@Column(name = "first_sku_name", length = 1024)
private String firstSkuName;
@Column(name = "first_price")
private Double firstPrice;
}

View File

@@ -1449,6 +1449,10 @@ public class JDUtil {
xbMessage.setCreateDate(LocalDate.now());
xbMessage.setTipOriginalMessage(message);
xbMessage.setFromWxid(wxid);
String firstLine = message.split("\n")[0];
Double price = parsePrice(message);
xbMessage.setFirstLine(firstLine);
xbMessage.setFirstPrice(price);
xbMessage = xbMessageRepository.save(xbMessage);
xbMessageId = xbMessage.getId();
}
@@ -2780,4 +2784,32 @@ public class JDUtil {
Matcher matcher = urlPattern.matcher(text);
return matcher.find() ? matcher.group(0) : null;
}
/**
* 从字符串中解析出价格数值
* @param input 包含价格的字符串(如"🔥7.2折⎜◉854.64💰"
* @return 解析出的价格double类型解析失败返回null
*/
public static Double parsePrice(String input) {
if (input == null || input.isEmpty()) {
return null;
}
// 正则表达式:匹配一个或多个数字,可包含一个小数点
Pattern pattern = Pattern.compile("\\d+\\.\\d+|\\d+");
Matcher matcher = pattern.matcher(input);
// 从右向左查找最后一个数字(价格通常在字符串末尾)
double price = -1;
while (matcher.find()) {
String numberStr = matcher.group();
try {
price = Double.parseDouble(numberStr);
} catch (NumberFormatException e) {
// 忽略转换失败的情况
continue;
}
}
return price >= 0 ? price : null;
}
}