From c2387eccf864f2a2279bf768242bfa5d6636b00c Mon Sep 17 00:00:00 2001 From: xiaoguo Date: Fri, 21 Jun 2024 21:54:19 +0800 Subject: [PATCH] =?UTF-8?q?cvd=20=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CVDEMCS/Devices/Impl/DeviceRun.cs | 57 +++++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 11 deletions(-) diff --git a/CVDEMCS/Devices/Impl/DeviceRun.cs b/CVDEMCS/Devices/Impl/DeviceRun.cs index db5590d..37f6187 100644 --- a/CVDEMCS/Devices/Impl/DeviceRun.cs +++ b/CVDEMCS/Devices/Impl/DeviceRun.cs @@ -138,7 +138,7 @@ namespace PVDEMCS.Devices.Impl } catch (Exception ex) { - ex.WriteErrorLog("设备记录日统计异常"); + ex.WriteErrorLog("设备记录日统计异常"); } Thread.Sleep(1000 * 60); @@ -146,6 +146,41 @@ namespace PVDEMCS.Devices.Impl } }); + //设备记录日统计(修复统计,解决出现跨天的数据统计不到的情况) + Task.Run(() => + { + //凌晨1点运行 + var now = DateTime.Now; + var targetTime = new DateTime(now.Year, now.Month, now.Day, 1, 0, 0); + if (targetTime <= now) + { + // 如果目标时间已经过去,则设置到明天 + targetTime = targetTime.AddDays(1); + } + while (true) + { + try + { + Thread.Sleep(TimeSpan.FromMilliseconds(targetTime.Subtract(DateTime.Now).TotalMilliseconds)); + + //这里修复10天前的 + for (int i = 10; i > 0; i--) + { + equipmentRecordService.RunEquipmentRecordDayTotal(DateTime.Now.AddDays(-i)); + } + + $" 设备记录日统计(修复统计) ".WriteInfoLog(); + } + catch (Exception ex) + { + ex.WriteErrorLog("设备记录日统计(修复统计)异常"); + } + + //明天继续 + targetTime = targetTime.AddDays(1); + } + }); + //设备记录统计 Task.Run(() => { @@ -155,11 +190,11 @@ namespace PVDEMCS.Devices.Impl { equipmentRecordService.RunEquipmentRecordTotal(); } - catch (Exception ex) + catch (Exception ex) { ex.WriteErrorLog("设备记录统计异常"); } - + Thread.Sleep(1000 * 1800); } }); @@ -205,28 +240,28 @@ namespace PVDEMCS.Devices.Impl else if (fault.GetValue()) { state = EquipmentState.Alarm; - + } //如果为报警状态,则判断是否设为手动,且为不报警,则屏蔽报警信号,不做记录 - if (state == EquipmentState.Alarm && - startStop.Model == EquipmentAlarmModel.Manual && + if (state == EquipmentState.Alarm && + startStop.Model == EquipmentAlarmModel.Manual && !startStop.IsAlarm) { continue; } //equipmentRecordService.AddUpdateEquipmentRecord(id, state, DateTime.Now); - models.Add(new EquipmentRecordUpdateModel + models.Add(new EquipmentRecordUpdateModel { - EquipmentId=id, - State=state, - DateTime=DateTime.Now + EquipmentId = id, + State = state, + DateTime = DateTime.Now }); } } } } - if (models.Count > 0) + if (models.Count > 0) { //批量更新 equipmentRecordService.AddUpdateEquipmentRecordBatch(models);