From 0138ef1182ab12141a59f927acf2965c4533e1f5 Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期三, 23 八月 2023 16:25:45 +0800
Subject: [PATCH] 修改获取文件、导入文件的业务逻辑

---
 DataLoader/CS/Importor.cs |  183 ++++++++++++++++-----------------------------
 1 files changed, 65 insertions(+), 118 deletions(-)

diff --git a/DataLoader/CS/Importor.cs b/DataLoader/CS/Importor.cs
index 34fd387..d9fa9c5 100644
--- a/DataLoader/CS/Importor.cs
+++ b/DataLoader/CS/Importor.cs
@@ -6,7 +6,6 @@
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
-using System.Windows.Documents;
 
 namespace DataLoader.CS
 {
@@ -138,7 +137,6 @@
             if (Directory.Exists(vd.FilePath))
             {
                 string[] files = Directory.GetFiles(vd.FilePath, "*", SearchOption.AllDirectories);
-
                 return GetFileSizes(files);
             }
 
@@ -229,25 +227,76 @@
 
             return isExclude;
         }
+        #endregion
+
+        #region 瀵煎叆
+        /// <summary>
+        /// 瀵煎叆鏂囦欢
+        /// </summary>
+        public static void ImportFiles(ObservableCollection<ViewData> viewDatas)
+        {
+            Parallel.ForEach(viewDatas, (vd, ParallelLoopState) =>
+            {
+                try
+                {
+                    vd.Status = "鐢熸垚MD5...";
+                    vd.Meta.guid = GetFilesMD5(vd);
+
+                    if (!string.IsNullOrEmpty(vd.Meta.guid) && DBHelper.IsFileExists(vd.Meta.guid))
+                    {
+                        vd.Status = "宸插瓨鍦紒";
+                        return;
+                    }
+
+                    vd.Status = "澶嶅埗鏂囦欢...";
+                    CopyFiles(vd);
+
+                    vd.Status = "鏁版嵁鍏ュ簱...";
+                    int id = DBHelper.InsertMeta(vd.Meta);
+                    vd.Status = id > 0 ? "鎴愬姛銆�" : "澶辫触锛�";
+                }
+                catch (Exception ex)
+                {
+                    LogOut.Error(ex.StackTrace);
+                    vd.Status = string.Format("澶辫触锛歿0}锛�", ex.Message);
+                }
+            });
+        }
 
         /// <summary>
-        /// 鑾峰彇鏂囦欢鐨凪D5鐮�
+        /// 鑾峰彇鏂囦欢鐨凪D5
         /// </summary>
-        private static string GetFileMD5(string file)
+        private static string GetFilesMD5(ViewData vd)
         {
-            if ("1" != Tools.GetSetting("GetMD5") || !File.Exists(file)) return null;
+            if ("1" != Tools.GetSetting("GetMD5")) return null;
 
-            return MD5Helper.GetMD5Hash(file);
+            if (File.Exists(vd.FilePath))
+            {
+                if (vd.Ext == StaticData.SHP)
+                {
+                    List<string> files = GetShpFiles(vd.FilePath);
+                    return GetFilesMD5(files.ToArray());
+                }
+                else
+                {
+                    return MD5Helper.GetMD5Hash(vd.FilePath);
+                }
+            }
+
+            if (Directory.Exists(vd.FilePath))
+            {
+                string[] files = Directory.GetFiles(vd.FilePath, "*", SearchOption.AllDirectories);
+                return GetFilesMD5(files);
+            }
+
+            return null;
         }
 
         /// <summary>
         /// 鑾峰彇澶氫釜鏂囦欢鐨凪D5鐮�
         /// </summary>
-        private static string GetFilesMD5(string path)
+        private static string GetFilesMD5(string[] files)
         {
-            if ("1" != Tools.GetSetting("GetMD5") || !Directory.Exists(path)) return null;
-
-            string[] files = Directory.GetFiles(path, "*", SearchOption.AllDirectories);
             if (null == files || files.Length == 0) return null;
 
             List<string> list = new List<string>();
@@ -264,100 +313,18 @@
 
             return MD5Helper.GetMD5Hash(bytes);
         }
