充电订单上传

master
smartwyy 6 months ago
parent 623f0e3bce
commit ba60504e10

@ -1,7 +1,4 @@
using System;
using System.Linq;
using System.Text;
using SqlSugar;
using SqlSugar;
namespace Entity.DbModel.Station
{
@ -13,9 +10,8 @@ namespace Entity.DbModel.Station
{
public ChargeOrder()
{
}
/// <summary>
/// Desc:id
/// Default:
@ -63,12 +59,14 @@ namespace Entity.DbModel.Station
/// </summary>
[SugarColumn(ColumnName = "charger_gun_no")]
public string ChargerGunNo { get; set; }
/// <summary>
/// 0站内充电 1站外充电
/// </summary>
[SugarColumn(ColumnName = "charge_mode")]
public int ChargeMode { get; set; }
/// <summary>
/// 1站控启动 2本地启动
/// </summary>
@ -298,6 +296,20 @@ namespace Entity.DbModel.Station
[SugarColumn(ColumnName = "cloud_sn")]
public string? CloudSn { get; set; }
/// <summary>
/// Desc:云平台订单编号
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName = "cloud_charge_order")]
public string CloudChargeOrder { get; set; }
/// <summary>
/// Desc:是否可以上传云平台 0-不可用1-可以
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName = "can_upload")]
public int? CanUpload { get; set; }
}
}

@ -25,6 +25,28 @@ public static class ObjUtils
return o != null;
}
/// <summary>
///
/// </summary>
/// <param name="list"></param>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public static bool IsEmpty<T>(List<T>? list)
{
return list == null || list.Count == 0;
}
/// <summary>
///
/// </summary>
/// <param name="list"></param>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public static bool IsNotEmpty<T>(List<T>? list)
{
return list is { Count: >= 0 };
}
/// <summary>
///
/// </summary>
@ -44,4 +66,6 @@ public static class ObjUtils
{
return !string.IsNullOrWhiteSpace(o);
}
public static readonly List<object> EmptyList = new List<object>(0);
}

@ -511,33 +511,46 @@ public class CloudClient : IMqttClientConnectedHandler, IMqttApplicationMessageR
/// <param name="op">1 自动; 2 人工手动</param>
/// <param name="timeSpan">超时等待</param>
/// <returns></returns>
public bool PublishChargeOrder(ChargeOrder chargeOrder, int op, TimeSpan? timeSpan = null)
public bool PublishChargeOrder(List<ChargeOrder> orders, int op, TimeSpan? timeSpan = null)
{
ChargeOrder chargeOrder = orders[0];
ChargeOrder lastChargeOrder = orders[^1];
string swapOrderSn = chargeOrder.SwapOrderSn;
SwapOrder? swapOrder = SwapOrderRepository.QueryByClause(it => it.Sn == swapOrderSn);
ChargeRecordUpLoad req = new ChargeRecordUpLoad()
{
chrsn = chargeOrder.Sn,
chrsn = chargeOrder.CloudChargeOrder,
son = swapOrderSn,
bid = chargeOrder.BatteryNo,
st = chargeOrder.StartTime ?? DateTime.Now,
et = chargeOrder.EndTime ?? DateTime.Now,
et = lastChargeOrder.EndTime ?? DateTime.Now,
ssoc = chargeOrder.StartSoc ?? 0,
esoc = chargeOrder.StopSoc ?? 0,
esoc = lastChargeOrder.StopSoc ?? 0,
//ssoe = chargeOrder.soe
//esoe
dcce = Convert.ToSingle(chargeOrder.StopDcElec ?? 0 - chargeOrder.StartDcElec ?? 0),
acce = Convert.ToSingle(chargeOrder.StopAcElec ?? 0 - chargeOrder.StartAcElec ?? 0),
tp = Convert.ToSingle(chargeOrder.SharpElecCount),
pp = Convert.ToSingle(chargeOrder.PeakElecCount),
fp = Convert.ToSingle(chargeOrder.FlatElecCount),
vp = Convert.ToSingle(chargeOrder.ValleyElecCount),
ct = ((chargeOrder.EndTime ?? DateTime.Now).Subtract(chargeOrder.StartTime ?? DateTime.Now)).Minutes,
cn = 1,
dcce =0,
acce =0,
tp = 0,
pp = 0,
fp = 0,
vp = 0,
ct = 0,
cn = orders.Count,
sfs = op,
vin = swapOrder?.VehicleVin,
sfoc = op,
vin = swapOrder.VehicleVin,
sfoc = 0,
};
foreach (ChargeOrder order in orders)
{
req.dcce += Convert.ToSingle(order.StopDcElec ?? 0 - order.StartDcElec ?? 0);
req.acce += Convert.ToSingle(order.StopAcElec ?? 0 - order.StartAcElec ?? 0);
req.tp += Convert.ToSingle(order.SharpElecCount);
req.pp += Convert.ToSingle(order.PeakElecCount);
req.fp += Convert.ToSingle(order.FlatElecCount);
req.vp += Convert.ToSingle(order.ValleyElecCount);
req.ct += ((order.EndTime ?? DateTime.Now).Subtract(order.StartTime ?? DateTime.Now)).Minutes;
}
this.SendChargeRecordUpLoad(req);
return true;
}

