换电订单上报云端

zw
lxw 6 months ago
parent b5f2cd0a75
commit e8f118f86f

@ -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<SwapOrderReportCloudRepository>();
private readonly SwapOrderRepository _swapOrderRepository =
AppInfo.Container.Resolve<SwapOrderRepository>();
private readonly SwapOrderBatteryRepository _swapOrderBatteryRepository =
AppInfo.Container.Resolve<SwapOrderBatteryRepository>();
private readonly BinInfoRepository _binInfoRepository =
AppInfo.Container.Resolve<BinInfoRepository>();
private readonly SwapOrderMgr _swapOrderMgr =
AppInfo.Container.Resolve<SwapOrderMgr>();
protected override int Interval()
{
@ -38,94 +33,7 @@ public class SwapOrderReportCloudTask : AbstractTaskHandler
{
List<SwapOrderReportCloud> list = _reportCloudRepository.QueryListByClause(i => i.CloudReportStatus == 0);
if (list.Count <= 0)
{
return;
}
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;
}
List<string> swapOrderSn = swapOrders.Select(i => i.Sn).ToList();
List<SwapOrderBattery> batterys =
_swapOrderBatteryRepository.QueryListByClause(i => swapOrderSn.Contains(i.SwapOrderSn));
if (batterys.Count <= 0)
{
return;
}
IDictionary<string, SwapOrderBattery> dictionary = batterys.ToDictionary(i => i.SwapOrderSn);
List<string> downBatteryBinNos = batterys.Select(i => i.DownBatteryBinNo.ToString()).ToList();
Dictionary<string, BinInfo> binInfosMap = _binInfoRepository
.QueryListByClause(i => downBatteryBinNos.Contains(i.No)).ToDictionary(i => i.No);
List<SwapOrderBattery> updateDbBattery = new List<SwapOrderBattery>();
List<SwapOrder> updateDbOrder = new List<SwapOrder>();
List<SwapOrderReportCloud> updateDbCloudReport = new List<SwapOrderReportCloud>();
Dictionary<int, SwapOrderReportCloud> 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()

@ -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<SwapOrderReportCloud> list)
{
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));
if (batterys.Count <= 0)
{
return false;
}
IDictionary<string, SwapOrderBattery> dictionary = batterys.ToDictionary(i => i.SwapOrderSn);
List<string> downBatteryBinNos = batterys.Select(i => i.DownBatteryBinNo.ToString()).ToList();
Dictionary<string, BinInfo> binInfosMap = _BinInfoRepository
.QueryListByClause(i => downBatteryBinNos.Contains(i.No)).ToDictionary(i => i.No);
Dictionary<int, SwapOrderReportCloud> swapOrderReportClouds = list.ToDictionary(i => i.SwapOrderId);
List<SwapOrderBattery> updateDbBattery = new List<SwapOrderBattery>();
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)
{
//更新换下电池包
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;
}
}

