From e90209beae6a4e822cecb18e6889f8bda23f630e Mon Sep 17 00:00:00 2001
From: 黄学彪 <hxb@hdlchina.com.cn>
Date: 星期一, 14 十二月 2020 11:16:06 +0800
Subject: [PATCH] 合并了晾衣架(非新云端)

---
 ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlResidenceLogic.cs |  366 ++++++++++++++++++++++++---------------------------
 1 files changed, 172 insertions(+), 194 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/Common/Logic/HdlResidenceLogic.cs b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlResidenceLogic.cs
similarity index 67%
rename from ZigbeeApp/Shared/Phone/Common/Logic/HdlResidenceLogic.cs
rename to ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlResidenceLogic.cs
index 1e746c4..c27635b 100644
--- a/ZigbeeApp/Shared/Phone/Common/Logic/HdlResidenceLogic.cs
+++ b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlResidenceLogic.cs
@@ -3,7 +3,7 @@
 using System.Collections.Generic;
 using System.Text;
 
-namespace Shared.Phone
+namespace Shared.Phone.UserCenter
 {
     /// <summary>
     /// 浣忓畢瀵硅薄鐨勯�昏緫
@@ -41,20 +41,20 @@
         /// <param name="residenceName">浣忓畢鍚嶇О</param>
         public string CreatNewResidence(string residenceName)
         {
-            var pra = new { homeId = 0, homeName = residenceName, homeType = "ZIGBEE" };
+            var Pra = new AddResidencePra();
+            Pra.Name = residenceName;
             //娣诲姞浣忓畢
-            var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("home-wisdom/home/add", RestSharp.Method.POST, pra);
-            //妫�娴嬬姸鎬佺爜
-            if (HdlCheckLogic.Current.CheckNetCode(result, ShowNetCodeMode.YES) == false)
+            string resultData = UserCenterLogic.GetResponseDataByRequestHttps("App/AddHome", false, Pra);
+            if (string.IsNullOrEmpty(resultData) == true)
             {
                 return null;
             }
-            var newInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<NewResidenceInfo>(result.Data.ToString());
+            var newInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<List<NewResidenceInfo>>(resultData);
 
             //娣诲姞浣忓畢鍒扮紦瀛�
-            this.AddHouseToMemmory(newInfo.Id, residenceName);
+            this.AddHouseToMemmory(newInfo[0].Id, residenceName);
 
-            return newInfo.Id;
+            return newInfo[0].Id;
         }
 
         /// <summary>
@@ -70,7 +70,7 @@
             var home = new Common.House();
             home.Id = houseId;
             home.Name = houseName;
-            home.IsOtherShare = isOthreShare;
+            home.IsOthreShare = isOthreShare;
             home.AccountType = accountType;
 
             //鍒涘缓鏂囦欢澶�
@@ -106,7 +106,7 @@
             Config.Instance.Home = this.GetHouseByHouseId(residenceId);
             Config.Instance.Save();
             //鍒锋柊涓汉涓績鐨勫唴瀛樺強绾跨▼
-            bool result = HdlUserCenterLogic.Current.InitUserCenterMenmoryAndThread(false);
+            bool result = UserCenterLogic.InitUserCenterMenmoryAndThread(false);
 
             //鍏抽棴杩涘害鏉�
             ProgressBar.Close();
@@ -126,18 +126,20 @@
         /// <returns></returns>
         public bool EditorResidenceName(string residenceId, string residenceName)
         {
-            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璐﹀彿鏉冮檺);
-            //妫�娴嬬姸鎬佺爜
-            if (HdlCheckLogic.Current.CheckNetCode(result, ShowNetCodeMode.YES) == false)
+            var Pra = new EditorResidencePra();
+            Pra.HomeId = residenceId;
+            Pra.Name = residenceName;
+            Pra.IsOtherAccountCtrl = false;
+            Pra.LoginAccessToken = Config.Instance.Token;
+
+            //缂栬緫浣忓畢
+            bool flage = UserCenterLogic.GetResultStatuByRequestHttps("App/EditHome", false, Pra);
+            if (flage == true)
             {
-                return false;
+                //鍒锋柊鍐呭瓨鐨勪綇瀹呭悕
+                this.EditorHouseByHouseId(residenceId, residenceName);
             }
-
-            //鍒锋柊鍐呭瓨鐨勪綇瀹呭悕
-            this.EditorHouseByHouseId(residenceId, residenceName);
-
-            return true;
+            return flage;
         }
 
         /// <summary>
