From cea29256c28a3ae4f216a39b882257c1af940e77 Mon Sep 17 00:00:00 2001 From: fyf Date: Thu, 12 May 2022 14:09:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=91=8A=E8=AD=A6=E6=B6=88?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DataVAPI.Model/AlarmTable.cs | 8 ++++++++ DataVAPI.ServerDB/MongoDB/MongodbHelper.cs | 11 ++++++++++- DataVAPI/Controllers/AlarmController.cs | 8 +++++++- DataVAPI/UpAndDown/ProcessServer.cs | 17 +++++++++++++++-- 4 files changed, 40 insertions(+), 4 deletions(-) diff --git a/DataVAPI.Model/AlarmTable.cs b/DataVAPI.Model/AlarmTable.cs index 16f53e8..3045f90 100644 --- a/DataVAPI.Model/AlarmTable.cs +++ b/DataVAPI.Model/AlarmTable.cs @@ -32,5 +32,13 @@ namespace DataVAPI.Model /// IP 地址 /// public string IP { get; set; } + /// + /// 状态描述 + /// + public string StatusMS { get; set; } + /// + /// 状态颜色 + /// + public object StatusColor { get; set; } } } diff --git a/DataVAPI.ServerDB/MongoDB/MongodbHelper.cs b/DataVAPI.ServerDB/MongoDB/MongodbHelper.cs index 59f3064..17547b1 100644 --- a/DataVAPI.ServerDB/MongoDB/MongodbHelper.cs +++ b/DataVAPI.ServerDB/MongoDB/MongodbHelper.cs @@ -182,7 +182,7 @@ namespace DataVAPI.ServerDB.MongoDB public List QueryClientId(string clientId) { - return collection.Find(a => a.ClientId == clientId && a.CreateTime >= DateTime.Now.Date && a.State == "y")?.ToList().OrderByDescending(a => a.CreateTime)?.ToList(); + return collection.Find(a => a.ClientId == clientId && a.CreateTime >= DateTime.Now.Date)?.ToList().OrderByDescending(a => a.CreateTime)?.ToList(); } public T QueryClientIdMax(string clientId) @@ -201,6 +201,11 @@ namespace DataVAPI.ServerDB.MongoDB return collection.Find(a => a.State.Equals("y"))?.ToList(); } + public T QueryKeyID(string key) + { + return collection.Find(a => a.KeyID== key)?.ToList().FirstOrDefault(); + } + public PaginationListModel BasePagQuery(string clientId, string deviceId, DateTime datesta, DateTime datastop, int PageNumber, int PageSize) { BasePaginationModel pagination = new BasePaginationModel() @@ -261,6 +266,10 @@ namespace DataVAPI.ServerDB.MongoDB /// [BsonDateTimeOptions(Kind = DateTimeKind.Local)] public DateTime UpdateTime { get; set; } + /// + /// key + /// + public string KeyID { get; set; } } diff --git a/DataVAPI/Controllers/AlarmController.cs b/DataVAPI/Controllers/AlarmController.cs index 7ed0887..29d29fe 100644 --- a/DataVAPI/Controllers/AlarmController.cs +++ b/DataVAPI/Controllers/AlarmController.cs @@ -13,7 +13,7 @@ namespace DataVAPI.Controllers /// public class AlarmController : BaseController { - MongoDbHelper mg = new MongoDbHelper(DataBus.connStr, DataBus.dbName); + public MongoDbHelper mg = new MongoDbHelper(DataBus.connStr, DataBus.dbName); MongoDbHelper mgsb = new MongoDbHelper(DataBus.connStr, DataBus.dbName); string st = System.Reflection.MethodBase.GetCurrentMethod().Name; @@ -106,6 +106,12 @@ namespace DataVAPI.Controllers st = System.Reflection.MethodBase.GetCurrentMethod().Name; try { + List al = mg.QueryClientId(clientId); + al?.ForEach(par => + { + if (par.State == "y") { par.StatusMS = "未处理"; par.StatusColor = new { r = 255, g = 0, b = 0, a = 1 }; } + else { par.StatusMS = "已处理"; par.StatusColor = new { r = 51, g = 232, b = 34, a = 1 }; } + }); return JsonMsg>.OK(mg.QueryClientId(clientId), st); } catch (Exception ex) diff --git a/DataVAPI/UpAndDown/ProcessServer.cs b/DataVAPI/UpAndDown/ProcessServer.cs index a127020..0133780 100644 --- a/DataVAPI/UpAndDown/ProcessServer.cs +++ b/DataVAPI/UpAndDown/ProcessServer.cs @@ -224,6 +224,8 @@ namespace DataVAPI.UpAndDown }); int index = 0; if (receiveModel.status.value == "离线") index = devModel.operatingDeviceStatus.data.Count - 1; + else index = devModel.operatingDeviceStatus.data.FindLastIndex(0,ar => ar.DeviceMS.Contains("在线"))+1; + if (index > devModel.operatingDeviceStatus.data.Count - 1) index = devModel.operatingDeviceStatus.data.Count - 1; int now = devModel.operatingDeviceStatus.data.IndexOf(dev); Swap(devModel.operatingDeviceStatus.data, index, now); } @@ -318,12 +320,23 @@ namespace DataVAPI.UpAndDown if (message.Contains("AlarmType")) { - alarmController.Create(Tools.JsonToObjectTools(message)); + AlarmTable alarm= Tools.JsonToObjectTools(message); + if (alarm.State == "n") + { + AlarmTable al = alarmController.mg.QueryKeyID(alarm.KeyID); + if (al != null) + { + alarmController.mg.Modify(al.Id, "State", "n"); + } + } + else + { + alarmController.Create(alarm); + } } else if (message.Contains("LogType")) { logController.Create(Tools.JsonToObjectTools(message)); - } } //else if (topic == IOTDevServer.TargetStatusSubTopic)//属性变更