-        #endregion
-
-        #region 瀵煎叆
-        /// <summary>
-        /// 瀵煎叆鏂囦欢
-        /// </summary>
-        public static void ImportFiles(ObservableCollection<ViewData> viewDatas)
-        {
-            Parallel.ForEach(viewDatas, (vd, ParallelLoopState) =>
-            {
-                try
-                {
-                    //
-
-                    SysMeta meta = new SysMeta();
-                    //
-
-                    int id = DBHelper.InsertMeta(meta);
-                    vd.Status = id > 0 ? "鎴愬姛銆�" : "澶辫触锛�";
-                }
-                catch (Exception ex)
-                {
-                    LogOut.Error(ex.StackTrace);
-                    vd.Status = string.Format("澶辫触锛歿0}锛�", ex.Message);
-                }
-            });
-        }
 
         /// <summary>
         /// 澶嶅埗鏂囦欢
         /// </summary>
-        private static void CopyFile(string source, string target)
+        private static void CopyFiles(ViewData vd)
         {
-            if (File.Exists(source))
-            {
-                File.Copy(source, target, true);
-            }
-        }
+            //mf.path = subPath + "\\" + mf.name;
 
-        public static void ImportFiles(ObservableCollection<ViewData> viewDatas, string target, int start)
-        {
-            /*Parallel.ForEach(viewDatas, (vd, ParallelLoopState) =>
-            {
-                try
-                {
-                    vd.Status = "鐢熸垚MD5鐮�...";
-                    string guid = MD5Helper.GetMD5Hash(vd.FilePath);
-                    if (!Exclusions.Contains(vd.Ext) && IsFileExists(guid))
-                    {
-                        vd.Status = "宸插瓨鍦紒";
-                        return;
-                    }
-
-                    vd.Status = "鑾峰彇鏁版嵁鐩綍...";
-                    int subPath = GetSubPath(target, start);
-                    SysMeta mf = GetMetaFile(vd, subPath, guid);
-
-                    vd.Status = "澶嶅埗鏂囦欢...";
-                    CopyFile(vd.FilePath, Path.Combine(target, mf.path));
-
-                    vd.Status = "鍑嗗鍏ュ簱";
-                    vd.Meta = mf;
-            });*/
-        }
-
-        public static void ImportFiles2(ObservableCollection<ViewData> viewDatas, string target)
-        {
-            int start = 1;
-            foreach (ViewData vd in viewDatas)
-            {
-                try
-                {
-                    vd.Status = "鎻掑叆鏁版嵁搴�...";
-                    start = GetSubPath(target, start);
-                    SysMeta mf = GetMetaFile(vd, start, "");
-
-                    int metaId = 0; // InsertMeta(mf);
-                    if (metaId == 0)
-                    {
-                        vd.Status = "鍏冩暟鎹嚭閿欙紒";
-                        continue;
-                    }
-
-                    vd.Status = "澶嶅埗鏂囦欢...";
-                    CopyFile(vd.FilePath, Path.Combine(target, mf.path));
-
-                    vd.Status = "瀹屾垚銆�";
-                }
-                catch (Exception ex)
-                {
-                    LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
-                    vd.Status = "澶辫触锛�";
-                }
-            }
+            //if (File.Exists(source))
+            //{
+            //    File.Copy(source, target, true);
+            //}
         }
 
         private static int GetSubPath(string target, int start = 1)
@@ -379,26 +346,6 @@
 
                 start++;
             }
-        }
-
-        private static SysMeta GetMetaFile(ViewData vd, int subPath, string guid)
-        {
-            SysMeta mf = new SysMeta();
-            mf.eventid = Guid.NewGuid().ToString();
-            mf.metaid = 0;
-            //mf.dirid = vd.Meta.dirid;
-            //mf.depid = vd.Meta.depid;
-            mf.verid = vd.Meta.verid;
-            mf.name = vd.Meta.name;
-            mf.type = vd.Meta.type;
-            mf.guid = guid;
-            mf.path = subPath + "\\" + mf.name;
-            mf.sizes = vd.Meta.sizes;
-            mf.tab = null;
-            mf.rows = 0;
-            mf.create_user = vd.Meta.create_user;
-
-            return mf;
         }
         #endregion
     }

--
Gitblit v1.9.3