diff --git a/BBWY.Server.API/Controllers/TestController.cs b/BBWY.Server.API/Controllers/TestController.cs index c05c2808..5099a92f 100644 --- a/BBWY.Server.API/Controllers/TestController.cs +++ b/BBWY.Server.API/Controllers/TestController.cs @@ -54,5 +54,11 @@ namespace BBWY.Server.API.Controllers { testBusiness.Test_20231221(); } + + [HttpPost] + public void UpdateSkuGift() + { + testBusiness.UpdateSkuGift(); + } } } diff --git a/BBWY.Server.Business/TestBusiness.cs b/BBWY.Server.Business/TestBusiness.cs index c8ed0a23..f8551db3 100644 --- a/BBWY.Server.Business/TestBusiness.cs +++ b/BBWY.Server.Business/TestBusiness.cs @@ -6,6 +6,7 @@ using BBWY.Server.Model.Db; using BBWY.Server.Model.Db.Mds; using BBWY.Server.Model.Dto; using FreeSql; +using Jd.Api.Request; using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.Options; using Newtonsoft.Json; @@ -425,6 +426,44 @@ namespace BBWY.Server.Business Console.WriteLine(b["123"]); } + public void UpdateSkuGift() + { + var dbSkuIdList = fsql.Select().Where(ps => ps.IsGift == false).ToList(ps => ps.Id); + var ptList = fsql.Select().Where(pt => !string.IsNullOrEmpty(pt.GiftTemplatePutNewSku)).ToList(); + var giftSkuList = new List(); + var splitChar = new char[] { ',' }; + foreach (var pt in ptList) + { + giftSkuList.AddRange(pt.GiftTemplatePutNewSku.Split(splitChar, StringSplitOptions.RemoveEmptyEntries)); + } + var updateGiftSkuIdList = dbSkuIdList.Intersect(giftSkuList).ToList(); + + var updateList = new List(); + var index = 1; + foreach (var skuId in updateGiftSkuIdList) + { + updateList.Add(skuId); + if (updateList.Count() == 20) + { + fsql.Transaction(() => + { + fsql.Update(updateList).Set(ps => ps.IsGift, true).ExecuteAffrows(); + }); + updateList.Clear(); + Console.WriteLine($"update productsku gift {index}"); + index++; + } + } + if (updateList.Count() > 0) + { + fsql.Transaction(() => + { + fsql.Update(updateList).Set(ps => ps.IsGift, true).ExecuteAffrows(); + }); + updateList.Clear(); + Console.WriteLine($"last update productsku gift"); + } + } }