From 9f326f4000847e6167d8166fa2f6a66f53cb3734 Mon Sep 17 00:00:00 2001
From: 黄学彪 <hxb@hdlchina.com.cn>
Date: 星期四, 17 十二月 2020 09:07:13 +0800
Subject: [PATCH] 新云端Ver1.3

---
 ZigbeeApp/Shared/Phone/Common/Logic/HdlResidenceLogic.cs |  252 +++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 226 insertions(+), 26 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/Common/Logic/HdlResidenceLogic.cs b/ZigbeeApp/Shared/Phone/Common/Logic/HdlResidenceLogic.cs
index 1e746c4..df92624 100644
--- a/ZigbeeApp/Shared/Phone/Common/Logic/HdlResidenceLogic.cs
+++ b/ZigbeeApp/Shared/Phone/Common/Logic/HdlResidenceLogic.cs
@@ -39,20 +39,36 @@
         /// 鍒涘缓鏂扮殑浣忓畢(杩斿洖浣忓畢id,null浠h〃澶辫触)
         /// </summary>
         /// <param name="residenceName">浣忓畢鍚嶇О</param>
-        public string CreatNewResidence(string residenceName)
+        /// <param name="listUintName">鑷畾涔夊崟鍏冪殑鏍囬鍚嶇О(homeApp璁剧疆涓簄ull)</param>
+        /// <param name="listUintContent">鑷畾涔夊崟鍏冪殑鍐呭(homeApp璁剧疆涓簄ull)</param>
+        /// <param name="TemplateMode">1:鏃犳ā鏉挎湁璁惧  2:鏈夋ā鏉挎湁璁惧  3:鏃犳ā鏉挎棤璁惧</param>
+        public string CreatNewResidence(string residenceName, List<string> listUintName,
+            List<string> listUintContent, int TemplateMode = 1)
         {
             var pra = new { homeId = 0, homeName = residenceName, homeType = "ZIGBEE" };
             //娣诲姞浣忓畢
-            var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("home-wisdom/home/add", RestSharp.Method.POST, pra);
+            var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("home-wisdom/app/home/add", RestSharp.Method.POST, pra);
             //妫�娴嬬姸鎬佺爜
             if (HdlCheckLogic.Current.CheckNetCode(result, ShowNetCodeMode.YES) == false)
             {
                 return null;
             }
-            var newInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<NewResidenceInfo>(result.Data.ToString());
+            var newInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<IdInfoClass>(result.Data.ToString());
+
+            if (listUintName != null)
+            {
+                //缂栬緫浣忓畢鍖哄煙
+                var success = this.EditorResidenceArea(newInfo.Id, listUintName, listUintContent);
+                if (success == false)
+                {
+                    //缂栬緫浣忓畢鍖哄煙澶辫触
+                    HdlMessageLogic.Current.ShowMassage(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.uEditorResidenceAreaFail));
+                }
+            }
 
             //娣诲姞浣忓畢鍒扮紦瀛�
-            this.AddHouseToMemmory(newInfo.Id, residenceName);
+            this.AddHouseToMemmory(newInfo.Id, residenceName, listUintName,
+                listUintContent, TemplateMode);
 
             return newInfo.Id;
         }
@@ -62,9 +78,13 @@
         /// </summary>
         /// <param name="houseId">浣忓畢id</param>
         /// <param name="houseName">浣忓畢鍚嶇О.</param>