@@ -163,55 +165,6 @@
             UserView.UserPage.Instance.RefreshAllForm = true;
         }
 
-
-        #endregion
-
-        #region 鈻� 缂栬緫浣忓畢缁忕含搴____________________
-
-        /// <summary>
-        /// 缂栬緫浣忓畢缁忕含搴�
-        /// </summary>
-        /// <param name="i_latitude">绾害</param>
-        /// <param name="i_longitude">缁忓害</param>
-        /// <param name="i_addresName">浣嶇疆鍚嶇О</param>
-        /// <param name="mode">澶辫触鏃舵槸鍚︽樉绀簍ip娑堟伅</param>
-        /// <returns></returns>
-        public bool EditorResidenceLongitudeAndLatitude(double i_latitude, double i_longitude, string i_addresName, ShowNetCodeMode mode = ShowNetCodeMode.YES)
-        {
-            //濡傛灉涓嶆槸铏氭嫙浣忓畢,鎵嶆洿鏂颁簯绔�
-            if (Config.Instance.Home.IsVirtually == true)
-            {
-                //淇濆瓨缂撳瓨
-                Config.Instance.Home.Longitude = i_longitude;
-                Config.Instance.Home.Latitude = i_latitude;
-                Config.Instance.Home.ResidenceAddressName = i_addresName;
-                Config.Instance.Home.Save();
-                return true;
-            }
-
-            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璐﹀彿鏉冮檺);
-            //妫�娴嬬姸鎬佺爜
-            if (HdlCheckLogic.Current.CheckNetCode(result, mode) == false)
-            {
-                return false;
-            }
-            //淇濆瓨缂撳瓨
-            Config.Instance.Home.Longitude = i_longitude;
-            Config.Instance.Home.Latitude = i_latitude;
-            Config.Instance.Home.ResidenceAddressName = i_addresName;
-            Config.Instance.Home.Save();
-
-            //璁剧疆鍏ㄩ儴缃戝叧鐨勪綇瀹呭湴鍧�
-            var listGateway = HdlGatewayLogic.Current.GetAllLocalGateway();
-            foreach (var gateway in listGateway)
-            {
-                //涓嶅垽鏂槸鍚﹀け璐�
-                HdlGatewayLogic.Current.SetGatewaySite(gateway.GwId, i_longitude, i_latitude, ShowErrorMode.NO);
-            }
-
-            return true;
-        }
 
         #endregion
 
@@ -252,120 +205,105 @@
         #endregion
 
         #region 鈻� 鑾峰彇浜戠浣忓畢鍒楄〃___________________
