自动充电策略

zw
smartwyy 6 months ago
parent e790eac75f
commit 1cbad0a52a

@ -1,7 +1,4 @@
using System; using SqlSugar;
using System.Linq;
using System.Text;
using SqlSugar;
namespace Entity.DbModel.Station namespace Entity.DbModel.Station
{ {
@ -11,185 +8,204 @@ namespace Entity.DbModel.Station
[SugarTable("bin_info")] [SugarTable("bin_info")]
public partial class BinInfo public partial class BinInfo
{ {
public BinInfo(){ public BinInfo()
{
}
}
/// <summary> /// <summary>
/// Desc:id /// Desc:id
/// Default: /// Default:
/// Nullable:False /// Nullable:False
/// </summary> /// </summary>
[SugarColumn(IsPrimaryKey=true,IsIdentity=true,ColumnName="id")] [SugarColumn(IsPrimaryKey = true, IsIdentity = true, ColumnName = "id")]
public int Id {get;set;} public int Id { get; set; }
/// <summary> /// <summary>
/// Desc:仓位编号 /// Desc:仓位编号
/// Default: /// Default:
/// Nullable:True /// Nullable:True
/// </summary> /// </summary>
[SugarColumn(ColumnName="no")] [SugarColumn(ColumnName = "no")]
public string No {get;set;} public string No { get; set; }
/// <summary> /// <summary>
/// Desc:仓位编码 /// Desc:仓位编码
/// Default: /// Default:
/// Nullable:True /// Nullable:True
/// </summary> /// </summary>
[SugarColumn(ColumnName="code")] [SugarColumn(ColumnName = "code")]
public string Code {get;set;} public string Code { get; set; }
/// <summary> /// <summary>
/// Desc:仓位名称 /// Desc:仓位名称
/// Default: /// Default:
/// Nullable:True /// Nullable:True
/// </summary> /// </summary>
[SugarColumn(ColumnName="name")] [SugarColumn(ColumnName = "name")]
public string Name {get;set;} public string Name { get; set; }
/// <summary> /// <summary>
/// Desc:电池编号 /// Desc:电池编号
/// Default: /// Default:
/// Nullable:True /// Nullable:True
/// </summary> /// </summary>
[SugarColumn(ColumnName="battery_no")] [SugarColumn(ColumnName = "battery_no")]
public string BatteryNo {get;set;} public string BatteryNo { get; set; }
/// <summary> /// <summary>
/// Desc:充电机编号 /// Desc:充电机编号
/// Default: /// Default:
/// Nullable:True /// Nullable:True
/// </summary> /// </summary>
[SugarColumn(ColumnName="charger_no")] [SugarColumn(ColumnName = "charger_no")]
public string ChargerNo {get;set;} public string ChargerNo { get; set; }
/// <summary> /// <summary>
/// Desc:充电枪编号 /// Desc:充电枪编号
/// Default: /// Default:
/// Nullable:True /// Nullable:True
/// </summary> /// </summary>
[SugarColumn(ColumnName="charger_gun_no")] [SugarColumn(ColumnName = "charger_gun_no")]
public string ChargerGunNo {get;set;} public string ChargerGunNo { get; set; }
/// <summary> /// <summary>
/// Desc:水冷编号 /// Desc:水冷编号
/// Default: /// Default:
/// Nullable:True /// Nullable:True
/// </summary> /// </summary>
[SugarColumn(ColumnName="water_cool_no")] [SugarColumn(ColumnName = "water_cool_no")]
public string WaterCoolNo {get;set;} public string WaterCoolNo { get; set; }
/// <summary> /// <summary>
/// Desc:是否有电插头;0-无电插头1-有电插头 /// Desc:是否有电插头;0-无电插头1-有电插头
/// Default: /// Default:
/// Nullable:True /// Nullable:True
/// </summary> /// </summary>
[SugarColumn(ColumnName="elec_plugin_flag")] [SugarColumn(ColumnName = "elec_plugin_flag")]
public int? ElecPluginFlag {get;set;} public int? ElecPluginFlag { get; set; }
/// <summary> /// <summary>
/// Desc:电插头状态;0-未知1-已经连接2-未连接 /// Desc:电插头状态;0-未知1-已经连接2-未连接
/// Default: /// Default:
/// Nullable:True /// Nullable:True
/// </summary> /// </summary>
[SugarColumn(ColumnName="elec_plugin_status")] [SugarColumn(ColumnName = "elec_plugin_status")]
public string ElecPluginStatus {get;set;} public string ElecPluginStatus { get; set; }
/// <summary> /// <summary>
/// Desc:是否有水插头;0-无水插头1-有水插头 /// Desc:是否有水插头;0-无水插头1-有水插头
/// Default: /// Default:
/// Nullable:False /// Nullable:False
/// </summary> /// </summary>
[SugarColumn(ColumnName="water_plugin_flag")] [SugarColumn(ColumnName = "water_plugin_flag")]
public string WaterPluginFlag {get;set;} public string WaterPluginFlag { get; set; }
/// <summary> /// <summary>
/// Desc:预约锁定;0-未锁定1-锁定 /// Desc:预约锁定;0-未锁定1-锁定
/// Default: /// Default:
/// Nullable:True /// Nullable:True
/// </summary> /// </summary>
[SugarColumn(ColumnName="amt_lock")] [SugarColumn(ColumnName = "amt_lock")]
public string AmtLock {get;set;} public string AmtLock { get; set; }
/// <summary> /// <summary>
/// Desc:soc /// Desc:soc
/// Default: /// Default:
/// Nullable:True /// Nullable:True
/// </summary> /// </summary>
[SugarColumn(ColumnName="soc")] [SugarColumn(ColumnName = "soc")]
public decimal? Soc {get;set;} public decimal? Soc { get; set; }
/// <summary> /// <summary>
/// Desc:soe /// Desc:soe
/// Default: /// Default:
/// Nullable:True /// Nullable:True
/// </summary> /// </summary>
[SugarColumn(ColumnName="soe")] [SugarColumn(ColumnName = "soe")]
public decimal? Soe {get;set;} public decimal? Soe { get; set; }
/// <summary> /// <summary>
/// Desc:soh /// Desc:soh
/// Default: /// Default:
/// Nullable:True /// Nullable:True
/// </summary> /// </summary>
[SugarColumn(ColumnName="soh")] [SugarColumn(ColumnName = "soh")]
public decimal? Soh {get;set;} public decimal? Soh { get; set; }
/// <summary> /// <summary>
/// Desc:电池入仓顺序 /// Desc:电池入仓顺序
/// Default: /// Default:
/// Nullable:True /// Nullable:True
/// </summary> /// </summary>
[SugarColumn(ColumnName="battery_enter_seq")] [SugarColumn(ColumnName = "battery_enter_seq")]
public int? BatteryEnterSeq {get;set;} public int? BatteryEnterSeq { get; set; }
/// <summary> /// <summary>
/// Desc:充电状态;0-未知1-正在充电2-无电池3-禁用4-充电停止 /// Desc:充电状态;0-未知1-正在充电2-无电池3-禁用4-充电停止
/// Default:0 /// Default:0
/// Nullable:True /// Nullable:True
/// </summary> /// </summary>
[SugarColumn(ColumnName="charge_status")] [SugarColumn(ColumnName = "charge_status")]
public int? ChargeStatus {get;set;} public int? ChargeStatus { get; set; }
/// <summary> /// <summary>
/// Desc:仓位状态;0-禁用1-启用 /// Desc:仓位状态;0-禁用1-启用
/// Default:1 /// Default:1
/// Nullable:True /// Nullable:True
/// </summary> /// </summary>
[SugarColumn(ColumnName="status")] [SugarColumn(ColumnName = "status")]
public int? Status {get;set;} public int? Status { get; set; }
/// <summary> /// <summary>
/// Desc:创建人 /// Desc:创建人
/// Default: /// Default:
/// Nullable:True /// Nullable:True
/// </summary> /// </summary>
[SugarColumn(ColumnName="created_by")] [SugarColumn(ColumnName = "created_by")]
public string CreatedBy {get;set;} public string CreatedBy { get; set; }
/// <summary> /// <summary>
/// Desc:创建时间 /// Desc:创建时间
/// Default:CURRENT_TIMESTAMP /// Default:CURRENT_TIMESTAMP
/// Nullable:True /// Nullable:True
/// </summary> /// </summary>
[SugarColumn(ColumnName="created_time")] [SugarColumn(ColumnName = "created_time")]
public DateTime? CreatedTime {get;set;} public DateTime? CreatedTime { get; set; }
/// <summary> /// <summary>
/// Desc:更新人 /// Desc:更新人
/// Default: /// Default:
/// Nullable:True /// Nullable:True
/// </summary> /// </summary>
[SugarColumn(ColumnName="updated_by")] [SugarColumn(ColumnName = "updated_by")]
public string UpdatedBy {get;set;} public string UpdatedBy { get; set; }
/// <summary> /// <summary>
/// Desc:更新时间 /// Desc:更新时间
/// Default:CURRENT_TIMESTAMP /// Default:CURRENT_TIMESTAMP
/// Nullable:True /// Nullable:True
/// </summary> /// </summary>
[SugarColumn(ColumnName="updated_time")] [SugarColumn(ColumnName = "updated_time")]
public DateTime? UpdatedTime {get;set;} 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> /// </summary>
/// <param name="socLimit">SOC限制.百分比</param> /// <param name="socLimit">SOC限制.百分比</param>
/// <param name="changePowerCmdType">功率调节指令类型.默认1 绝对功率值</param> /// <param name="changePowerCmdType">功率调节指令类型.默认1 绝对功率值</param>
/// <param name="changePower">0.1kw/位,默认3600</param> /// <param name="changePower">1kw/位,默认3600</param>
/// <param name="chargeOrderNo">充电流水号</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) string? chargeOrderNo = null)
{ {
if (!Connected) if (!Connected)

@ -166,14 +166,6 @@ public static class ClientMgr
continue; 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 电价模型 #region 电价模型
@ -222,27 +214,57 @@ public static class ClientMgr
} }
int needBatteryCount = opModelDetails[0].BatteryCount ?? 8; 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}"); Log.Info($"lack of needBatteryCount {needBatteryCount}");
continue; continue;
} }
if(canSwapList.Count > needBatteryCount)
#endregion
foreach (BinInfo binInfo in socNeedChargeList)
{ {
if (Dictionary.TryGetValue(binInfo.ChargerNo, out var client)) List<BinInfo> chargingList = binInfos.Where(it => it.ChargeStatus == 1).ToList();
int needStopCount = chargingList.Count - (canSwapList.Count - needBatteryCount);
if (needStopCount > 0)
{ {
Result<bool> result = client.StartCharge(); chargingList.Sort((a,b) => (a.Soc??0).CompareTo(b.Soc??0));
Log.Info($"start {binInfo.ChargerNo} charge {result.IsSuccess}:{result.Msg}"); for (int i = 0; i < needStopCount; i++)
{
Log.Info($"auto stop charge {chargingList[i].No}");
GetBySn(chargingList[i].No)?.SendRemoteStopCharging();
}
} }
else }
else
{
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)
{ {
Log.Info($"can not find {binInfo.ChargerNo} in dict"); 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) catch (Exception e)
{ {

@ -63,9 +63,9 @@ public class StaticStationInfo
set => Set(StationParamConst.SwapFinishChargeTime, value); 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); set => Set(StationParamConst.SwapSoc, value);
} }

Loading…
Cancel
Save