From 652243206427f35a256400a149a1734085824cb9 Mon Sep 17 00:00:00 2001
From: 陈嘉乐 <cjl@hdlchina.com.cn>
Date: 星期三, 02 九月 2020 17:35:03 +0800
Subject: [PATCH] 2020-09-02-4

---
 ZigbeeApp/Shared/Common/House.cs |  461 +++++++++------------------------------------------------
 1 files changed, 73 insertions(+), 388 deletions(-)

diff --git a/ZigbeeApp/Shared/Common/House.cs b/ZigbeeApp/Shared/Common/House.cs
index 871b61b..ae86e44 100755
--- a/ZigbeeApp/Shared/Common/House.cs
+++ b/ZigbeeApp/Shared/Common/House.cs
@@ -60,343 +60,63 @@
         /// </summary>
         public string ResidenceAddressName = string.Empty;
         /// <summary>
-        /// 鎴块棿鍒楄〃(鎴块棿鐨処D)
-        /// </summary>
-        public List<string> ListRooms = new List<string>();
-        /// <summary>
         /// 妤煎眰瀛楀吀
         /// key:FloorId
         /// value:FloorName
         /// </summary>
         public Dictionary<string,string> FloorDics = new Dictionary<string,string> { };
         /// <summary>
-        /// 褰撳墠妤煎眰Id
+        /// -1:鏈厤缃�(闇�瑕侀噸鏂伴�夋嫨) 1:鏃犳ā鏉挎湁璁惧  2:鏈夋ā鏉挎湁璁惧  3:鏃犳ā鏉挎棤璁惧(璇锋棤瑙嗚繖涓彉閲�)
         /// </summary>
-        public string CurrentFloorId = string.Empty;
-
-        #endregion
-
-        #region 鈼� 浣忓畢____________________________
-
-        #region 鈼� 娣诲姞浣忓畢_________________________
-
+        public int TemplateMode = -1;
         /// <summary>
-        /// 娣诲姞浣忓畢
+        /// 璇ヤ綇瀹呮槸鍚︽槸灞曠ず妯℃澘(姝ゅ彉閲忔槸缁欐煡鐪嬫ā鏉挎暟鎹椂浣跨敤鐨�,璇锋棤瑙嗚繖涓彉閲�)
         /// </summary>
-        /// <param name="houseId">浣忓畢id</param>
-        /// <param name="houseName">浣忓畢鍚嶇О.</param>
-        /// <param name="numHomeId">浣忓畢鏁板瓧鍨媔d</param>
-        public static void AddHouse(string houseId, string houseName, int numHomeId)
-        {
-            AddHouse(houseId, houseName, false, 0);
-        }
-
+        [Newtonsoft.Json.JsonIgnore]
+        public bool IsShowTemplate = false;
         /// <summary>
-        /// 娣诲姞浣忓畢
+        /// 褰撳墠浣忓畢閫夋嫨鐨勬ā鏉垮悕瀛�(璇锋棤瑙嗚繖涓彉閲�)
         /// </summary>
-        /// <param name="houseId">浣忓畢id</param>
-        /// <param name="houseName">浣忓畢鍚嶇О.</param>
-        /// <param name="isOthreShare">鏄惁涓哄叾浠栦富鐢ㄦ埛鍒嗕韩杩囨潵鐨勪綇瀹�</param>
-        /// <param name="accountType">浠呭瓙璐﹀彿鐧婚檰鐨勬椂鍊欎娇鐢�,褰撱�怚sOthreShare銆戜负"true"锛屽苟涓斻�怉ccountType銆戜负"1"鏃讹紝璇ヨ处鍙锋嫢鏈夌鐞嗗憳鏉冮檺</param>
-        public static void AddHouse(string houseId, string houseName, bool isOthreShare, int accountType)
-        {
-            var home = new House
-            {
-                Id = houseId,
-                Name = houseName,
-                IsOthreShare = isOthreShare,
-                AccountType = accountType
-            };
-            //鍒涘缓鏂囦欢澶�
-            Global.CreateHomeDirectory(houseId);
-            home.Save();
-            Config.Instance.HomeFilePathList.Add(home.FileName);
-            Config.Instance.Save();
-        }
-
-
-        #endregion
-
-        #region 鈼� 鍒犻櫎浣忓畢_________________________
-
+        public string SelectTemplate = string.Empty;
         /// <summary>
