From d268a17a58eb893ecefe8e034af8f191a5fb922b Mon Sep 17 00:00:00 2001 From: sanji Date: Tue, 12 Dec 2023 17:23:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=80=E8=BF=91=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sync/OrderEstimateCostSyncBusiness.cs | 118 +++++++++++++++--- 1 file changed, 99 insertions(+), 19 deletions(-) diff --git a/BBWY.Server.Business/Sync/OrderEstimateCostSyncBusiness.cs b/BBWY.Server.Business/Sync/OrderEstimateCostSyncBusiness.cs index 60bbfe88..79c3370e 100644 --- a/BBWY.Server.Business/Sync/OrderEstimateCostSyncBusiness.cs +++ b/BBWY.Server.Business/Sync/OrderEstimateCostSyncBusiness.cs @@ -67,6 +67,8 @@ namespace BBWY.Server.Business try { var shopId = long.Parse(shop.ShopId); + + var yesterdaycostDetailist = fsql.Select() .InnerJoin((ocd, o) => ocd.OrderId == o.Id) .Where((ocd, o) => o.ShopId == shopId && @@ -78,7 +80,7 @@ namespace BBWY.Server.Business ocd.IsEnabled == true && ocd.IsEstimateCost == false) .GroupBy((ocd, o) => ocd.SkuId) - .WithTempQuery(g => new { MaxId = g.Sum(g.Value.Item1.Id), SkuId = g.Key }) + .WithTempQuery(g => new { MaxId = g.Max(g.Value.Item1.Id), SkuId = g.Key }) .From() .InnerJoin((ocd1, ocd2) => ocd1.MaxId == ocd2.Id) .ToList((ocd1, ocd2) => ocd2); @@ -108,17 +110,28 @@ namespace BBWY.Server.Business var skuRecentCost = dbSkuRecentCostList.FirstOrDefault(x => x.SkuId == yesocd.SkuId); if (skuRecentCost != null) { - skuRecentCost.SingleConsumableAmount = singleConsumableAmount; - skuRecentCost.SingleDeliveryFreight = singleDeliveryFreight; - skuRecentCost.SingleFirstFreight = singleFirstFreight; - skuRecentCost.SingleFreight = singleFreight; - skuRecentCost.SingleInStorageAmount = singleInStorageAmount; - skuRecentCost.SingleOutStorageAmount = singleOutStorageAmount; - skuRecentCost.SingleSkuAmount = singleSkuAmount; - skuRecentCost.SingleStorageAmount = singleStorageAmount; - skuRecentCost.UpdateTime = DateTime.Now; - var update = fsql.Update(yesocd.SkuId).SetSource(skuRecentCost); - updateSkuRecentCostList.Add(update); + if (skuRecentCost.SingleConsumableAmount != singleConsumableAmount || + skuRecentCost.SingleDeliveryFreight != singleDeliveryFreight || + skuRecentCost.SingleFirstFreight != singleFirstFreight || + skuRecentCost.SingleFreight != singleFreight || + skuRecentCost.SingleInStorageAmount != singleInStorageAmount || + skuRecentCost.SingleOutStorageAmount != singleOutStorageAmount || + skuRecentCost.SingleSkuAmount != singleSkuAmount || + skuRecentCost.SingleStorageAmount != singleStorageAmount) + { + skuRecentCost.UpdateTime = DateTime.Now; + var update = fsql.Update(yesocd.SkuId) + .SetIf(skuRecentCost.SingleConsumableAmount != singleConsumableAmount, s => s.SingleConsumableAmount, singleConsumableAmount) + .SetIf(skuRecentCost.SingleDeliveryFreight != singleDeliveryFreight, s => s.SingleDeliveryFreight, singleDeliveryFreight) + .SetIf(skuRecentCost.SingleFirstFreight != singleFirstFreight, s => s.SingleFirstFreight, singleFirstFreight) + .SetIf(skuRecentCost.SingleFreight != singleFreight, s => s.SingleFreight, singleFreight) + .SetIf(skuRecentCost.SingleInStorageAmount != singleInStorageAmount, s => s.SingleInStorageAmount, singleInStorageAmount) + .SetIf(skuRecentCost.SingleOutStorageAmount != singleOutStorageAmount, s => s.SingleOutStorageAmount, singleOutStorageAmount) + .SetIf(skuRecentCost.SingleSkuAmount != singleSkuAmount, s => s.SingleSkuAmount, singleSkuAmount) + .SetIf(skuRecentCost.SingleStorageAmount != singleStorageAmount, s => s.SingleStorageAmount, singleStorageAmount) + .Set(s => s.UpdateTime, DateTime.Now); + updateSkuRecentCostList.Add(update); + } } else { @@ -143,19 +156,86 @@ namespace BBWY.Server.Business } } - fsql.Transaction(() => + if (insertSkuRecetCostList.Count() > 0) { - if (insertSkuRecetCostList.Count() > 0) - fsql.Insert(insertSkuRecetCostList).ExecuteAffrows(); - if (updateSkuRecentCostList.Count() > 0) + var insertList = new List(); + var index = 0; + foreach (var insert in insertSkuRecetCostList) { - foreach (var update in updateSkuRecentCostList) - update.ExecuteAffrows(); + insertList.Add(insert); + if (insertList.Count() == 50) + { + index++; + Console.WriteLine($"SKU最近成本同步-{shop.ShopName},执行插入{index}"); + fsql.Transaction(() => + { + fsql.Insert(insertList).ExecuteAffrows(); + }); + insertList.Clear(); + } } - }); + + if (insertList.Count() > 0) + { + index++; + Console.WriteLine($"SKU最近成本同步-{shop.ShopName},执行最后插入{index}"); + fsql.Transaction(() => + { + fsql.Insert(insertList).ExecuteAffrows(); + }); + insertList.Clear(); + } + insertSkuRecetCostList.Clear(); + } + + if (updateSkuRecentCostList.Count() > 0) + { + List> updateList = new List>(); + var index = 0; + foreach (var update in updateSkuRecentCostList) + { + updateList.Add(update); + if (updateList.Count == 20) + { + index++; + Console.WriteLine($"SKU最近成本同步-{shop.ShopName},执行更新{index}"); + fsql.Transaction(() => + { + foreach (var _update in updateList) + _update.ExecuteAffrows(); + }); + updateList.Clear(); + } + } + + if (updateList.Count > 0) + { + index++; + Console.WriteLine($"SKU最近成本同步-{shop.ShopName},执行最后更新{index}"); + fsql.Transaction(() => + { + foreach (var _update in updateList) + _update.ExecuteAffrows(); + }); + updateList.Clear(); + } + updateSkuRecentCostList.Clear(); + } + + //fsql.Transaction(() => + //{ + // if (insertSkuRecetCostList.Count() > 0) + // fsql.Insert(insertSkuRecetCostList).ExecuteAffrows(); + // if (updateSkuRecentCostList.Count() > 0) + // { + // foreach (var update in updateSkuRecentCostList) + // update.ExecuteAffrows(); + // } + //}); } catch (Exception ex) { + Console.WriteLine($"{shop.ShopName},{ex.Message}"); nLogManager.GetLogger($"SKU最近成本-{shop.ShopName}").Error(ex); } }