You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

163 lines
6.4 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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)
{
while (true)
{
if (string.IsNullOrWhiteSpace(waterCoolClient.ChargeSn))
{
var dictionary =
StaticStationInfo.RelationMap.Values.ToDictionary(i => i.WaterCoolerCode,
i => i.ChargeCode);
waterCoolClient.ChargeSn = dictionary[waterCoolClient.Sn];
}
var chargerClient = ClientMgr.GetBySn(waterCoolClient.ChargeSn);
if (chargerClient == null)
{
return;
}
if (!waterCoolClient.StopFlag)
{
//Tmin<=12℃且Tmean<=15℃
if (!waterCoolClient.HortStrategyFlag && chargerClient.BatteryPackDataVoltage
?.CellTemperatureMax <=
15
&& chargerClient.BatteryPackDataVoltage
?.CellTemperatureMin <=
12)
{
waterCoolClient.HortStrategyFlag = true;
}
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;
}
}
}
else
{
//TODO:: 停止需要干什么事情
}
}
}
}
}
public bool Stoped()
{
return _stop;
}
public void Stop()
{
_stop = true;
}
public void ResetStop()
{
_stop = false;
}
}