diff --git a/Entity/DbModel/Station/BinInfo.cs b/Entity/DbModel/Station/BinInfo.cs index 9d0df00..dbaffd2 100644 --- a/Entity/DbModel/Station/BinInfo.cs +++ b/Entity/DbModel/Station/BinInfo.cs @@ -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(){ - - - } - /// - /// Desc:id - /// Default: - /// Nullable:False - /// - [SugarColumn(IsPrimaryKey=true,IsIdentity=true,ColumnName="id")] - public int Id {get;set;} - - /// - /// Desc:仓位编号 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="no")] - public string No {get;set;} - - /// - /// Desc:仓位编码 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="code")] - public string Code {get;set;} - - /// - /// Desc:仓位名称 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="name")] - public string Name {get;set;} - - /// - /// Desc:电池编号 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="battery_no")] - public string BatteryNo {get;set;} - - /// - /// Desc:充电机编号 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="charger_no")] - public string ChargerNo {get;set;} - - /// - /// Desc:充电枪编号 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="charger_gun_no")] - public string ChargerGunNo {get;set;} - - /// - /// Desc:水冷编号 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="water_cool_no")] - public string WaterCoolNo {get;set;} - - /// - /// Desc:是否有电插头;0-无电插头;1-有电插头 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="elec_plugin_flag")] - public int? ElecPluginFlag {get;set;} - - /// - /// Desc:电插头状态;0-未知;1-已经连接;2-未连接 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="elec_plugin_status")] - public string ElecPluginStatus {get;set;} - - /// - /// Desc:是否有水插头;0-无水插头;1-有水插头 - /// Default: - /// Nullable:False - /// - [SugarColumn(ColumnName="water_plugin_flag")] - public string WaterPluginFlag {get;set;} - - /// - /// Desc:预约锁定;0-未锁定;1-锁定 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="amt_lock")] - public string AmtLock {get;set;} - - /// - /// Desc:soc - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="soc")] - public decimal? Soc {get;set;} - - /// - /// Desc:soe - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="soe")] - public decimal? Soe {get;set;} - - /// - /// Desc:soh - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="soh")] - public decimal? Soh {get;set;} - - /// - /// Desc:电池入仓顺序 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="battery_enter_seq")] - public int? BatteryEnterSeq {get;set;} - - /// - /// Desc:充电状态;0-未知;1-正在充电;2-无电池;3-禁用;4-充电停止 - /// Default:0 - /// Nullable:True - /// - [SugarColumn(ColumnName="charge_status")] - public int? ChargeStatus {get;set;} - - /// - /// Desc:仓位状态;0-禁用;1-启用 - /// Default:1 - /// Nullable:True - /// - [SugarColumn(ColumnName="status")] - public int? Status {get;set;} - - /// - /// Desc:创建人 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="created_by")] - public string CreatedBy {get;set;} - - /// - /// Desc:创建时间 - /// Default:CURRENT_TIMESTAMP - /// Nullable:True - /// - [SugarColumn(ColumnName="created_time")] - public DateTime? CreatedTime {get;set;} - - /// - /// Desc:更新人 - /// Default: - /// Nullable:True - /// - [SugarColumn(ColumnName="updated_by")] - public string UpdatedBy {get;set;} - - /// - /// Desc:更新时间 - /// Default:CURRENT_TIMESTAMP - /// Nullable:True - /// - [SugarColumn(ColumnName="updated_time")] - public DateTime? UpdatedTime {get;set;} - + public BinInfo() + { + } + + /// + /// Desc:id + /// Default: + /// Nullable:False + /// + [SugarColumn(IsPrimaryKey = true, IsIdentity = true, ColumnName = "id")] + public int Id { get; set; } + + /// + /// Desc:仓位编号 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "no")] + public string No { get; set; } + + /// + /// Desc:仓位编码 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "code")] + public string Code { get; set; } + + /// + /// Desc:仓位名称 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "name")] + public string Name { get; set; } + + /// + /// Desc:电池编号 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "battery_no")] + public string BatteryNo { get; set; } + + /// + /// Desc:充电机编号 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "charger_no")] + public string ChargerNo { get; set; } + + /// + /// Desc:充电枪编号 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "charger_gun_no")] + public string ChargerGunNo { get; set; } + + /// + /// Desc:水冷编号 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "water_cool_no")] + public string WaterCoolNo { get; set; } + + /// + /// Desc:是否有电插头;0-无电插头;1-有电插头 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "elec_plugin_flag")] + public int? ElecPluginFlag { get; set; } + + /// + /// Desc:电插头状态;0-未知;1-已经连接;2-未连接 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "elec_plugin_status")] + public string ElecPluginStatus { get; set; } + + /// + /// Desc:是否有水插头;0-无水插头;1-有水插头 + /// Default: + /// Nullable:False + /// + [SugarColumn(ColumnName = "water_plugin_flag")] + public string WaterPluginFlag { get; set; } + + /// + /// Desc:预约锁定;0-未锁定;1-锁定 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "amt_lock")] + public string AmtLock { get; set; } + + /// + /// Desc:soc + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "soc")] + public decimal? Soc { get; set; } + + /// + /// Desc:soe + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "soe")] + public decimal? Soe { get; set; } + + /// + /// Desc:soh + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "soh")] + public decimal? Soh { get; set; } + + /// + /// Desc:电池入仓顺序 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "battery_enter_seq")] + public int? BatteryEnterSeq { get; set; } + + /// + /// Desc:充电状态;0-未知;1-正在充电;2-无电池;3-禁用;4-充电停止 + /// Default:0 + /// Nullable:True + /// + [SugarColumn(ColumnName = "charge_status")] + public int? ChargeStatus { get; set; } + + /// + /// Desc:仓位状态;0-禁用;1-启用 + /// Default:1 + /// Nullable:True + /// + [SugarColumn(ColumnName = "status")] + public int? Status { get; set; } + + /// + /// Desc:创建人 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "created_by")] + public string CreatedBy { get; set; } + + /// + /// Desc:创建时间 + /// Default:CURRENT_TIMESTAMP + /// Nullable:True + /// + [SugarColumn(ColumnName = "created_time")] + public DateTime? CreatedTime { get; set; } + + /// + /// Desc:更新人 + /// Default: + /// Nullable:True + /// + [SugarColumn(ColumnName = "updated_by")] + public string UpdatedBy { get; set; } + + /// + /// Desc:更新时间 + /// Default:CURRENT_TIMESTAMP + /// Nullable:True + /// + [SugarColumn(ColumnName = "updated_time")] + public DateTime? UpdatedTime { get; set; } + + /// + /// 缓存仓标记 0:不是 1:是 + /// + [SugarColumn(ColumnName = "cache_bin_flag")] + public int CacheBinFlag { get; set; } + + + /// + /// 换电禁用标志 0:不可换电 1:可以换电 + /// + [SugarColumn(ColumnName = "can_swap_flag")] + public int CanSwapFlag { get; set; } + + + /// + /// 充电禁用标志 0:不可充电 1:可以充电 + /// + [SugarColumn(ColumnName = "can_charge_flag")] + public int CanChargeFlag { get; set; } } -} +} \ No newline at end of file diff --git a/Service/Charger/Client/ChargerClient.cs b/Service/Charger/Client/ChargerClient.cs index b54bf31..e17726f 100644 --- a/Service/Charger/Client/ChargerClient.cs +++ b/Service/Charger/Client/ChargerClient.cs @@ -238,9 +238,9 @@ public class ChargerClient : TcpClient /// /// SOC限制.百分比 /// 功率调节指令类型.默认1 绝对功率值 - /// 0.1kw/位,默认3600 + /// 1kw/位,默认3600 /// 充电流水号 - public Result SendRemoteStartCharging(byte socLimit, float changePower = 3600, byte changePowerCmdType = 1, + public Result SendRemoteStartCharging(byte socLimit, float changePower = 360, byte changePowerCmdType = 1, string? chargeOrderNo = null) { if (!Connected) diff --git a/Service/Charger/Client/ClientMgr.cs b/Service/Charger/Client/ClientMgr.cs index 0c8b078..4d02615 100644 --- a/Service/Charger/Client/ClientMgr.cs +++ b/Service/Charger/Client/ClientMgr.cs @@ -166,14 +166,6 @@ public static class ClientMgr continue; } - var chargeSoc = StaticStationInfo.ChargeSoc; - List 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 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; } - - #endregion - - - foreach (BinInfo binInfo in socNeedChargeList) + if(canSwapList.Count > needBatteryCount) { - if (Dictionary.TryGetValue(binInfo.ChargerNo, out var client)) + List chargingList = binInfos.Where(it => it.ChargeStatus == 1).ToList(); + + int needStopCount = chargingList.Count - (canSwapList.Count - needBatteryCount); + if (needStopCount > 0) { - Result result = client.StartCharge(); - Log.Info($"start {binInfo.ChargerNo} charge {result.IsSuccess}:{result.Msg}"); + chargingList.Sort((a,b) => (a.Soc??0).CompareTo(b.Soc??0)); + for (int i = 0; i < needStopCount; i++) + { + Log.Info($"auto stop charge {chargingList[i].No}"); + GetBySn(chargingList[i].No)?.SendRemoteStopCharging(); + } } - else + } + else + { + List 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? 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) { diff --git a/Service/Init/StaticStationInfo.cs b/Service/Init/StaticStationInfo.cs index ec3f013..ae27002 100644 --- a/Service/Init/StaticStationInfo.cs +++ b/Service/Init/StaticStationInfo.cs @@ -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); }