自动充电策略

zw
smartwyy 6 months ago
parent e790eac75f
commit 1cbad0a52a

@ -1,7 +1,4 @@
using System;
using System.Linq;
using System.Text;
using SqlSugar;
using SqlSugar;
namespace Entity.DbModel.Station
{
@ -11,185 +8,204 @@ namespace Entity.DbModel.Station
[SugarTable("bin_info")]
public partial class BinInfo
{
public BinInfo(){
public BinInfo()
{
}
/// <summary>
/// Desc:id
/// Default:
/// Nullable:False
/// </summary>
[SugarColumn(IsPrimaryKey=true,IsIdentity=true,ColumnName="id")]
public int Id {get;set;}
[SugarColumn(IsPrimaryKey = true, IsIdentity = true, ColumnName = "id")]
public int Id { get; set; }
/// <summary>
/// Desc:仓位编号
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName="no")]
public string No {get;set;}
[SugarColumn(ColumnName = "no")]
public string No { get; set; }
/// <summary>
/// Desc:仓位编码
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName="code")]
public string Code {get;set;}
[SugarColumn(ColumnName = "code")]
public string Code { get; set; }
/// <summary>
/// Desc:仓位名称
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName="name")]
public string Name {get;set;}
[SugarColumn(ColumnName = "name")]
public string Name { get; set; }
/// <summary>
/// Desc:电池编号
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName="battery_no")]
public string BatteryNo {get;set;}
[SugarColumn(ColumnName = "battery_no")]
public string BatteryNo { get; set; }
/// <summary>
/// Desc:充电机编号
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName="charger_no")]
public string ChargerNo {get;set;}
[SugarColumn(ColumnName = "charger_no")]
public string ChargerNo { get; set; }
/// <summary>
/// Desc:充电枪编号
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName="charger_gun_no")]
public string ChargerGunNo {get;set;}
[SugarColumn(ColumnName = "charger_gun_no")]
public string ChargerGunNo { get; set; }
/// <summary>
/// Desc:水冷编号
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName="water_cool_no")]
public string WaterCoolNo {get;set;}
[SugarColumn(ColumnName = "water_cool_no")]
public string WaterCoolNo { get; set; }
/// <summary>
/// Desc:是否有电插头;0-无电插头1-有电插头
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName="elec_plugin_flag")]
public int? ElecPluginFlag {get;set;}
[SugarColumn(ColumnName = "elec_plugin_flag")]
public int? ElecPluginFlag { get; set; }
/// <summary>
/// Desc:电插头状态;0-未知1-已经连接2-未连接
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName="elec_plugin_status")]
public string ElecPluginStatus {get;set;}
[SugarColumn(ColumnName = "elec_plugin_status")]
public string ElecPluginStatus { get; set; }
/// <summary>
/// Desc:是否有水插头;0-无水插头1-有水插头
/// Default:
/// Nullable:False
/// </summary>
[SugarColumn(ColumnName="water_plugin_flag")]
public string WaterPluginFlag {get;set;}
[SugarColumn(ColumnName = "water_plugin_flag")]
public string WaterPluginFlag { get; set; }
/// <summary>
/// Desc:预约锁定;0-未锁定1-锁定
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName="amt_lock")]
public string AmtLock {get;set;}
[SugarColumn(ColumnName = "amt_lock")]
public string AmtLock { get; set; }
/// <summary>
/// Desc:soc
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName="soc")]
public decimal? Soc {get;set;}
[SugarColumn(ColumnName = "soc")]
public decimal? Soc { get; set; }
/// <summary>
/// Desc:soe
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName="soe")]
public decimal? Soe {get;set;}
[SugarColumn(ColumnName = "soe")]
public decimal? Soe { get; set; }
/// <summary>
/// Desc:soh
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName="soh")]
public decimal? Soh {get;set;}
[SugarColumn(ColumnName = "soh")]
public decimal? Soh { get; set; }
/// <summary>
/// Desc:电池入仓顺序
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName="battery_enter_seq")]
public int? BatteryEnterSeq {get;set;}
[SugarColumn(ColumnName = "battery_enter_seq")]
public int? BatteryEnterSeq { get; set; }
/// <summary>
/// Desc:充电状态;0-未知1-正在充电2-无电池3-禁用4-充电停止
/// Default:0
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName="charge_status")]
public int? ChargeStatus {get;set;}
[SugarColumn(ColumnName = "charge_status")]
public int? ChargeStatus { get; set; }
/// <summary>
/// Desc:仓位状态;0-禁用1-启用
/// Default:1
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName="status")]
public int? Status {get;set;}
[SugarColumn(ColumnName = "status")]
public int? Status { get; set; }
/// <summary>
/// Desc:创建人
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName="created_by")]
public string CreatedBy {get;set;}
[SugarColumn(ColumnName = "created_by")]
public string CreatedBy { get; set; }
/// <summary>
/// Desc:创建时间
/// Default:CURRENT_TIMESTAMP
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName="created_time")]
public DateTime? CreatedTime {get;set;}
[SugarColumn(ColumnName = "created_time")]
public DateTime? CreatedTime { get; set; }
/// <summary>
/// Desc:更新人
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName="updated_by")]
public string UpdatedBy {get;set;}
[SugarColumn(ColumnName = "updated_by")]
public string UpdatedBy { get; set; }
/// <summary>
/// Desc:更新时间
/// Default:CURRENT_TIMESTAMP
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName="updated_time")]
public DateTime? UpdatedTime {get;set;}
[SugarColumn(ColumnName = "updated_time")]
public DateTime? UpdatedTime { get; set; }
/// <summary>
/// 缓存仓标记 0:不是 1:是
/// </summary>
[SugarColumn(ColumnName = "cache_bin_flag")]
public int CacheBinFlag { get; set; }
/// <summary>
/// 换电禁用标志 0:不可换电 1:可以换电
/// </summary>
[SugarColumn(ColumnName = "can_swap_flag")]
public int CanSwapFlag { get; set; }
/// <summary>
/// 充电禁用标志 0:不可充电 1:可以充电
/// </summary>
[SugarColumn(ColumnName = "can_charge_flag")]
public int CanChargeFlag { get; set; }
}
}