-
-        /// <summary>
-        /// 鐧婚檰鐨勬椂鍊�,鑾峰彇浜戠浣忓畢鍒楄〃(0:褰撳墠娌℃湁缃戠粶鐨勬儏鍐典笅鍔犺浇鏈湴浣忓畢  1:閫氳繃鑱旂綉鍔犺浇鍙婃牎楠屾湰鍦颁綇瀹�)
-        /// </summary>
-        /// <param name="mode">澶辫触鏃舵槸鍚︽樉绀簍ip娑堟伅</param>
-        /// <returns></returns>
-        public int GetHomeListsFromDbOnLogin(ShowNetCodeMode mode = ShowNetCodeMode.YES)
-        {
-            //鑾峰彇浜戠浣忓畢鏁版嵁
-            var listHouseData = this.GetHomeListsFromDb(mode);
-            if (listHouseData == null)
-            {
-                return 0;
-            }
-
-            //娓呯┖褰撳墠浣忓畢鍒楄〃
-            Config.Instance.HomeFilePathList.Clear();
-            var listHouse = new List<House>();
-            foreach (var residence in listHouseData)
-            {
-                //鍒锋柊浣忓畢瀵硅薄鐨勭紦瀛�
-                var house = this.RefreshResidenceMemory(residence);
-
-                listHouse.Add(house);
-            }
-
-            //妫�娴嬫湰鍦扮殑浣忓畢鏂囦欢鏄惁鍚堟硶
-            var listLocal = this.GetAllLocalResidenceListByDirectory();
-            foreach (var myHouse in listLocal)
-            {
-                //濡傛灉鏈湴瀛樺湪涓嶅睘浜庝粬鐨勪綇瀹呮枃浠�,鍒欏垹闄�
-                if (myHouse.HouseDataDiv == 1 && Config.Instance.HomeFilePathList.Contains(myHouse.FileName) == false)
-                {
-                    string housePath = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, Config.Instance.Guid, myHouse.Id);
-                    HdlFileLogic.Current.DeleteDirectory(housePath);
-                }
-            }
-
-            //濡傛灉鍒囨崲浜嗚处鍙�,鎴栬�呭師鏉ョ殑id涓嶅瓨鍦�,鍒欓噸缃綇瀹匢D
-            if (Config.Instance.TheSameLoginAccount == false ||
-                Config.Instance.HomeFilePathList.Find((obj) => obj == $"House_{Config.Instance.HomeId}.json") == null)
-            {
-                Config.Instance.HomeId = listHouse.Count > 0 ? listHouse[0].Id : string.Empty;
-                foreach (var house in listHouse)
-                {
-                    //鍒濆閫夋嫨瀹冭嚜宸辩殑浣忓畢
-                    if (house.IsOtherShare == false)
-                    {
-                        Config.Instance.HomeId = house.Id;
-                        Config.Instance.Home = GetHouseByHouseId(house.Id);
-                        break;
-                    }
-                }
-            }
-            Config.Instance.Save();
-            return 1;
-        }
-
         /// <summary>
         /// 鑾峰彇浜戠浣忓畢鍒楄〃
         /// </summary>
-        /// <param name="mode">澶辫触鏃舵槸鍚︽樉绀簍ip娑堟伅</param>
+        /// <param name="checkNetwork">鏄惁妫�娴嬬綉缁�,濡傛灉璁剧疆妫�娴嬬殑璇�,褰撲笉鑳借仈缃戞椂,鐩存帴杩斿洖鏈湴浣忓畢</param>
         /// <returns></returns>
-        public List<ResidenceInformation> GetHomeListsFromDb(ShowNetCodeMode mode = ShowNetCodeMode.YES)
+        public List<string> GetHomeListsFromDb(bool checkNetwork)
         {
-            var pra = new { homeType = "ZIGBEE" };
-
-            var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("home-wisdom/home/list", RestSharp.Method.POST, pra);
-            //妫�娴嬬姸鎬佺爜
-            if (HdlCheckLogic.Current.CheckNetCode(result, mode) == false)
+            if (checkNetwork == true && HdlWifiLogic.Current.CanAccessHttp == false)
             {
-                return null;
+                //褰撳墠鏃犳硶鑱旂綉
+                return Config.Instance.HomeFilePathList;
             }
-            var listTemp = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ResidenceInformation>>(result.Data.ToString());
-            var listData = new List<ResidenceInformation>();
-            foreach (var data in listTemp)
+            var requestObj = new SendDataToServer.ResidenceListReqDto()
             {
-                if (data.HomeType == "ZIGBEE")
+                RequestVersion = CommonPage.RequestVersion,
+                ReqDto = new SendDataToServer.ResidenceListObj()
                 {
-                    listData.Add(data);
+                    LoginAccessToken = Config.Instance.Token,
+                    PageSetting = new SendDataToServer.ResidenceListPageSettingObj { PageSize = 999 }
+                }
+            };
+            try
+            {
+                var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(requestObj);
+                var revertObj = CommonPage.Instance.RequestHttpsZigbeeAsync("App/GetHomePager", System.Text.Encoding.UTF8.GetBytes(requestJson), 5);
+                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)
+                    {
+                        //娓呯┖褰撳墠浣忓畢鍒楄〃
+                        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);
+                        }
+                        //妫�娴嬫湰鍦扮殑浣忓畢鏂囦欢鏄惁鍚堟硶
+                        var listLocal = this.GetAllLocalResidenceListByDirectory();
+                        foreach (var myHouse in listLocal)
+                        {
+                            //濡傛灉鏈湴瀛樺湪涓嶅睘浜庝粬鐨勪綇瀹呮枃浠�,鍒欏垹闄�
+                            if (myHouse.HouseDataDiv == 1 && Config.Instance.HomeFilePathList.Contains(myHouse.FileName) == false)
+                            {
+                                string housePath = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, Config.Instance.Guid, myHouse.Id);
+                                HdlFileLogic.Current.DeleteDirectory(housePath);
+                            }
+                        }
+                        //濡傛灉鍒囨崲浜嗚处鍙�,鎴栬�呭師鏉ョ殑id涓嶅瓨鍦�,鍒欓噸缃綇瀹匢D
+                        if (Config.Instance.TheSameLoginAccount == false ||
+                            Config.Instance.HomeFilePathList.Contains($"House_{Config.Instance.HomeId}.json") == false)
+                        {
+                            Config.Instance.HomeId = listHouse[0].Id;
+                            if (listHouse.Count > 0)
+                            {
+                                Config.Instance.HomeId = listHouse[0].Id;
+                                Config.Instance.Home = GetHouseByHouseId(listHouse[0].Id);
+                            }
+                        }
+                        Config.Instance.Save();
+                    }
                 }
             }