@ -20,14 +20,17 @@ public class ChargeOrderUploadTask : AbstractTaskHandler
protected override void Handle()
{
List<ChargeOrder>? chargeOrders = _chargeOrderRepository.QueryListByClause(it => it.CloudReportStatus ==0);
List<ChargeOrder>? chargeOrders = _chargeOrderRepository.QueryListByClause(it => it.CloudReportStatus ==0 && it.CanUpload == 1);
Log.Info($"there are {chargeOrders?.Count ?? 0} to upload");
if (chargeOrders is { Count: > 0 })
{
foreach (ChargeOrder chargeOrder in chargeOrders)
var group = chargeOrders.GroupBy(it => it.CloudChargeOrder);
foreach (IGrouping<string,ChargeOrder> grouping in group)
{
CloudClientMgr.CloudClient?.PublishChargeOrder(chargeOrder, 1);
List<ChargeOrder> orders = grouping.ToList();
CloudClientMgr.CloudClient?.PublishChargeOrder(orders, 1);
}
}
}

@ -27,7 +27,7 @@ public class ChargeRecordUploadResHandler : IBaseHandler
Log.Info($"receive ChargeRecordUploadRes chargeOrderNo={reqChrsn} {JsonConvert.SerializeObject(res)}");
if (!string.IsNullOrWhiteSpace(reqChrsn) && res.re == 0)
{
ChargeOrderRepository.Update(it => it.CloudReportStatus == 1, it => it.Sn == reqChrsn);
ChargeOrderRepository.Update(it => it.CloudReportStatus == 1, it => it.CloudChargeOrder == reqChrsn);
}
}
}

@ -1,12 +1,11 @@
using System.Linq.Expressions;
using Entity.Api.Req;
using Entity.Api.Resp;
using Entity.DbModel.Station;
using HybirdFrameworkCore.Autofac.Attribute;
using HybirdFrameworkCore.Entity;
using Repository.Station;
using SqlSugar;
using System.Linq.Expressions;
using HybirdFrameworkCore.Utils;
using Repository.Station;
using Service.Cloud.Client;
namespace Service.Station;
@ -130,20 +129,20 @@ public class ChargeOrderService : BaseServices<ChargeOrder>
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public async Task<Result<bool>> Upload2Cloud(int id)
public Result<bool> Upload2Cloud(string cloudChargerOrder)
{
ChargeOrder? order = await BaseDal.QueryByIdAsync(id);
if (ObjUtils.IsNull(order))
List<ChargeOrder> orders = BaseDal.QueryListByClause(it => it.CloudChargeOrder == cloudChargerOrder);
if (ObjUtils.IsEmpty(orders))
{
return Result<bool>.Fail("数据不存在");
}
if (order.CloudReportStatus == 1)
if ( orders[0].CloudReportStatus == 1)
{
return Result<bool>.Success("已经上传到云平台");
}
CloudClientMgr.CloudClient?.PublishChargeOrder(order, 2);
CloudClientMgr.CloudClient?.PublishChargeOrder(orders, 2);
return Result<bool>.Success();
}
}
Loading…
Cancel
Save