+        /// <param name="listUintName">鑷畾涔夊崟鍏冪殑鏍囬鍚嶇О(homeApp璁剧疆涓簄ull)</param>
+        /// <param name="listUintContent">鑷畾涔夊崟鍏冪殑鍐呭(homeApp璁剧疆涓簄ull)</param>
+        /// <param name="TemplateMode">1:鏃犳ā鏉挎湁璁惧  2:鏈夋ā鏉挎湁璁惧  3:鏃犳ā鏉挎棤璁惧</param>
         /// <param name="isOthreShare">鏄惁涓哄叾浠栦富鐢ㄦ埛鍒嗕韩杩囨潵鐨勪綇瀹�</param>
         /// <param name="accountType">浠呭瓙璐﹀彿鐧婚檰鐨勬椂鍊欎娇鐢�,褰撱�怚sOthreShare銆戜负"true"锛屽苟涓斻�怉ccountType銆戜负"1"鏃讹紝璇ヨ处鍙锋嫢鏈夌鐞嗗憳鏉冮檺</param>
         public void AddHouseToMemmory(string houseId, string houseName,
+            List<string> listUintName, List<string> listUintContent, int TemplateMode = 1,
             bool isOthreShare = false, int accountType = 0)
         {
             var home = new Common.House();
@@ -72,6 +92,18 @@
             home.Name = houseName;
             home.IsOtherShare = isOthreShare;
             home.AccountType = accountType;
+
+            if (listUintName != null)
+            {
+                home.ListUintName.AddRange(listUintName);
+                home.ListUintContent.AddRange(listUintContent);
+            }
+            home.TemplateMode = TemplateMode;
+            if (TemplateMode == 3)
+            {
+                //鏍囪涓鸿櫄鎷熶綇瀹�
+                home.IsVirtually = true;
+            }
 
             //鍒涘缓鏂囦欢澶�
             Common.Global.CreateHomeDirectory(houseId);
@@ -123,19 +155,32 @@
         /// </summary>
         /// <param name="residenceId">浣忓畢id</param>
         /// <param name="residenceName">浣忓畢鍚嶇О</param>
+        /// <param name="listUintName">鑷畾涔夊崟鍏冪殑鏍囬鍚嶇О(homeApp璁剧疆涓簄ull)</param>
+        /// <param name="listUintContent">鑷畾涔夊崟鍏冪殑鍐呭(homeApp璁剧疆涓簄ull)</param>
+        /// <param name="TemplateMode">1:鏃犳ā鏉挎湁璁惧  2:鏈夋ā鏉挎湁璁惧  3:鏃犳ā鏉挎棤璁惧</param>
         /// <returns></returns>
-        public bool EditorResidenceName(string residenceId, string residenceName)
+        public bool EditorResidenceName(string residenceId, string residenceName,
+            List<string> listUintName, List<string> listUintContent, int TemplateMode = 1)
         {
             var pra = new { homeId = Config.Instance.Home.Id, homeType = "ZIGBEE", homeName = residenceName };
-            var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("home-wisdom/home/update", RestSharp.Method.POST, pra, null, null, CheckMode.A璐﹀彿鏉冮檺);
+            var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("home-wisdom/app/home/update", RestSharp.Method.POST, pra, null, null, CheckMode.A璐﹀彿鏉冮檺);
             //妫�娴嬬姸鎬佺爜
             if (HdlCheckLogic.Current.CheckNetCode(result, ShowNetCodeMode.YES) == false)
             {
                 return false;
             }
-
+            if (listUintName != null)
+            {
+                //缂栬緫浣忓畢鍖哄煙
+                var success = this.EditorResidenceArea(residenceId, listUintName, listUintContent);
+                if (success == false)
+                {
+                    //缂栬緫浣忓畢鍖哄煙澶辫触
+                    HdlMessageLogic.Current.ShowMassage(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.uEditorResidenceAreaFail));
+                }
+            }
             //鍒锋柊鍐呭瓨鐨勪綇瀹呭悕
-            this.EditorHouseByHouseId(residenceId, residenceName);
+            this.EditorHouseByHouseId(residenceId, residenceName, listUintName, listUintContent, TemplateMode);
 
             return true;
         }
@@ -145,24 +190,54 @@
         /// </summary>
         /// <param name="residenceId">浣忓畢id</param>
         /// <param name="residenceName">浣忓畢鍚嶇О</param>
