From c7df85937f73fb347ee0b19e9c052d2d00a6df6c Mon Sep 17 00:00:00 2001
From: 黄学彪 <hxb@hdlchina.com.cn>
Date: 星期五, 18 九月 2020 13:58:19 +0800
Subject: [PATCH] 新版本

---
 ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlSafeguardLogic.cs |  204 ++++++++++++++++++++++++++++++++++----------------
 1 files changed, 138 insertions(+), 66 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlSafeguardLogic.cs b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlSafeguardLogic.cs
index 9f5fe85..1758563 100755
--- a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlSafeguardLogic.cs
+++ b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlSafeguardLogic.cs
@@ -56,18 +56,7 @@
         /// 瀹夐槻鏁版嵁缂撳瓨
         /// </summary>
         private Dictionary<int, SafeguardZoneInfo> dicAllZoneInfo = new Dictionary<int, SafeguardZoneInfo>();
-        /// <summary>
-        /// 瀹夐槻涓婃姤淇℃伅
-        /// </summary>
-        public List<SafeguardAlarmInfo> listAlarmInfo = new List<SafeguardAlarmInfo>();
-        /// <summary>
-        /// 涓婁竴娆″畨闃蹭笂鎶ヤ俊鎭繚瀛樼殑鏂囦欢鍚嶅瓧(鑰冭檻鍒扮敤鎴锋湁鍙兘24鐐圭殑鏃跺�欙紝涓嶉��鍑篈PP)
-        /// </summary>
-        private string oldDeviceAlarmFile = string.Empty;
-        /// <summary>
-        /// 閿�
-        /// </summary>
-        private object objLock = new object();
+
         #endregion
 
         #region 鈻� 鍒锋柊瀹夐槻___________________________
@@ -88,7 +77,7 @@
                 this.ShowTipMsg(msg);
                 return false;
             }
-            var mainWayId = HdlGatewayLogic.Current.GetGatewayId(mainGateway);
+            var mainWayId = mainGateway.GwId;
 
             //涓婚鏁板浐瀹�5+3+1
             int topicCount = 9;
