using Autofac; using Entity.DbModel.Station; using HybirdFrameworkCore.Autofac; using HybirdFrameworkCore.AutoTask; using HybirdFrameworkCore.Redis; using Newtonsoft.Json; using Repository.Station; using Service.Charger.Client; using Service.Init; using Service.Swap.Dto; namespace Service.MyTask; public class BatteryInfoUploadTask : ITask { private RedisHelper RedisHelper { get; set; } = AppInfo.Container.Resolve(); private BinInfoRepository BinInfoRepository = AppInfo.Container.Resolve(); private static bool _stop; public string Name() { return nameof(BatteryInfoUploadTask); } public int Interval() { return 1000 * 30; } public void Handle() { DateTime now = DateTime.Now; List binInfos = BinInfoRepository.Query(); List batInfos = binInfos.Where(it => it.Exists == 1).Select(it => { ChargerClient? client = ClientMgr.GetBySn(it.ChargerNo); SingleBatInfo batInfo = new SingleBatInfo() { bn = it.BatteryNo, bt = now, sd = it.ChargerNo, cno = Convert.ToInt32(it.ChargerNo.Substring(1)), el = 0, hc = Convert.ToInt32(it.ChargeStatus), hst=Convert.ToSingle(client?.BatteryPackDataVoltage?.CellTemperatureMax), hsv = Convert.ToSingle(client?.BatteryPackDataVoltage?.CellVoltageMax), lst = Convert.ToSingle(client?.BatteryPackDataVoltage?.CellTemperatureMin), lsv = Convert.ToSingle(client?.BatteryPackDataVoltage?.CellVoltageMin), soc = Convert.ToSingle(it.Soc), soe = Convert.ToSingle(it.Soe), soh = Convert.ToSingle(it.Soh) }; return batInfo; }).ToList(); BatDataInfo batDataInfo = new BatDataInfo { batn = batInfos.Count, sn = StaticStationInfo.StationNo, datainfo = batInfos }; RedisHelper.PublishAsync("BatteryInfoUploadTask", JsonConvert.SerializeObject(batDataInfo)); } public bool Stoped() { return _stop; } public void Stop() { _stop = true; } public void ResetStop() { _stop = false; } }