-        /// 鍒犻櫎浣忓畢
+        /// 鑷畾涔夊崟鍏冪殑鏍囬鍚嶇О(涓嶭istUintContent涓暟鍖归厤,璇锋棤瑙嗚繖涓彉閲�)
         /// </summary>
-        /// <param name="filePath">File path.</param>
-        public static void DeleteHouse(string filePath)
-        {
-            var delPath = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, Config.Instance.Guid, GetHouseIdByFilePath(filePath));
-            if (System.IO.Directory.Exists(delPath) == false)
-            {
-                return;
-            }
-            var fileList = GetHouseFileListByFilePath(filePath);
-            foreach (var file in fileList)
-            {
-                //鍒犻櫎鏂囦欢
-                System.IO.File.Delete(System.IO.Path.Combine(delPath, file));
-            }
-            //鍒犻櫎鏂囦欢澶�
-            System.IO.Directory.Delete(delPath, true);
-            //HomeFilePathList涓垹闄よ鍒楄〃
-            Common.Config.Instance.HomeFilePathList.RemoveAll((obj) => obj == filePath);
-            Config.Instance.Save();
-        }
-
+        public List<string> ListUintName = new List<string>();
         /// <summary>
-        /// 鍒犻櫎浣忓畢
+        /// 鑷畾涔夊崟鍏冪殑鍐呭(涓嶭istUintName涓暟鍖归厤,璇锋棤瑙嗚繖涓彉閲�)
         /// </summary>
-        /// <param name="houseId">House identifier.</param>
-        public static void DeleteHouseByHouseId(string houseId)
-        {
-            DeleteHouse(GetHouseFilePathByHouseId(houseId));
-        }
-
-        #endregion
-
-        #region 鈼� 淇敼浣忓畢_________________________
-
+        public List<string> ListUintContent = new List<string>();
         /// <summary>
-        /// 淇敼浣忓畢.
+        /// 鏈�鍚庣紪杈戠殑浜嬩欢(2020.05.26杩藉姞) 1970/12/31 23:59鏍煎紡
         /// </summary>
-        /// <param name="houseId">House identifier.</param>
-        /// <param name="houseName">House name.</param>
-        public static void EditorHouseByHouseId(string houseId, string houseName)
-        {
-            if (Config.Instance.Home.Id == houseId)
-            {
-                Config.Instance.Home.Name = houseName;
-            }
-            var home = GetHouseByHouseId(houseId);
-            if (home == null)
-            {
-                return;
-            }
-            home.Name = houseName;
-            home.Save();
-        }
-
-        #endregion
-
-        #region 鈼� 鑾峰彇浣忓畢_________________________
+        public string LastEditorTime = "1970/12/31 23:59";
         /// <summary>
-        /// 閫氳繃銆恑d銆戣幏鍙栦綇瀹�
+        /// 鏍囪瘑姝や綇瀹呯殑鏁版嵁鏄惁宸茬粡鍙戦�佽繃妯℃澘鏁版嵁缁欑綉鍏�(鍙拡瀵筎emplateMode=2,璇锋棤瑙嗚繖涓彉閲�)
         /// </summary>
-        /// <returns>The house by house identifier.</returns>
-        /// <param name="houseId">浣忓畢id</param>
-        public static House GetHouseByHouseId(string houseId)
-        {
-            var path = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, Config.Instance.Guid, houseId, $"House_{houseId}.json");
-            var file = Shared.IO.FileUtils.ReadFile(path);
-            if (file == null)
-            {
-                return null;
-            }
-            return Newtonsoft.Json.JsonConvert.DeserializeObject<House>(System.Text.Encoding.UTF8.GetString(file));
-        }
-
+        public bool SendTemplateSuccess = false;
         /// <summary>
-        /// 閫氳繃銆愭枃浠惰矾寰勩�戣幏鍙栦綇瀹�
+        /// 杩欎釜浣忓畢涓嬫墍鎷ユ湁鐨勭綉鍏砳d(2020.05.26杩藉姞,null浠h〃娌℃湁澶勭悊杩�,璇锋棤瑙嗚繖涓彉閲�)
         /// </summary>
