From f4c25e70497a233caba9e208c13f1b663bf0623f Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期六, 29 七月 2023 18:30:38 +0800
Subject: [PATCH] 删除服务时物理删除发布文件

---
 ExportMap/cs/Tools.cs                      |   35 +++++++++++++++++
 ExportMap/Controllers/ConvertController.cs |   28 ++++++++++++++
 ExportMap/cs/TerraUtils.cs                 |    4 +-
 ExportMap/export.html                      |    4 +-
 ExportMap/db/PubDBHelper.cs                |   18 +++++++-
 5 files changed, 82 insertions(+), 7 deletions(-)

diff --git a/ExportMap/Controllers/ConvertController.cs b/ExportMap/Controllers/ConvertController.cs
index 229da19..a851b75 100644
--- a/ExportMap/Controllers/ConvertController.cs
+++ b/ExportMap/Controllers/ConvertController.cs
@@ -219,6 +219,34 @@
         }
 
         /// <summary>
+        /// 鍒犻櫎鏂囦欢
+        /// </summary>
+        [HttpPost]
+        public ResponseMsg<string> DeleteFiles([FromBody]XYZArgs args)
+        {
+            try
+            {
+                ResponseMsg<string> msg = checkArgs(args, true);
+                if (null != msg) return msg;
+
+                string err = null;
+                List<int> rs = Tools.DeleteFiles(args, ref err);
+                if (null == rs || rs.Count == 0)
+                {
+                    return ResponseMsg<string>.fail(null == err ? "澶辫触" : err);
+                }
+
+                return ResponseMsg<string>.success("鎴愬姛", string.Join(",", rs), rs.Count);
+            }
+            catch (Exception ex)
+            {
+                LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
+                return ResponseMsg<string>.fail(ex.Message);
+            }
+
+        }
+
+        /// <summary>
         /// 妫�鏌ュ弬鏁�
         /// </summary>
         private ResponseMsg<string> checkArgs(XYZArgs args, bool checkDir = false)
diff --git a/ExportMap/cs/TerraUtils.cs b/ExportMap/cs/TerraUtils.cs
index 0974dc4..b6721a6 100644
--- a/ExportMap/cs/TerraUtils.cs
+++ b/ExportMap/cs/TerraUtils.cs
@@ -261,8 +261,8 @@
                 {
                     if (!ids.Contains(m.id)) PubDBHelper.InsertMetaPub(m.id, pubid, args.userId);
                 }
-                string json = GetPointZ(args);
-                if (!string.IsNullOrEmpty(json)) PubDBHelper.UpdatePublishCoord(pubid, json);
+                string geom = GetPointZ(args);
+                if (!string.IsNullOrEmpty(geom)) PubDBHelper.UpdatePublishGeom(pubid, geom);
 
                 return pubid;
             }
diff --git a/ExportMap/cs/Tools.cs b/ExportMap/cs/Tools.cs
index 000724c..6c8223d 100644
--- a/ExportMap/cs/Tools.cs
+++ b/ExportMap/cs/Tools.cs
@@ -288,6 +288,41 @@
             }
         }
 
+        /// <summary>
+        /// 鍒犻櫎鏂囦欢
+        /// </summary>
+        public static List<int> DeleteFiles(XYZArgs args, ref string err)
+        {
+            List<SysPublish> pubs = PubDBHelper.SelectPublishs(args.ids);
+            if (null == pubs || pubs.Count == 0) return null;
+
+            List<int> list = new List<int>();
+            foreach (SysPublish pub in pubs)
+            {
+                try
+                {
+                    if (string.IsNullOrEmpty(pub.url) || string.IsNullOrEmpty(pub.path)) continue;
+
+                    String path = SGUtils.LFData + "\\" + pub.path.Replace("\\tileset.json", "");
+                    if (pub.url.Contains("/SG/") || !Directory.Exists(path))
+                    {
+                        list.Add(pub.id);
+                        continue;
+                    }
+
+                    DelPath(path);
+                    list.Add(pub.id);
+                }
+                catch (Exception ex)
+                {
+                    LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
+                    err = ex.Message;
+                }
+            }
+
+            return list;
+        }
+
         [DllImport("ReadLas.dll")]
         public extern static int get_las_cs(string file_name);
     }
diff --git a/ExportMap/db/PubDBHelper.cs b/ExportMap/db/PubDBHelper.cs
index bc1ffca..1b0703a 100644
--- a/ExportMap/db/PubDBHelper.cs
+++ b/ExportMap/db/PubDBHelper.cs
@@ -98,10 +98,10 @@
         /// <summary>
         /// 鏇存柊鍙戝竷鏁版嵁鐨勫潗鏍�
         /// </summary>
-        public static int UpdatePublishCoord(int pid, string json)
+        public static int UpdatePublishGeom(int pid, string geom)
         {
-            string sql = string.Format("update lf.sys_publish set json = @json where id = {0}", pid);
-            DbParameter dp = new NpgsqlParameter("@json", json);
+            string sql = string.Format("update lf.sys_publish set geom = @geom where id = {0}", pid);
+            DbParameter dp = new NpgsqlParameter("@geom", geom);
 
             return Tools.DBHelper.ExecuteNonQuery(sql, dp);
         }
@@ -275,6 +275,18 @@
         }
 
         /// <summary>
+        /// 鏌ヨ鍙戝竷鏁版嵁
+        /// </summary>
+        public static List<SysPublish> SelectPublishs(List<int> ids)
+        {
+            string sql = string.Format("select id, name, url, path, type, status, dirid, depid, min, max, json, create_user, create_time, update_user, update_time, st_astext(geom) geom, bak from lf.sys_publish where id in ({0}) order by id desc", string.Join(",", ids));
+            DataTable dt = Tools.DBHelper.GetDataTable(sql);
+            List<SysPublish> list = ModelHandler.FillModel<SysPublish>(dt);
+
+            return list;
+        }
+
+        /// <summary>
         /// 鑾峰彇鍙傛暟鍒楄〃
         /// </summary>
         public static List<DbParameter> GetParams<T>(string sql, T t)
diff --git a/ExportMap/export.html b/ExportMap/export.html
index a5dd935..533a9f3 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 = "5f98316d-de91-4850-a20f-44080a278115";
+    var token = "dba75438-71f2-4a67-91ef-8919cd9b16cc";
 
     // Ajax
     function ajax(url, type, data, dataType, contentType, fn) {
@@ -127,7 +127,7 @@
     
     // 娴嬭瘯Terra锛�10526锛�10527
     function toTerra() {
-      var data = { token: token, ids: [10526, 10527], min: 0, max: 18, depcode: "00", dircode: "09", userId: 1, name: "BN_GD" };
+      var data = { token: token, ids: [10531], min: 0, max: 18, depcode: "00", dircode: "090000", userId: 1, name: "涓紖" };
       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