@ -115,6 +115,7 @@ public class MonitorService
return Result<DeviceStateResp>.Success(resp);
}
//TODO:: 首页--当月,当日换电量
public Result<SwapAndChargingCountResp> SwapAndChargingCount()
{
SwapAndChargingCountResp chargingCountResp = new()

@ -6,22 +6,42 @@ using HybirdFrameworkCore.Entity;
using Repository.Station;
using SqlSugar;
using System.Linq.Expressions;
using Service.Mgr;
namespace Service.Station;
/// <summary>
/// 充电订单
/// </summary>
[Scope("SingleInstance")]
public class SwapOrderService : BaseServices<SwapOrder>
{
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<bool> UploadCloud(int id)
{
List<SwapOrderReportCloud> list =
SwapOrderReportCloudRepository.QueryListByClause(i => i.CloudReportStatus == 0 && i.SwapOrderId == id);
if (list.Count <= 0)
{
return Result<bool>.Fail("当前换电订单不满足上报云平台的条件");
}
return SwapOrderMgr.UploadCloud(list) ? Result<bool>.Success() : Result<bool>.Fail();
}
/// <summary>
/// 根据条件查询分页数据
/// </summary>
@ -29,48 +49,76 @@ public class SwapOrderService : BaseServices<SwapOrder>
/// <returns></returns>
public PageResult<SwapOrderResp> QuerySwapOrder(QuerySwapOrderPageReq swapOrder)
{
//创建一个空的表达式树
Expression<Func<SwapOrder, bool>> where = null;
//// 定义参数表达式
ParameterExpression parameter = Expression.Parameter(typeof(SwapOrder), "u");
#region 构建动态查询树
if (!string.IsNullOrEmpty(swapOrder.Sn))
{
Expression<Func<SwapOrder, bool>> condition2Expr = u => u.Sn == swapOrder.Sn;
where = where == null ? condition2Expr : Expression.Lambda<Func<SwapOrder, bool>>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter);
where = where == null
? condition2Expr
: Expression.Lambda<Func<SwapOrder, bool>>(Expression.AndAlso(where.Body, condition2Expr.Body),
parameter);
}
if (!string.IsNullOrEmpty(swapOrder.VehicleNo))
{
Expression<Func<SwapOrder, bool>> condition2Expr = u => u.VehicleNo == swapOrder.VehicleNo;
where = where == null ? condition2Expr : Expression.Lambda<Func<SwapOrder, bool>>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter);
where = where == null
? condition2Expr
: Expression.Lambda<Func<SwapOrder, bool>>(Expression.AndAlso(where.Body, condition2Expr.Body),
parameter);
}
if (!string.IsNullOrEmpty(swapOrder.VehicleMac))
{
Expression<Func<SwapOrder, bool>> condition2Expr = u => u.VehicleMac == swapOrder.VehicleMac;
where = where == null ? condition2Expr : Expression.Lambda<Func<SwapOrder, bool>>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter);
where = where == null
? condition2Expr
: Expression.Lambda<Func<SwapOrder, bool>>(Expression.AndAlso(where.Body, condition2Expr.Body),
parameter);
}
if (!string.IsNullOrEmpty(swapOrder.VehicleVin))
{
Expression<Func<SwapOrder, bool>> condition2Expr = u => u.VehicleVin == swapOrder.VehicleVin;
where = where == null ? condition2Expr : Expression.Lambda<Func<SwapOrder, bool>>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter);
where = where == null
? condition2Expr
: Expression.Lambda<Func<SwapOrder, bool>>(Expression.AndAlso(where.Body, condition2Expr.Body),
parameter);
}
if (swapOrder.SwapBeginTime != null && swapOrder.SwapBeginTime != DateTime.MinValue)
{
Expression<Func<SwapOrder, bool>> condition2Expr = u => u.SwapBeginTime == swapOrder.SwapBeginTime;
where = where == null ? condition2Expr : Expression.Lambda<Func<SwapOrder, bool>>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter);
where = where == null
? condition2Expr
: Expression.Lambda<Func<SwapOrder, bool>>(Expression.AndAlso(where.Body, condition2Expr.Body),
parameter);
}
if (swapOrder.SwapEndTime != null && swapOrder.SwapEndTime != DateTime.MinValue)
{
Expression<Func<SwapOrder, bool>> condition2Expr = u => u.SwapEndTime == swapOrder.SwapEndTime;
where = where == null ? condition2Expr : Expression.Lambda<Func<SwapOrder, bool>>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter);
where = where == null
? condition2Expr
: Expression.Lambda<Func<SwapOrder, bool>>(Expression.AndAlso(where.Body, condition2Expr.Body),
parameter);
}
if (swapOrder.SwapResult != 0)
{
Expression<Func<SwapOrder, bool>> condition2Expr = u => u.SwapResult == swapOrder.SwapResult;
where = where == null ? condition2Expr : Expression.Lambda<Func<SwapOrder, bool>>(Expression.AndAlso(where.Body, condition2Expr.Body), parameter);
where = where == null
? condition2Expr
: Expression.Lambda<Func<SwapOrder, bool>>(Expression.AndAlso(where.Body, condition2Expr.Body),
parameter);
}
#endregion
//查询
@ -84,7 +132,5 @@ public class SwapOrderService : BaseServices<SwapOrder>
//List<SwapOrderBatteryResp> BatteryList = new List<SwapOrderBatteryResp>();
//List<SwapOrderStepResp> StepList = new List<SwapOrderStepResp>();
return PageResult<SwapOrderResp>.ConvertPage(swapOrderRepository.QueryIPageByCause(swapOrder, where));
}
}

@ -150,8 +150,9 @@ public class SwapOrderController : ControllerBase
/// </summary>
/// <returns></returns>
[HttpGet("UploadCloud/{id}")]
public async Task<Result<bool>> UploadCloud(long id)
public Result<bool> UploadCloud(int id)
{
return Result<bool>.Success(null);
return swapOrderService.UploadCloud(id);
}
}
Loading…
Cancel
Save