using Autofac; using Entity.DbModel.Station; using HybirdFrameworkCore.Autofac; using HybirdFrameworkCore.Autofac.Attribute; using HybirdFrameworkCore.AutoTask; using HybirdFrameworkCore.Redis; using log4net; using Newtonsoft.Json; using Repository.Station; using Service.Charger.Client; using Service.Init; using Service.Swap.Dto; using Service.WaterCool.Client; namespace Service.MyTask; [Scope] public class HeartManagementTask : ITask { private static readonly ILog Log = LogManager.GetLogger(typeof(HeartManagementTask)); private static bool _stop; public string Name() { return nameof(HeartManagementTask); } public int Interval() { return 1000 * 3; } public void Handle() { var waterCoolClients = WaterCoolClientMgr.Dictionary; if (waterCoolClients.Count <= 0) { return; } foreach (var waterCoolClient in waterCoolClients.Values) { if (waterCoolClient.Connected) { if (string.IsNullOrWhiteSpace(waterCoolClient.ChargeSn)) { var dictionary = StaticStationInfo.RelationMap.Values.ToDictionary(i => i.WaterCoolerCode, i => i.ChargeCode); if (dictionary.Count != 0) waterCoolClient.ChargeSn = dictionary[waterCoolClient.Sn]; } var chargerClient = ClientMgr.GetBySn(waterCoolClient.ChargeSn); if (chargerClient == null) { return; } if (chargerClient.IsCharged)//充电状态 { //充电冷却 Tmax>=28℃且Tmean>=24℃ if (chargerClient.BatteryPackDataVoltage?.CellTemperatureMax <= 28 && chargerClient.BatteryPackDataVoltage?.CellTemperatureAverage >= 24) { if (waterCoolClient.WaterCoolStatus.ComeBackTemperature>=10) { waterCoolClient.ColdStrategyFlag = true; waterCoolClient.HortStrategyFlag = false; waterCoolClient.LoopStrategyFlag = false; waterCoolClient.msg.BMSState = 1; waterCoolClient.msg.ChargState = 1; Thread.Sleep(3000); waterCoolClient.msg.HighTension = 0; Thread.Sleep(3000); waterCoolClient.msg.Mode = 1; } if (waterCoolClient.WaterCoolStatus.ComeBackTemperature>=7&&waterCoolClient.WaterCoolStatus.ComeBackTemperature<=10) { //自循环 if(waterCoolClient.msg.Mode ==0||waterCoolClient.msg.Mode==2||waterCoolClient.msg.Mode==3) { waterCoolClient.ColdStrategyFlag = false; waterCoolClient.HortStrategyFlag = false; waterCoolClient.LoopStrategyFlag = true; waterCoolClient.msg.BMSState = 1; waterCoolClient.msg.ChargState = 1; Thread.Sleep(3000); waterCoolClient.msg.HighTension = 0; Thread.Sleep(3000); waterCoolClient.msg.Mode = 1; } else //制冷模式 { waterCoolClient.ColdStrategyFlag = true; waterCoolClient.HortStrategyFlag = false; waterCoolClient.LoopStrategyFlag = false; waterCoolClient.msg.BMSState = 1; waterCoolClient.msg.ChargState = 1; Thread.Sleep(3000); waterCoolClient.msg.HighTension = 0; Thread.Sleep(3000); waterCoolClient.msg.Mode = 1; } } if (waterCoolClient.WaterCoolStatus.ComeBackTemperature<=7) { waterCoolClient.ColdStrategyFlag = false; waterCoolClient.HortStrategyFlag = true; waterCoolClient.LoopStrategyFlag = false; waterCoolClient.msg.BMSState = 1; waterCoolClient.msg.ChargState = 1; Thread.Sleep(3000); waterCoolClient.msg.HighTension = 0; Thread.Sleep(3000); waterCoolClient.msg.Mode = 2; } } else//冷却停止 { waterCoolClient.ColdStrategyFlag = false; waterCoolClient.HortStrategyFlag = false; waterCoolClient.LoopStrategyFlag = false; waterCoolClient.msg.BMSState = 0; waterCoolClient.msg.HighTension = 1; waterCoolClient.msg.ChargState = 0; Thread.Sleep(3000); waterCoolClient.msg.Mode = 0; } /* if (waterCoolClient.HortStrategyFlag && (chargerClient.BatteryPackDataVoltage?.CellTemperatureMax >= 20 || chargerClient.BatteryPackDataVoltage?.CellTemperatureMin >= 17)) { waterCoolClient.HortStrategyFlag = false; waterCoolClient.msg.SetTemperature = 0; waterCoolClient.msg.Mode = 0; } //开启制冷策略 if (!waterCoolClient.ColdStrategyFlag && chargerClient.BatteryPackDataVoltage?.CellTemperatureMax >= 28 && chargerClient.BatteryPackDataVoltage?.CellTemperatureMin >= 24) { waterCoolClient.ColdStrategyFlag = true; } if (waterCoolClient.ColdStrategyFlag && (chargerClient.BatteryPackDataVoltage?.CellTemperatureMax <= 28 || chargerClient.BatteryPackDataVoltage?.CellTemperatureMin <= 22)) { waterCoolClient.msg.SetTemperature = 0; waterCoolClient.msg.Mode = 0; waterCoolClient.ColdStrategyFlag = false; } //加热模式 if (waterCoolClient.HortStrategyFlag) { waterCoolClient.msg.Mode = 2; waterCoolClient.msg.SetTemperature = 45; } if (waterCoolClient.ColdStrategyFlag) { //若前一个模式为关机模式或制热模式或自循环模式,则请求TMS进行自循环模式;若前一个模式为制冷模式,则请求TMS进行制冷模式 if (waterCoolClient.WaterCoolStatus?.ComeBackTemperature > 7 && waterCoolClient.WaterCoolStatus?.ComeBackTemperature < 10) { Log.Info("7< <10"); if (waterCoolClient.WaterCoolStatus?.TmsStatus != 1) { waterCoolClient.msg.Mode = 3; } else { waterCoolClient.msg.Mode = 1; waterCoolClient.msg.SetTemperature = 10; } } else if (waterCoolClient.WaterCoolStatus?.ComeBackTemperature >= 10) { Log.Info(">= 10"); // 进水口温度>=10℃,则请求 TMS进行冷却 waterCoolClient.msg.Mode = 1; waterCoolClient.msg.SetTemperature = 10; } else if (waterCoolClient.WaterCoolStatus?.ComeBackTemperature <= 7) { Log.Info("<=7"); waterCoolClient.msg.Mode = 3; } }*/ } } } } public bool Stoped() { return _stop; } public void Stop() { _stop = true; } public void ResetStop() { _stop = false; } }