From f14dcfd967404e197e7ec995ca8d6f2b090d3b7d Mon Sep 17 00:00:00 2001
From: xm <1271024303@qq.com>
Date: 星期五, 11 九月 2020 09:16:59 +0800
Subject: [PATCH] 优化多功能面板:绑定温湿度传感器目标,和设备列表回路显示。优化数据矫正功能温湿度度不设置的情况。优化门锁时间设置最后一天和最后最后一个月的时间显示等 细节

---
 ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlAutoBackupLogic.cs |  503 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 503 insertions(+), 0 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlAutoBackupLogic.cs b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlAutoBackupLogic.cs
new file mode 100755
index 0000000..99c3486
--- /dev/null
+++ b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlAutoBackupLogic.cs
@@ -0,0 +1,503 @@
+锘縰sing Newtonsoft.Json;
+using Shared.Common;
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Shared.Phone.UserCenter
+{
+    /// <summary>
+    /// 鑷姩澶囦唤鐨勯�昏緫
+    /// </summary>
+    public class HdlAutoBackupLogic
+    {
+        #region 鈻� 鍙橀噺澹版槑___________________________
+
+        #endregion
+
+        #region 鈻� 涓婁紶澶囦唤___________________________
+
+        /// <summary>
+        /// 鎵ц涓婁紶鑷姩澶囦唤鏁版嵁(0:娌℃湁鍙笂浼犵殑鑷姩澶囦唤鏁版嵁 1:鎴愬姛 -1锛氬け璐�)
+        /// </summary>
+        /// <returns></returns>
+        public static int DoUpLoadAutoBackupData()
+        {
+            //鑾峰彇app鐨勮嚜鍔ㄥ浠�
+            var data = HdlBackupLogic.Current.GetBackupListNameFromDB(1);
+            if (data == null)
+            {
+                return -1;
+            }
+
+            if (data.Count == 0)
+            {
+                //鍒犻櫎鍏ㄩ儴鐨勮嚜鍔ㄥ浠界殑鏈湴鏂囦欢
+                DeleteAllAutoBackupFile();
+                //濡傛灉娌℃湁鑷姩澶囦唤鏁版嵁,鍒欐妸鏈湴鍏ㄩ儴涓滆タ涓婁紶
+                var pathTemp = DirNameResourse.AutoBackupDirectory;
+                //澶嶅埗鏈湴鎵�鏈夋枃浠惰繃鍘�
+                List<string> listAllFile = HdlFileLogic.Current.GetRootPathListFile();
+                foreach (string fileName in listAllFile)
+                {
+                    string oldFile = System.IO.Path.Combine(Config.Instance.FullPath, fileName);
+                    string newFile = System.IO.Path.Combine(pathTemp, fileName);
+                    //澶嶅埗鏂囦欢
+                    HdlFileLogic.Current.CopyFile(oldFile, newFile);
+                }
+            }
+
+            //缂栬緫鏂囦欢
+            List<string> listEditor = GetAutoBackupEditorFile();
+            //鍒犻櫎鏂囦欢
+            List<string> listDelete = GetAutoBackupDeleteFile();
+            //娌℃湁鏁版嵁
+            if (listEditor.Count == 0 && listDelete.Count == 0)
+            {
+                return 0;
+            }
+
+            //寮�鍚繘搴︽潯 姝e湪涓婁紶澶囦唤鏂囦欢
+            ProgressFormBar.Current.Start();
+            ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uBackupFileUploading));
+
+            //涓婁紶鏂囦欢鍒颁簯绔�
+            bool result = UpLoadBackupFileToDB(listEditor);
+            if (result == false)
+            {
+                ProgressFormBar.Current.Close();
+                return -1;
+            }
+
+            //鍒犻櫎鏂囦欢
+            result = DoDeleteFileFromDB(listDelete);
+            if (result == false)
+            {
+                ProgressFormBar.Current.Close();
+                return -1;
+            }
+
+            ProgressFormBar.Current.Close();
+
+            return 1;
+        }
+
+        /// <summary>
+        /// 涓婁紶鏂囦欢鍒颁簯绔�
+        /// </summary>
+        /// <param name="listFile"></param>
+        /// <returns></returns>
+        private static bool UpLoadBackupFileToDB(List<string> listFile)
+        {
+            int listFileCount = listFile.Count;
+            string backUpDir = DirNameResourse.AutoBackupDirectory;
+            for (int i = 0; i < listFile.Count; i++)
+            {
+                string file = listFile[i];
+                var datainfo = new FileInfoData();
+                datainfo.BackupFileName = file;
+                datainfo.BackupFileContent = HdlFileLogic.Current.ReadFileByteContent(System.IO.Path.Combine(backUpDir, file));
+                if (datainfo.BackupFileContent == null)
+                {
+                    continue;
+                }
+                var list = new List<FileInfoData>();
+                list.Add(datainfo);
+
+                //鎵ц鏄笂浼�
+                bool falge = DoUpLoadInfoToDB(list);
+                if (falge == false)
+                {
+                    return false;
+                }
+                //璁剧疆杩涘害鍊�
+                ProgressFormBar.Current.SetValue(i + 1, listFileCount);
+            }
+            return true;
+        }
+
+        /// <summary>
+        /// 浜戠鎵ц鍒犻櫎鎸囧畾鏂囦欢
+        /// </summary>
+        /// <param name="listData">鍒犻櫎鐨勬枃浠�</param>
+        /// <returns></returns>
+        private static bool DoDeleteFileFromDB(List<string> listData)
+        {
+            if (listData.Count == 0)
+            {
+                return true;
+            }
+
+            //鑾峰彇app鐨勮嚜鍔ㄥ浠�
+            var data = HdlBackupLogic.Current.GetBackupListNameFromDB(1);
+            if (data == null || data.Count == 0)
+            {
+                return true;
+            }
+            //鑷姩澶囦唤鍙湁涓�涓�
+            var autoBackupId = data[0].Id;
+            var nowZigbeeNumHomeId = Shared.Common.Config.Instance.Home.Id;
+
+            var upData = new DeleteFilePra();
+            upData.BackupClassId = autoBackupId;
+            upData.HomeId = nowZigbeeNumHomeId;
+            upData.DeleteFileNameLists = listData;
+            //鑾峰彇鎺у埗涓讳汉璐﹀彿鐨凾oken
+            upData.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
+
+            bool falge = UserCenterLogic.GetResultStatuByRequestHttps("App/DeleteAppBackupFile", true, upData);
+            if (falge == false)
+            {
+                return false;
+            }
+
+            //鍒犻櫎鏂囦欢
+            var backPath = DirNameResourse.AutoBackupdeleteDirectory;
+            foreach (var file in listData)
+            {
+                string fullName = System.IO.Path.Combine(backPath, file);
+                HdlFileLogic.Current.DeleteFile(fullName);
+            }
+            return true;
+        }
+
+        /// <summary>
+        /// 鎵ц涓婁紶鏂囦欢鍒颁簯绔�
+        /// </summary>
+        /// <param name="listData">涓婁紶鐨勬暟鎹�</param>
+        /// <returns></returns>
+        private static bool DoUpLoadInfoToDB(List<FileInfoData> listData)
+        {
+            var nowZigbeeNumHomeId = Shared.Common.Config.Instance.Home.Id;
+
+            var upData = new UpLoadDataPra();
+            upData.HomeId = nowZigbeeNumHomeId;
+            upData.UploadSubFileLists = listData;
+            //鑾峰彇鎺у埗涓讳汉璐﹀彿鐨凾oken
+            upData.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
+
+            bool falge = UserCenterLogic.GetResultStatuByRequestHttps("App/HomeAppAutoDataBackup", true, upData, null, true);
+            if (falge == false)
+            {
+                return false;
+            }
+
+            //鍒犻櫎鏂囦欢
+            var backPath = DirNameResourse.AutoBackupDirectory;
+            foreach (var file in listData)
+            {
+                string fullName = System.IO.Path.Combine(backPath, file.BackupFileName);
+                HdlFileLogic.Current.DeleteFile(fullName);
+            }
+
+            return true;
+        }
+
+        #endregion
+
+        #region 鈻� 鑾峰彇鏂囦欢___________________________
+
+        /// <summary>
+        /// 鑾峰彇鑷姩澶囦唤鐩綍涓嬬殑娣诲姞鎴栬�呯紪杈戠殑鏂囦欢
+        /// </summary>
+        /// <returns></returns>
+        public static List<string> GetAutoBackupEditorFile()
+        {
+            return HdlFileLogic.Current.GetFileFromDirectory(DirNameResourse.AutoBackupDirectory);
+        }
+
+        /// <summary>
+        /// 鑾峰彇鑷姩澶囦唤鐩綍涓嬬殑鍒犻櫎鐨勬枃浠�
+        /// </summary>
+        /// <returns></returns>
+        public static List<string> GetAutoBackupDeleteFile()
+        {
+            return HdlFileLogic.Current.GetFileFromDirectory(DirNameResourse.AutoBackupdeleteDirectory);
+        }
+
+        #endregion
+
+        #region 鈻� 璁剧疆鏂囦欢鐘舵�乢______________________
+
+        /// <summary>
+        /// 娣诲姞鎴栬�呬慨鏀规枃浠�
+        /// </summary>
+        /// <param name="fileName">鏂囦欢鐨勫悕瀛�,涓嶅惈璺緞</param>
+        public static void AddOrEditorFile(string fileName)
+        {
+            fileName = System.IO.Path.GetFileName(fileName);
+            //鑷姩澶囦唤鐩綍
+            string strBackPath = DirNameResourse.AutoBackupDirectory;
+            if (System.IO.Directory.Exists(strBackPath) == false)
+            {
+                //棰勫垱寤轰釜浜轰腑蹇冨叏閮ㄧ殑鏂囦欢澶�
+                HdlFileLogic.Current.CreatAllUserCenterDirectory();
+            }
+
+            //鑷姩鍒犻櫎澶囦唤鐩綍
+            string strdelBackPath = DirNameResourse.AutoBackupdeleteDirectory;
+            //濡傛灉鍒犻櫎鍒楄〃閲岄潰鏈夎繖涓笢瑗跨殑璇濓紝绉婚櫎鎺�
+            string delFile = System.IO.Path.Combine(strdelBackPath, fileName);
+            HdlFileLogic.Current.DeleteFile(delFile);
+
+            string soureFile = System.IO.Path.Combine(Common.Config.Instance.FullPath, fileName);
+            string newFile = System.IO.Path.Combine(strBackPath, fileName);
+
+            //鍘熷師鏈湰鐨勫鍒舵枃浠跺埌鎸囧畾鏂囦欢澶�
+            HdlFileLogic.Current.CopyFile(soureFile, newFile);
+        }
+
+        /// <summary>
+        /// 鍒犻櫎鏂囦欢
+        /// </summary>
+        /// <param name="fileName">鏂囦欢鐨勫悕瀛�,涓嶅惈璺緞</param>
+        public static void DeleteFile(string fileName)
+        {
+            fileName = System.IO.Path.GetFileName(fileName);
+            //鑷姩鍒犻櫎澶囦唤鐩綍
+            string strBackPath = DirNameResourse.AutoBackupdeleteDirectory;
+            string newFile = System.IO.Path.Combine(strBackPath, fileName);
+
+            //鍒涘缓涓�涓┖鏂囦欢
+            var file = System.IO.File.Create(newFile);
+            file.Close();
+
+            //鑷姩澶囦唤鐩綍
+            strBackPath = DirNameResourse.AutoBackupDirectory;
+            //濡傛灉澶囦唤鍒楄〃閲岄潰鏈夎繖涓笢瑗跨殑璇濓紝绉婚櫎鎺�
+            string delFile = System.IO.Path.Combine(strBackPath, fileName);
+
+            HdlFileLogic.Current.DeleteFile(delFile);
+        }
+
+        #endregion
+
+        #region 鈻� 鍚屾鏁版嵁___________________________
+
+        /// <summary>
+        /// 鍚屾浜戠鏁版嵁(浠呴檺APP鍚姩涔嬪悗) -1锛氬紓甯�   0:宸茬粡鍚屾杩囷紝涓嶉渶瑕佸悓姝�  1锛氭甯稿悓姝�  2:娌℃湁鑷姩澶囦唤鏁版嵁
+        /// </summary>
+        /// <returns></returns>
+        public static int SynchronizeDbAutoBackupData()
+        {
+            //鍒ゆ柇鏄惁鑳藉鍚屾鏁版嵁
+            string checkFile = DirNameResourse.AutoDownLoadBackupCheckFile;
+            //濡傛灉鏈湴宸茬粡鎷ユ湁浜嗚繖涓枃浠讹紝鍒欒鏄庝笉鏄柊鎵嬫満锛屼笉鍐嶈嚜鍔ㄨ繕鍘�
+            if (System.IO.File.Exists(checkFile) == true)
+            {
+                //鍚屾鏈嶅姟鍣ㄧ殑鍒嗕韩鍐呭
+                HdlShardLogic.Current.SynchronizeDbSharedContent();
+                return 0;
+            }
+
+            //鏆傛椂涓嶆敮鎸佹垚鍛�
+            if (UserCenterResourse.UserInfo.AuthorityNo == 3)
+            {
+                //鍚屾鏈嶅姟鍣ㄧ殑鍒嗕韩鍐呭
+                HdlShardLogic.Current.SynchronizeDbSharedContent();
+                //鍒涘缓涓�涓┖鏂囦欢(鏍囪瘑宸茬粡瀹屾垚鍚屾)
+                var file = System.IO.File.Create(checkFile);
+                file.Close();
+                return 1;
+            }
+
+            //鑾峰彇app鐨勮嚜鍔ㄥ浠�
+            var data = HdlBackupLogic.Current.GetBackupListNameFromDB(1);
+            if (data == null)
+            {
+                return -1;
+            }
+            if (data.Count == 0)
+            {
+                //鍚屾鏈嶅姟鍣ㄧ殑鍒嗕韩鍐呭
+                HdlShardLogic.Current.SynchronizeDbSharedContent();
+                //鍒涘缓涓�涓┖鏂囦欢(鏍囪瘑宸茬粡瀹屾垚鍚屾)
+                var file = System.IO.File.Create(checkFile);
+                file.Close();
+                return 2;
+            }
+            //鑷姩澶囦唤鍙湁涓�涓�
+            string backId = data[0].Id;
+
+            //璐﹀彿鏁版嵁鍚屾涓�
+            ProgressFormBar.Current.Start();
+            ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uAccountDataIsSynchronizing));
+
+            //浠庝簯绔幏鍙栧浠界殑鏂囦欢锛岀劧鍚庡瓨鍏ユ湰鍦版寚瀹氱殑涓存椂鏂囦欢澶�
+            string tempDir = HdlBackupLogic.Current.GetBackFileFromDBAndSetToLocation(backId);
+            if (tempDir == null)
+            {
+                //鍒犻櫎妫�娴嬫枃浠�
+                System.IO.File.Delete(checkFile);
+                //鍏抽棴杩涘害鏉�
+                ProgressFormBar.Current.Close();
+                //鍚屾澶辫触
+                return -1;
+            }
+            //濡傛灉璇诲彇鍒扮殑鏂囦欢瀹屽叏娌℃湁闂锛屽垯娓呯悊鏈湴鐨勬枃浠�
+            HdlFileLogic.Current.DeleteAllLocationFile(false);
+
+            //娌℃湁閿欒鐨勮瘽锛屽垯绉诲姩鍒板綋鍓嶄綇瀹呮枃浠跺す涓嬮潰
+            HdlFileLogic.Current.MoveDirectoryFileToHomeDirectory(tempDir, true);
+
+            //鍒涘缓涓�涓┖鏂囦欢(鏍囪瘑宸茬粡瀹屾垚鍚屾)
+            var file2 = System.IO.File.Create(checkFile);
+            file2.Close();
+
+            //閲嶆柊鍒锋柊浣忓畢瀵硅薄
+            UserCenterLogic.RefreshHomeObject();
+
+            //鍏抽棴杩涘害鏉�
+            ProgressFormBar.Current.Close();
+
+            return 1;
+        }
+
+        #endregion
+
+        #region 鈻� 涓�鑸柟娉昣__________________________
+
+        /// <summary>
+        /// 鍒犻櫎鍏ㄩ儴鐨勮嚜鍔ㄥ浠界殑鏈湴鏂囦欢(姝ゅ嚱鏁扮敤浜庤鍙栬嚜鍔ㄥ浠界殑鏃跺�欎娇鐢�)
+        /// </summary>
+        public static void DeleteAllAutoBackupFile()
+        {
+            //娓呯┖鑷姩澶囦唤銆愭枃浠跺す銆�(缂栬緫,杩藉姞)
+            string dirPath = DirNameResourse.AutoBackupDirectory;
+            HdlFileLogic.Current.DeleteDirectory(dirPath);
+            HdlFileLogic.Current.CreateDirectory(dirPath, true);
+
+            //娓呯┖鑷姩澶囦唤銆愭枃浠跺す銆�(鍒犻櫎)
+            dirPath = DirNameResourse.AutoBackupdeleteDirectory;
+            HdlFileLogic.Current.DeleteDirectory(dirPath);
+            HdlFileLogic.Current.CreateDirectory(dirPath, true);
+        }
+
+        #endregion
+
+        #region 鈻� 澶囦唤鎻愰啋___________________________
+
+        /// <summary>
+        /// 淇濆瓨澶囦唤鎻愰啋璁剧疆鍒版湰鍦�
+        /// </summary>
+        /// <param name="notPrompted">涓嶅啀鎻愮ず</param>
+        /// <param name="day"></param>
+        public static void SaveBackupNotPrompted(bool notPrompted, int day = -1)
+        {
+            //鏂囦欢鍏ㄨ矾寰�
+            string fullName = DirNameResourse.AutoBackupNotPromptedFile;
+            BackupNotPrompted info = null;
+            if (System.IO.File.Exists(fullName) == true)
+            {
+                var data = HdlFileLogic.Current.ReadFileByteContent(fullName);
+                info = JsonConvert.DeserializeObject<BackupNotPrompted>(System.Text.Encoding.UTF8.GetString(data));
+            }
+            if (info == null)
+            {
+                info = new BackupNotPrompted();
+            }
+
+            info.NotPrompted = notPrompted;
+            if (day != -1)
+            {
+                info.OldDay = DateTime.Now.ToString("yyyy-MM-dd");
+                info.Day = day;
+            }
+            //淇濆瓨
+            HdlFileLogic.Current.SaveFileContent(fullName, info);
+        }
+
+        /// <summary>
+        /// 鏄剧ず鑷姩澶囦唤鐨勭晫闈�
+        /// </summary>
+        public static void ShowAutoBackupPromptedForm()
+        {
+            if (UserCenterResourse.UserInfo.AuthorityNo == 3)
+            {
+                //鏆備笉鏀寔鎴愬憳
+                return;
+            }
+
+            List<string> listFile1 = HdlFileLogic.Current.GetFileFromDirectory(DirNameResourse.AutoBackupDirectory);
+            List<string> listFile2 = GetAutoBackupDeleteFile();
+
+            if (listFile1.Count == 0 && listFile2.Count == 0)
+            {
+                return;
+            }
+            if (listFile1.Count == 1 && listFile1[0] == "Room_Favorite.json")
+            {
+                //杩欎釜涓滆タ濂藉儚APP鍚姩鐨勬椂鍊欓兘浼氬垱寤虹殑鏍峰瓙
+                return;
+            }
+
+            //鏂囦欢鍏ㄨ矾寰�
+            string fullName = DirNameResourse.AutoBackupNotPromptedFile;
+            if (System.IO.File.Exists(fullName) == false)
+            {
+                HdlThreadLogic.Current.RunMain(() =>
+                {
+                    var form = new HdlBackup.HdlAutoBackupForm();
+                    form.AddForm();
+                });
+                return;
+            }
+            BackupNotPrompted info = null;
+            var data = HdlFileLogic.Current.ReadFileByteContent(fullName);
+            info = JsonConvert.DeserializeObject<BackupNotPrompted>(System.Text.Encoding.UTF8.GetString(data));
+            if (info.NotPrompted == true)
+            {
+                //涓嶅啀鎻愮ず
+                return;
+            }
+            if (info.Day == 0)
+            {
+                HdlThreadLogic.Current.RunMain(() =>
+                {
+                    var form = new HdlBackup.HdlAutoBackupForm();
+                    form.AddForm();
+                });
+                return;
+            }
+
+            DateTime oldTime = Convert.ToDateTime(info.OldDay);
+            int intDay = (DateTime.Now - oldTime).Days;
+            //鏃堕棿宸茬粡瓒呰繃
+            if (intDay > info.Day)
+            {
+                HdlThreadLogic.Current.RunMain(() =>
+                {
+                    var form = new HdlBackup.HdlAutoBackupForm();
+                    form.AddForm();
+                });
+                return;
+            }
+        }
+
+        #endregion
+
+        #region 鈻� 鏁版嵁缁撴瀯___________________________
+
+        /// <summary>
+        /// 鑷姩澶囦唤涓嶉渶瑕佸啀娆℃彁閱掔殑缁撴瀯浣�
+        /// </summary>
+        private class BackupNotPrompted
+        {
+            /// <summary>
+            /// 涓嶅啀鎻愮ず
+            /// </summary>
+            public bool NotPrompted = false;
+            /// <summary>
+            /// 鍓嶄竴娆$殑鏃ユ湡锛�2019-01-01(鏍煎紡)
+            /// </summary>
+            public string OldDay = string.Empty;
+            /// <summary>
+            /// 鐩搁殧鏃ユ湡澶╂暟
+            /// </summary>
+            public int Day = 0;
+        }
+
+        #endregion
+    }
+}

--
Gitblit v1.8.0