-        /// <returns>The house by file path.</returns>
-        /// <param name="filePath">鏂囦欢璺緞</param>
-        public static House GetHouseByFilePath(string filePath)
-        {
-            var path = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, Config.Instance.Guid, GetHouseIdByFilePath(filePath), filePath);
-            var file = Shared.IO.FileUtils.ReadFile(path);
-            if (file == null)
-            {
-                return null;
-            }
-            return Newtonsoft.Json.JsonConvert.DeserializeObject<House>(System.Text.Encoding.UTF8.GetString(file));
-        }
-
-        #endregion
-
-        #region 鈼� 鑾峰彇浣忓畢鍒楄〃_____________________
+        [Newtonsoft.Json.JsonIgnore]
+        public List<string> listGatewayId = null;
         /// <summary>
-        /// Gets the home lists.鑾峰彇浣忓畢鍒楄〃
+        /// <para>鏍囪瘑浣忓畢鏁版嵁鐨勫尯鍒�(鏂囦欢璇诲彇鏃堕厤缃�,璇锋棤瑙嗚繖涓彉閲�)锛�</para>
+        /// <para>1:鏈韩鑷繁鐨勬暟鎹�(鏂囦欢澶瑰悕瀛椾负浣忓畢id)</para>
+        /// <para>2:鑷繁鎵嬪姩鍒涘缓鐨勪繚瀛樺湪鏈満鐨勫浠�(鏂囦欢澶瑰悕瀛椾互銆怋ackupResidenceData銆戝紑澶�)</para>
+        /// <para>3:姝ゆ暟鎹粠浜戠涓嬭浇鑰屾潵(鏂囦欢澶瑰悕瀛椾互銆怐ownLoadResidenceData銆戝紑澶�)</para>
         /// </summary>
-        public static async System.Threading.Tasks.Task<List<string>> GetHomeLists()
-        {
-            var pageSetting = new SendDataToServer.ResidenceListPageSettingObj()
-            {
-                PageSize = CommonPage.PageSize
-            };
-
-            var reqDto = new SendDataToServer.ResidenceListObj()
-            {
-                LoginAccessToken = Config.Instance.Token,
-                PageSetting = pageSetting
-            };
-            var requestObj = new SendDataToServer.ResidenceListReqDto()
-            {
-                ReqDto = reqDto,
-                RequestVersion = CommonPage.RequestVersion,
-            };
-            try
-            {
-                var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(requestObj);
-                var revertObj = await CommonPage.Instance.RequestHttpsZigbeeAsync("App/GetHomePager", System.Text.Encoding.UTF8.GetBytes(requestJson));
-                if (revertObj == null)
-                {
-                    return null;
-                }
-                if (revertObj.StateCode.ToUpper() == "SUCCESS")
-                {
-                    var responseDataObj = Newtonsoft.Json.JsonConvert.DeserializeObject<Shared.Common.ResponseEntity.ResidenceRes>(revertObj.ResponseData.ToString());
-                    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.Confrim));
-                        alert.Show();
-                        alert.ResultEventHandler += (sender, e) =>
-                        {
-                            if (e)
-                            {
-                                //
-                            }
-                        };
-                    }
-                    else
-                    {
-                        //娓呯┖褰撳墠浣忓畢鍒楄〃
-                        Config.Instance.HomeFilePathList.Clear();
-                        var listHouse = new List<House>();
-                        foreach (var residence in responseDataObj.PageData)
-                        {
-                            Config.Instance.HomeFilePathList.Add($"House_{residence.Id}.json");
-                            var house = GetHouseByHouseId(residence.Id);
-                            if (house == null)
-                            {
-                                house = new House
-                                {
-                                    Id = residence.Id,
-                                    Name = residence.Name,
-                                    IsOthreShare = residence.IsOthreShare,
-                                    AccountType = residence.AccountType,
-                                    MainUserDistributedMark = residence.MainUserDistributedMark,
-                                    Longitude = residence.Longitude,
-                                    Latitude = residence.Latitude
-                                };
-                            }
-                            else
-                            {
-                                house.Id = residence.Id;
-                                house.Name = residence.Name;
-                                house.IsOthreShare = residence.IsOthreShare;
-                                house.AccountType = residence.AccountType;
-                                house.MainUserDistributedMark = residence.MainUserDistributedMark;
-                                house.Longitude = residence.Longitude;
-                                house.Latitude = residence.Latitude;
-                            }
-                            Global.CreateHomeDirectory(residence.Id);
-                            house.Save(false);
-                            listHouse.Add(house);
-                        }
-                        //濡傛灉鍒囨崲浜嗚处鍙�,鎴栬�呭師鏉ョ殑id涓嶅瓨鍦�,鍒欓噸缃綇瀹匢D
-                        if (UserCenterResourse.ResidenceOption.TheSameLoginAccount == false ||
-                            Config.Instance.HomeFilePathList.Find((obj) => obj == $"House_{Config.Instance.HomeId}.json") == null)
-                        {
-                            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();
-                    }
-                }
-            }
-            catch (Exception ex)
-            {
-                System.Console.WriteLine($"鑾峰彇澶辫触{ex.Message}");
-            }
-            finally
-            {
-            }
-            return Config.Instance.HomeFilePathList;
-        }
-
-        #endregion
-
-        #region 鈼� 鑾峰彇浣忓畢id_______________________
+        [Newtonsoft.Json.JsonIgnore]
+        public int HouseDataDiv = 1;
         /// <summary>
