using Autofac; using Entity.Ammeter; using Entity.Constant; using Entity.DbModel.Station; using HybirdFrameworkCore.Autofac; using HybirdFrameworkCore.Autofac.Attribute; using HybirdFrameworkCore.Redis; using log4net; using Newtonsoft.Json; using OfficeOpenXml.FormulaParsing.Excel.Functions.Text; using Repository.Station; using Service.Ammeter; using Service.Cloud.Msg; using Service.Cloud.Msg.Cloud.Resp; using Service.Cloud.Msg.Host.Req; using Service.Execute.Api; using Service.FireControl.Client; using Service.Init; using Service.Station; using SqlSugar; using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; namespace Service.Cloud.Client; [Scope("SingleInstance")] public class CloudClientMgr { private static readonly ILog Log = LogManager.GetLogger(typeof(CloudClientMgr)); public static CloudClient? CloudClient { get; set; } static EmeterDayEnergyService emeterDayEnergyService = AppInfo.Container.Resolve(); static EmeterHourEnergyService emeterHourEnergyService = AppInfo.Container.Resolve(); static BinInfoRepository binInfoRepository = AppInfo.Container.Resolve(); private static DateTime _dateTime = DateTime.Now.AddSeconds(-30); private static DateTime _dateTime1 = DateTime.Now.AddSeconds(-30); private static DateTime _dateTime2 = DateTime.Now.AddSeconds(-10); private static DateTime _dateTime3 = DateTime.Now.AddSeconds(-10); private static DateTime _dateTime4 = DateTime.Now.AddSeconds(-10); private static DateTime _dateTime5 = DateTime.Now.AddMinutes(-15);//15分钟 private static DateTime _dateTime6 = DateTime.Now.AddMinutes(-15);//15分钟 private static DateTime _dateTime7 = DateTime.Today.AddHours(DateTime.Now.Hour-1);//小时 private static DateTime _dateTime8 = DateTime.Now.AddDays(-1).Date.AddHours(2);//天,每天两点 private static DateTime _dateTime9 = DateTime.Today.AddHours(DateTime.Now.Hour - 1);//小时 private static DateTime _dateTime10 = DateTime.Now.AddDays(-1).Date.AddHours(2);//天,每天两点 private static DateTime _dateTime11 = DateTime.Now.AddDays(-1).Date.AddHours(2);//天,每天两点 private static DateTime _dateTime12 = DateTime.Now.AddSeconds(-30); private static DateTime _dateTime13 = DateTime.Now.AddSeconds(-30); private static DateTime _dateTime14 = DateTime.Now.AddSeconds(-30); private const int TimeSpan = 5; private static ChargeDevDataInfo req = new ChargeDevDataInfo(); public static async void Init() { CloudClient = AppInfo.Container.Resolve(); CloudClient.MqttVersion = StaticStationInfo.CloudServerMqttVersion; CloudClient.ServerIp = StaticStationInfo.CloudServerIp; CloudClient.ServerPort = StaticStationInfo.CloudServerPort; CloudClient.ClientId = StaticStationInfo.CloudClientId; CloudClient.Username = StaticStationInfo.CloudUsername; CloudClient.Password = StaticStationInfo.CloudPassword; CloudClient.SubTopic = StaticStationInfo.CloudSubTopic; CloudClient.PubTopic = StaticStationInfo.CloudPubTopic; CloudClient.StationNo = StaticStationInfo.StationNo; CloudClient.AutoReConnect = true; CloudClient.InitHandler(); Task.Run(() => CloudClient.Connect()); RedisHelper? redisHelper = AppInfo.Container.Resolve(); BinInfoRepository binInfoRepository = AppInfo.Container.Resolve(); #region 遥测合并上报 req.datainfo = new List(); redisHelper?.GetSubscriber().Subscribe("UploadTelemetryData", (channel, value) => { try { if (value.HasValue) { UploadTelemetryData? data = JsonConvert.DeserializeObject(value.ToString()); if (data != null) { BinInfo? binInfo = binInfoRepository.QueryByClause(it => it.ChargerNo == data.ChargerNo); //ChargeDevDataInfo req = new ChargeDevDataInfo(); req.sn = StaticStationInfo.StationNo; DataInfo dataInfo = new DataInfo(); dataInfo.en = StaticStationInfo.StationNo + data.ChargerNo; var areNotEqual = !dataInfo.en.Equals( req.datainfo.Select(d => d.en) .ToList() .Any(x => x == dataInfo.en)); if (areNotEqual)//如果没有重复的 { dataInfo.sd = "A" + int.Parse(binInfo.No); dataInfo.mtp = StaticStationInfo.ChargePower; dataInfo.mcr = 1; dataInfo.hb = binInfo?.Exists ?? 0; dataInfo.el = 0; dataInfo.cno = int.Parse(binInfo.No); dataInfo.cs = binInfo.ChargeStatus ?? 0; dataInfo.fs = 0; dataInfo.@as = 0; //fc = data., //st = data., dataInfo.ct = data.ChargingTime; //ssoc = data., dataInfo.csoc = data.CurrentSoc; //ssoe = data., //csoe = data., dataInfo.cvot = data.BmsChargingVoltage; dataInfo.ccur = data.BmsChargingCurrent; dataInfo.nvot = data.BmsNeedVoltage; dataInfo.ncur = data.BmsNeedCurrent; dataInfo.lsv = data.SingleBatteryMinVoltage; dataInfo.hsv = data.SingleBatteryMaxVoltage; dataInfo.lst = data.MinBatteryTemp; dataInfo.hst = data.MaxBatteryTemp; dataInfo.ws = 0xFF; dataInfo.it = 0xFF; dataInfo.ot = 0xFF; dataInfo.bt = DateTime.Now; if (req.datainfo.Count < 7) { req.datainfo.Add(dataInfo); } } if ((DateTime.Now - _dateTime).TotalSeconds <= 30) { return; } _dateTime = DateTime.Now; if (req.datainfo.Count > 0) { CloudClient?.SendChargeDevDataInfo(req); req = new ChargeDevDataInfo(); req.datainfo = new List(); } Log.Info($"receive UploadTelemetryData={value}"); } } } catch (Exception e) { Log.Info("error", e); } }); #endregion redisHelper?.GetSubscriber().Subscribe("BatteryInfoUploadTask", (channel, value) => { try { Log.Info($"receive BatteryInfoUploadTask={value}"); if (value.HasValue) { BatDataInfo? data = JsonConvert.DeserializeObject(value.ToString()); if (data != null) { if ((DateTime.Now - _dateTime1).TotalSeconds <= 30) { return; } _dateTime1 = DateTime.Now; CloudClient?.SendBatDataInfo(data); } } } catch (Exception e) { Log.Info("error", e); } }); StartAsyncLoop(); } private static async Task StartAsyncLoop() { await Task.Run(() => { try { while (CloudClient!=null) { if (CloudClient.Connected) { if (StationConstant.StationModel.Remote == BaseEnumExtensions.GetEnumByCode( StaticStationInfo.StationModel)) { CloudApi.SendStateLog(); } TaskHostStatusReported(); TaskAirConditioningData(); TaskTemperatureHumidityData(); TaskPowerTotal(); TaskStaChargingTota(); TaskMeterEnergyKwh(); TaskMeterDayEnergyVal(); TaskStaHourEnergyVal(); TaskStaDayEnergyVal(); TaskStaDayOpeEnergyVal(); SendRealTimeFaultInfo(); //SendStartLogMessage(); //SendBatteryTotal(); //SendChargingTotalDis(); } Thread.Sleep(1000); } } catch (Exception ex) { Log.Error(ex); } }); } static int os = 0; /// /// 上传换电站状态 10s /// private static void TaskHostStatusReported() { if (os != StaticStationInfo.StationStatus) { if ((DateTime.Now - _dateTime2).TotalSeconds <= 30) { return; } _dateTime2 = DateTime.Now; //EquipAlarmRecordRepository equipAlarmRecordRepository = AppInfo.Container.Resolve(); //var EquipAlarm = equipAlarmRecordRepository.Query(); //var ErrorLevel = Convert.ToInt32(EquipAlarm.Min(x => x.ErrorLevel)); StationRunStatus stationRunStatus = new() { rs = StaticStationInfo.Sevstatus, os = StaticStationInfo.StationStatus, fl =Convert.ToInt32( StaticStationInfo.Faultlevel), }; CloudApi.SendHostStatusReported(stationRunStatus); } os = StaticStationInfo.StationStatus; } /// /// 空调数据上报 10s /// private static void TaskAirConditioningData() { if ((DateTime.Now - _dateTime3).TotalSeconds <= 60) { return; } _dateTime3 = DateTime.Now; AcDataInfo airConditioningData = new() { sn = StaticStationInfo.StationNo, ad = "", an = "", au = 0, am = 3, ap = 0, bt = DateTime.Now, }; CloudApi.SendAirConditioningData(airConditioningData); } /// /// 温湿度 10s /// private static void TaskTemperatureHumidityData() { if ((DateTime.Now - _dateTime4).TotalSeconds <= 30) { return; } _dateTime4 = DateTime.Now; EvmDataInfo evmDataInfo = new() { sn = StaticStationInfo.StationNo, ea = "电池仓", et = FireControlMgr.Temperature, eh = FireControlMgr.Humidity, bt = DateTime.Now, }; CloudApi.SendEvmDataInfo(evmDataInfo); } /// /// 电能表累计值信息 15m /// private static void TaskPowerTotal() { if ((DateTime.Now - _dateTime5).TotalMinutes <= 15) { return; } _dateTime5 = DateTime.Now; EmeterEnergyService emeterEnergyService = AppInfo.Container.Resolve(); EmeterEnergyChangeService emeterEnergyChangeService = AppInfo.Container.Resolve(); List emeterEnergy = emeterEnergyService.QueryListByClause(u=>u.UploadFlag==0, 7,i => i.UploadTime, OrderByType.Desc); emeterEnergy = emeterEnergy.OrderBy(p => p.Code).ToList(); var emeterEnergyChange = emeterEnergyChangeService.QueryListByClause(u => u.UploadFlag == 0, 7, i => i.UploadTime, OrderByType.Desc); emeterEnergyChange = emeterEnergyChange.OrderBy(p => p.Code).ToList(); PowerTotal powerTotal = new() { sn = StaticStationInfo.StationNo, }; powerTotal.meter = new List(); for (int i = 0; i < emeterEnergy.Count; i++) { meter meter = new() { addr = i + 1, desc = (i + 2).ToString() + "号仓直流表", ms = emeterEnergy[i].Code, mk = emeterEnergy[i].Value, }; powerTotal.meter.Add(meter); } for (int i = 0; i < emeterEnergyChange.Count; i++) { meter meter = new() { addr = i + 1, desc = (i + 2).ToString() + "号仓交流表", ms = emeterEnergyChange[i].Code, mk = emeterEnergyChange[i].Value, }; powerTotal.meter.Add(meter); } CloudApi.SendPowerTotal(powerTotal); } /// /// 电能表变化值信息 15m /// private static void TaskStaChargingTota() { if ((DateTime.Now - _dateTime6).TotalMinutes <= 15) { return; } _dateTime6 = DateTime.Now; EmeterEnergyService emeterEnergyService = AppInfo.Container.Resolve(); EmeterEnergyChangeService emeterEnergyChangeService = AppInfo.Container.Resolve(); List emeterEnergy = emeterEnergyService.QueryListByClause(u => u.UploadFlag == 0, 7, i => i.UploadTime, OrderByType.Desc); emeterEnergy = emeterEnergy.OrderBy(p => p.Code).ToList(); var emeterEnergyChange = emeterEnergyChangeService.QueryListByClause(u => u.UploadFlag == 0, 7, i => i.UploadTime, OrderByType.Desc); emeterEnergyChange = emeterEnergyChange.OrderBy(p => p.Code).ToList(); StaChargingTotal staChargingTotal = new() { sn = StaticStationInfo.StationNo, }; staChargingTotal.meter = new List(); for (int i = 0; i < emeterEnergy.Count; i++) { meter2 meter = new() { addr = i + 1, desc = (i + 2).ToString() + "号仓直流表", ms = emeterEnergy[i].Code, mk = emeterEnergy[i].Value, st = DateTime.Now.AddMinutes(-15), et = DateTime.Now, }; staChargingTotal.meter.Add(meter); } for (int i = 0; i < emeterEnergyChange.Count; i++) { meter2 meter = new() { addr = i + 1, desc = (i + 2).ToString() + "号仓交流表", ms = emeterEnergyChange[i].Code, mk = emeterEnergyChange[i].Value, st = DateTime.Now.AddMinutes(-15), et = DateTime.Now, }; staChargingTotal.meter.Add(meter); } CloudApi.SendStaChargingTotal(staChargingTotal); } /// /// 电能表小时能耗值信息 1h /// private static void TaskMeterEnergyKwh() { if ((DateTime.Now - _dateTime7).TotalHours <= 1) { return; } _dateTime7 = DateTime.Today.AddHours(DateTime.Now.Hour); var emeterEnergy = emeterHourEnergyService.QueryListByClause(u => u.UploadFlag == 0, 14, i => i.Time, OrderByType.Desc); emeterEnergy = emeterEnergy.OrderBy(p => p.Code).ToList(); var emeterEnergy1= emeterEnergy.Where(p => p.Type==1).ToList(); var emeterEnergy2= emeterEnergy.Where(p => p.Type==2).ToList(); MeterEnergyKwh meterEnergyKwh = new() { sn = StaticStationInfo.StationNo, }; meterEnergyKwh.meter = new List(); for (int i = 0; i < emeterEnergy1.Count; i++) { meter2 meter = new() { addr = i + 1, desc = (i + 2).ToString() + "号仓直流表", ms = emeterEnergy1[i].Code, mk = emeterEnergy1[i].Value, //st = DateTime.Now.AddMinutes(-60), //et = DateTime.Now, st = Convert.ToDateTime(emeterEnergy1[i].Time), et = Convert.ToDateTime(emeterEnergy1[i].Time).AddHours(1), }; meterEnergyKwh.meter.Add(meter); } for (int i = 0; i < emeterEnergy2.Count; i++) { meter2 meter = new() { addr = i + 1, desc = (i + 2).ToString() + "号仓交流表", ms = emeterEnergy2[i].Code, mk = emeterEnergy2[i].Value, //st = DateTime.Now.AddMinutes(-15), //et = DateTime.Now, st = Convert.ToDateTime(emeterEnergy2[i].Time), et = Convert.ToDateTime(emeterEnergy2[i].Time).AddHours(1), }; meterEnergyKwh.meter.Add(meter); } CloudApi.SendMeterEnergyKwh(meterEnergyKwh); for (int i = 0; i < emeterEnergy.Count; i++) { emeterEnergy[i].UploadFlag = 1; } emeterHourEnergyService.Update(emeterEnergy); } /// /// 电能表天能耗值信息 1d /// private static void TaskMeterDayEnergyVal() { if ((DateTime.Now - _dateTime8).TotalDays < 1) { return; } _dateTime8 = DateTime.Now.Date.AddHours(2); EmeterDayEnergyService emeterDayEnergyService = AppInfo.Container.Resolve(); var emeterEnergy = emeterDayEnergyService.QueryListByClause(u => u.UploadFlag == 0, 14, i => i.Time, OrderByType.Desc); emeterEnergy = emeterEnergy.OrderBy(p => p.Code).ToList(); var emeterEnergy1 = emeterEnergy.Where(p => p.Type == 1).ToList(); var emeterEnergy2 = emeterEnergy.Where(p => p.Type == 2).ToList(); MeterDayEnergyVal meterEnergyKwh = new() { sn = StaticStationInfo.StationNo, }; meterEnergyKwh.meter = new List(); for (int i = 0; i < emeterEnergy1.Count; i++) { meter2 meter = new() { addr = i + 1, desc = (i + 2).ToString() + "号仓直流表", ms = emeterEnergy1[i].Code, mk = emeterEnergy1[i].Value, //st = DateTime.Now.AddDays(-1), //et = DateTime.Now, st = Convert.ToDateTime(emeterEnergy1[i].Time).AddDays(-1), et = Convert.ToDateTime(emeterEnergy1[i].Time), }; meterEnergyKwh.meter.Add(meter); } for (int i = 0; i < emeterEnergy2.Count; i++) { meter2 meter = new() { addr = i + 1, desc = (i + 2).ToString() + "号仓交流表", ms = emeterEnergy2[i].Code, mk = emeterEnergy2[i].Value, //st = DateTime.Now.AddDays(-1), //et = DateTime.Now, st = Convert.ToDateTime(emeterEnergy2[i].Time).AddDays(-1), et = Convert.ToDateTime(emeterEnergy2[i].Time), }; meterEnergyKwh.meter.Add(meter); } CloudApi.SendMeterDayEnergyVal(meterEnergyKwh); for (int i = 0; i < emeterEnergy.Count; i++) { emeterEnergy[i].UploadFlag = 1; } emeterDayEnergyService.Update(emeterEnergy); } /// /// 换电站分时用电统计信息 1h /// private static void TaskStaHourEnergyVal() { if ((DateTime.Now - _dateTime9).TotalHours <= 1) { return; } _dateTime9 = DateTime.Today.AddHours(DateTime.Now.Hour); var emeterEnergy = emeterHourEnergyService.QueryListByClause(u => u.Type == 1, 7, i => i.Time, OrderByType.Desc); float hc = emeterEnergy.Sum(e => e.Value); StaHourEnergyVal meterEnergyKwh = new() { sn = StaticStationInfo.StationNo, ht= hc, hc = hc, hs =0, ho=0, //st = DateTime.Now.AddHours(-1), //et = DateTime.Now, st = Convert.ToDateTime(emeterEnergy?.First().Time), et = Convert.ToDateTime(emeterEnergy?.First().Time).AddHours(1), }; CloudApi.SendStaHourEnergyVal(meterEnergyKwh); } /// /// 换电站每天用电统计信息 1d /// private static void TaskStaDayEnergyVal() { if ((DateTime.Now - _dateTime10).TotalDays < 1) { return; } _dateTime10 = DateTime.Now.Date.AddHours(2); var emeterEnergy = emeterDayEnergyService.QueryListByClause(u => u.Type == 1, 7, i => i.Time, OrderByType.Desc); float dc = emeterEnergy.Sum(e => e.Value); StaDayEnergyVal staDayEnergyVal = new() { sn = StaticStationInfo.StationNo, ht = dc, hc = dc, hs = 0, ho = 0, //st = DateTime.Now.AddDays(-1), //et = DateTime.Now, st = Convert.ToDateTime(emeterEnergy?.First().Time).AddDays(-1), et = Convert.ToDateTime(emeterEnergy?.First().Time), }; CloudApi.SendStaDayEnergyVal(staDayEnergyVal); } /// /// 换电站日运行统计结果 1d /// private static void TaskStaDayOpeEnergyVal() { if ((DateTime.Now - _dateTime11).TotalDays < 1) { return; } _dateTime11 = DateTime.Now.Date.AddHours(2); ExStationDayRunResultService exStationDayRunResultService = AppInfo.Container.Resolve(); var exStationDayRunResult = exStationDayRunResultService.QueryByClause(u => u.Id !=0, i => i.CreatedTime, OrderByType.Desc); if (exStationDayRunResult!=null) { StaDayOpeEnergyVal staDayOpeEnergyVal = new() { sn = StaticStationInfo.StationNo, sm = StaticStationInfo.StationName, st = Convert.ToDateTime(exStationDayRunResult?.RunStartTime), et = Convert.ToDateTime(exStationDayRunResult?.RunEndTime), tt = Convert.ToInt32(exStationDayRunResult?.ToltalTimeCount), ft = exStationDayRunResult?.FristSwapTime, sp = exStationDayRunResult?.StopTime, ts = Convert.ToSingle(exStationDayRunResult?.ToltalSwapAllTime * 60), tc = Convert.ToInt32(exStationDayRunResult?.ToltalSwapCount), cc = Convert.ToInt32(exStationDayRunResult?.ChgCount), os = Convert.ToByte(exStationDayRunResult?.State), at = Convert.ToSingle(exStationDayRunResult?.AvgRepTime), ct = Convert.ToSingle(exStationDayRunResult?.AvgChgTime), dt = Convert.ToDateTime(exStationDayRunResult?.SwapDate), }; CloudApi.SendStaDayOpeEnergyVal(staDayOpeEnergyVal); } } /// /// 换电站分时用电统计信息(站控不计价,这一帧不要) /// private static void TaskStaHourAmountVal() { //if ((DateTime.Now - _dateTime2).TotalSeconds <= 30) //{ // return; //} //_dateTime2 = DateTime.Now; //var emeterEnergy = emeterDayEnergyService.QueryListByClause(u => u.Type == 1, 7, i => i.Time, // OrderByType.Desc); //float hc = emeterEnergy.Sum(e => e.Value); //ElecPriceModelVersionDetailServices elecPriceModelVersionDetailServices = AppInfo.Container.Resolve(); //var elecPriceModelVersionDetail= elecPriceModelVersionDetailServices.QueryListByClause(u=>u.Version==1); //var timeList = elecPriceModelVersionDetail.Select(u => u.StartHour).ToList(); //int targetTime = DateTime.Now.Hour; //int index1 = timeList.FindIndex(time => time > targetTime)-1; //index1 = index1<0? timeList.Count-1: index1; //int index2 = timeList.FindIndex(time => time == targetTime); //int index3 = index2 == -1 ? index1 : index2; //var price = elecPriceModelVersionDetail[index3].Price; //StaHourAmountVal staHourAmountVal = new() //{ // sn = StaticStationInfo.StationNo, // ht = Convert.ToSingle(hc * price), // hc = Convert.ToSingle(hc * price), // hs = 0, // ho = 0, // //st = DateTime.Now.AddHours(-1), // //et = DateTime.Now, // st = Convert.ToDateTime(emeterEnergy?.First().Time), // et = Convert.ToDateTime(emeterEnergy?.First().Time).AddHours(1), //}; //CloudApi.SendStaHourAmountVal(staHourAmountVal); } /// /// 换电站上报设备列表 /// public static void SendDevList(int ot) { EquipInfoRepository equipInfoRepository = AppInfo.Container.Resolve(); var equipList = equipInfoRepository.Query(); DevList devList = new() { ot = ot, sn = StaticStationInfo.StationNo, vs = "1.0", }; devList.d_info = new List(); for (int i = 0; i < equipList.Count; i++) { D_INFO d_INFO = new D_INFO(); d_INFO.dn = (equipList[i].TypeCode==0?"充电机":"电表")+ equipList[i].Code; d_INFO.dt = equipList[i].TypeCode == 0 ? "充电机" : "电表"; d_INFO.dc = equipList[i].TypeCode.ToString(); d_INFO.tc = equipList[i].Status.ToString(); d_INFO.ds = equipList[i].Id.ToString(); d_INFO.sn = equipList[i].Code; d_INFO.en = ""; d_INFO.hv = ""; d_INFO.sv = ""; d_INFO.mn = ""; d_INFO.ns = equipList[i].Addr.ToString(); d_INFO.ti = equipList[i].CreatedTime.ToString(); devList.d_info.Add(d_INFO); } CloudApi.SendDevList(devList); } /// /// 实时故障信息上传 /// public static void SendRealTimeFaultInfo() { EquipAlarmRecordRepository equipAlarmRecordRepository = AppInfo.Container.Resolve(); var AlarmList = equipAlarmRecordRepository.QueryListByClause(u => u.UploadStatus == 0); EquipAlarmProcessRecordRepository equipAlarmProcessRecordRepository = AppInfo.Container.Resolve(); var AlarmProcessList = equipAlarmProcessRecordRepository.QueryListByClause(u => u.UploadStatus == 0); //产生上传 for (int i = 0; i < AlarmList.Count; i++) { FaultReport faultReport = new() { sn = StaticStationInfo.StationNo, en= AlarmList[i].EquipCode, fc= AlarmList[i].ErrorCode, ft= AlarmList[i].ErrorMsg, fl= Convert.ToInt32( AlarmList[i].ErrorLevel), fg= 1, bt= AlarmList[i].StartTime.ToString(), cm=1, }; CloudApi.SendRealTimeFaultInfo(faultReport); Thread.Sleep(500); } //消失上传 for (int i = 0; i < AlarmProcessList.Count; i++) { FaultReport faultReport = new() { sn = StaticStationInfo.StationNo, en = AlarmProcessList[i].EquipCode, fc = AlarmProcessList[i].ErrorCode, ft = AlarmProcessList[i].ErrorMsg, fl = Convert.ToInt32(AlarmProcessList[i].ErrorLevel), fg = 2, bt = AlarmProcessList[i].ProcessTime.ToString(), cm = 1, }; CloudApi.SendRealTimeFaultInfo(faultReport); Thread.Sleep(500); } } static List equipInfos; static bool variation = false; /// /// 换电站设备状态开始和结束日志信息 /// public static void SendStartLogMessage() { if ((DateTime.Now - _dateTime12).TotalSeconds <= 30) { return; } _dateTime12 = DateTime.Now; EquipInfoRepository equipInfoRepository = AppInfo.Container.Resolve(); var equipList = equipInfoRepository.Query(); if (equipInfos == null) { equipInfos = equipList; } if (variation) { for (int i = 0; i < equipList.Count; i++) { if (equipInfos[i].UpdatedTime != equipList[i].UpdatedTime) { EqmStateEndLogInfo req = new() { en = StaticStationInfo.StationNo + equipInfos[i].Code, sv = Convert.ToByte(equipInfos[i].Status), sm = equipInfos[i].Status == 1 ? "启用" : "停用", st = equipInfos[i].UpdatedTime, et = equipList[i].UpdatedTime, ke= (int)(equipList[i].UpdatedTime- equipInfos[i].UpdatedTime).TotalSeconds, cm = 1, }; CloudApi.SendEndLogMessage(req); variation = false; } } } for (int i = 0; i < equipList.Count; i++) { if (equipInfos[i].UpdatedTime != equipList[i].UpdatedTime) { EqmStateStartLogInfo req = new() { en = StaticStationInfo.StationNo + equipInfos[i].Code, SV = Convert.ToByte(equipInfos[i].Status), sm = equipInfos[i].Status == 1 ? "启用": "停用" , st = equipList[i].UpdatedTime, cm = 1, }; CloudApi.SendStartLogMessage(req); variation= true; } } equipInfos = equipList; } /// /// 换电站上报电池状态分布统计信息 2分钟 /// public static void SendBatteryTotal() { if ((DateTime.Now - _dateTime13).TotalMinutes <= 2) { return; } _dateTime13 = DateTime.Now; var binList = binInfoRepository.Query(); int bt = binList.Select(u => u.Exists == 1).Count(); int ct = binList.Select(u => u.Soc >= StaticStationInfo.SwapSoc).Count(); int cc = binList.Select(u => u.ChargeStatus ==1).Count(); int ca = binList.Select(u => u.Soc < StaticStationInfo.SwapSoc).Count(); BatteryTotal devList = new() { sn= StaticStationInfo.StationNo, btc=1, sm="99999999", bn="默认型号", bc= bt, ct= ct, cc=cc, ca=ca, ut=DateTime.Now, }; CloudApi.SendBatteryTotal(devList); } /// /// 换电站充电电池电量分布统计信息 2分钟 /// public static void SendChargingTotalDis() { if ((DateTime.Now - _dateTime14).TotalMinutes <= 2) { return; } _dateTime14 = DateTime.Now; var binList = binInfoRepository.Query(); int hc = binList.Select(u => u.Soc >= 90).Count(); int mc = binList.Select(u => u.Soc >= 80&& u.Soc<90).Count(); int lc = binList.Select(u => u.Soc >= 0&& u.Soc<80).Count(); ChargingTotalDis req = new() { sn = StaticStationInfo.StationNo, bs = "99999999", bn = "默认型号", hc = hc, mc = mc, lc = lc, }; CloudApi.SendChargingTotalDis(req); } }