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
{
var shopId = long.Parse(shop.ShopId);
var yesterdaycostDetailist = fsql.Select<OrderCostDetail, Order>()
.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<OrderCostDetail>()
.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<SkuRecentCost>(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<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
{
@ -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<SkuRecentCost>();
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<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)
{
Console.WriteLine($"{shop.ShopName},{ex.Message}");
nLogManager.GetLogger($"SKU最近成本-{shop.ShopName}").Error(ex);
}
}

Loading…
Cancel
Save