using System.Text.RegularExpressions; using RoBot.Core.ConstValue; using RoBot.Core.Helper; using RoBot.Goods.Dto; namespace RoBot.Goods.Service { public class GoodsService { private static Regex Regex = new Regex(@"价格[::](\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", ""); // 去除零宽字符 results.Add(new() { Name = name, Price = Convert.ToDecimal(price.Replace("万", "")), LastUpdateTime = DateTime.Now }); } foreach (GoodsInfo item in results) { RedisHelper.Client.HSet(RedisPrefix.GoodsKey, item.Name, item); } } } }