using System.Text.RegularExpressions;
using RoBot.Core;
using RoBot.Core.ConstValue;
using RoBot.Core.Helper;
using RoBot.Start.Service.Dto;
namespace RoBot.Start.Service.Impl
{
public class GoodsService
{
private static Regex Regex = new Regex(@"价格[::](\d+(?:\.\d+)?[万亿])\s+([^\s]+)");
///
/// 解析物品信息
///
///
public static void AnalysisGoodsText(string text)
{
if (string.IsNullOrWhiteSpace(text)) return;
List results = new();
MatchCollection matches = Regex.Matches(text);
foreach (Match match in matches)
{
string price = match.Groups[1].Value;
string name = match.Groups[2].Value.Replace("\u200b", "").Replace("\u200c", "").Replace("\u200d", ""); // 去除零宽字符
GoodsInfo gds = new()
{
Name = name,
Price = Utils.ParseChineseNumber(price),
ShowPriceDesc = price,
LastUpdateTime = DateTime.Now
};
results.Add(gds);
}
foreach (GoodsInfo item in results)
{
RedisHelper.Client.HSet(RedisPrefix.GoodsKey, item.Name, item);
}
}
}
}