-            return this.SortHouse(listData);
-        }
-
-        /// <summary>
-        /// 鍒锋柊浣忓畢瀵硅薄鐨勭紦瀛�
-        /// </summary>
-        /// <param name="i_residence">浜戠杩斿洖鐨勬暟鎹浆鎹㈡垚鐨勬暟鎹�</param>
-        public House RefreshResidenceMemory(ResidenceInformation i_residence)
-        {
-            string fileName = $"House_{i_residence.Id}.json";
-            if (Config.Instance.HomeFilePathList.Contains(fileName) == false)
+            catch (Exception ex)
             {
-                Config.Instance.HomeFilePathList.Add(fileName);
+                HdlLogLogic.Current.WriteLog(ex);
             }
-            var house = this.GetHouseByHouseId(i_residence.Id);
-            if (house == null)
-            {
-                house = new House();
-            }
-            house.Id = i_residence.Id;
-            house.Name = i_residence.HomeName;
-            house.IsOtherShare = i_residence.IsOtherShare;
-            house.AccountType = i_residence.AccountType == "ADMIN" ? 1 : 0;
-            house.Longitude = i_residence.Longitude;
-            house.Latitude = i_residence.Latitude;
-            house.IsRemoteControl = i_residence.IsRemoteControl;
-
-            Global.CreateHomeDirectory(i_residence.Id);
-
-            house.Save(false);
-
-            return house;
+            return Config.Instance.HomeFilePathList;
         }
 
         #endregion
@@ -451,7 +389,7 @@
             {
                 listName.Add(house.Name);
             }
-            int numberLength = HdlCommonLogic.Current.GetNumberMaxLength(listName);
+            int numberLength = this.GetNumberMaxLength(listName);
 
             var listSort = new List<string[]>();
             var dicHouse = new Dictionary<string, House>();
@@ -510,18 +448,18 @@
         /// </summary>
         /// <param name="i_listData"></param>
         /// <returns></returns>
