From 6fa9d69da922c8049f5acfcbb9ce9fd26811024c Mon Sep 17 00:00:00 2001
From: xm <1271024303@qq.com>
Date: 星期四, 16 四月 2020 17:10:57 +0800
Subject: [PATCH] 请合并代码

---
 ZigbeeApp/Shared/Common/House.cs |  154 +++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 123 insertions(+), 31 deletions(-)

diff --git a/ZigbeeApp/Shared/Common/House.cs b/ZigbeeApp/Shared/Common/House.cs
old mode 100644
new mode 100755
index 8b7f693..d8a2c06
--- a/ZigbeeApp/Shared/Common/House.cs
+++ b/ZigbeeApp/Shared/Common/House.cs
@@ -46,12 +46,35 @@
         /// <summary>
         /// 浠呭瓙璐﹀彿鐧婚檰鐨勬椂鍊欎娇鐢�,褰撱�怚sOthreShare銆戜负"true"锛屽苟涓斻�怉ccountType銆戜负"1"鏃讹紝璇ヨ处鍙锋嫢鏈夌鐞嗗憳鏉冮檺
         /// </summary>
-        public int AccountType;
+        public int AccountType;
+        /// <summary>
+        /// 缁忓害
+        /// </summary>
+        public double Longitude = 0;
+        /// <summary>
+        /// 绾害
+        /// </summary>
+        public double Latitude = 0;
+        /// <summary>
+        /// 浣忓畢鎵�鍦ㄧ殑鍦扮悊浣嶇疆鐨勫悕绉�
+        /// </summary>
+        public string ResidenceAddressName = string.Empty;
 
         /// <summary>
-        /// 鎴块棿璺緞鍒楄〃
+        /// 鎴块棿鍒楄〃(鎴块棿鐨処D)
         /// </summary>
-        public List<string> RoomFilePathList = new List<string> { };
+        public List<string> ListRooms = new List<string>();
+
+        /// <summary>
+        /// 妤煎眰瀛楀吀
+        /// key:FloorId
+        /// value:FloorName
+        /// </summary>
+        public Dictionary<string,string> FloorDics = new Dictionary<string,string> { };
+        /// <summary>
+        /// 褰撳墠妤煎眰Id
+        /// </summary>
+        public string CurrentFloorId = string.Empty;
 
         /// <summary>
         /// 鍏ㄥ眬鍦烘櫙璺緞鍒楄〃---澶囩敤
@@ -170,6 +193,7 @@
             }
             home.Name = houseName;
             home.Save();
+            Config.Instance.Save();
         }
 
         #endregion
@@ -215,8 +239,6 @@
         /// </summary>
         public static async System.Threading.Tasks.Task<List<string>> GetHomeLists()
         {
-            //娓呯┖褰撳墠浣忓畢鍒楄〃
-            Config.Instance.HomeFilePathList.Clear();
             var pageSetting = new SendDataToServer.ResidenceListPageSettingObj()
             {
                 PageSize = CommonPage.PageSize
@@ -234,9 +256,6 @@
             };
             try
             {
-                //澶嶅師绠$悊鍛樻爣璇�(鑾峰彇浣忓畢鏃讹紝浣跨敤浠栧師鏉ヨ嚜宸辩殑Token)
-                Common.Config.Instance.isAdministrator = false;
-
                 var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(requestObj);
                 var revertObj = await CommonPage.Instance.RequestHttpsZigbeeAsync("App/GetHomePager", System.Text.Encoding.UTF8.GetBytes(requestJson));
                 if (revertObj == null)
@@ -249,7 +268,7 @@
                     if (responseDataObj.TotalCount == 0)
                     {
                         //褰撲綇瀹呬负绌烘椂鍏堟彁绀虹敤鎴锋柊寤轰綇瀹�
-                        var alert = new Alert(Language.StringByID(R.MyInternationalizationString.TIP), Language.StringByID(R.MyInternationalizationString.CurrentlyTheUserIshHouseIsEmptyPleaseBuildANewHouseFirst), Language.StringByID(R.MyInternationalizationString.Close), Language.StringByID(R.MyInternationalizationString.OK));
+                        var alert = new Alert(Language.StringByID(R.MyInternationalizationString.TIP), Language.StringByID(R.MyInternationalizationString.CurrentlyTheUserIshHouseIsEmptyPleaseBuildANewHouseFirst), Language.StringByID(R.MyInternationalizationString.Close), Language.StringByID(R.MyInternationalizationString.Confrim));
                         alert.Show();
                         alert.ResultEventHandler += (sender, e) =>
                         {
@@ -261,6 +280,9 @@
                     }
                     else
                     {
+                        //娓呯┖褰撳墠浣忓畢鍒楄〃
+                        Config.Instance.HomeFilePathList.Clear();
+                        var listHouse = new List<House>();
                         foreach (var residence in responseDataObj.PageData)
                         {
                             Config.Instance.HomeFilePathList.Add($"House_{residence.Id}.json");
@@ -273,7 +295,9 @@
                                     Name = residence.Name,
                                     IsOthreShare = residence.IsOthreShare,
                                     AccountType = residence.AccountType,
-                                    MainUserDistributedMark = residence.MainUserDistributedMark
+                                    MainUserDistributedMark = residence.MainUserDistributedMark,
+                                    Longitude = residence.Longitude,
+                                    Latitude = residence.Latitude
                                 };
                             }
                             else
@@ -282,15 +306,29 @@
                                 house.Name = residence.Name;
                                 house.IsOthreShare = residence.IsOthreShare;
                                 house.AccountType = residence.AccountType;
-                                house.MainUserDistributedMark = residence.MainUserDistributedMark;
+                                house.MainUserDistributedMark = residence.MainUserDistributedMark;
+                                house.Longitude = residence.Longitude;
+                                house.Latitude = residence.Latitude;
                             }
                             Global.CreateHomeDirectory(residence.Id);
-                            house.Save();
+                            house.Save(false);
+                            listHouse.Add(house);
                         }
-                        //鍖归厤褰撳墠浣忓畢
-                        if (Config.Instance.HomeFilePathList.Find((obj) => obj == $"House_{Config.Instance.HomeId}.json") == null)
+                        //濡傛灉鍒囨崲浜嗚处鍙�,鎴栬�呭師鏉ョ殑id涓嶅瓨鍦�,鍒欓噸缃綇瀹匢D
+                        if (UserCenterResourse.ResidenceOption.TheSameLoginAccount == false ||
+                            Config.Instance.HomeFilePathList.Find((obj) => obj == $"House_{Config.Instance.HomeId}.json") == null)
                         {
-                            Config.Instance.HomeId = GetHouseIdByFilePath(Config.Instance.HomeFilePathList[0]);
+                            Config.Instance.HomeId = listHouse[0].Id;
+                            foreach (var house in listHouse)
+                            {
+                                //鍒濆閫夋嫨瀹冭嚜宸辩殑浣忓畢
+                                if (house.IsOthreShare == false)
+                                {
+                                    Config.Instance.HomeId = house.Id;
+                                    Config.Instance.Home = House.GetHouseByHouseId(house.Id);
+                                    break;
+                                }
+                            }
                         }
                         Config.Instance.Save();
                     }
