diff --git a/BBWYB.Server.API/Controllers/DataRepairController.cs b/BBWYB.Server.API/Controllers/DataRepairController.cs index bd03010..cbf964c 100644 --- a/BBWYB.Server.API/Controllers/DataRepairController.cs +++ b/BBWYB.Server.API/Controllers/DataRepairController.cs @@ -116,10 +116,10 @@ namespace BBWYB.Server.API.Controllers dataRepairBusiness.SyncPurchaserCategory(); } - [HttpGet] - public void Test() + [HttpPost] + public void RepairPurchaserLocation() { - dataRepairBusiness.Test("广东省"); + dataRepairBusiness.RepairPurchaserLocation(); } } } diff --git a/BBWYB.Server.Business/DataRepair/DataRepairBusiness.cs b/BBWYB.Server.Business/DataRepair/DataRepairBusiness.cs index 991f37c..770fec1 100644 --- a/BBWYB.Server.Business/DataRepair/DataRepairBusiness.cs +++ b/BBWYB.Server.Business/DataRepair/DataRepairBusiness.cs @@ -1143,8 +1143,51 @@ namespace BBWYB.Server.Business } - public void Test(string location) + public void RepairPurchaserLocation() { + var purchaserList = fsql.Select().ToList(); + List> updateList = new List>(); + + foreach (var purchaser in purchaserList) + { + var location = FormatteLocation(purchaser.Location); + if (location != purchaser.Location) + { + updateList.Add(fsql.Update(purchaser.Id).Set(p => p.Location, location)); + } + } + List> tempUpdateList = new List>(); + for (var i = 0; i < updateList.Count(); i++) + { + tempUpdateList.Add(updateList[i]); + if (i != 0 && i % 10 == 0) + { + fsql.Transaction(() => + { + foreach (var update in tempUpdateList) + update.ExecuteAffrows(); + }); + tempUpdateList.Clear(); + } + } + + if (tempUpdateList.Count() > 0) + { + fsql.Transaction(() => + { + foreach (var update in tempUpdateList) + update.ExecuteAffrows(); + }); + tempUpdateList.Clear(); + } + } + + private string FormatteLocation(string location) + { + if (string.IsNullOrEmpty(location)) + return location; + location = location.Trim().Replace(" ", string.Empty); + IDictionary> provinceDictionary = new Dictionary>() { { "省", new List() @@ -1163,24 +1206,19 @@ namespace BBWYB.Server.Business foreach (var provincekey in provinceDictionary.Keys) { var province = provinceDictionary[provincekey].FirstOrDefault(p => location.StartsWith(p)); + if (string.IsNullOrEmpty(province)) + continue; + if (location.Contains(provincekey)) + return location; + location = location.Replace(province, $"{province}{provincekey}"); + if (location.EndsWith(provincekey)) + return location; + if (!location.EndsWith("市")) + location = $"{location}市"; } - - Console.WriteLine(); - } - - private string NormalizeLocationString(string input) - { - // 使用正则表达式移除多余的空格和省市之间的空格 - string normalizedString = Regex.Replace(input, @"\s+", ""); - - // 如果字符串中没有省市的分隔符,则添加一个 - if (!normalizedString.Contains("省") && !normalizedString.Contains("市")) - { - int index = normalizedString.Length / 2; - normalizedString = normalizedString.Insert(index, "省"); - } - - return normalizedString; + //Console.WriteLine(location); + return location; } } } + diff --git a/BBWYB.Server.Business/PurchaseScheme/PurchaseProductAPIService.cs b/BBWYB.Server.Business/PurchaseScheme/PurchaseProductAPIService.cs index 181b34a..1c096f6 100644 --- a/BBWYB.Server.Business/PurchaseScheme/PurchaseProductAPIService.cs +++ b/BBWYB.Server.Business/PurchaseScheme/PurchaseProductAPIService.cs @@ -8,6 +8,7 @@ using Microsoft.Extensions.Caching.Memory; using Newtonsoft.Json.Linq; using System.Net.Http.Headers; using System.Text.RegularExpressions; +using static Google.Protobuf.Reflection.SourceCodeInfo.Types; namespace BBWYB.Server.Business { @@ -35,6 +36,7 @@ namespace BBWYB.Server.Business private List purchaserNameIdList; private IList invalidPurchaserNameList; + private IDictionary> provinceDictionary; public PurchaseProductAPIService(RestApiService restApiService, IMemoryCache memoryCache) { @@ -70,6 +72,21 @@ namespace BBWYB.Server.Business priceIdList = new List() { "1081181309582", "1081181309582", "16347413030316", "13772573013151" }; purchaserNameIdList = new List() { "38229149", "38229148", "38229150" }; + + provinceDictionary = new Dictionary>() + { + { "省", new List() + { + "黑龙江","吉林","辽宁","河北","山西","陕西","甘肃","青海","河南","湖北","湖南","山东","江苏","安徽","浙江","江西","福建","台湾","贵州","四川","云南","广东","海南" + } + }, + { "自治区", new List(){ "内蒙古","西藏"}}, + { "回族自治区", new List(){"宁夏"}}, + { "维吾尔自治区", new List(){"新疆"}}, + { "壮族自治区", new List(){"广西"}}, + { "特别行政区",new List(){ "香港","澳门"}}, + { "市",new List(){ "重庆","北京","天津","上海"}} + }; } public PurchaseSkuBasicInfoResponse GetProductInfo(PurchaseSkuBasicInfoRequest request) @@ -342,6 +359,8 @@ namespace BBWYB.Server.Business } } + location = FormatteLocation(location); + var purchaser = new Purchaser() { Id = jobject["globalData"]["tempModel"]["sellerUserId"].ToString(), @@ -415,34 +434,27 @@ namespace BBWYB.Server.Business } } - //private (Purchaser purchaser, IList purchaseSchemeProductSkus)? LoadFromQTSpider(Platform platform, string productId, string skuId, string purchaseProductId, PurchaseOrderMode priceMode) - //{ - // try - // { - // var response = quanTanProductClient.GetProductInfo(purchaseProductId, qtAppId, qtAppSecret); - // if (response.Status != 200) - // return null; - // return (new Purchaser() - // { - // Id = response.Data.Supplier.VenderId, - // Name = response.Data.Supplier.VerdenName, - // Location = response.Data.Supplier.Location - // }, response.Data.ProductSku.Select(qtsku => new PurchaseSchemeProductSku() - // { - // ProductId = productId, - // SkuId = skuId, - // PurchaseProductId = purchaseProductId, - // Price = qtsku.Price, - // Title = qtsku.Title, - // PurchaseSkuId = qtsku.SkuId, - // PurchaseSkuSpecId = string.Empty, - // Logo = qtsku.Logo - // }).ToList()); - // } - // catch - // { - // return null; - // } - //} + private string FormatteLocation(string location) + { + if (string.IsNullOrEmpty(location)) + return location; + location = location.Trim().Replace(" ", string.Empty); + + foreach (var provincekey in provinceDictionary.Keys) + { + var province = provinceDictionary[provincekey].FirstOrDefault(p => location.StartsWith(p)); + if (string.IsNullOrEmpty(province)) + continue; + if (location.Contains(provincekey)) + return location; + location = location.Replace(province, $"{province}{provincekey}"); + if (location.EndsWith(provincekey)) + return location; + if (!location.EndsWith("市")) + location = $"{location}市"; + } + //Console.WriteLine(location); + return location; + } } }