From 557c8c4f75aafc97533721766272410042440d34 Mon Sep 17 00:00:00 2001
From: wei <kaede@kaededeMacBook-Air.local>
Date: 星期六, 21 八月 2021 11:00:29 +0800
Subject: [PATCH] 安防功能

---
 HDL_ON/Entity/Function/SecurityAlarm.cs |  270 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 267 insertions(+), 3 deletions(-)

diff --git a/HDL_ON/Entity/Function/SecurityAlarm.cs b/HDL_ON/Entity/Function/SecurityAlarm.cs
index e342c89..4eda460 100644
--- a/HDL_ON/Entity/Function/SecurityAlarm.cs
+++ b/HDL_ON/Entity/Function/SecurityAlarm.cs
@@ -1,12 +1,117 @@
 锘縰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 SecurityCenter
+    {
+        static SecurityCenter _center;
+
+        public static SecurityCenter Security
+        {
+            get
+            {
+                if(_center == null)
+                {
+                    _center = new SecurityCenter();
+                }
+                return _center;
+            }
+        }
+
+        SecurityAlarm _securityAlarm;
+        /// <summary>
+        /// 褰撳墠甯冮槻妯″紡
+        /// </summary>
+        public SecurityAlarm CurrentDefenseMode
+        {
+            get
+            {
+                return _securityAlarm;
+            }
+            set
+            {
+                _securityAlarm = value;
+                UI.HomePage.LoadEvent_RefreshSecurityStatus();
+            }
+        }
+
+        HttpServerRequest httpServerRequest = new HttpServerRequest();
+
+
+
+        List<SecurityAlarm> _securityAlarmList;
+        /// <summary>
+        /// 闃插尯鍒楄〃
+        /// </summary>
+        public List<SecurityAlarm> securityAlarmList
+        {
+            get
+            {
+                if(_securityAlarmList == null)
+                {
+                  _securityAlarmList =  GetSecurityAlarmList();
+                }
+                return _securityAlarmList;
+            }
+        }
+
+
+        /// <summary>
+        /// 璇诲彇浜戠瀹夐槻鍒楄〃
+        /// </summary>
+        /// <returns></returns>
+        public List<SecurityAlarm> GetSecurityAlarmList()
+        {
+            var pack = httpServerRequest.GetSecurityList();
+            if(pack.Code == StateCode.SUCCESS)
+            {
+                var revData = Newtonsoft.Json.JsonConvert.DeserializeObject<List<SecurityAlarm>>(pack.Data.ToString());
+                if(revData!= null)
+                {
+                    _securityAlarmList = revData;
+                    return revData;
+                }
+            }
+            return new List<SecurityAlarm>();
+        }
+
+        /// <summary>
+        /// 鐘舵�� enable甯冮槻銆乨isable鎾掗槻
+        /// </summary>
+        public string status
+        {
+            get
+            {
+                string result = "disable";
+                foreach(var s in securityAlarmList)
+                {
+                    if(s.status == "enable")
+                    {
+                        result = "enable";
+                        break;
+                    }
+                }
+                return result;
+            }
+        }
+
+
+    }
+
+
     public class SecurityAlarm
     {
+        /// <summary>
+        /// 瀹夐槻浜戠id
+        /// </summary>
+        public string userSecurityId;
         /// <summary>
         /// 瀹夐槻sid
         /// </summary>
@@ -22,7 +127,7 @@
         /// <summary>
         /// 鐘舵�� enable甯冮槻銆乨isable鎾掗槻
         /// </summary>
-        public string status;
+        public string status = "disable";
         /// <summary>
         /// 绫诲瀷
         /// "all"--鍏ㄥ畢甯冮槻锛�
@@ -30,7 +135,7 @@
         /// "all_day":24灏忔椂,
         /// "mute"锛氶潤闊�
         /// </summary>
-        public string type;
+        public string type = "normal";
         /// <summary>
         /// 鏇存柊鏃堕棿
         /// </summary>
@@ -71,6 +176,93 @@
             var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this));
             FileUtlis.Files.WriteFileByBytes(savePath, ssd);
         }
+
+        /// <summary>
+        /// 淇濆瓨瀹夐槻淇℃伅
+        /// </summary>
+        public string SaveInfo()
+        {
+            HttpServerRequest hsr = new HttpServerRequest();
+            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 < SecurityCenter.Security.securityAlarmList.Count; i++)
+                {
+                    string s = SecurityCenter.Security.securityAlarmList[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 +319,6 @@
         public string bypass;
     }
 
-
     /// <summary>
     /// 瀹夐槻杈撳叆
     /// </summary>
@@ -147,6 +338,13 @@
         /// </summary>
         public List<SecurityInputCondition> condition = new List<SecurityInputCondition>();
 
+        /// <summary>
+        /// 鍔犲叆杈撳叆鏉′欢
+        /// 鏈湴鍒ゆ柇浣跨敤
+        /// </summary>
+        [Newtonsoft.Json.JsonIgnore]
+        public bool addCondition = false;
+
         [Newtonsoft.Json.JsonIgnore]
         Function _function = null;
         /// <summary>
@@ -160,6 +358,65 @@
                 _function = FunctionList.List.Functions.Find((obj) => obj.sid == sid);
             }
             return _function;
+        }
+
+        /// <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>
@@ -276,6 +533,13 @@
         /// </summary>
         public List<SecurityOutputStatus> status = new List<SecurityOutputStatus>();
 
+        /// <summary>
+        /// 鍔犲叆杈撳叆鏉′欢
+        /// 鏈湴鍒ゆ柇浣跨敤
+        /// </summary>
+        [Newtonsoft.Json.JsonIgnore]
+        public bool addCondition = false;
+
         [Newtonsoft.Json.JsonIgnore]
         Function _function = null;
         /// <summary>

--
Gitblit v1.8.0