Browse Source

最近同步

pjzs_starttask_update
sanji 2 years ago
parent
commit
d268a17a58
  1. 118
      BBWY.Server.Business/Sync/OrderEstimateCostSyncBusiness.cs

118
BBWY.Server.Business/Sync/OrderEstimateCostSyncBusiness.cs

@ -67,6 +67,8 @@ namespace BBWY.Server.Business
try try
{ {
var shopId = long.Parse(shop.ShopId); var shopId = long.Parse(shop.ShopId);
var yesterdaycostDetailist = fsql.Select<OrderCostDetail, Order>() var yesterdaycostDetailist = fsql.Select<OrderCostDetail, Order>()
.InnerJoin((ocd, o) => ocd.OrderId == o.Id) .InnerJoin((ocd, o) => ocd.OrderId == o.Id)
.Where((ocd, o) => o.ShopId == shopId && .Where((ocd, o) => o.ShopId == shopId &&
@ -78,7 +80,7 @@ namespace BBWY.Server.Business
ocd.IsEnabled == true && ocd.IsEnabled == true &&
ocd.IsEstimateCost == false) ocd.IsEstimateCost == false)
.GroupBy((ocd, o) => ocd.SkuId) .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<OrderCostDetail>() .From<OrderCostDetail>()
.InnerJoin((ocd1, ocd2) => ocd1.MaxId == ocd2.Id) .InnerJoin((ocd1, ocd2) => ocd1.MaxId == ocd2.Id)
.ToList((ocd1, ocd2) => ocd2); .ToList((ocd1, ocd2) => ocd2);
@ -108,17 +110,28 @@ namespace BBWY.Server.Business
var skuRecentCost = dbSkuRecentCostList.FirstOrDefault(x => x.SkuId == yesocd.SkuId); var skuRecentCost = dbSkuRecentCostList.FirstOrDefault(x => x.SkuId == yesocd.SkuId);
if (skuRecentCost != null) if (skuRecentCost != null)
{ {
skuRecentCost.SingleConsumableAmount = singleConsumableAmount; if (skuRecentCost.SingleConsumableAmount != singleConsumableAmount ||
skuRecentCost.SingleDeliveryFreight = singleDeliveryFreight; skuRecentCost.SingleDeliveryFreight != singleDeliveryFreight ||
skuRecentCost.SingleFirstFreight = singleFirstFreight; skuRecentCost.SingleFirstFreight != singleFirstFreight ||
skuRecentCost.SingleFreight = singleFreight; skuRecentCost.SingleFreight != singleFreight ||
skuRecentCost.SingleInStorageAmount = singleInStorageAmount; skuRecentCost.SingleInStorageAmount != singleInStorageAmount ||
skuRecentCost.SingleOutStorageAmount = singleOutStorageAmount; skuRecentCost.SingleOutStorageAmount != singleOutStorageAmount ||
skuRecentCost.SingleSkuAmount = singleSkuAmount; skuRecentCost.SingleSkuAmount != singleSkuAmount ||
skuRecentCost.SingleStorageAmount = singleStorageAmount; skuRecentCost.SingleStorageAmount != singleStorageAmount)
skuRecentCost.UpdateTime = DateTime.Now; {
var update = fsql.Update<SkuRecentCost>(yesocd.SkuId).SetSource(skuRecentCost); skuRecentCost.UpdateTime = DateTime.Now;
updateSkuRecentCostList.Add(update); var update = fsql.Update<SkuRecentCost>(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 else
{ {
@ -143,19 +156,86 @@ namespace BBWY.Server.Business
} }
} }
fsql.Transaction(() => if (insertSkuRecetCostList.Count() > 0)
{ {
if (insertSkuRecetCostList.Count() > 0) var insertList = new List<SkuRecentCost>();
fsql.Insert(insertSkuRecetCostList).ExecuteAffrows(); var index = 0;
if (updateSkuRecentCostList.Count() > 0) foreach (var insert in insertSkuRecetCostList)
{ {
foreach (var update in updateSkuRecentCostList) insertList.Add(insert);
update.ExecuteAffrows(); 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<IUpdate<SkuRecentCost>> updateList = new List<IUpdate<SkuRecentCost>>();
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) catch (Exception ex)
{ {
Console.WriteLine($"{shop.ShopName},{ex.Message}");
nLogManager.GetLogger($"SKU最近成本-{shop.ShopName}").Error(ex); nLogManager.GetLogger($"SKU最近成本-{shop.ShopName}").Error(ex);
} }
} }

Loading…
Cancel
Save