From 1b1991be1910597dc082d92a423f7092e3aae0b2 Mon Sep 17 00:00:00 2001 From: fyf Date: Thu, 12 May 2022 16:58:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=91=8A=E8=AD=A6=E6=8E=92?= =?UTF-8?q?=E5=BA=8F=E4=B8=8E=E8=AE=BE=E5=A4=87=E7=8A=B6=E6=80=81=E6=95=B0?= =?UTF-8?q?=E9=87=8F=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DataVAPI.ServerDB/MongoDB/MongodbHelper.cs | 5 ++ DataVAPI/Controllers/AlarmController.cs | 1 + DataVAPI/Controllers/DeviceStatsController.cs | 52 ++++++++++++++----- 3 files changed, 46 insertions(+), 12 deletions(-) diff --git a/DataVAPI.ServerDB/MongoDB/MongodbHelper.cs b/DataVAPI.ServerDB/MongoDB/MongodbHelper.cs index 17547b1..bb346fe 100644 --- a/DataVAPI.ServerDB/MongoDB/MongodbHelper.cs +++ b/DataVAPI.ServerDB/MongoDB/MongodbHelper.cs @@ -206,6 +206,11 @@ namespace DataVAPI.ServerDB.MongoDB return collection.Find(a => a.KeyID== key)?.ToList().FirstOrDefault(); } + public List ALLData(string key) + { + return collection.Find(a => a.ClientId == key)?.ToList(); + } + public PaginationListModel BasePagQuery(string clientId, string deviceId, DateTime datesta, DateTime datastop, int PageNumber, int PageSize) { BasePaginationModel pagination = new BasePaginationModel() diff --git a/DataVAPI/Controllers/AlarmController.cs b/DataVAPI/Controllers/AlarmController.cs index 9133996..524a0d5 100644 --- a/DataVAPI/Controllers/AlarmController.cs +++ b/DataVAPI/Controllers/AlarmController.cs @@ -112,6 +112,7 @@ namespace DataVAPI.Controllers 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 }; } }); + al.Sort((a, b) => -a.State.CompareTo(b.State)); return JsonMsg>.OK(al, st); } catch (Exception ex) diff --git a/DataVAPI/Controllers/DeviceStatsController.cs b/DataVAPI/Controllers/DeviceStatsController.cs index 414c6c9..64869e2 100644 --- a/DataVAPI/Controllers/DeviceStatsController.cs +++ b/DataVAPI/Controllers/DeviceStatsController.cs @@ -29,16 +29,16 @@ namespace DataVAPI.Controllers st = System.Reflection.MethodBase.GetCurrentMethod().Name; try { - string gj_time="未知"; + string gj_time = "未知"; string sx_time = "未知"; string xx_time = "未知"; AlarmTable alarmTable = mggj.QueryClientIdMax(clientId); List log = mglog.QueryClientId(clientId); if (alarmTable != null) gj_time = alarmTable.AlarmTime; - LogTable logTable1= log.Find(par => par.LogMessage.Contains("设备在线了")); + LogTable logTable1 = log.Find(par => par.LogMessage.Contains("设备在线了")); LogTable logTable2 = log.Find(par => par.LogMessage.Contains("设备离线了")); - if(logTable1!=null) sx_time = logTable1.LogTime; + if (logTable1 != null) sx_time = logTable1.LogTime; if (logTable2 != null) xx_time = logTable2.LogTime; List list = new List(); @@ -48,7 +48,7 @@ namespace DataVAPI.Controllers OnlineTime = sx_time, OfflineTime = xx_time }); - + return JsonMsg.OK(list, st); } catch (Exception ex) @@ -63,7 +63,7 @@ namespace DataVAPI.Controllers /// /// [HttpGet] - public JsonMsg StatsTargetStatus(string clientId,string deviceId) + public JsonMsg StatsTargetStatus(string clientId, string deviceId) { object obj; List returns = new List(); st = System.Reflection.MethodBase.GetCurrentMethod().Name; @@ -76,10 +76,10 @@ namespace DataVAPI.Controllers if (largeScreen.json != null && largeScreen.json.Contains("data")) { TargetStatus _Target = Tools.JsonToObjectTools(largeScreen.json); - TargetStatusList statusList= _Target?.data?.Find(ar => ar.DeviceId.ToString()== deviceId); + TargetStatusList statusList = _Target?.data?.Find(ar => ar.DeviceId.ToString() == deviceId); if (statusList != null) { - + foreach (var item in statusList.Status) { //PLC.MorksMachine.IsConnected @@ -88,17 +88,17 @@ namespace DataVAPI.Controllers string Ms = string.Empty; if (item.Key.Contains(".")) { - string sta = item.Key.Split('.')[0]; + string sta = item.Key.Split('.')[0]; string sop = item.Key.Split('.')[item.Key.Split('.').Length - 1]; name = sop; string value = item.Value.ToString(); - if (keyValues.ContainsKey(sta)) sta = keyValues[sta]; + if (keyValues.ContainsKey(sta)) sta = keyValues[sta]; if (keyValues.ContainsKey(sop)) sop = keyValues[sop]; if (keyValues.ContainsKey(value)) value = keyValues[value]; Ms = $"[{sta}]-[{sop}]-[{value}]"; } - returns.Add(new returnStatus { Name = name, Status = item.Value.ToString(),Ms=Ms}); + returns.Add(new returnStatus { Name = name, Status = item.Value.ToString(), Ms = Ms }); } } } @@ -115,7 +115,35 @@ namespace DataVAPI.Controllers } } - public Dictionary keyValues = new Dictionary() + /// + /// 统计数量 + /// + /// + /// + [HttpGet] + public JsonMsg StatsConut(string clientId) + { + st = System.Reflection.MethodBase.GetCurrentMethod().Name; + try + { + List log = mglog.ALLData(clientId); + List alarm = mggj.ALLData(clientId); + List list = new List(); + + list.Add(new { Name = "运行次数", Count = log?.FindAll(par => par.LogMessage.Contains("设备在线了")).Count.ToString() }); + list.Add(new { Name = "故障次数", Count = alarm?.Count.ToString() }); + list.Add(new { Name = "故障率", Count = $"{(alarm?.Count * 100) / 100}%" }); + + return JsonMsg.OK(list, st); + } + catch (Exception ex) + { + return JsonMsg.Error(null, st, ex.Message); + } + } + + + public Dictionary keyValues = new Dictionary() { {"PLC","煮面机机器人" }, {"Lebai","乐白机器人" }, @@ -169,7 +197,7 @@ namespace DataVAPI.Controllers _status = value; if (_status == "False" || _status == "True") { - if(_status== "True") + if (_status == "True") StatusColor = new ALYColor { r = 51, g = 232, b = 34, a = 1 }; else StatusColor = new ALYColor { r = 255, g = 0, b = 0, a = 1 };