From d6fb0646531172f23648441c224cdcccd721b894 Mon Sep 17 00:00:00 2001
From: xm <1271024303@qq.com>
Date: 星期一, 14 十二月 2020 09:59:01 +0800
Subject: [PATCH] 请合并代码,完成晾衣架最终功能。

---
 ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlRoomLogic.cs |  327 ++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 279 insertions(+), 48 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlRoomLogic.cs b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlRoomLogic.cs
index a777b63..e0c1f4e 100755
--- a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlRoomLogic.cs
+++ b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlRoomLogic.cs
@@ -62,7 +62,7 @@
             //妫�娴嬫垜鐨勫枩鐖辫繖涓埧闂村璞�
             this.CheckLoveRoom();
 
-            var listFile = Global.FileListByHomeId();
+            var listFile = HdlFileLogic.Current.GetRootPathListFile();
             foreach (var fileName in listFile)
             {
                 if (fileName.StartsWith("Room_") == true)
@@ -75,8 +75,6 @@
                     }
                 }
             }
-            //璁剧疆褰撳墠妤煎眰鐨処D
-            Config.Instance.Home.SetCurrentFloorId();
             //椤轰究鍒锋柊鍦烘櫙
             HdlSceneLogic.Current.ReFreshByLocal();
             //鍒锋柊鎴块棿瑙嗗浘鍒楄〃
@@ -88,7 +86,7 @@
         /// </summary>
         public void RefreshAllRoomByLocation()
         {
-            var listFile = Global.FileListByHomeId();
+            var listFile = HdlFileLogic.Current.GetRootPathListFile();
 
             //鎴戠殑鍠滅埍鐨勬埧闂村繀椤昏鍦ㄧ0浣嶆墠琛�
             string fRoom = "Room_Favorite.json";
@@ -242,6 +240,17 @@
         /// <returns></returns>
         public void RemoveRoom(string roomId, bool refreshLeftView = true)
         {
+            if (this.NowMainPageRoom != null && this.NowMainPageRoom.Id == roomId)
+            {
+                //褰撳垹闄ょ殑鏄富椤电殑鎴块棿鐨勬椂鍊�
+                this.NowMainPageRoom = this.GetLoveRoom();
+            }
+            if (this.NowCategoryRoom != null && this.NowCategoryRoom.Id == roomId)
+            {
+                //褰撳垹闄ょ殑鏄垎绫荤殑鎴块棿鐨勬椂鍊�
+                this.NowCategoryRoom = this.GetLoveRoom();
+            }
+
             //鏍规嵁鎴块棿Id锛岃幏鍙栨埧闂村璞�
             var room = this.GetRoomById(roomId);
             if (room == null)
@@ -289,7 +298,6 @@
             Common.LocalDevice.Current.DeleteRealDeviceByRoomId(roomId);
             if (refreshLeftView == true)
             {
-                //HdlAutoBackupLogic.DeleteFile(roomFilePath);
                 //鍒锋柊鎴块棿瑙嗗浘鍒楄〃
                 this.RefreshRoomListView();
             }
@@ -482,7 +490,7 @@
                     }
                 }
             }
-            return listRoom;
+            return this.SortRoom(listRoom);
         }
 
         /// <summary>
@@ -497,35 +505,6 @@
                 listRoom.Add(room);
             }
             return this.SortRoom(listRoom);
-        }
-
-        /// <summary>
-        /// 鑾峰彇褰撳墠妤煎眰鐨勬埧闂村悕绉�
-        /// </summary>
-        /// <param name="id"></param>
-        /// <returns></returns>
-        public List<string> GetRoomNamesByFloorId(string id)
-        {
-            var listName = new List<string>();
-            if (Config.Instance.Home.FloorDics.Count == 0)
-            {
-                //娌℃湁妤煎眰
-                foreach (var room in this.dicRooms.Values)
-                {
-                    listName.Add(room.Name);
-                }
-            }
-            else
-            {
-                foreach (var room in this.dicRooms.Values)
-                {
-                    if (room.FloorId == id)
-                    {
-                        listName.Add(room.Name);
-                    }
-                }
-            }
-            return listName;
         }
 
         /// <summary>
@@ -557,17 +536,10 @@
                     }
                 }
             }
+            listRoom = this.SortRoom(listRoom);
+
             listRoom.Insert(0, GetLoveRoom());
             return listRoom;
-        }
-
-        /// <summary>
-        /// 鑾峰彇褰撳墠妤煎眰鐨勬埧闂�(鎷兼帴浜嗐�愬父鐢ㄣ�戝湪绗竴浣�)
-        /// </summary>
-        /// <returns></returns>
-        public List<Room> GetRoomsByCurrentFloorIdAppendLoveRoom()
-        {
-            return this.GetRoomsByFloorIdAppendLoveRoom(Config.Instance.Home.CurrentFloorId);
         }
 
         #endregion