@@ -115,7 +104,7 @@
                 {
                     var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
 
-                    var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZigBee.Device.Safeguard.ErrorResponData>(jobject["Data"].ToString());
+                    var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
                     if (temp != null)
                     {
                         string msg = HdlCheckLogic.Current.CheckCommonErrorCode(temp.Error);
@@ -188,16 +177,18 @@
             try
             {
                 var jObject = new Newtonsoft.Json.Linq.JObject() { { "Cluster_ID", 0 }, { "Command", 4036 } };
-                await mainGateway.Send("Security/GetSecurityInfo", jObject.ToString());
+                mainGateway.Send("Security/GetSecurityInfo", jObject.ToString());
             }
             catch { }
 
             var dateTime = DateTime.Now;
             while ((DateTime.Now - dateTime).TotalMilliseconds < 3000)
             {
-                if (topicCount <= 0 || error == true)
+                //if (error == true) { break; }
+                if (topicCount <= 0)
                 {
                     //9娆′富棰樺叏閮ㄦ帴鏀跺畬鎴�
+                    await Task.Delay(1000);
                     break;
                 }
                 await Task.Delay(50);
@@ -242,10 +233,13 @@
             zoneInfo.ZoneId = allData.ZoneId;
             zoneInfo.ZoneName = allData.ZoneName;
 
+            //淇℃伅鎺ㄩ��
+            zoneInfo.InformationPush = allData.IsDisablePushMessage;
+
             //澶勭悊璁惧
             foreach (var data2 in allData.DeviceList)
             {
-                string mainKey = data2.MacAddr + data2.Epoint;
+                string mainKey = LocalDevice.Current.GetDeviceMainKeys(data2.MacAddr, data2.Epoint);
                 //浼犳劅鍣ㄨ澶囦俊鎭�
                 var Deviceinfo = new Safeguard.ZoneDeviceListData();
                 Deviceinfo.IsBypass = data2.IsBypass;
@@ -297,16 +291,13 @@
             zoneInfo.dicAlarmDevice.Clear();
             zoneInfo.dicScenes.Clear();
 
-            //淇℃伅鎺ㄩ��
-            zoneInfo.InformationPush = resData.IsDisablePushMessage;
-
             foreach (var data in resData.Actions)
             {
                 //璁惧
                 if (data.Type == 0)
                 {
                     //鏈湴鏄惁鏈夎繖涓澶�
-                    string mainKey = data.DeviceAddr + data.Epoint;
+                    string mainKey = LocalDevice.Current.GetDeviceMainKeys(data.DeviceAddr, data.Epoint);
                     //鎶ヨ淇℃伅
                     zoneInfo.dicAlarmDevice[mainKey] = data;
                     CommonDevice device = LocalDevice.Current.GetDevice(mainKey);
@@ -466,7 +457,7 @@
             foreach (var device in listdevice)
             {
                 int MomentStatus = 1;
-                int TriggerZoneStatus = 1;
+                int TriggerZoneStatus = 3;
                 //鑾峰彇瀹夐槻浼犳劅鍣ㄧ殑鐬棿鐘舵�佽瀹氬��
                 this.GetSafeguardSensorMomentStatus(device, ref MomentStatus, ref TriggerZoneStatus);
 
@@ -570,7 +561,7 @@
                 //涓�鎵硅澶囬噷闈紝鎴愬姛娣诲姞鐨�
                 if (data.Status == 0)
                 {
-                    listSuccess.Add(data.MacAddr + data.Epoint);
+                    listSuccess.Add(LocalDevice.Current.GetDeviceMainKeys(data.MacAddr, data.Epoint));
                 }
                 else if (data.Status == 1)
                 {
@@ -605,43 +596,43 @@
             if (device.IasDeviceType == 13)
             {
                 MomentStatus = 1;
-                TriggerZoneStatus = 1;
+                TriggerZoneStatus = 3;
             }
             //鐑熼浘浼犳劅鍣�
             else if (device.IasDeviceType == 40)
             {
                 MomentStatus = 1;
-                TriggerZoneStatus = 1;
+                TriggerZoneStatus = 3;
             }
             //姘翠镜浼犳劅鍣�
             else if (device.IasDeviceType == 42)
             {
                 MomentStatus = 1;
-                TriggerZoneStatus = 1;
+                TriggerZoneStatus = 3;
             }
             //鐕冩皵浼犳劅鍣�
             else if (device.IasDeviceType == 43)
             {
                 MomentStatus = 1;
-                TriggerZoneStatus = 1;
+                TriggerZoneStatus = 3;
             }
             //绱ф�ユ寜閽�
             else if (device.IasDeviceType == 44)
             {
                 MomentStatus = 1;
-                TriggerZoneStatus = 1;
+                TriggerZoneStatus = 3;
             }
             //閽ュ寵鎵�
             else if (device.IasDeviceType == 277)
             {
                 MomentStatus = 1;
-                TriggerZoneStatus = 1;
+                TriggerZoneStatus = 3;
             }
             //闂ㄧ獥浼犳劅鍣�
             else if (device.IasDeviceType == 21 || device.IasDeviceType == 22)
             {
                 MomentStatus = 0;
-                TriggerZoneStatus = 1;
+                TriggerZoneStatus = 3;
             }
             //濡傛灉鏄櫄鎷熻澶囷紝鍒欒繖涓笢瑗挎案鎭掍负0
             if (device.DriveCode > 0)
@@ -756,7 +747,7 @@
             {
                 if (data.Status == 0)
                 {
-                    listKeys.Add(data.MacAddr + data.Epoint);
+                    listKeys.Add(LocalDevice.Current.GetDeviceMainKeys(data.MacAddr, data.Epoint));
                 }
             }
 
@@ -1165,10 +1156,10 @@
                     }
                     else if (data.Type == "1")
                     {
-                        var scene = Common.SceneRoomUI.AllSceneRoomUIList.Find((obj) => obj.sceneUI.Id == data.ScenesId);
+                        var scene = HdlSceneLogic.Current.GetSceneUIBySceneId(data.ScenesId);
                         if (scene != null)
                         {
-                            string msg = scene.sceneUI.Name + "\r\n";
+                            string msg = scene.Name + "\r\n";
                             //鐩爣鍦烘櫙涓嶅瓨鍦�
                             msg += Language.StringByID(R.MyInternationalizationString.uTargetSceneIsNotExsit);
                             this.ShowTipMsg(msg);
@@ -1377,7 +1368,7 @@
 
             if (this.UserPassword == null)
             {
-                var data = Global.ReadFileByDirectory(DirNameResourse.LocalMemoryDirectory, DirNameResourse.SafeguardUserPassword);
+                var data = HdlFileLogic.Current.ReadFileByteContent(DirNameResourse.SafeguardUserPassword);
                 if (data != null)
                 {
                     this.UserPassword = System.Text.Encoding.UTF8.GetString(data);
@@ -1395,7 +1386,7 @@
                 if (result != GarrisonMode.None && result != GarrisonMode.RemoveGarrison)
                 {
                     //淇濆瓨鍔犲瘑鐨勫瘑鐮佸埌鏈湴
-                    Global.WriteFileToDirectoryByBytes(DirNameResourse.LocalMemoryDirectory, DirNameResourse.SafeguardUserPassword, System.Text.Encoding.UTF8.GetBytes(this.UserPassword));
+                    HdlFileLogic.Current.SaveTextToFile(DirNameResourse.SafeguardUserPassword, this.UserPassword);
                 }
                 return result;
             }
@@ -1416,6 +1407,13 @@
             //鍏堟妸褰撳墠鐨勬ā寮忕粰绉婚櫎鎺�
             var flage = await this.RemoveSafetyGarrison(garrison, showPswForm);
             if (flage == -1)
+            {
+                return GarrisonMode.None;
+            }
+            //鍒ゆ柇鏈夋病鏈夊叾浠栭�昏緫鍘讳慨鏀逛簡甯冮槻妯″紡
+            //鎵�浠ュ啀娆¤幏鍙栨ā寮�
+            var safetyMode = await this.GetSafetyMode();
+            if (safetyMode != null)
             {
                 return GarrisonMode.None;
             }
@@ -1477,7 +1475,7 @@
                     if (result2 != GarrisonMode.None && result2 != GarrisonMode.RemoveGarrison)
                     {
                         //淇濆瓨鍔犲瘑瀵嗙爜鍒版湰鍦�
-                        Global.WriteFileToDirectoryByBytes(DirNameResourse.LocalMemoryDirectory, DirNameResourse.SafeguardUserPassword, System.Text.Encoding.UTF8.GetBytes(this.UserPassword));
+                        HdlFileLogic.Current.SaveTextToFile(DirNameResourse.SafeguardUserPassword, this.UserPassword);
                     }
                     return result2;
                 }
@@ -1504,10 +1502,6 @@
                 this.ShowErrorMsg(msg);
                 return GarrisonMode.RemoveGarrison;
             }
-
-            //淇濆瓨甯冮槻鎿嶄綔淇℃伅鍒版湰鍦�
-            HdlAlarmsLogic.Current.SaveSafeguardAlarmInfo(garrison);
-
             return garrison;
         }
 
@@ -1596,7 +1590,7 @@
                     if (result2 != -1)
                     {
                         //淇濆瓨鍒板姞瀵嗗瘑鐮佹湰鍦�
-                        Global.WriteFileToDirectoryByBytes(DirNameResourse.LocalMemoryDirectory, DirNameResourse.SafeguardUserPassword, System.Text.Encoding.UTF8.GetBytes(this.UserPassword));
+                        HdlFileLogic.Current.SaveTextToFile(DirNameResourse.SafeguardUserPassword, this.UserPassword);
                     }
                     return result2;
                 }
@@ -1608,13 +1602,6 @@
                 this.ShowErrorMsg(msg);
                 return -1;
             }
-
-            if (garrison == GarrisonMode.RemoveGarrison)
-            {
-                //淇濆瓨甯冮槻鎿嶄綔淇℃伅鍒版湰鍦�
-                HdlAlarmsLogic.Current.SaveSafeguardAlarmInfo(garrison);
-            }
-
             return 1;
         }
 
@@ -1723,11 +1710,6 @@
             {
                 return false;
             }
-
-            if (zoneId > 3)
-            {
-                zoneId = 3;
-            }
             //鐘舵�佸彉鏇�
             var result = await Safeguard.DisablePushMessageAsync(zoneId, statu);
             if (result == null || result.disablePushMessageResponseData == null || result.disablePushMessageResponseData.Result == 1)
@@ -1757,10 +1739,6 @@
         /// <returns>0:鎺ㄩ��  1:涓嶆帹閫�</returns>
         public int GetGarrisonInformationPushStatu(int zoneId)
         {
-            if (zoneId > 3)
-            {
-                zoneId = 3;
-            }
             if (this.dicAllZoneInfo.ContainsKey(zoneId) == false)
             {
                 return 1;
@@ -1978,14 +1956,14 @@
 
         #endregion
 
-        #region 鈻� 鎶ヨ鐩爣鐘舵�佺殑缈昏瘧鏂囨湰_____________
+        #region 鈻� 鎵ц鐩爣鐘舵�佺殑缈昏瘧鏂囨湰_____________
 
         /// <summary>
-        /// 鑾峰彇鐏厜绫诲瀷鐨勬姤璀︾洰鏍囩殑鐘舵�佹枃鏈�
+        /// 鑾峰彇鎵ц鐩爣鐨勭姸鎬佹枃鏈�
         /// </summary>
         /// <param name="listTaskInfo">鍔ㄤ綔瀵硅薄,鍙互涓虹┖</param>
         /// <returns></returns>
-        public string GetLightAlarmStatuText(List<Safeguard.TaskListInfo> listTaskInfo)
+        public string GetAdjustTargetStatuText(List<Safeguard.TaskListInfo> listTaskInfo)
         {
             if (listTaskInfo == null || listTaskInfo.Count == 0)
             {
@@ -1994,13 +1972,22 @@
             }
             //瑕佽�冭檻瀹冪殑鎺掑垪椤哄簭(鍙互鎸夐渶姹傚彉鏇寸紪鍙�)
             Dictionary<int, string> dicSort = new Dictionary<int, string>();
+            //鏈�澶х紪鍙�
+            int MaxNo = 4;
             //寮�鍏崇殑浣嶇疆缂栧彿
             int ControlNo = 0;
             //鐧惧垎姣旂殑浣嶇疆缂栧彿
             int persentNo = 1;
+            //绌鸿皟娓╁害鐨勪綅缃紪鍙�
+            int temparetureNo = 2;
+            //绌鸿皟妯″紡鐨勪綅缃紪鍙�
+            int modelNo = 3;
+            //绌鸿皟椋庨�熺殑浣嶇疆缂栧彿
+            int windNo = 4;
 
             foreach (var info in listTaskInfo)
             {
+                #region 鈻� 寮�鍏虫帶鍒禵___
                 //寮�鍏虫帶鍒�
                 if (info.TaskType == 1)
                 {
@@ -2015,11 +2002,25 @@
                         dicSort[ControlNo] = Language.StringByID(R.MyInternationalizationString.uSimpleClose);
                     }
                 }
+                #endregion
+
+                #region 鈻� 浜害璋冭妭____
                 //浜害璋冭妭
                 else if (info.TaskType == 3)
                 {
-                    dicSort[persentNo] = info.Data1 + "%";
+                    if (info.Data1 == 0)
+                    {
+                        //鍏�
+                        dicSort[persentNo] = Language.StringByID(R.MyInternationalizationString.uSimpleClose);
+                    }
+                    else
+                    {
+                        dicSort[persentNo] = $"{(int)(info.Data1 * 1.0 / 254 * 100)}%";
+                    }
                 }
+                #endregion
+
+                #region 鈻� 绐楀笜璁惧____
                 //绐楀笜璁惧(瀹冪殑寮�鍏冲拰寮�鍏虫帶鍒舵槸鍙嶈繃鏉ョ殑)
                 else if (info.TaskType == 6)
                 {
@@ -2039,13 +2040,84 @@
                         dicSort[persentNo] = info.Data2 + "%";
                     }
                 }
+                #endregion
+
+                #region 鈻� 绌鸿皟璁惧____
+                //绌鸿皟璁惧
+                else if (info.TaskType == 5)
+                {
+                    if (info.Data1 == 3)
+                    {
+                        if (info.Data2 == 0)
+                        {
+                            return Language.StringByID(R.MyInternationalizationString.uSimpleClose);
+                        }
+                        else if (info.Data2 == 1)
+                        {
+                            //鑷姩
+                            dicSort[modelNo] = Language.StringByID(R.MyInternationalizationString.Mode_Auto);
+                        }
+                        else if (info.Data2 == 3)
+                        {
+                            //鍒跺喎
+                            dicSort[modelNo] = Language.StringByID(R.MyInternationalizationString.Mode_Cool);
+                        }
+                        else if (info.Data2 == 4)
+                        {
+                            //鍒剁儹
+                            dicSort[modelNo] = Language.StringByID(R.MyInternationalizationString.Mode_Heat);
+                        }
+                        else if (info.Data2 == 7)
+                        {
+                            //閫侀
+                            dicSort[modelNo] = Language.StringByID(R.MyInternationalizationString.Mode_FanOnly);
+                        }
+                        else if (info.Data2 == 8)
+                        {
+                            //闄ゆ箍
+                            dicSort[modelNo] = Language.StringByID(R.MyInternationalizationString.Mode_Dry);
+                        }
+                    }
+                    else if (info.Data1 == 4 || info.Data1 == 5|| info.Data1 == 7)
+                    {
+                        //娓╁害
+                        dicSort[temparetureNo] = $"{ info.Data2 / 100}鈩�";
+                    }
+                    else if (info.Data1 == 6)
+                    {
+                        if (info.Data2 == 1)
+                        {
+                            //浣庨
+                            dicSort[windNo] = Language.StringByID(R.MyInternationalizationString.Fan_Low);
+                        }
+                        else if (info.Data2 == 2)
+                        {
+                            //涓
+                            dicSort[windNo] = Language.StringByID(R.MyInternationalizationString.Fan_Middle);
+                        }
+                        else if (info.Data2 == 3)
+                        {
+                            //楂橀
+                            dicSort[windNo] = Language.StringByID(R.MyInternationalizationString.Fan_Height);
+                        }
+                    }
+                }
+                #endregion
+            }
+            //濡傛灉寮�鍏冲拰鐧惧垎姣斾竴璧峰瓨鍦ㄧ殑璇�,鍒欎笉鏄剧ず寮�鍏虫枃瀛�
+            if (dicSort.ContainsKey(ControlNo) == true && dicSort.ContainsKey(persentNo) == true)
+            {
+                dicSort.Remove(ControlNo);
             }
 
             //鎷兼帴鏂囨湰
             string txtvalue = string.Empty;
-            for (int i = 0; i < dicSort.Count; i++)
+            for (int i = 0; i <= MaxNo; i++)
             {
-                txtvalue += dicSort[i] + " ";
+                if (dicSort.ContainsKey(i) == true)
+                {
+                    txtvalue += dicSort[i] + " ";
+                }
             }
 
             return txtvalue.Trim();
@@ -2075,7 +2147,7 @@
             bool success = false;
             //瓒呮椂鏃堕棿
             int TimeOut = 0;
-            string checkTopic = HdlGatewayLogic.Current.GetGatewayId(realWay) + "/Security/AdminSetNewPassword_Respon";
+            string checkTopic = realWay.GwId + "/Security/AdminSetNewPassword_Respon";
             Action<string, string> getResultAction = (topic, message) =>
             {
                 try
@@ -2098,7 +2170,7 @@
                 var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 4033 } };
                 var data = new Newtonsoft.Json.Linq.JObject { { "HomeId", Common.Config.Instance.HomeId }, { "Password", password } };
                 jObject.Add("Data", data);
-                await realWay.Send("Security/AdminSetNewPassword", jObject.ToString());
+                realWay.Send("Security/AdminSetNewPassword", jObject.ToString());
             }
             catch
             {
@@ -2261,7 +2333,7 @@
             /// </summary>
             public string ZoneName;
             /// <summary>
-            /// 淇℃伅鎺ㄩ�� 0:鎺ㄩ��  1:涓嶆帹閫� (鍙湁闃插尯ID:1,2,3鎵嶄細鏈夈��4,5鐨勯兘褰掍负3,鍥犱负瀹冩槸浠ラ槻鍖烘ā寮廔D(ActionType)涓哄崟浣嶇殑)
+            /// 淇℃伅鎺ㄩ�� 0:鎺ㄩ��  1:涓嶆帹閫� 
             /// </summary>
             public int InformationPush = 1;
             /// <summary>

--
Gitblit v1.8.0