@@ -382,24 +420,76 @@
 
         #endregion
 
+        #region 鈼� 妤煎眰____________________________
+
+        /// <summary>
+        /// GetCurrentFloorName
+        /// </summary>
+        /// <returns></returns>
+        public string GetCurrentFloorName
+        {
+            get
+            {
+                return GetFloorNameById(CurrentFloorId);
+            }
+        }
+
+        /// <summary>
+        /// 鑾峰彇妤煎眰鍚嶇О
+        /// </summary>
+        /// <param name="floorId"></param>
+        /// <returns></returns>
+        public string GetFloorNameById(string floorId)
+        {
+            if (Config.Instance.Home.FloorDics.Count == 0)
+            {
+                return string.Empty;
+            }
+
+            foreach (var floor in Config.Instance.Home.FloorDics)
+            {
+                if (floorId == floor.Key)
+                {
+                    return floor.Value;
+                }
+            }
+            return string.Empty;
+        }
+
+        /// <summary>
+        /// 璁剧疆褰撳墠妤煎眰鐨処D
+        /// </summary>
+        public void SetCurrentFloorId()
+        {
+            if (Config.Instance.Home.FloorDics.Count > 0 && string.IsNullOrEmpty(CurrentFloorId))
+            {
+                foreach (var floor in Config.Instance.Home.FloorDics)
+                {
+                    CurrentFloorId = floor.Key;
+                    Save(false);
+                    return;
+                }
+            }
+        }
+
+        #endregion
+
         #region 鈼� 鎴块棿____________________________
 
         #region 鈼� 娣诲姞鎴块棿璺緞_________________________
 
         /// <summary>
-        /// 娣诲姞銆愭埧闂磋矾寰勩�戝埌鎴块棿璺緞鍒楄〃
+        /// 娣诲姞鎴块棿ID
         /// </summary>
         /// <returns><c>true</c>, if room list file path was added, <c>false</c> otherwise.</returns>
         /// <param name="roomFilePath">Room file path.</param>
-        public bool AddRoomListFilePath(string roomFilePath)
+        public void AddRoomId(string roomId)
         {
-            if (RoomFilePathList.Contains(roomFilePath))
-            {
-                return false;
+            if (ListRooms.Contains(roomId) == false)
+            {
+                ListRooms.Add(roomId);
+                this.Save();
             }
-            RoomFilePathList.Add(roomFilePath);
-            Save();
-            return true;
         }
 
         #endregion
@@ -407,19 +497,17 @@
         #region 鈼� 鍒犻櫎鎴块棿璺緞_________________________
 
         /// <summary>
-        /// 绉婚櫎鎴块棿璺緞
+        /// 绉婚櫎鎴块棿Id
         /// </summary>
         /// <returns><c>true</c>, if room list file path was added, <c>false</c> otherwise.</returns>
         /// <param name="roomFilePath">Room file path.</param>
-        public bool RemoveRoomListFilePath(string roomFilePath)
+        public void RemoveRoomId(string roomId)
         {
-            if (!RoomFilePathList.Contains(roomFilePath))
-            {
-                return false;
+            if (ListRooms.Contains(roomId)==true)
+            {
+                ListRooms.Remove(roomId);
+                Save();
             }
-            RoomFilePathList.Remove(roomFilePath);
-            Save();
-            return true;
         }
 
         #endregion
@@ -442,6 +530,10 @@
             }
             path = System.IO.Path.Combine(path, FileName);
             Shared.IO.FileUtils.WriteFileByBytes(path, System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this)));
+            if (autoBackup == true && Id == Config.Instance.HomeId)
+            {
+                HdlAutoBackupLogic.AddOrEditorFile(FileName);
+            }
         }
         #endregion
     }

--
Gitblit v1.8.0