From 9d9f97954c5eef9ee909eda39f082e0f19247111 Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期二, 21 三月 2023 14:14:29 +0800
Subject: [PATCH] 1

---
 ExportMap/cs/ExportUtil.cs   |    4 
 ExportMap/cs/SGUtils.cs      |   16 ++--
 ExportMap/cs/Tools.cs        |    2 
 ExportMap/cs/XYZUtils.cs     |  120 ++++++++++++++++++---------------------
 ExportMap/cs/ConvertUtils.cs |   10 +-
 ExportMap/db/SQLiteHelper.cs |    2 
 ExportMap/ExportMap.csproj   |    2 
 ExportMap/export.html        |    2 
 ExportMap/db/PubDBHelper.cs  |   14 ++--
 9 files changed, 82 insertions(+), 90 deletions(-)

diff --git a/ExportMap/ExportMap.csproj b/ExportMap/ExportMap.csproj
index 7e00cca..8945205 100644
--- a/ExportMap/ExportMap.csproj
+++ b/ExportMap/ExportMap.csproj
@@ -140,7 +140,7 @@
     <Compile Include="cs\LogOut.cs" />
     <Compile Include="cs\NoBufferPolicySelector.cs" />
     <Compile Include="cs\SGUtils.cs" />
-    <Compile Include="cs\Tool.cs" />
+    <Compile Include="cs\Tools.cs" />
     <Compile Include="cs\XYZUtils.cs" />
     <Compile Include="db\ModelHandler.cs" />
     <Compile Include="db\PostgreHelper.cs" />