-        public List<ResidenceInformation> SortHouse(List<ResidenceInformation> i_listData)
+        public List<Common.ResponseEntity.ResidenceObj> SortHouse(List<Common.ResponseEntity.ResidenceObj> i_listData)
         {
             //浠庝竴鍫嗘枃瀛椾腑,鑾峰彇杩欎竴鍫嗘枃瀛楅噷闈㈡暟瀛楀瓧绗︿覆鐨勬渶闀块暱搴�
             var listName = new List<string>();
             foreach (var house in i_listData)
             {
-                listName.Add(house.HomeName);
+                listName.Add(house.Name);
             }
-            int numberLength = HdlCommonLogic.Current.GetNumberMaxLength(listName);
+            int numberLength = this.GetNumberMaxLength(listName);
 
             var listSort = new List<string[]>();
-            var dicHouse = new Dictionary<string, ResidenceInformation>();
+            var dicHouse = new Dictionary<string, Common.ResponseEntity.ResidenceObj>();
             foreach (var house in i_listData)
             {
                 //涓存椂缂撳瓨
@@ -532,7 +470,7 @@
                 strArry[1] = string.Empty;
 
                 string value = string.Empty;
-                foreach (var c in house.HomeName)
+                foreach (var c in house.Name)
                 {
                     if (char.IsNumber(c) == true)
                     {
@@ -564,7 +502,7 @@
                 }
                 return -1;
             });
-            var listSortHouse = new List<ResidenceInformation>();
+            var listSortHouse = new List<Common.ResponseEntity.ResidenceObj>();
             foreach (var strArry in listSort)
             {
                 listSortHouse.Add(dicHouse[strArry[0]]);
@@ -572,26 +510,47 @@
             return listSortHouse;
         }
 
+        /// <summary>
+        /// 浠庝竴鍫嗘枃瀛椾腑,鑾峰彇杩欎竴鍫嗘枃瀛楅噷闈㈡暟瀛楀瓧绗︿覆鐨勬渶闀块暱搴�
+        /// </summary>
+        /// <param name="listText"></param>
+        /// <returns></returns>
+        private int GetNumberMaxLength(List<string> listText)
+        {
+            int maxLength = 0;
+            foreach (var text in listText)
+            {
+                string value = string.Empty;
+                foreach (var c in text)
+                {
+                    if (char.IsNumber(c) == true)
+                    {
+                        //鏁板瓧
+                        value += c.ToString();
+                        continue;
+                    }
+                    else if (value != string.Empty)
+                    {
+                        //鍒ゆ柇鏁板瓧闀垮害
+                        if (maxLength <= value.Length)
+                        {
+                            maxLength = value.Length;
+                        }
+                        value = string.Empty;
+                    }
+                }
+                //鍒ゆ柇鏁板瓧闀垮害
+                if (maxLength <= value.Length)
+                {
+                    maxLength = value.Length;
+                }
+            }
+            return maxLength;
+        }
+
         #endregion
 
         #region 鈻� 鍒犻櫎浣忓畢___________________________
-
-        /// <summary>
-        /// 鍒犻櫎浜戠浣忓畢
-        /// </summary>
-        /// <param name="houseId">鍒犻櫎鎸囧畾浣忓畢</param>
-        /// <returns></returns>
-        public bool DeleteCloundHouse(string houseId)
-        {
-            var pra = new { homeId = houseId };
-            var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("home-wisdom/home/delete", RestSharp.Method.POST, pra);
-            //妫�娴嬬姸鎬佺爜
-            if (HdlCheckLogic.Current.CheckNetCode(result, ShowNetCodeMode.YES) == false)
-            {
-                return false;
-            }
-            return true;
-        }
 
         /// <summary>
         /// 鍒犻櫎浣忓畢
@@ -694,6 +653,25 @@
         #region 鈻� 缁撴瀯浣揰____________________________
 
         /// <summary>
+        ///  娣诲姞浣忓畢鐨勫惎鍔ㄥ弬鏁�
+        /// </summary>
+        private class AddResidencePra : IfacePraCommon
+        {
+            /// <summary>
+            /// RequestVersion
+            /// </summary>
+            public string RequestVersion = Common.CommonPage.RequestVersion;
+            /// <summary>
+            /// LoginAccessToken
+            /// </summary>
+            public string LoginAccessToken = Common.Config.Instance.Token;
+            /// <summary>
+            /// Name
+            /// </summary>
+            public string Name = string.Empty;
+        }
+
+        /// <summary>
         /// 鏂颁綇瀹呯殑淇℃伅
         /// </summary>
         private class NewResidenceInfo

--
Gitblit v1.8.0