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