diff --git a/BBWY.Server.API/Controllers/TestController.cs b/BBWY.Server.API/Controllers/TestController.cs index fce9a488..edbdf8b6 100644 --- a/BBWY.Server.API/Controllers/TestController.cs +++ b/BBWY.Server.API/Controllers/TestController.cs @@ -36,5 +36,11 @@ namespace BBWY.Server.API.Controllers { testBusiness.DeleteJDTask(); } + + [HttpPost] + public void RepairOrderProfit() + { + testBusiness.RepairOrderProfit(); + } } } diff --git a/BBWY.Server.Business/TestBusiness.cs b/BBWY.Server.Business/TestBusiness.cs index a21a887a..848d4938 100644 --- a/BBWY.Server.Business/TestBusiness.cs +++ b/BBWY.Server.Business/TestBusiness.cs @@ -272,6 +272,55 @@ namespace BBWY.Server.Business } } + public void RepairOrderProfit() + { + var startTime = DateTime.Parse("2023-10-16"); + var orderList = fsql.Select().Where(o => o.FreightPrice > 0 && + o.IsGift == false && + o.OrderState != Enums.OrderState.已取消 && + o.StorageType != null && + o.StorageType != Enums.StorageType.SD && + o.StartTime >= startTime) + .ToList(); + + var orderIdList = orderList.Select(o => o.Id).ToList(); + var orderCostList = fsql.Select(orderIdList).ToList(); + List> updateList = new List>(); + int index = 0; + foreach (var orderCost in orderCostList) + { + index++; + Console.WriteLine($"{DateTime.Now} OrderProgress {index}/{orderCostList.Count()}"); + var order = orderList.FirstOrDefault(o => o.Id == orderCost.OrderId); + if (order == null) + continue; + orderCost.CalculationOrderProfitAndCost(order, null); + updateList.Add(fsql.Update(orderCost.OrderId).Set(oc => oc.Profit, orderCost.Profit) + .Set(oc => oc.PlatformCommissionAmount, orderCost.PlatformCommissionAmount)); + if (updateList.Count() > 10) + { + Console.WriteLine($"{DateTime.Now} 执行数据库更新"); + fsql.Transaction(() => + { + foreach (var update in updateList) + update.ExecuteAffrows(); + }); + updateList.Clear(); + } + } + + if (updateList.Count() > 0) + { + Console.WriteLine($"{DateTime.Now} 最后执行数据库更新"); + fsql.Transaction(() => + { + foreach (var update in updateList) + update.ExecuteAffrows(); + }); + updateList.Clear(); + } + } + public void DeleteJDTask() { var appKey = "E1AA9247D5583A6D87449CE6AB290185";