-        /// 閫氳繃銆愭枃浠惰矾寰勩�戣幏鍙栦綇瀹卛d
+        /// 褰撳墠浣忓畢鐨勫湪绾跨姸鎬� -1:铏氭嫙 0:绂荤嚎 1:鏈湴 2:杩滅▼ 3:璇诲彇涓�(璇锋棤瑙嗚繖涓彉閲�)
         /// </summary>
-        /// <returns>The house identifier by file path.</returns>
-        /// <param name="filePath">鏂囦欢璺緞</param>
-        public static string GetHouseIdByFilePath(string filePath)
-        {
-            string[] sArray = filePath.Split(new string[] { "House_", ".json" }, StringSplitOptions.RemoveEmptyEntries);
-            if (sArray.Length >= 1)
-            {
-                return sArray[0];
-            }
-            return null;
-        }
-
-        #endregion
-
-        #region 鈼� 鑾峰彇浣忓畢璺緞_____________________
+        [Newtonsoft.Json.JsonIgnore]
+        public string NowHomeOnlineStatu = "3";
         /// <summary>
-        /// 閫氳繃銆愪綇瀹卛d銆戣幏鍙栦綇瀹呰矾寰�
+        /// 褰撳墠瀛樻斁浣忓畢鏁版嵁鐨勬枃浠跺す鍚嶅瓧(姝ゅ彉閲忔槸缁欐湰鏈哄浠�,鎴栬�呬簯绔笅杞藉浠戒娇鐢ㄧ殑,璇锋棤瑙嗚繖涓彉閲�)
         /// </summary>
-        /// <returns>The house identifier by file path.</returns>
-        /// <param name="houseId">浣忓畢id</param>
-        public static string GetHouseFilePathByHouseId(string houseId)
-        {
-            if (string.IsNullOrEmpty(houseId))
-            {
-                return null;
-            }
-            return $"House_{houseId}.json";
-        }
-
-        #endregion
-
-        #region 鈼� 鑾峰彇璇ヤ綇瀹呯殑鏂囦欢鍒楄〃______________
-
-        /// <summary>
-        /// 閫氳繃銆恏ouseId銆戣幏鍙栬浣忓畢鐨勬枃浠跺垪琛�
-        /// </summary>
-        /// <returns>The house file list by home identifier.</returns>
-        /// <param name="houseId">House identifier.</param>
-        public static List<string> GetHouseFileListByHomeId(string houseId)
-        {
-            var list = new List<string> { };
-            var path = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, Config.Instance.Guid, houseId);
-            if (!System.IO.Directory.Exists(path))
-            {
-                return new List<string> { };
-            }
-            var files = System.IO.Directory.GetFiles(path);
-            foreach (var file in files)
-            {
-                var f = file.Substring(path.Length + 1);
-                System.Console.WriteLine(f);
-                list.Add(f);
-            }
-            return list;
-        }
-
-        /// <summary>
-        /// 閫氳繃銆愭枃浠惰矾寰勩�戣幏鍙栦綇瀹呬笅鏂囦欢鍒楄〃
-        /// </summary>
-        /// <returns>The house file list by file path.</returns>
-        /// <param name="filePath">File path.</param>
-        public static List<string> GetHouseFileListByFilePath(string filePath)
-        {
-            return GetHouseFileListByHomeId(GetHouseIdByFilePath(filePath));
-        }
-
-        #endregion
+        [Newtonsoft.Json.JsonIgnore]
+        public string SaveDirctoryName = string.Empty;
 
         #endregion
 