@@ -590,7 +562,7 @@
                 //绉婚櫎鎴戠殑鍠滅埍
                 this.DeleteLoveDevice(device);
                 //璁惧鏀瑰彉鎴块棿鐨勮瘽,涓婚〉闇�瑕侀噸鏂板埛鏂�
-                UserView.UserPage.Instance.RefreshForm = true;
+                UserView.UserPage.Instance.RefreshAllForm = true;
                 return;
             }
             //鎴块棿鏄惁淇敼
@@ -608,7 +580,7 @@
                 this.AddDevice(room, device, saveRealRoom);
             }
             //璁惧鏀瑰彉鎴块棿鐨勮瘽,涓婚〉闇�瑕侀噸鏂板埛鏂�
-            UserView.UserPage.Instance.RefreshForm = true;
+            UserView.UserPage.Instance.RefreshAllForm = true;
         }
 
         /// <summary>
@@ -681,6 +653,8 @@
                     //淇濆瓨鍒版湰鍦�
                     loveRoom.ListDevice.Add(mainkeys);
                     loveRoom.Save();
+                    //娣诲姞鏀惰棌璁惧鏃�,闇�瑕佸埛鏂颁富椤�
+                    UserView.UserPage.Instance.RefreshAllForm = true;
                 }
             }
         }
@@ -744,6 +718,8 @@
                 loveRoom.Save();
                 //鏇存敼鑷姩澶囦唤
                 HdlAutoBackupLogic.AddOrEditorFile(loveRoom.FileName);
+                //娣诲姞鏀惰棌璁惧鏃�,闇�瑕佸埛鏂颁富椤�
+                UserView.UserPage.Instance.RefreshAllForm = true;
             }
         }
 
