自动充电策略

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,10 +8,10 @@ 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:
@ -191,5 +188,24 @@ namespace Entity.DbModel.Station
[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)
{
List<BinInfo> chargingList = binInfos.Where(it => it.ChargeStatus == 1).ToList();
#endregion int needStopCount = chargingList.Count - (canSwapList.Count - needBatteryCount);
if (needStopCount > 0)
foreach (BinInfo binInfo in socNeedChargeList)
{ {
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($"auto stop charge {chargingList[i].No}");
Log.Info($"start {binInfo.ChargerNo} charge {result.IsSuccess}:{result.Msg}"); GetBySn(chargingList[i].No)?.SendRemoteStopCharging();
}
}
} }
else 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) 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