@ -238,9 +238,9 @@ public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
/// </summary>
/// <param name="socLimit">SOC限制.百分比</param>
/// <param name="changePowerCmdType">功率调节指令类型.默认1 绝对功率值</param>
/// <param name="changePower">0.1kw/位,默认3600</param>
/// <param name="changePower">1kw/位,默认3600</param>
/// <param name="chargeOrderNo">充电流水号</param>
public Result<string> SendRemoteStartCharging(byte socLimit, float changePower = 3600, byte changePowerCmdType = 1,
public Result<string> SendRemoteStartCharging(byte socLimit, float changePower = 360, byte changePowerCmdType = 1,
string? chargeOrderNo = null)
{
if (!Connected)

@ -166,14 +166,6 @@ public static class ClientMgr
continue;
}
var chargeSoc = StaticStationInfo.ChargeSoc;
List<BinInfo> socNeedChargeList = binInfos.Where(t => t.Soc < chargeSoc).ToList();
if (socNeedChargeList.Count < 0)
{
Log.Info($"lack of binInfos.soc < {chargeSoc}");
continue;
}
#region 电价模型
@ -222,27 +214,57 @@ public static class ClientMgr
}
int needBatteryCount = opModelDetails[0].BatteryCount ?? 8;
if ((binInfos.Count - socNeedChargeList.Count) >= needBatteryCount)
List<BinInfo> canSwapList = binInfos.Where(it => it.Soc != null && Convert.ToSingle(it.Soc) >= StaticStationInfo.SwapSoc).ToList();
if (canSwapList.Count == needBatteryCount)
{
Log.Info($"lack of needBatteryCount {needBatteryCount}");
continue;
}
if(canSwapList.Count > needBatteryCount)
{
List<BinInfo> chargingList = binInfos.Where(it => it.ChargeStatus == 1).ToList();
#endregion
foreach (BinInfo binInfo in socNeedChargeList)
int needStopCount = chargingList.Count - (canSwapList.Count - needBatteryCount);
if (needStopCount > 0)
{
if (Dictionary.TryGetValue(binInfo.ChargerNo, out var client))
chargingList.Sort((a,b) => (a.Soc??0).CompareTo(b.Soc??0));
for (int i = 0; i < needStopCount; i++)
{
Result<bool> result = client.StartCharge();
Log.Info($"start {binInfo.ChargerNo} charge {result.IsSuccess}:{result.Msg}");
Log.Info($"auto stop charge {chargingList[i].No}");
GetBySn(chargingList[i].No)?.SendRemoteStopCharging();
}
}
}
else
{
Log.Info($"can not find {binInfo.ChargerNo} in dict");
List<BinInfo> canChargeList = binInfos.Where(it => it.Soc != null && Convert.ToSingle(it.Soc) < StaticStationInfo.SwapSoc && it.CanChargeFlag == 1).ToList();
canChargeList.Sort((a,b) => (b.Soc??0).CompareTo(a.Soc??0));
byte chargeSoc = StaticStationInfo.ChargeSoc;
float chargePower = StaticStationInfo.ChargePower;
int count = needBatteryCount - canSwapList.Count;
int number = 0;
foreach (var binInfo in canChargeList)
{
Result<string>? result = GetBySn(binInfo.ChargerNo)?.SendRemoteStartCharging(chargeSoc, chargePower);
if (result is {IsSuccess: true} )
{
Log.Info($"auto start charge {binInfo.ChargerNo}");
number++;
}
if (count == number)
{
Log.Info($"auto start charge count {count}");
break;
}
}
}
#endregion
}
catch (Exception e)
{

@ -63,9 +63,9 @@ public class StaticStationInfo
set => Set(StationParamConst.SwapFinishChargeTime, value);
}
public static string SwapSoc
public static float SwapSoc
{
get => Resolve(StationParamConst.SwapSoc);
get => float.Parse(Resolve(StationParamConst.SwapSoc));
set => Set(StationParamConst.SwapSoc, value);
}

Loading…
Cancel
Save