-        public void EditorHouseByHouseId(string residenceId, string residenceName)
+        /// <param name="listUintName">鑷畾涔夊崟鍏冪殑鏍囬鍚嶇О(homeApp璁剧疆涓簄ull)</param>
+        /// <param name="listUintContent">鑷畾涔夊崟鍏冪殑鍐呭(homeApp璁剧疆涓簄ull)</param>
+        /// <param name="TemplateMode">1:鏃犳ā鏉挎湁璁惧  2:鏈夋ā鏉挎湁璁惧  3:鏃犳ā鏉挎棤璁惧</param>
+        public void EditorHouseByHouseId(string residenceId, string residenceName,
+            List<string> listUintName, List<string> listUintContent, int TemplateMode = 1)
         {
-            if (Config.Instance.Home.Id == residenceId)
+            House home = Config.Instance.Home;
+            if (Config.Instance.Home.Id != residenceId)
             {
-                Config.Instance.Home.Name = residenceName;
+                //浠庣紦瀛樹腑鑾峰彇
+                home = GetHouseByHouseId(residenceId);
             }
-
-            var home = GetHouseByHouseId(residenceId);
             if (home == null)
             {
                 return;
             }
             home.Name = residenceName;
+            if (listUintName != null)
+            {
+                home.ListUintName.Clear();
+                home.ListUintName.AddRange(listUintName);
+
+                home.ListUintContent.Clear();
+                home.ListUintContent.AddRange(listUintContent);
+            }
+            home.TemplateMode = TemplateMode;
+            if (TemplateMode == 3)
+            {
+                //鏍囪涓鸿櫄鎷熶綇瀹�
+                home.IsVirtually = true;
+            }
             home.Save();
             //浣忓畢淇敼鍚嶇О鐨勮瘽,涓婚〉闇�瑕侀噸鏂板埛鏂�
             UserView.UserPage.Instance.RefreshAllForm = true;
         }
 
+        /// <summary>
+        /// 缂栬緫浣忓畢鍖哄煙
+        /// </summary>
+        /// <param name="residenceId">浣忓畢id</param>
+        /// <param name="listUintName">鑷畾涔夊崟鍏冪殑鏍囬鍚嶇О</param>
+        /// <param name="listUintContent">鑷畾涔夊崟鍏冪殑鍐呭</param>
+        /// <returns></returns>
+        private bool EditorResidenceArea(string residenceId, List<string> listUintName, List<string> listUintContent)
+        {
+            //鈽嗐優銉笺偗鈽� 浣忓畢鍖哄煙
+            return true;
+        }
 
         #endregion
 
@@ -190,7 +265,7 @@
             }
 
             var pra = new { homeId = Config.Instance.Home.Id, homeType = "ZIGBEE", latitude = i_latitude, longitude = i_longitude };
