diff --git a/BPASmartClient.DRCoffee/CoffeeMachine.cs b/BPASmartClient.DRCoffee/CoffeeMachine.cs index ea60763b..7f2f7bb6 100644 --- a/BPASmartClient.DRCoffee/CoffeeMachine.cs +++ b/BPASmartClient.DRCoffee/CoffeeMachine.cs @@ -164,7 +164,7 @@ namespace BPASmartClient.DRCoffee { status["Status"] = DrCoffeeStatus.Wait; status["AppStatus"] = DrCoffeeAppStatus.应用无状态; - status["Warning"] = DrCoffeeWarning.无警告; + status["Warning"] = DrCoffeeWarning.冲泡器未安装到位; status["Fault"] = DrCoffeeFault.无故障; } diff --git a/BPASmartClient.Device/BaseDevice.cs b/BPASmartClient.Device/BaseDevice.cs index 74e2e75b..adc293e7 100644 --- a/BPASmartClient.Device/BaseDevice.cs +++ b/BPASmartClient.Device/BaseDevice.cs @@ -98,6 +98,10 @@ namespace BPASmartClient.Device /// 外设设备集合 /// private List peripherals; + + public Action AddErrorAction { get; set; } + public Action DeleteErrorAction { get; set; } + #endregion /// @@ -144,8 +148,43 @@ namespace BPASmartClient.Device foreach (var key in peripheral.GetAllStatus().Keys) { peripheralStatus[key] = peripheral.GetAllStatus()[key]; - if(TypeName!= "PLC.MorksMachine") + if (TypeName != "PLC.MorksMachine") + { Status.Update($"{TypeName}.{key}", peripheral.GetAllStatus()[key]); + } + } + + + } + + foreach (var item in Status.GetStatusT()) + { + if (item.Name == "Warning" || item.Name == "Fault") + { + if (item.Status != "无故障" && item.Status != "无警告" && item.Status != "未发生故障") + { + var res = Error?.FirstOrDefault(p => p.GetType().GetProperty("Text").GetValue(p).ToString() == item.Ms); + if (res == null) + { + object obj = new + { + Time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), + Type = item.Name == "Warning" ? "警告" : "故障", + Text = item.Ms + }; + Error.Add(obj); + AddErrorAction?.Invoke(obj); + } + } + else + { + var res = Error?.FirstOrDefault(p => p.GetType().GetProperty("Text").GetValue(p).ToString().Contains(item.id)); + if (res != null) + { + Error.Remove(res); + DeleteErrorAction?.Invoke(res); + } + } } } Thread.Sleep(100); @@ -186,12 +225,16 @@ namespace BPASmartClient.Device { var res = alarmHelper.Alarms.FirstOrDefault(p => p.Info == s); if (res != null) - Error.Add(new + { + object obj = new { Time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), Type = res.Grade, Text = res.Info - }); + }; + Error.Add(obj); + AddErrorAction?.Invoke(obj); + } }); alarmHelper.RemoveAction = new Action((s) => { @@ -199,6 +242,7 @@ namespace BPASmartClient.Device if (res != null && Error.Contains(res)) { Error.Remove(res); + DeleteErrorAction?.Invoke(res); } }); ThreadManage.GetInstance().StartLong(new Action(() => diff --git a/BPASmartClient.Device/DeviceStatus.cs b/BPASmartClient.Device/DeviceStatus.cs index d7743dff..f60f10ba 100644 --- a/BPASmartClient.Device/DeviceStatus.cs +++ b/BPASmartClient.Device/DeviceStatus.cs @@ -62,6 +62,7 @@ namespace BPASmartClient.Device { string name = item.Key; string Ms = string.Empty; + string id = string.Empty; if (item.Key.Contains(".")) { string sta = item.Key.Split('.')[0]; @@ -72,15 +73,42 @@ namespace BPASmartClient.Device if (keyValues.ContainsKey(value)) value = keyValues[value]; Ms = $"[{sta}]-[{sop}]-[{value}]"; + id = $"[{sta}]-[{sop}]"; } - StatusALL.Add(new DevStatus { Name = name, Status = item.Value.ToString(), Ms = Ms }); + StatusALL.Add(new DevStatus { id = id, Name = name, Status = item.Value.ToString(), Ms = Ms }); } return new { data = StatusALL }; } + + public List GetStatusT() + { + List StatusALL = new List(); + foreach (var item in status) + { + string name = item.Key; + string Ms = string.Empty; + string id=string.Empty; + if (item.Key.Contains(".")) + { + 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(sop)) sop = keyValues[sop]; + if (keyValues.ContainsKey(value)) value = keyValues[value]; + + Ms = $"[{sta}]-[{sop}]-[{value}]"; + id= $"[{sta}]-[{sop}]"; + } + StatusALL.Add(new DevStatus {id= id, Name = name, Status = item.Value.ToString(), Ms = Ms }); + } + return StatusALL; + } } public class DevStatus { + public string id { get; set; } public string Name { get; set; } private string _status { get; set; } public string Status diff --git a/BPASmartClient.Device/IDevice.cs b/BPASmartClient.Device/IDevice.cs index eb0fbe70..ef47bf8e 100644 --- a/BPASmartClient.Device/IDevice.cs +++ b/BPASmartClient.Device/IDevice.cs @@ -81,5 +81,8 @@ namespace BPASmartClient.Device /// /// object GetPropertyValue(object info, string field); + + Action AddErrorAction { get; set; } + Action DeleteErrorAction { get; set; } } } diff --git a/BPASmartClient.IoT/DataVClient.cs b/BPASmartClient.IoT/DataVClient.cs index 0d858e2a..1ec97450 100644 --- a/BPASmartClient.IoT/DataVClient.cs +++ b/BPASmartClient.IoT/DataVClient.cs @@ -8,6 +8,7 @@ using BPASmartClient.Message; using BPASmartDatavDeviceClient.IoT; using System; using System.Collections.Generic; +using System.Linq; using System.Threading; namespace BPASmartClient.IoT @@ -125,6 +126,11 @@ namespace BPASmartClient.IoT { MessageLog.GetInstance.ShowEx(message); } + Plugin.GetInstance()?.GetPlugin()?.GetDevices()?.ForEach(device => + { + device.AddErrorAction+= AddErrorAction; + device.DeleteErrorAction += DeleteErrorAction; + }); } /// @@ -139,7 +145,6 @@ namespace BPASmartClient.IoT List dataVNode = new List(); Plugin.GetInstance()?.GetPlugin()?.GetDevices()?.ForEach(device => { - //List GJXX var obj = new { DeviceId = device.DeviceId.ToString(), @@ -169,6 +174,34 @@ namespace BPASmartClient.IoT #endregion #region 私有 + + /// + /// 增加告警 + /// + /// + private void AddErrorAction(object obj) + { + HttpAddAlarm(new AlarmTable + { + AlarmTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), + AlarmType = GetPropertyValue(obj, "Type").ToString(), + AlarmMessage = GetPropertyValue(obj, "Text").ToString(), + AlarmVla = "告警", + }); + } + + /// + /// 删除告警 + /// + /// + private void DeleteErrorAction(object obj) + { + HttpAddAlarm(new AlarmTable + { + + }); + } + /// /// 接收云端消息 /// @@ -183,6 +216,19 @@ namespace BPASmartClient.IoT ActionManage.GetInstance.Send("IotBroadcast", iOTCommand); } } + + /// + /// 获取某个对象中的属性值 + /// + /// + /// + public object GetPropertyValue(object info, string field) + { + if (info == null) return null; + Type t = info.GetType(); + IEnumerable property = from pi in t.GetProperties() where pi.Name.ToLower() == field.ToLower() select pi; + return property.First().GetValue(info, null); + } #endregion