Browse Source

产业带合并

liangku_skuoptimazation
shanji 1 year ago
parent
commit
5b6851e7ca
  1. 6
      BBWYB.Server.API/Controllers/DataRepairController.cs
  2. 74
      BBWYB.Server.Business/DataRepair/DataRepairBusiness.cs
  3. 70
      BBWYB.Server.Business/PurchaseScheme/PurchaseProductAPIService.cs

6
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();
}
}
}

74
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<Purchaser>().ToList();
List<IUpdate<Purchaser>> updateList = new List<IUpdate<Purchaser>>();
foreach (var purchaser in purchaserList)
{
var location = FormatteLocation(purchaser.Location);
if (location != purchaser.Location)
{
updateList.Add(fsql.Update<Purchaser>(purchaser.Id).Set(p => p.Location, location));
}
}
List<IUpdate<Purchaser>> tempUpdateList = new List<IUpdate<Purchaser>>();
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<string, List<string>> provinceDictionary = new Dictionary<string, List<string>>()
{
{ "省", new List<string>()
@ -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;
}
}
}

70
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<string> purchaserNameIdList;
private IList<string> invalidPurchaserNameList;
private IDictionary<string, List<string>> provinceDictionary;
public PurchaseProductAPIService(RestApiService restApiService, IMemoryCache memoryCache)
{
@ -70,6 +72,21 @@ namespace BBWYB.Server.Business
priceIdList = new List<string>() { "1081181309582", "1081181309582", "16347413030316", "13772573013151" };
purchaserNameIdList = new List<string>() { "38229149", "38229148", "38229150" };
provinceDictionary = new Dictionary<string, List<string>>()
{
{ "省", new List<string>()
{
"黑龙江","吉林","辽宁","河北","山西","陕西","甘肃","青海","河南","湖北","湖南","山东","江苏","安徽","浙江","江西","福建","台湾","贵州","四川","云南","广东","海南"
}
},
{ "自治区", new List<string>(){ "内蒙古","西藏"}},
{ "回族自治区", new List<string>(){"宁夏"}},
{ "维吾尔自治区", new List<string>(){"新疆"}},
{ "壮族自治区", new List<string>(){"广西"}},
{ "特别行政区",new List<string>(){ "香港","澳门"}},
{ "市",new List<string>(){ "重庆","北京","天津","上海"}}
};
}
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<PurchaseSchemeProductSku> 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;
}
}
}

Loading…
Cancel
Save