-            var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("home-wisdom/home/update", RestSharp.Method.POST, pra, null, null, CheckMode.A璐﹀彿鏉冮檺);
+            var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("home-wisdom/app/home/update", RestSharp.Method.POST, pra, null, null, CheckMode.A璐﹀彿鏉冮檺);
             //妫�娴嬬姸鎬佺爜
             if (HdlCheckLogic.Current.CheckNetCode(result, mode) == false)
             {
@@ -319,7 +394,7 @@
         {
             var pra = new { homeType = "ZIGBEE" };
 
-            var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("home-wisdom/home/list", RestSharp.Method.POST, pra);
+            var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("home-wisdom/app/home/list", RestSharp.Method.POST, pra);
             //妫�娴嬬姸鎬佺爜
             if (HdlCheckLogic.Current.CheckNetCode(result, mode) == false)
             {
@@ -360,12 +435,48 @@
             house.Longitude = i_residence.Longitude;
             house.Latitude = i_residence.Latitude;
             house.IsRemoteControl = i_residence.IsRemoteControl;
+            house.LastEditorTime = HdlCommonLogic.Current.ConvertUtcTimeToLocalTime2(i_residence.ModifyTime).ToString("yyyy/MM/dd HH:mm");
 
             Global.CreateHomeDirectory(i_residence.Id);
 
             house.Save(false);
 
             return house;
+        }
+
+        /// <summary>
+        /// 浠庝簯绔�,鍒锋柊浣忓畢鐨勫尯鍩�(true:浼氬埛鏂癷_house鐨凩ist鍙橀噺, false:浠�涔堥兘涓嶅鐞�)
+        /// </summary>
+        /// <param name="i_homeId">浣忓畢ID</param>
+        public bool RefreshHomeAreaFromDb(string i_homeId)
+        {
+            var house = this.GetHouseByHouseId(i_homeId);
+            if (house == null)
+            {
+                return false;
+            }
+            //var pra2 = new
+            //{
+            //    RequestVersion = CommonPage.RequestVersion,
+            //    RequestSource = 5,
+            //    LoginAccessToken = Common.Config.Instance.Token,
+            //    HomeId = i_house.Id
+            //};
+            //var result = UserCenterLogic.GetResponseDataByRequestHttps("App/GetHomeDirectory", false, pra2, new List<string> { "NotCheck" });
+            //if (result != null)
+            //{
+            //    var listData = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ResidenceAreaInfo>>(result);
+            //    //鍒濆鍖�
+            //    i_house.ListUintContent = new List<string>();
+            //    i_house.ListUintName = new List<string>();
+            //    foreach (var data in listData)
+            //    {
+            //        i_house.ListUintName.Add(data.Tag);
+            //        i_house.ListUintContent.Add(data.Remark);
+            //    }
+            //    return true;
+            //}
+            return false;
         }
 
         #endregion
@@ -401,8 +512,9 @@
         /// <summary>
         /// 浠庢枃浠跺す涓幏鍙栧叏閮ㄧ殑浣忓畢瀵硅薄
         /// </summary>
+        /// <param name="getGatewayId">鏄惁鑾峰彇缃戝叧ID(瀛樺湪listGatewayId閲岄潰)</param>
         /// <returns></returns>
-        public List<Common.House> GetAllLocalResidenceListByDirectory()
+        public List<House> GetAllLocalResidenceListByDirectory(bool getGatewayId = false)
         {
             var strPath = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, Common.Config.Instance.Guid);
             var listHome = new List<Common.House>();
@@ -429,9 +541,85 @@
                     }
                     var myHouse = Newtonsoft.Json.JsonConvert.DeserializeObject<Common.House>(textValue);
                     listHome.Add(myHouse);
+                    //濡傛灉璇诲彇缃戝叧id鐨勮瘽
+                    if (getGatewayId == true)
+                    {
+                        //鏍囪瘑鍒濆鍖栧畬鎴�
+                        myHouse.listGatewayId = new List<string>();
+                        //鑾峰彇缃戝叧鏂囦欢
+                        var arryGateway = System.IO.Directory.GetFiles(nowPath, "Gateway_*");
+                        foreach (var myFile in arryGateway)
+                        {
+                            string[] Arry = myFile.Split(new string[] { "_" }, StringSplitOptions.RemoveEmptyEntries);
+                            if (Arry.Length >= 3)
+                            {
+                                //鑾峰彇鍏剁綉鍏砳d
+                                myHouse.listGatewayId.Add(Arry[2]);
+                            }
+                        }
+                    }
                 }
             }
             return this.SortHouse(listHome);
