充电订单上传

master
smartwyy 6 months ago
parent 623f0e3bce
commit ba60504e10

@ -1,7 +1,4 @@
using System; using SqlSugar;
using System.Linq;
using System.Text;
using SqlSugar;
namespace Entity.DbModel.Station namespace Entity.DbModel.Station
{ {
@ -13,9 +10,8 @@ namespace Entity.DbModel.Station
{ {
public ChargeOrder() public ChargeOrder()
{ {
} }
/// <summary> /// <summary>
/// Desc:id /// Desc:id
/// Default: /// Default:
@ -63,12 +59,14 @@ namespace Entity.DbModel.Station
/// </summary> /// </summary>
[SugarColumn(ColumnName = "charger_gun_no")] [SugarColumn(ColumnName = "charger_gun_no")]
public string ChargerGunNo { get; set; } public string ChargerGunNo { get; set; }
/// <summary> /// <summary>
/// 0站内充电 1站外充电 /// 0站内充电 1站外充电
/// </summary> /// </summary>
[SugarColumn(ColumnName = "charge_mode")] [SugarColumn(ColumnName = "charge_mode")]
public int ChargeMode { get; set; } public int ChargeMode { get; set; }
/// <summary> /// <summary>
/// 1站控启动 2本地启动 /// 1站控启动 2本地启动
/// </summary> /// </summary>
@ -108,13 +106,13 @@ namespace Entity.DbModel.Station
[SugarColumn(ColumnName = "stop_soc")] [SugarColumn(ColumnName = "stop_soc")]
public int? StopSoc { get; set; } public int? StopSoc { get; set; }
/// <summary> /// <summary>
/// Desc:充电时长 /// Desc:充电时长
/// Default: /// Default:
/// Nullable:True /// Nullable:True
/// </summary> /// </summary>
[SugarColumn(ColumnName="charge_time_count")] [SugarColumn(ColumnName = "charge_time_count")]
public int? ChargeTimeCount {get;set;} public int? ChargeTimeCount { get; set; }
/// <summary> /// <summary>
/// Desc:充电电量 /// Desc:充电电量
@ -124,21 +122,21 @@ namespace Entity.DbModel.Station
[SugarColumn(ColumnName = "elec_count")] [SugarColumn(ColumnName = "elec_count")]
public decimal? ElecCount { get; set; } public decimal? ElecCount { get; set; }
/// <summary> /// <summary>
/// Desc:交流电表量 /// Desc:交流电表量
/// Default: /// Default:
/// Nullable:True /// Nullable:True
/// </summary> /// </summary>
[SugarColumn(ColumnName="ac_elec_count")] [SugarColumn(ColumnName = "ac_elec_count")]
public decimal? AcElecCount {get;set;} public decimal? AcElecCount { get; set; }
/// <summary> /// <summary>
/// Desc:充电开始交流表电量 /// Desc:充电开始交流表电量
/// Default: /// Default:
/// Nullable:True /// Nullable:True
/// </summary> /// </summary>
[SugarColumn(ColumnName="start_ac_elec")] [SugarColumn(ColumnName = "start_ac_elec")]
public decimal? StartAcElec {get;set;} public decimal? StartAcElec { get; set; }
/// <summary> /// <summary>
/// Desc:充电结束交流表电量 /// Desc:充电结束交流表电量
@ -298,6 +296,20 @@ namespace Entity.DbModel.Station
[SugarColumn(ColumnName = "cloud_sn")] [SugarColumn(ColumnName = "cloud_sn")]
public string? CloudSn { get; set; } 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; 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>
/// ///
/// </summary> /// </summary>
@ -44,4 +66,6 @@ public static class ObjUtils
{ {
return !string.IsNullOrWhiteSpace(o); 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="op">1 自动; 2 人工手动</param>
/// <param name="timeSpan">超时等待</param> /// <param name="timeSpan">超时等待</param>
/// <returns></returns> /// <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; string swapOrderSn = chargeOrder.SwapOrderSn;
SwapOrder? swapOrder = SwapOrderRepository.QueryByClause(it => it.Sn == swapOrderSn); SwapOrder? swapOrder = SwapOrderRepository.QueryByClause(it => it.Sn == swapOrderSn);
ChargeRecordUpLoad req = new ChargeRecordUpLoad() ChargeRecordUpLoad req = new ChargeRecordUpLoad()
{ {
chrsn = chargeOrder.Sn, chrsn = chargeOrder.CloudChargeOrder,
son = swapOrderSn, son = swapOrderSn,
bid = chargeOrder.BatteryNo, bid = chargeOrder.BatteryNo,
st = chargeOrder.StartTime ?? DateTime.Now, st = chargeOrder.StartTime ?? DateTime.Now,
et = chargeOrder.EndTime ?? DateTime.Now, et = lastChargeOrder.EndTime ?? DateTime.Now,
ssoc = chargeOrder.StartSoc ?? 0, ssoc = chargeOrder.StartSoc ?? 0,
esoc = chargeOrder.StopSoc ?? 0, esoc = lastChargeOrder.StopSoc ?? 0,
//ssoe = chargeOrder.soe //ssoe = chargeOrder.soe
//esoe //esoe
dcce = Convert.ToSingle(chargeOrder.StopDcElec ?? 0 - chargeOrder.StartDcElec ?? 0), dcce =0,
acce = Convert.ToSingle(chargeOrder.StopAcElec ?? 0 - chargeOrder.StartAcElec ?? 0), acce =0,
tp = Convert.ToSingle(chargeOrder.SharpElecCount), tp = 0,
pp = Convert.ToSingle(chargeOrder.PeakElecCount), pp = 0,
fp = Convert.ToSingle(chargeOrder.FlatElecCount), fp = 0,
vp = Convert.ToSingle(chargeOrder.ValleyElecCount), vp = 0,
ct = ((chargeOrder.EndTime ?? DateTime.Now).Subtract(chargeOrder.StartTime ?? DateTime.Now)).Minutes, ct = 0,
cn = 1, cn = orders.Count,
sfs = op, sfs = op,
vin = swapOrder?.VehicleVin, vin = swapOrder.VehicleVin,
sfoc = op, 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); this.SendChargeRecordUpLoad(req);
return true; return true;
} }

@ -20,14 +20,17 @@ public class ChargeOrderUploadTask : AbstractTaskHandler
protected override void Handle() 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"); Log.Info($"there are {chargeOrders?.Count ?? 0} to upload");
if (chargeOrders is { Count: > 0 }) 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)}"); Log.Info($"receive ChargeRecordUploadRes chargeOrderNo={reqChrsn} {JsonConvert.SerializeObject(res)}");
if (!string.IsNullOrWhiteSpace(reqChrsn) && res.re == 0) 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.Req;
using Entity.Api.Resp; using Entity.Api.Resp;
using Entity.DbModel.Station; using Entity.DbModel.Station;
using HybirdFrameworkCore.Autofac.Attribute; using HybirdFrameworkCore.Autofac.Attribute;
using HybirdFrameworkCore.Entity; using HybirdFrameworkCore.Entity;
using Repository.Station;
using SqlSugar;
using System.Linq.Expressions;
using HybirdFrameworkCore.Utils; using HybirdFrameworkCore.Utils;
using Repository.Station;
using Service.Cloud.Client; using Service.Cloud.Client;
namespace Service.Station; namespace Service.Station;
@ -130,20 +129,20 @@ public class ChargeOrderService : BaseServices<ChargeOrder>
/// </summary> /// </summary>
/// <param name="id"></param> /// <param name="id"></param>
/// <returns></returns> /// <returns></returns>
public async Task<Result<bool>> Upload2Cloud(int id) public Result<bool> Upload2Cloud(string cloudChargerOrder)
{ {
ChargeOrder? order = await BaseDal.QueryByIdAsync(id); List<ChargeOrder> orders = BaseDal.QueryListByClause(it => it.CloudChargeOrder == cloudChargerOrder);
if (ObjUtils.IsNull(order)) if (ObjUtils.IsEmpty(orders))
{ {
return Result<bool>.Fail("数据不存在"); return Result<bool>.Fail("数据不存在");
} }
if (order.CloudReportStatus == 1) if ( orders[0].CloudReportStatus == 1)
{ {
return Result<bool>.Success("已经上传到云平台"); return Result<bool>.Success("已经上传到云平台");
} }
CloudClientMgr.CloudClient?.PublishChargeOrder(order, 2); CloudClientMgr.CloudClient?.PublishChargeOrder(orders, 2);
return Result<bool>.Success(); return Result<bool>.Success();
} }
} }
Loading…
Cancel
Save