Browse Source

批量检测现有sku是否为赠品

master
sanji 1 year ago
parent
commit
05e850bfc5
  1. 6
      BBWY.Server.API/Controllers/TestController.cs
  2. 39
      BBWY.Server.Business/TestBusiness.cs

6
BBWY.Server.API/Controllers/TestController.cs

@ -54,5 +54,11 @@ namespace BBWY.Server.API.Controllers
{ {
testBusiness.Test_20231221(); testBusiness.Test_20231221();
} }
[HttpPost]
public void UpdateSkuGift()
{
testBusiness.UpdateSkuGift();
}
} }
} }

39
BBWY.Server.Business/TestBusiness.cs

@ -6,6 +6,7 @@ using BBWY.Server.Model.Db;
using BBWY.Server.Model.Db.Mds; using BBWY.Server.Model.Db.Mds;
using BBWY.Server.Model.Dto; using BBWY.Server.Model.Dto;
using FreeSql; using FreeSql;
using Jd.Api.Request;
using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Newtonsoft.Json; using Newtonsoft.Json;
@ -425,6 +426,44 @@ namespace BBWY.Server.Business
Console.WriteLine(b["123"]); Console.WriteLine(b["123"]);
} }
public void UpdateSkuGift()
{
var dbSkuIdList = fsql.Select<ProductSku>().Where(ps => ps.IsGift == false).ToList(ps => ps.Id);
var ptList = fsql.Select<PromotionTask>().Where(pt => !string.IsNullOrEmpty(pt.GiftTemplatePutNewSku)).ToList();
var giftSkuList = new List<string>();
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<string>();
var index = 1;
foreach (var skuId in updateGiftSkuIdList)
{
updateList.Add(skuId);
if (updateList.Count() == 20)
{
fsql.Transaction(() =>
{
fsql.Update<ProductSku>(updateList).Set(ps => ps.IsGift, true).ExecuteAffrows();
});
updateList.Clear();
Console.WriteLine($"update productsku gift {index}");
index++;
}
}
if (updateList.Count() > 0)
{
fsql.Transaction(() =>
{
fsql.Update<ProductSku>(updateList).Set(ps => ps.IsGift, true).ExecuteAffrows();
});
updateList.Clear();
Console.WriteLine($"last update productsku gift");
}
}
} }

Loading…
Cancel
Save