From e8f118f86f3b735c19b29efb011582a00dd6e279 Mon Sep 17 00:00:00 2001 From: lxw Date: Fri, 31 May 2024 12:14:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8D=A2=E7=94=B5=E8=AE=A2=E5=8D=95=E4=B8=8A?= =?UTF-8?q?=E6=8A=A5=E4=BA=91=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MyTask/SwapOrderReportCloudTask.cs | 100 +--------------- Service/Mgr/SwapOrderMgr.cs | 112 ++++++++++++++++++ Service/Station/MonitorService.cs | 1 + Service/Station/SwapOrderService.cs | 72 +++++++++-- WebStarter/Controllers/SwapOrderController.cs | 5 +- 5 files changed, 179 insertions(+), 111 deletions(-) create mode 100644 Service/Mgr/SwapOrderMgr.cs diff --git a/Service/BusinessTask/MyTask/SwapOrderReportCloudTask.cs b/Service/BusinessTask/MyTask/SwapOrderReportCloudTask.cs index 2ce035f..57bbb66 100644 --- a/Service/BusinessTask/MyTask/SwapOrderReportCloudTask.cs +++ b/Service/BusinessTask/MyTask/SwapOrderReportCloudTask.cs @@ -7,6 +7,7 @@ using Repository.Station; using Service.Execute; using Service.Execute.Api; using Service.Execute.Model; +using Service.Mgr; namespace Service.BusinessTask.MyTask; @@ -20,14 +21,8 @@ public class SwapOrderReportCloudTask : AbstractTaskHandler private readonly SwapOrderReportCloudRepository _reportCloudRepository = AppInfo.Container.Resolve(); - private readonly SwapOrderRepository _swapOrderRepository = - AppInfo.Container.Resolve(); - - private readonly SwapOrderBatteryRepository _swapOrderBatteryRepository = - AppInfo.Container.Resolve(); - - private readonly BinInfoRepository _binInfoRepository = - AppInfo.Container.Resolve(); + private readonly SwapOrderMgr _swapOrderMgr = + AppInfo.Container.Resolve(); protected override int Interval() { @@ -38,94 +33,7 @@ public class SwapOrderReportCloudTask : AbstractTaskHandler { List list = _reportCloudRepository.QueryListByClause(i => i.CloudReportStatus == 0); - if (list.Count <= 0) - { - return; - } - - List swapOrderIds = list.Select(i => i.SwapOrderId).ToList(); - - List swapOrders = - _swapOrderRepository.QueryListByClause(i => swapOrderIds.Contains(i.Id) && i.CloudReportStatus == 0); - - if (swapOrders.Count <= 0) - { - return; - } - - List swapOrderSn = swapOrders.Select(i => i.Sn).ToList(); - - List batterys = - _swapOrderBatteryRepository.QueryListByClause(i => swapOrderSn.Contains(i.SwapOrderSn)); - - if (batterys.Count <= 0) - { - return; - } - - IDictionary dictionary = batterys.ToDictionary(i => i.SwapOrderSn); - - List downBatteryBinNos = batterys.Select(i => i.DownBatteryBinNo.ToString()).ToList(); - Dictionary binInfosMap = _binInfoRepository - .QueryListByClause(i => downBatteryBinNos.Contains(i.No)).ToDictionary(i => i.No); - - List updateDbBattery = new List(); - List updateDbOrder = new List(); - List updateDbCloudReport = new List(); - - - Dictionary swapOrderReportClouds = list.ToDictionary(i => i.SwapOrderId); - foreach (var swapOrder in swapOrders) - { - dictionary.TryGetValue(swapOrder.Sn, out SwapOrderBattery swapOrderBattery); - if (null == swapOrderBattery) - { - continue; - } - - if (null == swapOrderBattery.DownBatteryNo) - { - //更新换下电池包 - binInfosMap.TryGetValue(swapOrderBattery.DownBatteryBinNo.ToString(), out BinInfo info); - if (info.BatteryNo == null || info.BatteryNo == "") - { - continue; - } - - swapOrderBattery.DownBatteryNo = info.BatteryNo; - swapOrderBattery.DownBatterySoc = info.Soc; - swapOrderBattery.DownBatterySoe = info.Soe; - updateDbBattery.Add(swapOrderBattery); - } - - //TODO::获取本日第几次换电 - var count = _swapOrderRepository.GetCount(i => - i.SwapResult == 1 && i.SwapEndTime >= DateTime.Today && i.SwapEndTime < swapOrder.SwapEndTime); - var uploadSwapOrder = CloudApi.UploadSwapOrder(swapOrder, count++, swapOrderBattery, 1); - if (uploadSwapOrder == 0) - { - swapOrder.CloudReportStatus = 1; - updateDbOrder.Add(swapOrder); - swapOrderReportClouds.TryGetValue(swapOrder.Id, out SwapOrderReportCloud value); - value.CloudReportStatus = 1; - updateDbCloudReport.Add(value); - } - } - - if (updateDbBattery.Count > 0) - { - _swapOrderBatteryRepository.Update(updateDbBattery); - } - - if (updateDbOrder.Count > 0) - { - _swapOrderRepository.Update(updateDbOrder); - } - - if (updateDbCloudReport.Count > 0) - { - _reportCloudRepository.Update(updateDbCloudReport); - } + _swapOrderMgr.UploadCloud(list); } protected override string Name() diff --git a/Service/Mgr/SwapOrderMgr.cs b/Service/Mgr/SwapOrderMgr.cs new file mode 100644 index 0000000..d11fb6c --- /dev/null +++ b/Service/Mgr/SwapOrderMgr.cs @@ -0,0 +1,112 @@ +using Entity.DbModel.Station; +using HybirdFrameworkCore.Autofac.Attribute; +using Repository.Station; +using Service.Execute.Api; + +namespace Service.Mgr; + +[Scope()] +public class SwapOrderMgr +{ + public SwapOrderReportCloudRepository _reportCloudRepository { get; set; } + + public SwapOrderRepository _swapOrderRepository { get; set; } + + public SwapOrderBatteryRepository _swapOrderBatteryRepository { get; set; } + + public BinInfoRepository _BinInfoRepository { get; set; } + + public bool UploadCloud(List list) + { + if (list.Count <= 0) + { + return false; + } + + List swapOrderIds = list.Select(i => i.SwapOrderId).ToList(); + List swapOrders = + _swapOrderRepository.QueryListByClause(i => swapOrderIds.Contains(i.Id) && i.CloudReportStatus == 0); + + if (swapOrders.Count <= 0) + { + return false; + } + + List swapOrderSn = swapOrders.Select(i => i.Sn).ToList(); + + List batterys = + _swapOrderBatteryRepository.QueryListByClause(i => swapOrderSn.Contains(i.SwapOrderSn)); + + if (batterys.Count <= 0) + { + return false; + } + + IDictionary dictionary = batterys.ToDictionary(i => i.SwapOrderSn); + + List downBatteryBinNos = batterys.Select(i => i.DownBatteryBinNo.ToString()).ToList(); + Dictionary binInfosMap = _BinInfoRepository + .QueryListByClause(i => downBatteryBinNos.Contains(i.No)).ToDictionary(i => i.No); + + + Dictionary swapOrderReportClouds = list.ToDictionary(i => i.SwapOrderId); + + + List updateDbBattery = new List(); + List updateDbOrder = new List(); + List updateDbCloudReport = new List(); + + foreach (var swapOrder in swapOrders) + { + dictionary.TryGetValue(swapOrder.Sn, out SwapOrderBattery swapOrderBattery); + if (null == swapOrderBattery) + { + continue; + } + + if (null == swapOrderBattery.DownBatteryNo) + { + //更新换下电池包 + binInfosMap.TryGetValue(swapOrderBattery.DownBatteryBinNo.ToString(), out BinInfo info); + if (info.BatteryNo == null || info.BatteryNo == "") + { + continue; + } + + swapOrderBattery.DownBatteryNo = info.BatteryNo; + swapOrderBattery.DownBatterySoc = info.Soc; + swapOrderBattery.DownBatterySoe = info.Soe; + updateDbBattery.Add(swapOrderBattery); + } + + var count = _swapOrderRepository.GetCount(i => + i.SwapResult == 1 && i.SwapEndTime >= DateTime.Today && i.SwapEndTime < swapOrder.SwapEndTime); + var uploadSwapOrder = CloudApi.UploadSwapOrder(swapOrder, count++, swapOrderBattery, 1); + if (uploadSwapOrder == 0) + { + swapOrder.CloudReportStatus = 1; + updateDbOrder.Add(swapOrder); + swapOrderReportClouds.TryGetValue(swapOrder.Id, out SwapOrderReportCloud value); + value.CloudReportStatus = 1; + updateDbCloudReport.Add(value); + } + } + + if (updateDbBattery.Count > 0) + { + _swapOrderBatteryRepository.Update(updateDbBattery); + } + + if (updateDbOrder.Count > 0) + { + _swapOrderRepository.Update(updateDbOrder); + } + + if (updateDbCloudReport.Count > 0) + { + _reportCloudRepository.Update(updateDbCloudReport); + } + + return true; + } +} \ No newline at end of file diff --git a/Service/Station/MonitorService.cs b/Service/Station/MonitorService.cs index 50750dc..e8ec5d5 100644 --- a/Service/Station/MonitorService.cs +++ b/Service/Station/MonitorService.cs @@ -115,6 +115,7 @@ public class MonitorService return Result.Success(resp); } + //TODO:: 首页--当月,当日换电量 public Result SwapAndChargingCount() { SwapAndChargingCountResp chargingCountResp = new() diff --git a/Service/Station/SwapOrderService.cs b/Service/Station/SwapOrderService.cs index 0d6cb9a..068dd4c 100644 --- a/Service/Station/SwapOrderService.cs +++ b/Service/Station/SwapOrderService.cs @@ -6,22 +6,42 @@ using HybirdFrameworkCore.Entity; using Repository.Station; using SqlSugar; using System.Linq.Expressions; +using Service.Mgr; namespace Service.Station; + /// /// 充电订单 /// [Scope("SingleInstance")] public class SwapOrderService : BaseServices { - SwapOrderRepository swapOrderRepository; + public SwapOrderRepository swapOrderRepository { get; set; } + public SwapOrderReportCloudRepository SwapOrderReportCloudRepository { get; set; } + + public SwapOrderMgr SwapOrderMgr { get; set; } + public SwapOrderService(SwapOrderRepository dal) { - swapOrderRepository = dal; BaseDal = dal; } + public Result UploadCloud(int id) + { + List list = + SwapOrderReportCloudRepository.QueryListByClause(i => i.CloudReportStatus == 0 && i.SwapOrderId == id); + + if (list.Count <= 0) + { + return Result.Fail("当前换电订单不满足上报云平台的条件"); + } + + + return SwapOrderMgr.UploadCloud(list) ? Result.Success() : Result.Fail(); + } + + /// /// 根据条件查询分页数据 /// @@ -29,48 +49,76 @@ public class SwapOrderService : BaseServices /// public PageResult QuerySwapOrder(QuerySwapOrderPageReq swapOrder) { - //创建一个空的表达式树 Expression> where = null; //// 定义参数表达式 ParameterExpression parameter = Expression.Parameter(typeof(SwapOrder), "u"); #region 构建动态查询树 + if (!string.IsNullOrEmpty(swapOrder.Sn)) { Expression> condition2Expr = u => u.Sn == swapOrder.Sn; - where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter); + where = where == null + ? condition2Expr + : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), + parameter); } + if (!string.IsNullOrEmpty(swapOrder.VehicleNo)) { Expression> condition2Expr = u => u.VehicleNo == swapOrder.VehicleNo; - where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter); + where = where == null + ? condition2Expr + : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), + parameter); } + if (!string.IsNullOrEmpty(swapOrder.VehicleMac)) { Expression> condition2Expr = u => u.VehicleMac == swapOrder.VehicleMac; - where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter); + where = where == null + ? condition2Expr + : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), + parameter); } + if (!string.IsNullOrEmpty(swapOrder.VehicleVin)) { Expression> condition2Expr = u => u.VehicleVin == swapOrder.VehicleVin; - where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter); + where = where == null + ? condition2Expr + : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), + parameter); } + if (swapOrder.SwapBeginTime != null && swapOrder.SwapBeginTime != DateTime.MinValue) { Expression> condition2Expr = u => u.SwapBeginTime == swapOrder.SwapBeginTime; - where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter); + where = where == null + ? condition2Expr + : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), + parameter); } + if (swapOrder.SwapEndTime != null && swapOrder.SwapEndTime != DateTime.MinValue) { Expression> condition2Expr = u => u.SwapEndTime == swapOrder.SwapEndTime; - where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter); + where = where == null + ? condition2Expr + : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), + parameter); } + if (swapOrder.SwapResult != 0) { Expression> condition2Expr = u => u.SwapResult == swapOrder.SwapResult; - where = where == null ? condition2Expr : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter); + where = where == null + ? condition2Expr + : Expression.Lambda>(Expression.AndAlso(where.Body, condition2Expr.Body), + parameter); } + #endregion //查询 @@ -80,11 +128,9 @@ public class SwapOrderService : BaseServices //{ // swapOrderResp.Rows[0].BatteryList.AddRange() //} - + //List BatteryList = new List(); //List StepList = new List(); return PageResult.ConvertPage(swapOrderRepository.QueryIPageByCause(swapOrder, where)); - - } } \ No newline at end of file diff --git a/WebStarter/Controllers/SwapOrderController.cs b/WebStarter/Controllers/SwapOrderController.cs index 6bea22e..acd358f 100644 --- a/WebStarter/Controllers/SwapOrderController.cs +++ b/WebStarter/Controllers/SwapOrderController.cs @@ -150,8 +150,9 @@ public class SwapOrderController : ControllerBase /// /// [HttpGet("UploadCloud/{id}")] - public async Task> UploadCloud(long id) + public Result UploadCloud(int id) { - return Result.Success(null); + + return swapOrderService.UploadCloud(id); } } \ No newline at end of file