diff --git a/ExportMap/cs/ConvertUtils.cs b/ExportMap/cs/ConvertUtils.cs
index b9fbcae..36a8d76 100644
--- a/ExportMap/cs/ConvertUtils.cs
+++ b/ExportMap/cs/ConvertUtils.cs
@@ -38,10 +38,10 @@
         public static int Convert(XYZArgs args)
         {
             int count = 0;
-            string uploadFolder = Tool.GetSetting("uploadFolder");
-            string tilesFolder = Path.Combine(Tool.GetSetting("lfData"), "3d\\3dtiles");
+            string uploadFolder = Tools.GetSetting("uploadFolder");
+            string tilesFolder = Path.Combine(Tools.GetSetting("lfData"), "3d\\3dtiles");
 
-            List<SysMeta> list = XYZUtils.selectMetas(args.ids, "and type in ('ifc', 'fbx', 'rvt')");
+            List<SysMeta> list = XYZUtils.SelectMetas(args.ids, "and type in ('ifc', 'fbx', 'rvt')");
             if (null == list || list.Count == 0) return 0;
 
             foreach (SysMeta meta in list)
@@ -49,7 +49,7 @@
                 string modelFile = Path.Combine(uploadFolder, meta.path);
                 if (!File.Exists(modelFile)) continue;
 
-                string configFile = Path.Combine(Tool.TempDir, ExportUtil.DateStr + ".json");
+                string configFile = Path.Combine(Tools.TempDir, ExportUtil.DateStr + ".json");
                 string outPath = Path.Combine(tilesFolder, meta.type, meta.id.ToString());
                 string jsonFile = Path.Combine(outPath, "tileset.json");
 
@@ -62,7 +62,7 @@
                 File.Delete(configFile);
                 if (File.Exists(jsonFile))
                 {
-                    string path = jsonFile.Replace(Tool.GetSetting("lfData") + "\\", "");
+                    string path = jsonFile.Replace(Tools.GetSetting("lfData") + "\\", "");
                     InsertToDB(meta, args, path);
 
                     count++;
diff --git a/ExportMap/cs/ExportUtil.cs b/ExportMap/cs/ExportUtil.cs
index d7534a2..8a1813c 100644
--- a/ExportMap/cs/ExportUtil.cs
+++ b/ExportMap/cs/ExportUtil.cs
@@ -31,7 +31,7 @@
             {
                 if (string.IsNullOrEmpty(sourcesPath))
                 {
-                    sourcesPath = Path.Combine(Tool.BaseDir, "Sources");
+                    sourcesPath = Path.Combine(Tools.BaseDir, "Sources");
                 }
 
                 return sourcesPath;
@@ -142,7 +142,7 @@
             CreateTemplate(args);
 
             string cmd = string.Format("python \"{0}\" -qgz {1} -qpt {2}", PyFile, qgz, args.qpt);
-            err = Tool.ExecCmd(cmd, true);
+            err = Tools.ExecCmd(cmd, true);
 
             string qptFile = Path.Combine(SourcesPath, args.qpt);
             if (File.Exists(qptFile)) File.Delete(qptFile);
diff --git a/ExportMap/cs/SGUtils.cs b/ExportMap/cs/SGUtils.cs
index 20a07d2..fbe3c59 100644
--- a/ExportMap/cs/SGUtils.cs
+++ b/ExportMap/cs/SGUtils.cs
@@ -60,7 +60,7 @@
         /// <returns>琛屾暟</returns>
         public int Release(XYZArgs args, ref string err)
         {
-            List<SysMeta> list = XYZUtils.selectMetas(args.ids, "and type in ('mpt', '3dml')");
+            List<SysMeta> list = XYZUtils.SelectMetas(args.ids, "and type in ('mpt', '3dml')");
             if (null == list || list.Count == 0) return 0;
 
             int maxId = GetMaxId(); // maxId = 411576;
@@ -120,7 +120,7 @@
         /// </summary>
         private void RomoveNoneFiles(List<SysMeta> list)
         {
-            string uploadFolder = Tool.GetSetting("uploadFolder");
+            string uploadFolder = Tools.GetSetting("uploadFolder");
 
             int i = 0;
             while (i < list.Count)
@@ -209,7 +209,7 @@
         /// </summary>
         private static void MoveFiles(List<SysMeta> metas)
         {
-            string uploadFolder = Tool.GetSetting("uploadFolder");
+            string uploadFolder = Tools.GetSetting("uploadFolder");
             string sgFolder = Path.Combine(uploadFolder, "SG");
             if (!Directory.Exists(sgFolder)) Directory.CreateDirectory(sgFolder);
 
@@ -283,7 +283,7 @@
 
             if (0 == list.Count) return "娌℃湁闇�瑕佹洿鏂板彂甯冪殑鏂囦欢";
 
-            return Tool.ExecCmd(list);
+            return Tools.ExecCmd(list);
         }
 
         /// <summary>
@@ -291,8 +291,8 @@
         /// </summary>
         private void AddMptLinkFile(List<string> list, SysMeta meta)
         {
-            string uploadFolder = Tool.GetSetting("uploadFolder");
-            string d3mlFolder = Tool.GetSetting("3dmlFolder");
+            string uploadFolder = Tools.GetSetting("uploadFolder");
+            string d3mlFolder = Tools.GetSetting("3dmlFolder");
 
             string targetFolder = Path.Combine(d3mlFolder, meta.id.ToString());
             if (!Directory.Exists(targetFolder)) Directory.CreateDirectory(targetFolder);
@@ -308,8 +308,8 @@
         /// </summary>
         private void AddD3mlLinkFile(List<string> list, SysMeta meta)
         {
-            string uploadFolder = Tool.GetSetting("uploadFolder");
-            string mptFolder = Tool.GetSetting("mptFolder");
+            string uploadFolder = Tools.GetSetting("uploadFolder");
+            string mptFolder = Tools.GetSetting("mptFolder");
 
             string targetFolder = Path.Combine(mptFolder, meta.id.ToString());
             if (!Directory.Exists(targetFolder)) Directory.CreateDirectory(targetFolder);
diff --git a/ExportMap/cs/Tool.cs b/ExportMap/cs/Tools.cs
similarity index 99%
rename from ExportMap/cs/Tool.cs
rename to ExportMap/cs/Tools.cs
index 1601884..5398849 100644
--- a/ExportMap/cs/Tool.cs
+++ b/ExportMap/cs/Tools.cs
@@ -16,7 +16,7 @@
 
 namespace ExportMap.cs
 {
-    public class Tool
+    public class Tools
     {
         /// <summary>
         /// 鍩虹鐩綍
diff --git a/ExportMap/cs/XYZUtils.cs b/ExportMap/cs/XYZUtils.cs
index c809e7c..b9f244b 100644
--- a/ExportMap/cs/XYZUtils.cs
+++ b/ExportMap/cs/XYZUtils.cs
@@ -43,6 +43,29 @@
         }
 
         /// <summary>
+        /// bat璺緞
+        /// </summary>
+        public static string BatPath
+        {
+            get
+            {
+                return @"C:\Program Files\QGIS 3.16\bin\";
+            }
+        }
+
+        /// <summary>
+        /// 鍩虹bat鏂囦欢
+        /// </summary>
+        public static string BaseBat
+        {
+            get
+            {
+                // python-qgis-ltr.bat锛宷gis_process-qgis-ltr.bat
+                return @"C:\Program Files\QGIS 3.16\bin\qgis_process-qgis-ltr.bat";
+            }
+        }
+
+        /// <summary>
         /// 鑾峰彇鍙戝竷鍦板潃
         /// </summary>
         public static string GetReleaseUrl(string dircode)
@@ -58,10 +81,12 @@
         /// <returns>鏁版嵁鍙戝竷ID</returns>
         public static int Generate(XYZArgs args, ref string err)
         {
-            List<SysMeta> list = selectMetas(args.ids, "and type in ('tif', 'tiff', 'img')");
+            List<SysMeta> list = SelectMetas(args.ids, "and type in ('tif', 'tiff', 'img')");
             if (null == list || list.Count == 0) return 0;
 
-            string tifFile = Path.Combine(Tool.TempDir, ExportUtil.DateStr + ".txt");
+            string dateStr = ExportUtil.DateStr;
+            string batFile = Path.Combine(BatPath, dateStr + ".bat");
+            string tifFile = Path.Combine(Tools.TempDir, ExportUtil.DateStr + ".txt");
             string xyzPath = Path.Combine(SGUtils.LFData, "2d\\tiles", args.dircode);
             if (!Directory.Exists(xyzPath)) Directory.CreateDirectory(xyzPath);
 
@@ -80,10 +105,17 @@
             //string newPy = tifFile.Replace(".txt", ".py").Replace("\\", "\\\\");
             //File.WriteAllText(newPy, pyText);
             //string cmd = string.Format("exec(open('{0}', 'r', encoding='utf-8').read()) & exit()", newPy);
+            //err = ExecCmd(cmd);
 
-            err = ExecCmd(cmd);
+            //List<string> cmds = GetCmds(cmd);
+            //err = Tools.ExecCmd(cmds);
+
+            List<string> cmds = GetCmds(batFile, cmd);
+            err = Tools.ExecCmd(cmds);
 
             if (File.Exists(tifFile)) File.Delete(tifFile);
+            if (File.Exists(batFile)) File.Delete(batFile);
+
             string viewFile = Path.Combine(xyzPath, "view.html");
             if (File.Exists(viewFile))
             {
@@ -96,12 +128,23 @@
         }
 
         /// <summary>
+        /// 鑾峰彇鍛戒护琛�
+        /// </summary>
+        private static List<string> GetCmds(string batFile, string cmd)
+        {
+            string str = File.ReadAllText(BaseBat) + cmd;
+            File.WriteAllText(batFile, str);
+
+            return new List<string>() { "\"" + batFile + "\"" };
+        }
+
+        /// <summary>
         /// 鏌ヨ鍏冩暟鎹�
         /// </summary>
-        public static List<SysMeta> selectMetas(List<int> ids, string types = "")
+        public static List<SysMeta> SelectMetas(List<int> ids, string types = "")
         {
             string sql = string.Format("select * from lf.sys_meta where id in ({0}) {1} order by id", string.Join(",", ids), types);
-            DataTable dt = Tool.DBHelper.GetDataTable(sql);
+            DataTable dt = Tools.DBHelper.GetDataTable(sql);
             List<SysMeta> list = ModelHandler.FillModel<SysMeta>(dt);
 
             return list;
@@ -112,70 +155,19 @@
         /// </summary>
         private static void WriteText(string file, List<SysMeta> list)
         {
-            string uploadFolder = Tool.GetSetting("uploadFolder");
+            string uploadFolder = Tools.GetSetting("uploadFolder");
 
             List<string> files = new List<string>();
-            foreach (SysMeta meta in list)
-            {
-                string filePath = Path.Combine(uploadFolder, meta.path);
-                if (File.Exists(filePath)) files.Add(filePath);
-            }
+            //foreach (SysMeta meta in list)
+            //{
+            //    string filePath = Path.Combine(uploadFolder, meta.path);
+            //    if (File.Exists(filePath)) files.Add(filePath);
+            //}
+            files.Add(@"E:\01.Data\33.DOM\2.澶у簡DOM\5154.50-415.50.tif");
+            files.Add(@"E:\01.Data\33.DOM\2.澶у簡DOM\5154.50-416.00.tif");
             string str = string.Join("\n", files);
 
             File.WriteAllText(file, str);
-        }
-
-        /// <summary>
-        /// 鎵цCMD
-        /// </summary>
-        /// <param name="cmd">鍛戒护琛�</param>
-        /// <returns>鎵ц缁撴灉鎴栧嚭閿欎俊鎭�</returns>
-        public static String ExecCmd(string cmd)
-        {
-            string str = null;
-            try
-            {
-                Process p = new Process();
-                p.StartInfo.FileName = "cmd.exe";
-                p.StartInfo.UseShellExecute = false;
-                p.StartInfo.CreateNoWindow = true;
-                p.StartInfo.RedirectStandardInput = true;
-                p.StartInfo.RedirectStandardOutput = true;
-                p.StartInfo.RedirectStandardError = true;
-                p.Start();
-
-                StreamWriter si = p.StandardInput; // 鏍囧噯杈撳叆娴� 
-                StreamReader so = p.StandardOutput; // 鏍囧噯杈撳嚭娴� 
-                StreamReader se = p.StandardError; // 鏍囧噯閿欒娴�
-
-                LogOut.Info("cmd = " + cmd);
-                si.AutoFlush = true;
-                si.WriteLine("cd \"C:\\Program Files\\QGIS 3.16\\apps\\Python37\"");
-                si.WriteLine("\"C:\\Program Files\\QGIS 3.16\\bin\\qgis_process-qgis-ltr.bat\"");
-                //si.WriteLine("\"C:\\Program Files\\QGIS 3.16\\bin\\python-qgis-ltr.bat\"");
-                //si.WriteLine("exit()");
-                si.WriteLine(cmd);
-                si.WriteLine("exit");
-
-                string info = so.ReadToEnd();
-                str = se.ReadToEnd();
-
-                if (!string.IsNullOrEmpty(info)) LogOut.Debug(info);
-                if (!string.IsNullOrEmpty(str)) LogOut.Error(str);
-                if (p.HasExited == false) p.Kill();
-
-                se.Close();
-                so.Close();
-                si.Close();
-                p.Close();
-            }
-            catch (Exception ex)
-            {
-                LogOut.Error(ex.StackTrace);
-                str = ex.Message;
-            }
-
-            return str;
         }
 
         /// <summary>
diff --git a/ExportMap/db/PubDBHelper.cs b/ExportMap/db/PubDBHelper.cs
index e97dfb9..0c99d8a 100644
--- a/ExportMap/db/PubDBHelper.cs
+++ b/ExportMap/db/PubDBHelper.cs
@@ -30,7 +30,7 @@
         {
             string sql = "select count(*) from lf.sys_meta_pub a inner join lf.sys_publish b on a.pubid = b.id where a.metaid = " + metaid;
 
-            object obj = Tool.DBHelper.GetScalar(sql);
+            object obj = Tools.DBHelper.GetScalar(sql);
             int count = obj == null ? 0 : Convert.ToInt32(obj);
 
             return count > 0;
@@ -44,7 +44,7 @@
             string sql = "select count(*) from lf.sys_meta_pub a inner join lf.sys_publish b on a.pubid = b.id where b.type = 'DOM' and b.dirid = @dirid";
             DbParameter dp = new NpgsqlParameter("@dirid", dirid);
 
-            object obj = Tool.DBHelper.GetScalar(sql, dp);
+            object obj = Tools.DBHelper.GetScalar(sql, dp);
             int count = obj == null ? 0 : Convert.ToInt32(obj);
 
             return count > 0;
@@ -57,7 +57,7 @@
         {
             string sql = string.Format(insertMetaPubSql, metaid, pubid, userId);
 
-            return Tool.DBHelper.ExecuteNonQuery(sql);
+            return Tools.DBHelper.ExecuteNonQuery(sql);
         }
 
         /// <summary>
@@ -65,10 +65,10 @@
         /// </summary>
         public static int InsertPublish(SysPublish sys)
         {
-            List<DbParameter> list = Tool.GetParams<SysPublish>(insertPublishSql, sys);
+            List<DbParameter> list = Tools.GetParams<SysPublish>(insertPublishSql, sys);
             string sql = string.Format(insertPublishSql, sys.geom == null ? "null" : sys.geom);
 
-            object obj = Tool.DBHelper.GetScalar(sql, list.ToArray());
+            object obj = Tools.DBHelper.GetScalar(sql, list.ToArray());
 
             return obj == null ? 0 : Convert.ToInt32(obj);
         }
@@ -93,7 +93,7 @@
             list.Add(new NpgsqlParameter("@user", sys.create_user));
             list.Add(new NpgsqlParameter("@elev", elev));
 
-            int rows = Tool.DBHelper.ExecuteNonQuery(insertLayerSql, list.ToArray());
+            int rows = Tools.DBHelper.ExecuteNonQuery(insertLayerSql, list.ToArray());
 
             return rows;
         }
@@ -107,7 +107,7 @@
             list.Add(new NpgsqlParameter("@id", meta.id));
             list.Add(new NpgsqlParameter("@path", meta.path));
 
-            int rows = Tool.DBHelper.ExecuteNonQuery(updateMetaSql, list.ToArray());
+            int rows = Tools.DBHelper.ExecuteNonQuery(updateMetaSql, list.ToArray());
 
             return rows;
         }
diff --git a/ExportMap/db/SQLiteHelper.cs b/ExportMap/db/SQLiteHelper.cs
index 4e0fae4..b8626fc 100644
--- a/ExportMap/db/SQLiteHelper.cs
+++ b/ExportMap/db/SQLiteHelper.cs
@@ -19,7 +19,7 @@
         static SQLiteHelper()
         {
             //SQLiteHelper.DB = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources\\Community.db");
-            DB = Tool.GetSetting("sgDB");
+            DB = Tools.GetSetting("sgDB");
         }
 
         /// <summary>
diff --git a/ExportMap/export.html b/ExportMap/export.html
index ce82c02..1ef2188 100644
--- a/ExportMap/export.html
+++ b/ExportMap/export.html
@@ -77,7 +77,7 @@
 
     // 娴嬭瘯鍒囧浘
     function convertXYZ() {
-      var data = { token: token, ids: [1526, 1527], id: 1, min: 12, max: 12, depcode: "000305", dircode: "0102", userId: 1, name: "DOM_0.2m" };
+      var data = { token: token, ids: [1526, 1527], id: 1, min: 8, max: 18, depcode: "000305", dircode: "0102", userId: 1, name: "DOM_0.2m" };
       ajax("Convert/ToTiles", "POST", JSON.stringify(data), null, null, function (rs) {
         alert("code = " + rs.code + ", msg = " + rs.msg + ", result = " + rs.result);
         console.log(rs);

--
Gitblit v1.9.3