@@ -1021,6 +997,11 @@
         /// <returns></returns>
         public Dictionary<string, string> GetFloorSortList()
         {
+            //娌℃湁妤煎眰
+            if (Config.Instance.Home.FloorDics.Count == 0)
+            {
+                return new Dictionary<string, string>();
+            }
             //浠庝竴鍫嗘枃瀛椾腑,鑾峰彇杩欎竴鍫嗘枃瀛楅噷闈㈡暟瀛楀瓧绗︿覆鐨勬渶闀块暱搴�
             var listName = new List<string>();
             foreach (var floorName in Config.Instance.Home.FloorDics.Values)
@@ -1080,6 +1061,258 @@
 
         #endregion
 
+        #region 鈻� 鍙戦�佹埧闂翠俊鎭粰缃戝叧_________________
+
+        /// <summary>
+        /// 鍙戦�佹埧闂翠俊鎭粰缃戝叧
+        /// </summary>
+        public void SetRoomInfoToGateway()
+        {
+            if (UserCenterResourse.UserInfo.AuthorityNo != 1 && UserCenterResourse.UserInfo.AuthorityNo != 2)
+            {
+                //涓嶆槸涓讳汉鍜岀鐞嗗憳,鍒欎笉澶勭悊
+                return;
+            }
+            var realMain = ZbGateway.MainGateWay;
+            if (realMain == null || Common.Config.Instance.Home.IsVirtually == true)
+            {
+                //娌℃湁涓荤綉鍏�,鍒欎笉鐞�
+                return;
+            }
+            //鑾峰彇鎴块棿鍏ㄩ儴鐨勮澶囧璞�
+            string strSendDeviceRoomInfo = string.Empty;
+            foreach (var room in this.dicRooms.Values)
+            {
+                if (room.IsSharedRoom || room.IsLove)
+                {
+                    continue;
+                }
+                var listDevice = this.GetRoomListDevice(room);
+                //鍙戦�佺粰缃戝叧鐨勮澶囨埧闂磈son
+                foreach (var device in listDevice)
+                {
+                    if (strSendDeviceRoomInfo != string.Empty)
+                    {
+                        strSendDeviceRoomInfo += "\r\n";
+                    }
+                    strSendDeviceRoomInfo += " " + this.SetDoublMark(device.DeviceAddr) + " ";
+                    strSendDeviceRoomInfo += this.SetDoublMark("0x" + Convert.ToString(device.DeviceEpoint, 16).PadLeft(2, '0')) + " ";
+                    strSendDeviceRoomInfo += this.SetDoublMark(LocalDevice.Current.GetDeviceEpointName(device).Replace(UserCenterResourse.douMarks, string.Empty)) + " ";
+                    strSendDeviceRoomInfo += this.SetDoublMark(room.Id);
+                }
+            }
+
+            var listAreaSpaceInfo = new List<AreaSpaceInfo>();
+            //棣栧厛娣诲姞浣忓畢
+            var houseInfo = new AreaSpaceInfo();
+            houseInfo.name = Common.Config.Instance.Home.Name;
+            houseInfo.uid = Common.Config.Instance.Home.Id;
+            houseInfo.parentId = "null";
+            listAreaSpaceInfo.Add(houseInfo);
+            //鐒跺悗娣诲姞妤煎眰
+            foreach (var floorId in Common.Config.Instance.Home.FloorDics.Keys)
+            {
+                var floorInfo = new AreaSpaceInfo();
+                floorInfo.name = Common.Config.Instance.Home.FloorDics[floorId];
+                floorInfo.uid = floorId;
+                floorInfo.parentId = Common.Config.Instance.Home.Id;
+                listAreaSpaceInfo.Add(floorInfo);
+            }
+            //鐒跺悗娣诲姞鎴块棿
+            var listRoom = this.GetAllListRooms();
+            foreach (var room in listRoom)
+            {
+                if (room.IsLove == true) { continue; }
+
+                var roomInfo = new AreaSpaceInfo();
+                roomInfo.name = room.Name;
+                roomInfo.uid = room.Id;
+                if (Common.Config.Instance.Home.FloorDics.ContainsKey(room.FloorId) == true)
+                {
+                    roomInfo.parentId = room.FloorId;
+                }
+                else
+                {
+                    roomInfo.parentId = Common.Config.Instance.Home.Id;
+                }
+                listAreaSpaceInfo.Add(roomInfo);
+            }
+            //鐒跺悗娣诲姞缃戝叧鎴块棿淇℃伅
+            var gatewayInfo = new GatewayAreaSpaceInfo();
+
+            var loaclGateway = HdlGatewayLogic.Current.GetLocalGateway(realMain.GwId);
+            if (loaclGateway == null || loaclGateway.GwMac == string.Empty)
+            {
+                //娌℃湁mac,鎴栬�呮壘涓嶅埌瀵硅薄,鍒欎笉涓婁紶
+                return;
+            }
+            string gwMac = loaclGateway.GwMac.Replace(":", string.Empty);
+            gatewayInfo.uid = "000101" + gwMac.Substring(2) + "07";
+            gatewayInfo.name = HdlGatewayLogic.Current.GetGatewayName(loaclGateway);
+
+            var roomGateway = HdlGatewayLogic.Current.GetRoomByGateway(loaclGateway);
+            if (roomGateway != null)
+            {
+                gatewayInfo.parentId = roomGateway.Id;
+            }
+            gatewayInfo.hwInfo = new GatewayHwInfo();
+            gatewayInfo.pkgInfo = new GatewayPkgInfo { version = loaclGateway.LinuxFirmwareVersion.ToString() };
+            gatewayInfo.swInfo = new List<GatewaySwInfo> { new GatewaySwInfo { ver = loaclGateway.LinuxFirmwareVersion.ToString() } };
+            gatewayInfo.ip = loaclGateway.GwIP;
+            gatewayInfo.mac = loaclGateway.GwMac;
+
+            var data = new { spaces = listAreaSpaceInfo, gateway = gatewayInfo };
+            string strSendRoomInfo = Newtonsoft.Json.JsonConvert.SerializeObject(data);
+
+            HdlThreadLogic.Current.RunThread(async () =>
+            {
+                //鍙戦�佽澶囧尯鍩熶俊鎭�
+                if (strSendDeviceRoomInfo != string.Empty)
+                {
+                    //鍒涘缓鏂囦欢瀵硅薄
+                    var result0 = await realMain.CreateFileAsync("DeviceRoomInfo.json");
+                    if (result0 == null || result0.Result != 0)
+                    {
+                        return;
+                    }
+                    //鍙戦�佹暟鎹祦
+                    var byteData = ASCIIEncoding.UTF8.GetBytes(strSendDeviceRoomInfo);
+                    var result1 = await realMain.SendFileAsync(byteData);
+                    if (result1 == null || result1.Result != 0)
+                    {
+                        return;
+                    }
+
+                }
+
+                //鍒涘缓鏂囦欢瀵硅薄
+                var result3 = await realMain.CreateFileAsync("space.json");
+                if (result3 == null || result3.Result != 0)
+                {
+                    return;
+                }
+
+                //鍙戦�佸尯鍩熶俊鎭�
+                var byteData2 = ASCIIEncoding.UTF8.GetBytes(strSendRoomInfo);
+                var result4 = await realMain.SendFileAsync(byteData2);
+            });
+        }
+
+        /// <summary>
+        /// 璁剧疆鍙屽紩鍙�
+        /// </summary>
+        /// <param name="i_text"></param>
+        /// <returns></returns>
+        private string SetDoublMark(string i_text)
+        {
+            return UserCenterResourse.douMarks + i_text + UserCenterResourse.douMarks;
+        }
+
+        /// <summary>
+        /// 绌洪棿鍖哄煙淇℃伅
+        /// </summary>
+        private class AreaSpaceInfo
+        {
+            /// <summary>
+            /// 浣忓畢ID 鎴栬�� 妤煎眰ID 鎴栬�� 鎴块棿ID
+            /// </summary>
+            public string uid = string.Empty;
+            /// <summary>
+            /// 浣忓畢鍚嶇О 鎴栬�� 妤煎眰鍚嶇О 鎴栬�� 鎴块棿鍚嶇О
+            /// </summary>
+            public string name = string.Empty;
+            /// <summary>
+            /// 褰撳墠ID鐨勭埗ID,濡傛灉娌℃湁,鍒欎负甯﹀弻寮曞彿鐨�"null" 姣斿 妤煎眰ID灏卞~浣忓畢ID  鎴块棿ID灏卞~妤煎眰ID
+            /// </summary>
+            public string parentId = string.Empty;
+        }
+
+        /// <summary>
+        /// 缃戝叧绌洪棿鍖哄煙淇℃伅
+        /// </summary>
+        private class GatewayAreaSpaceInfo
+        {
+            /// <summary>
+            /// 銆�000101銆�+缁戝畾缃戝叧鐨勬椂闂存埑杞�16杩涘埗+銆�07銆�
+            /// </summary>
+            public string uid = string.Empty;
+            /// <summary>
+            /// 杩欎釜鍥哄畾
+            /// </summary>
+            public string name = "hdl_bus_gatway";
+            /// <summary>
+            /// 缃戝叧鎵�鍦ㄧ殑鎴块棿ID
+            /// </summary>
+            public string parentId = string.Empty;
+            /// <summary>
+            /// 杩欎釜鍥哄畾
+            /// </summary>
+            public int deviceType = 61184;
+            /// <summary>
+            /// 缃戝叧纭欢淇℃伅
+            /// </summary>
+            public GatewayHwInfo hwInfo = null;
+            /// <summary>
+            /// 缃戝叧鏍囧噯淇℃伅
+            /// </summary>
+            public GatewayPkgInfo pkgInfo = null;
+            /// <summary>
+            /// 缃戝叧鍥轰欢鐗堟湰
+            /// </summary>
+            public List<GatewaySwInfo> swInfo = null;
+            /// <summary>
+            /// 缃戝叧IP
+            /// </summary>
+            public string ip = string.Empty;
+            /// <summary>
+            /// 缃戝叧鐨凪ac
+            /// </summary>
+            public string mac = string.Empty;
+        }
+
+        /// <summary>
+        /// 缃戝叧纭欢淇℃伅
+        /// </summary>
+        private class GatewayHwInfo
+        {
+            /// <summary>
+            /// 杩欎釜鍥哄畾
+            /// </summary>
+            public string brand = "MIPS";
+            /// <summary>
+            /// 杩欎釜鍥哄畾
+            /// </summary>
+            public string model = "MT7688";
+        }
+
+        /// <summary>
+        /// 缃戝叧鏍囧噯淇℃伅
+        /// </summary>
+        private class GatewayPkgInfo
+        {
+            /// <summary>
+            /// 杩欎釜鏄疞inux鐨勫浐浠剁増鏈�
+            /// </summary>
+            public string version = string.Empty;
+        }
+
+        /// <summary>
+        /// 缃戝叧鍥轰欢鐗堟湰
+        /// </summary>
+        private class GatewaySwInfo
+        {
+            /// <summary>
+            /// 杩欎釜鍥哄畾
+            /// </summary>
+            public string name = "HDL";
+            /// <summary>
+            /// 杩欎釜鏄疞inux鐨勫浐浠剁増鏈�
+            /// </summary>
+            public string ver = string.Empty;
+        }
+
+        #endregion
+
         #region 鈻� 鍏嬮殕鎴块棿瀵硅薄_______________________
 
         /// <summary>
@@ -1093,9 +1326,7 @@
             newRoom.Id = i_room.Id;
             newRoom.FloorId = i_room.FloorId;
             newRoom.TemperatrueDevice = i_room.TemperatrueDevice;
-            newRoom.Temperatrue = i_room.Temperatrue;
             newRoom.HumidityDevice = i_room.HumidityDevice;
-            newRoom.Humidity = i_room.Humidity;
             newRoom.Name = i_room.Name;
             newRoom.BackgroundImage = i_room.BackgroundImage;
             newRoom.BackgroundImageType = i_room.BackgroundImageType;

--
Gitblit v1.8.0