+        }
+
+        /// <summary>
+        /// 浠庢枃浠跺す涓幏鍙栧叏閮ㄥ浠戒綇瀹呭璞�
+        /// </summary>
+        /// <returns></returns>
+        public List<House> GetAllLocalBackupResidenceListByDirectory()
+        {
+            var strPath = System.IO.Path.Combine(IO.FileUtils.RootPath, Config.Instance.Guid);
+            var listHome = new List<House>();
+            //鑾峰彇鍏ㄩ儴鐨勬枃浠跺す
+            var listDirectory = new List<string>();
+            var arryDirs = System.IO.Directory.GetDirectories(strPath);
+            foreach (var file in arryDirs)
+            {
+                string[] arry = file.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries);
+                listDirectory.Add(arry[arry.Length - 1]);
+            }
+            foreach (var myDir in listDirectory)
+            {
+                if (myDir.StartsWith("BackupResidenceData") == false
+                    && myDir.StartsWith("DownLoadResidenceData") == false)
+                {
+                    //鍙鎵嬪姩澶囦唤鍜屼簯绔笅杞界殑
+                    continue;
+                }
+                //鑾峰彇鍚勪釜鏂囦欢澶归噷闈㈢殑浣忓畢鏂囦欢
+                string nowPath = System.IO.Path.Combine(strPath, myDir);
+                var arryHouse = System.IO.Directory.GetFiles(nowPath, "House_*");
+                if (arryHouse.Length > 0)
+                {
+                    //璇诲彇鏂囦欢鍐呭
+                    var textValue = HdlFileLogic.Current.ReadFileTextContent(System.IO.Path.Combine(nowPath, arryHouse[0]));
+                    if (textValue == null)
+                    {
+                        continue;
+                    }
+                    var myHouse = Newtonsoft.Json.JsonConvert.DeserializeObject<House>(textValue);
+                    if (myHouse.Id != Config.Instance.Home.Id)
+                    {
+                        //涓嶆槸杩欎釜浣忓畢鐨勫浠�
+                        continue;
+                    }
+                    if (myDir.StartsWith("BackupResidenceData") == true)
+                    {
+                        //姝や綇瀹呮暟鎹槸涓存椂澶囦唤鏁版嵁
+                        myHouse.HouseDataDiv = 2;
+                        myHouse.SaveDirctoryName = myDir;
+                    }
+                    else if (myDir.StartsWith("DownLoadResidenceData") == true)
+                    {
+                        //姝や綇瀹呮暟鎹槸浠庝簯绔笅杞界殑澶囦唤鏁版嵁
+                        myHouse.HouseDataDiv = 3;
+                        myHouse.SaveDirctoryName = myDir;
+                    }
+                    listHome.Add(myHouse);
+                }
+            }
+            return listHome;
         }
 
         #endregion
@@ -584,7 +772,7 @@
         public bool DeleteCloundHouse(string houseId)
         {
             var pra = new { homeId = houseId };
-            var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("home-wisdom/home/delete", RestSharp.Method.POST, pra);
+            var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("home-wisdom/app/home/delete", RestSharp.Method.POST, pra);
             //妫�娴嬬姸鎬佺爜
             if (HdlCheckLogic.Current.CheckNetCode(result, ShowNetCodeMode.YES) == false)
             {
@@ -689,20 +877,32 @@
             return $"House_{houseId}.json";
         }
 
-        #endregion
-
-        #region 鈻� 缁撴瀯浣揰____________________________
+        /// <summary>
+        /// 鑾峰彇浣忓畢鐨勫尯鍩熸枃鏈�
+        /// </summary>
+        /// <param name="i_house"></param>
+        /// <returns></returns>
+        public string GetResidenceAreaText(House i_house)
+        {
+            return this.GetResidenceAreaText(i_house.ListUintName, i_house.ListUintContent);
+        }
 
         /// <summary>
-        /// 鏂颁綇瀹呯殑淇℃伅
+        /// 鑾峰彇浣忓畢鐨勫尯鍩熸枃鏈�
         /// </summary>
-        private class NewResidenceInfo
+        /// <param name="i_ListUintName">鍗曞厓鏍囬</param>
+        /// <param name="i_ListUintContent">鍗曞厓鍐呭</param>
+        /// <returns></returns>
+        public string GetResidenceAreaText(List<string> i_ListUintName, List<string> i_ListUintContent)
         {
-            /// <summary>
-            /// ZigbeeHomeGuid
-            /// </summary>
-            public string Id = string.Empty;
+            string textArea = string.Empty;
+            for (int i = 0; i < i_ListUintName.Count; i++)
+            {
+                textArea += i_ListUintContent[i] + i_ListUintName[i] + "_";
+            }
+            return textArea.TrimEnd('_');
         }
+
         #endregion
     }
 }

--
Gitblit v1.8.0