From e71c57108e6dd407c2c6f0361f68150f2ff9aed5 Mon Sep 17 00:00:00 2001 From: wxr <464027401@qq.com> Date: 星期三, 15 十二月 2021 13:41:16 +0800 Subject: [PATCH] 版本备份 --- HDL_ON/Entity/Function/SecurityAlarm.cs | 373 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 348 insertions(+), 25 deletions(-) diff --git a/HDL_ON/Entity/Function/SecurityAlarm.cs b/HDL_ON/Entity/Function/SecurityAlarm.cs index e342c89..ea29373 100644 --- a/HDL_ON/Entity/Function/SecurityAlarm.cs +++ b/HDL_ON/Entity/Function/SecurityAlarm.cs @@ -1,12 +1,25 @@ 锘縰sing System; using System.Collections.Generic; using HDL_ON.Common; +using HDL_ON.DAL.Server; using Shared; namespace HDL_ON.Entity { + /// <summary> + /// + /// </summary> public class SecurityAlarm { + public SecurityAlarm() + { + + } + + /// <summary> + /// 瀹夐槻浜戠id + /// </summary> + public string userSecurityId; /// <summary> /// 瀹夐槻sid /// </summary> @@ -18,11 +31,17 @@ /// <summary> /// 瀹夐槻寤舵椂 /// </summary> - public string delay; + public string delay ="0"; /// <summary> - /// 鐘舵�� enable甯冮槻銆乨isable鎾掗槻 + /// 鐘舵�� + /// 甯冮槻:enable + /// 鎾掗槻:disable /// </summary> - public string status; + public string status = "disable"; + /// <summary> + /// 鎶ヨ鐘舵�� + /// </summary> + public bool alarm = false; /// <summary> /// 绫诲瀷 /// "all"--鍏ㄥ畢甯冮槻锛� @@ -30,7 +49,7 @@ /// "all_day":24灏忔椂, /// "mute"锛氶潤闊� /// </summary> - public string type; + public string type = "normal"; /// <summary> /// 鏇存柊鏃堕棿 /// </summary> @@ -71,6 +90,121 @@ var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this)); FileUtlis.Files.WriteFileByBytes(savePath, ssd); } + /// <summary> + /// 鍒锋柊鏈湴鏁版嵁 + /// </summary> + /// <returns></returns> + public SecurityAlarm RefeshData() + { + var dataBytes = FileUtlis.Files.ReadFile(savePath); + var dataString = System.Text.Encoding.UTF8.GetString(dataBytes); + var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<SecurityAlarm>(dataString); + return temp; + } + + /// <summary> + /// 淇濆瓨瀹夐槻淇℃伅 + /// </summary> + public string SaveInfo() + { + HttpServerRequest hsr = new HttpServerRequest(); + if (string.IsNullOrEmpty(this.noticeConfig.noticeContent)) + { + this.noticeConfig.noticeContent = Language.StringByID(StringId.SecurityAlarmTipString).Replace("{0}", name); + } + if (this.noticeConfig.enable) + { + if (this.pushConfigs.Count == 0) + { + pushConfigs.Add(new SecurityPushConfig() + { + pushMethod = "APP", + pushTarget = new List<string>() { UserInfo.Current.ID } + }); + } + } + + if (string.IsNullOrEmpty(sid)) + { + NewSid(); + var pack = hsr.AddSecurity(new List<SecurityAlarm>() { this }); + if (pack.Code == StateCode.SUCCESS) + { + SaveFile(); + } + else + { + sid = ""; + } + return pack.Code; + } + else + { + var pack = hsr.EditSecurity(new List<SecurityAlarm>() { this }); + if (pack.Code == StateCode.SUCCESS) + { + SaveFile(); + } + return pack.Code; + } + } + + + /// <summary> + /// 鐢熸垚sid鏂规硶 + /// </summary> + public void NewSid() + { + try + { + string sOidBeginsWith = "000101";//鍘傚晢 + 閫氳鏂瑰紡 + DateTime dt = DateTime.Now; + DateTime startTime = TimeZoneInfo.ConvertTimeToUtc(new DateTime(2020, 1, 1)); + long m = (long)((dt - startTime).TotalMilliseconds / 10); + string sTimeSpan = "00000000"; + + byte[] arry = new byte[4]; + arry[0] = (byte)(m & 0xFF); + arry[1] = (byte)((m & 0xFF00) >> 8); + arry[2] = (byte)((m & 0xFF0000) >> 16); + arry[3] = (byte)((m >> 24) & 0xFF); + sTimeSpan = arry[0].ToString("X2") + arry[1].ToString("X2") + arry[2].ToString("X2") + arry[3].ToString("X2"); + + + if (sTimeSpan.Length >= 8) + { + sTimeSpan = sTimeSpan.Substring(0, 8); + } + else + { + sTimeSpan = Guid.NewGuid().ToString().Substring(0, 8); + //sTimeSpan = "00000000"; + } + + sid = sOidBeginsWith + sTimeSpan; + + sid += "16"; + sid += "1601"; + int maxId = 1; + + + for (int i = 0; i < FunctionList.List.securities.Count; i++) + { + string s = FunctionList.List.securities[i].sid.Substring(20, 4); + int iThisSceneId = Convert.ToInt16(s, 16); + if (iThisSceneId > maxId) + maxId = iThisSceneId; + } + + sid += (maxId + 1).ToString("X4"); + sid += "0000"; + } + catch + { + } + } + + } /// <summary> @@ -127,7 +261,6 @@ public string bypass; } - /// <summary> /// 瀹夐槻杈撳叆 /// </summary> @@ -147,6 +280,18 @@ /// </summary> public List<SecurityInputCondition> condition = new List<SecurityInputCondition>(); + /// <summary> + /// 鍔犲叆杈撳叆鏉′欢 + /// 鏈湴鍒ゆ柇浣跨敤 + /// </summary> + //[Newtonsoft.Json.JsonIgnore] + //public bool addCondition = false; + + /// <summary> + /// 鍒ゆ柇鏉′欢 + /// </summary> + public string comparator = "="; + [Newtonsoft.Json.JsonIgnore] Function _function = null; /// <summary> @@ -163,6 +308,65 @@ } /// <summary> + /// 鑾峰彇鍗曚釜鐘舵�佺殑鏄剧ず鏂囨湰 + /// </summary> + /// <param name="inputValue"></param> + /// <returns></returns> + public string GetStateText(string inputValue) + { + string text = ""; + + if (GetFunction() == null) + return text; + switch (GetFunction().spk) + { + case SPK.SensorGas: + case SPK.SensorSmoke: + if (inputValue == "true") + { + text += Language.StringByID(StringId.InAlarm) + " "; + } + else if (inputValue == "false") + { + text += Language.StringByID(StringId.Normal) + " "; + } + break; + case SPK.SensorPir: + if (inputValue == "true") + { + text += Language.StringByID(StringId.youren) + " "; + } + else if (inputValue == "false") + { + text += Language.StringByID(StringId.wuren) + " "; + } + break; + case SPK.SensorWater: + if (inputValue == "true") + { + text += Language.StringByID(StringId.WaterLeakage) + " "; + } + else if (inputValue == "false") + { + text += Language.StringByID(StringId.Normal) + " "; + } + break; + case SPK.SensorDoorWindow: + if (inputValue == "true") + { + text += Language.StringByID(StringId.Open) + " "; + } + else if (inputValue == "false") + { + text += Language.StringByID(StringId.Close) + " "; + } + break; + } + + return text; + } + + /// <summary> /// 鐘舵�佹枃鏈� /// </summary> /// <returns></returns> @@ -175,11 +379,11 @@ case SPK.SensorSmoke: foreach (var con in condition) { - if (con.value == "true") + if (con.value == "true" || con.value == "alarm") { text += Language.StringByID(StringId.InAlarm) + " "; } - else if (con.value == "false") + else if (con.value == "false" || con.value == "normal") { text += Language.StringByID(StringId.Normal) + " "; } @@ -201,11 +405,11 @@ case SPK.SensorWater: foreach (var con in condition) { - if (con.value == "true") + if (con.value == "true" || con.value == "alarm") { text += Language.StringByID(StringId.WaterLeakage) + " "; } - else if (con.value == "false") + else if (con.value == "false" || con.value == "normal") { text += Language.StringByID(StringId.Normal) + " "; } @@ -214,11 +418,11 @@ case SPK.SensorDoorWindow: foreach (var con in condition) { - if (con.value == "true") + if (con.value == "true" || con.value == "open") { text += Language.StringByID(StringId.Open) + " "; } - else if (con.value == "false") + else if (con.value == "false" || con.value == "close") { text += Language.StringByID(StringId.Close) + " "; } @@ -266,7 +470,7 @@ /// 1:鍦烘櫙 /// 2:鑷姩鍖� /// </summary> - public string target_type ="0"; + public string target_type = "0"; /// <summary> /// 杈撳嚭鐩爣鐨剆id /// </summary> @@ -276,19 +480,108 @@ /// </summary> public List<SecurityOutputStatus> status = new List<SecurityOutputStatus>(); - [Newtonsoft.Json.JsonIgnore] - Function _function = null; /// <summary> - /// 瀵瑰簲鐨勫姛鑳藉璞� + /// 鏈湴涓嶅瓨鍦ㄦ暟鎹紙鏁版嵁鍙兘琚垹浜嗭級 /// </summary> - /// <returns></returns> - public Function GetFunction() + public bool NoLocalData () { - if (_function == null) + var function = FunctionList.List.GetLightList().Find((obj) => obj.sid == sid); + if (function != null) { - _function = FunctionList.List.Functions.Find((obj) => obj.sid == sid); + return true; } - return _function; + else + { + var scene = FunctionList.List.scenes.Find((obj) => obj.sid == sid); + if (scene != null) + { + return true; + } + } + return false; + } + + + string _name; + [Newtonsoft.Json.JsonIgnore] + public string name + { + get + { + if (string.IsNullOrEmpty(_name)) + { + + var function = FunctionList.List.GetLightList().Find((obj) => obj.sid == sid); + if (function != null) + { + _name = function.name; + } + else + { + var scene = FunctionList.List.scenes.Find((obj) => obj.sid == sid); + if (scene != null) + { + _name = scene.name; + } + } + } + return _name; + } + set + { + _name = value; + } + } + + + + string _roomName; + [Newtonsoft.Json.JsonIgnore] + public string RoomName + { + get + { + if (string.IsNullOrEmpty(_roomName)) + { + + var function = FunctionList.List.GetLightList().Find((obj) => obj.sid == sid); + if (function != null) + { + _roomName = function.GetRoomListName(); + } + else + { + var scene = FunctionList.List.scenes.Find((obj) => obj.sid == sid); + if (scene != null) + { + _roomName = scene.GetRoomListName(); + } + } + } + return _roomName; + } + set + { + _roomName = value; + } + } + + string _spk; + [Newtonsoft.Json.JsonIgnore] + public string spk + { + get + { + if (string.IsNullOrEmpty(_spk)) + { + var function = FunctionList.List.GetLightList().Find((obj) => obj.sid == sid); + if (function != null) + { + _spk = function.spk; + } + } + return _spk; + } } @@ -301,7 +594,7 @@ string text = ""; if (target_type == "0") { - switch (GetFunction().spk) + switch (spk) { case SPK.LightDimming: case SPK.LightCCT: @@ -309,7 +602,18 @@ case SPK.LightSwitch: foreach (var state in status) { - if (state.key == FunctionAttributeKey.Brightness) + if(state.key == FunctionAttributeKey.OnOff) + { + if (state.value == "off") + { + text = Language.StringByID(StringId.Close); + } + else + { + text = Language.StringByID(StringId.Open); + } + } + else if (state.key == FunctionAttributeKey.Brightness) { if (state.value == "0") { @@ -325,7 +629,7 @@ } }else if(target_type == "1") { - + text = Language.StringByID(StringId.Open); } return text; @@ -349,7 +653,7 @@ /// <summary> /// 鏄惁寮�鍚�氱煡 /// </summary> - public bool enable; + public bool enable = true; /// <summary> /// 閫氱煡鍐呭 /// </summary> @@ -366,10 +670,29 @@ /// APP:app push /// SMS:鐭俊 /// </summary> - public string pushMethod; + public string pushMethod = "APP"; /// <summary> /// 鎺ㄩ�佺洰鏍� /// </summary> public List<string> pushTarget = new List<string>(); } + + + /// <summary> + /// A鍗忚鎺у埗鏁版嵁鐨勫璞� + /// </summary> + public class SecurityStatusObj + { + public List<SecurityStatusData> objects = new List<SecurityStatusData>(); + + public string time_stamp = ""; + public string id = ""; + } + + public class SecurityStatusData + { + public string sid; + public string status ="disable" ; + public bool alarm = false; + } } -- Gitblit v1.8.0