@@ -406,91 +126,48 @@
         /// GetCurrentFloorName
         /// </summary>
         /// <returns></returns>
+        [Newtonsoft.Json.JsonIgnore]
         public string GetCurrentFloorName
         {
             get
-            {
-                return GetFloorNameById(CurrentFloorId);
+            {
+                return HdlResidenceLogic.Current.GetFloorNameById(CurrentFloorId);
             }
-        }
-
+        }
+        /// <summary>
+        /// 褰撳墠妤煎眰id
+        /// </summary>
+        private string m_CurrentFloorId = string.Empty;
         /// <summary>
-        /// 鑾峰彇妤煎眰鍚嶇О
+        /// 褰撳墠妤煎眰Id
         /// </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;
-                }
+        [Newtonsoft.Json.JsonIgnore]
+        public string CurrentFloorId
+        {
+            //鏉ュ洖鍒囨崲澶囦唤,浼氬嚭鐜伴棶棰�,妤煎眰id娌℃竻闄�
+            get
+            {
+                //娌℃湁妤煎眰
+                if (this.FloorDics.Count == 0) { return string.Empty; }
+
+                if (this.FloorDics.ContainsKey(m_CurrentFloorId) == true)
+                {
+                    //褰撳墠鐨勬ゼ灞俰d娌¢棶棰�
+                    return m_CurrentFloorId;
+                }
+                //濡傛灉褰撳墠璁剧疆鐨勬ゼ灞俰d骞朵笉瀛樺湪鐨勮瘽,閲嶆柊璁剧疆
+                m_CurrentFloorId = string.Empty;
+                var dicFloor = HdlRoomLogic.Current.GetFloorSortList();
+                foreach (var floorId in dicFloor.Keys)
+                {
+                    //缁欎竴涓繃鍘诲嵆鍙�
+                    m_CurrentFloorId = floorId;
+                    break;
+                }
+                return m_CurrentFloorId;
             }
-            return string.Empty;
+            set { m_CurrentFloorId = value; }
         }
-
-        /// <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 void AddRoomId(string roomId)
-        {
-            if (ListRooms.Contains(roomId) == false)
-            {
-                ListRooms.Add(roomId);
-                this.Save();
-            }
-        }
-
-        #endregion
-
-        #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 void RemoveRoomId(string roomId)
-        {
-            if (ListRooms.Contains(roomId)==true)
-            {
-                ListRooms.Remove(roomId);
-                Save();
-            }
-        }
-
-        #endregion
 
         #endregion
 
@@ -502,6 +179,13 @@
         /// <param name="autoBackup">鏄惁澶囦唤</param>
         public void Save(bool autoBackup = true)
         {
+            //濡傛灉褰撳墠鏄睍绀烘ā鏉�,鍒欎笉鍏佽淇濆瓨
+            if (this.IsShowTemplate == true)
+            {
+                return;
+            }
+            //淇敼鏃堕棿
+            this.LastEditorTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm");
             var path = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, Config.Instance.Guid, Id);
             //濡傛灉娌℃湁瀛樺湪浣忓畢鐩綍锛屽厛鍒涘缓
             if (!System.IO.Directory.Exists(path))
@@ -509,7 +193,8 @@
                 System.IO.Directory.CreateDirectory(path);
             }
             path = System.IO.Path.Combine(path, FileName);
-            Shared.IO.FileUtils.WriteFileByBytes(path, System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this)));
+            HdlFileLogic.Current.SaveFileContent(path, this);
+
             if (autoBackup == true && Id == Config.Instance.HomeId)
             {
                 HdlAutoBackupLogic.AddOrEditorFile(FileName);

--
Gitblit v1.8.0