From d6bc097e6974c0ba8f7ff74b9f8a86ba5addf036 Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期二, 25 七月 2023 10:52:52 +0800
Subject: [PATCH] 1

---
 ExportMap/cs/TerraUtils.cs  |   39 ++++++++++++++++++++++++++++++++++-----
 ExportMap/export.html       |    4 ++--
 ExportMap/db/PubDBHelper.cs |    5 +++--
 3 files changed, 39 insertions(+), 9 deletions(-)

diff --git a/ExportMap/cs/TerraUtils.cs b/ExportMap/cs/TerraUtils.cs
index 1525973..0974dc4 100644
--- a/ExportMap/cs/TerraUtils.cs
+++ b/ExportMap/cs/TerraUtils.cs
@@ -134,14 +134,34 @@
             string txtFile = null;
             try
             {
-                txtFile = Path.Combine(Tools.TempDir, ExportUtil.DateStr + ".txt");
                 string dirPath = GetTerrainPath(args.dircode);
                 if (!Directory.Exists(dirPath)) Directory.CreateDirectory(dirPath);
 
+                txtFile = Path.Combine(Tools.TempDir, ExportUtil.DateStr + ".txt");
                 string tifFile = Path.Combine(dirPath, args.dircode + ".tif");
-                //if (File.Exists(tifFile)) File.Delete(tifFile);
 
-                WriteText(txtFile, metas);
+                int pubid = PubDBHelper.GetPushlishId(args.dircode, "DEM");
+                if (pubid > 0 && File.Exists(tifFile))
+                {
+                    List<int> ids = PubDBHelper.GetPublishMetaId(pubid);
+
+                    List<SysMeta> news = new List<SysMeta>();
+                    foreach (SysMeta m in metas)
+                    {
+                        if (!ids.Contains(m.id)) news.Add(m);
+                    }
+                    if (0 == news.Count) return tifFile;
+
+                    string oldTif = Path.Combine(dirPath, args.dircode + "_old.tif");
+                    if (File.Exists(oldTif)) File.Delete(oldTif);
+                    File.Move(tifFile, oldTif);
+                    WriteText(txtFile, news, oldTif);
+                }
+                else
+                {
+                    if (File.Exists(tifFile)) File.Delete(tifFile);
+                    WriteText(txtFile, metas, null);
+                }
 
                 string cmd = string.Format("python \"{0}\" -qgz {1} -file \"{2}\" -out \"{3}\"", PyFile, Qgz, txtFile, tifFile);
                 err = Tools.ExecCmd(cmd, true, false);
@@ -157,24 +177,30 @@
             finally
             {
                 if (!string.IsNullOrEmpty(txtFile) && File.Exists(txtFile)) File.Delete(txtFile);
+
+                string dirPath = GetTerrainPath(args.dircode);
+                string tifFile = Path.Combine(dirPath, args.dircode + ".tif");
+                string oldTif = Path.Combine(dirPath, args.dircode + "_old.tif");
+                if (File.Exists(tifFile) && File.Exists(oldTif)) File.Delete(oldTif);
             }
         }
 
         /// <summary>
         /// 鍐欐枃鏈枃浠�
         /// </summary>
-        private static void WriteText(string txtFile, List<SysMeta> list)
+        private static void WriteText(string txtFile, List<SysMeta> list, string tif)
         {
             string uploadFolder = Tools.GetSetting("uploadFolder");
 
             List<string> files = new List<string>();
+            if (!string.IsNullOrEmpty(tif)) files.Add(tif);
             foreach (SysMeta meta in list)
             {
                 string filePath = Path.Combine(uploadFolder, meta.path);
                 if (File.Exists(filePath)) files.Add(filePath);
             }
-            string str = string.Join("\r\n", files);
 
+            string str = string.Join("\r\n", files);
             File.WriteAllText(txtFile, str);
         }
 
@@ -235,6 +261,9 @@
                 {
                     if (!ids.Contains(m.id)) PubDBHelper.InsertMetaPub(m.id, pubid, args.userId);
                 }
+                string json = GetPointZ(args);
+                if (!string.IsNullOrEmpty(json)) PubDBHelper.UpdatePublishCoord(pubid, json);
+
                 return pubid;
             }
 
diff --git a/ExportMap/db/PubDBHelper.cs b/ExportMap/db/PubDBHelper.cs
index 5f60ebb..bc1ffca 100644
--- a/ExportMap/db/PubDBHelper.cs
+++ b/ExportMap/db/PubDBHelper.cs
@@ -100,9 +100,10 @@
         /// </summary>
         public static int UpdatePublishCoord(int pid, string json)
         {
-            string sql = string.Format("update lf.sys_publish set json = '{0}' where id = {1}", json, pid);
+            string sql = string.Format("update lf.sys_publish set json = @json where id = {0}", pid);
+            DbParameter dp = new NpgsqlParameter("@json", json);
 
-            return Tools.DBHelper.ExecuteNonQuery(sql);
+            return Tools.DBHelper.ExecuteNonQuery(sql, dp);
         }
 
         /// <summary>
diff --git a/ExportMap/export.html b/ExportMap/export.html
index 6b23fb6..a5dd935 100644
--- a/ExportMap/export.html
+++ b/ExportMap/export.html
@@ -10,7 +10,7 @@
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
   <script src="js/jquery.1.12.4.js"></script>
   <script>
-    var token = "0de31b49-1957-4e15-8258-965a35ea56cb";
+    var token = "5f98316d-de91-4850-a20f-44080a278115";
 
     // Ajax
     function ajax(url, type, data, dataType, contentType, fn) {
@@ -127,7 +127,7 @@
     
     // 娴嬭瘯Terra锛�10526锛�10527
     function toTerra() {
-      var data = { token: token, ids: [10526], min: 0, max: 18, depcode: "00", dircode: "09", userId: 1, name: "BN_GD" };
+      var data = { token: token, ids: [10526, 10527], min: 0, max: 18, depcode: "00", dircode: "09", userId: 1, name: "BN_GD" };
       ajax("Convert/ToTerra", "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