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 == "" || info.BatteryNo=="-1") { 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; } }