|
|
|
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 bool UploadCloud(List<SwapOrderReportCloud> list, int uploadType)
|
|
|
|
{
|
|
|
|
if (list.Count <= 0)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
List<int> swapOrderIds = list.Select(i => i.SwapOrderId).ToList();
|
|
|
|
List<SwapOrder> swapOrders =
|
|
|
|
_swapOrderRepository.QueryListByClause(i => swapOrderIds.Contains(i.Id) && i.CloudReportStatus == 0);
|
|
|
|
|
|
|
|
if (swapOrders.Count <= 0)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
List<string> swapOrderSn = swapOrders.Select(i => i.Sn).ToList();
|
|
|
|
|
|
|
|
List<SwapOrderBattery> batterys =
|
|
|
|
_swapOrderBatteryRepository.QueryListByClause(i =>
|
|
|
|
swapOrderSn.Contains(i.SwapOrderSn) && i.DownBatteryNo != null);
|
|
|
|
|
|
|
|
if (batterys.Count <= 0)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
IDictionary<string, SwapOrderBattery> dictionary = batterys.ToDictionary(i => i.SwapOrderSn);
|
|
|
|
|
|
|
|
|
|
|
|
Dictionary<int, SwapOrderReportCloud> swapOrderReportClouds = list.ToDictionary(i => i.SwapOrderId);
|
|
|
|
|
|
|
|
|
|
|
|
List<SwapOrder> updateDbOrder = new List<SwapOrder>();
|
|
|
|
List<SwapOrderReportCloud> updateDbCloudReport = new List<SwapOrderReportCloud>();
|
|
|
|
|
|
|
|
foreach (var swapOrder in swapOrders)
|
|
|
|
{
|
|
|
|
dictionary.TryGetValue(swapOrder.Sn, out SwapOrderBattery swapOrderBattery);
|
|
|
|
if (null == swapOrderBattery)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (null == swapOrderBattery.DownBatteryNo)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(swapOrder.CloudSn))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
var count = _swapOrderRepository.GetCount(i =>
|
|
|
|
i.SwapResult == 1 && i.SwapEndTime >= DateTime.Today && i.SwapEndTime < swapOrder.SwapEndTime);
|
|
|
|
|
|
|
|
var uploadSwapOrder = CloudApi.UploadSwapOrder(swapOrder, count++, swapOrderBattery, uploadType);
|
|
|
|
swapOrderReportClouds.TryGetValue(swapOrder.Id, out SwapOrderReportCloud value);
|
|
|
|
if (uploadSwapOrder == 0)
|
|
|
|
{
|
|
|
|
swapOrder.CloudReportStatus = 1;
|
|
|
|
updateDbOrder.Add(swapOrder);
|
|
|
|
|
|
|
|
value.CloudReportStatus = 1;
|
|
|
|
value.UploadTime = DateTime.Now;
|
|
|
|
updateDbCloudReport.Add(value);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//当 cloudReportStatus >=100 就不需要上传了
|
|
|
|
value.CloudReportStatus++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (updateDbOrder.Count > 0)
|
|
|
|
{
|
|
|
|
_swapOrderRepository.Update(updateDbOrder);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (updateDbCloudReport.Count > 0)
|
|
|
|
{
|
|
|
|
_reportCloudRepository.Update(updateDbCloudReport);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|