From 2e2f1f542db7d709813efd6dcce14e3bc076bfa0 Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期四, 03 八月 2023 11:45:31 +0800
Subject: [PATCH] 1

---
 ExportMap/db/TaskDBHelper.cs |   15 +++++++
 ExportMap/cs/Tools.cs        |   63 ++++++++++++++++++++++++++++++-
 ExportMap/cs/CommonUtils.cs  |   10 ++++-
 ExportMap/cs/ConvertUtils.cs |   12 ++++--
 ExportMap/export.html        |   11 +++++
 5 files changed, 101 insertions(+), 10 deletions(-)

diff --git a/ExportMap/cs/CommonUtils.cs b/ExportMap/cs/CommonUtils.cs
index 682e148..744421e 100644
--- a/ExportMap/cs/CommonUtils.cs
+++ b/ExportMap/cs/CommonUtils.cs
@@ -61,10 +61,16 @@
                 {
                     if (ip != task.ip || task.status > 1) continue;
 
-                    task.err = KillProcess(task.id);
                     task.status = 3;
                     task.update_user = args.userId;
                     TaskDBHelper.Update(task);
+                    list.Add(task.id);
+
+                    task.err = KillProcess(task.pid);
+                    if (!string.IsNullOrEmpty(task.err))
+                    {
+                        TaskDBHelper.Update(task);
+                    }
                 }
             }
             catch (Exception ex)
@@ -85,7 +91,7 @@
             string cmd = string.Format("taskkill /f /t /pid {0}", processId);
             list.Add(cmd);
 
-            return Tools.ExecCmd(list, false);
+            return Tools.ExecCmd(list);
         }
     }
 }
diff --git a/ExportMap/cs/ConvertUtils.cs b/ExportMap/cs/ConvertUtils.cs
index 93e2d2e..53c5c0f 100644
--- a/ExportMap/cs/ConvertUtils.cs
+++ b/ExportMap/cs/ConvertUtils.cs
@@ -100,13 +100,18 @@
                 // 璁╃粍浠舵棤闄愭湡鍦扮瓑寰呭叧鑱旇繘绋嬮��鍑�
                 p.WaitForExit();
 
-                task.status = 2;
-                TaskDBHelper.Update(task);
+                task = TaskDBHelper.SelectById(task.id);
+                if (null != task && task.status < 2)
+                {
+                    task.status = 2;
+                    TaskDBHelper.Update(task);
+                }
             }
             catch (Exception ex)
             {
                 LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
-                if (task.id > 0 && task.status < 2)
+                task = TaskDBHelper.SelectById(task.id);
+                if (null != task && task.status < 2)
                 {
                     task.err = ex.Message;
                     task.status = 4;
@@ -118,7 +123,6 @@
                 if (p != null)
                 {
                     p.Close();
-                    p.Dispose();
                     p = null;
                 }
             }
diff --git a/ExportMap/cs/Tools.cs b/ExportMap/cs/Tools.cs
index b9ccb8d..c251067 100644
--- a/ExportMap/cs/Tools.cs
+++ b/ExportMap/cs/Tools.cs
@@ -166,9 +166,12 @@
         /// <summary>
         /// 鎵цCMD
         /// </summary>
+        /// <param name="task">浠诲姟</param>
         /// <param name="cmd">鍛戒护琛�</param>
+        /// <param name="isPy">鏄惁涓篞GIS Py鑴氭湰</param>
+        /// <param name="isOut">鏄惁杈撳嚭閿欒</param>
         /// <returns>鎵ц缁撴灉鎴栧嚭閿欎俊鎭�</returns>
-        public static string ExecCmd(string cmd, bool isPy = false, bool isOut = false)
+        public static string ExecCmd(SysTask task, string cmd, bool isPy = false, bool isOut = false)
         {
             List<string> list = new List<string>();
             if (isPy)
@@ -180,7 +183,7 @@
             }
             list.Add(cmd);
 
-            string str = ExecCmd(list, isOut);
+            string str = ExecCmd(task, list, isOut);
 
             return str;
         }
@@ -188,9 +191,11 @@
         /// <summary>
         /// 鎵цCMD
         /// </summary>
+        /// <param name="task">浠诲姟</param>
         /// <param name="list">鍛戒护闆嗗悎</param>
+        /// <param name="isOut">鏄惁杈撳嚭閿欒</param>
         /// <returns>鎵ц缁撴灉鎴栧嚭閿欎俊鎭�</returns>
-        public static string ExecCmd(List<string> list, bool isOut = false)
+        public static string ExecCmd(SysTask task, List<string> list, bool isOut = false)
         {
             string str = null;
             try
@@ -204,6 +209,8 @@
                 p.StartInfo.RedirectStandardOutput = true;
                 p.StartInfo.RedirectStandardError = true;
                 p.Start();
+
+                //p.Id;
 
                 StreamWriter si = p.StandardInput; // 鏍囧噯杈撳叆娴� 
                 StreamReader so = isOut ? p.StandardOutput : null; // 鏍囧噯杈撳嚭娴� 
@@ -239,6 +246,56 @@
         }
 
         /// <summary>
+        /// 鎵ц鍛戒护
+        /// </summary>
+        /// <param name="list">鍛戒护闆嗗悎</param>
+        public static string ExecCmd(List<string> list)
+        {
+            string str = null;
+            Process p = null;
+            try
+            {
+                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 se = p.StandardError;
+
+                LogOut.Info("cmd = " + string.Join("锛�", list));
+                si.AutoFlush = true;
+                foreach (string cmd in list)
+                {
+                    si.WriteLine(cmd);
+                }
+                si.WriteLine("exit");
+
+                str = se.ReadToEnd();
+                se.Close();
+                si.Close();
+            }
+            catch (Exception ex)
+            {
+                LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
+                str = ex.Message;
+            }
+            finally
+            {
+                if (p != null)
+                {
+                    p.Close();
+                    p = null;
+                }
+            }
+            return str;
+        }
+
+        /// <summary>
         /// 鍒涘缓鏁版嵁鍙戝竷绫�
         /// </summary>
         public static SysPublish NewPublish(SysMeta meta, XYZArgs args, string url, string path)
diff --git a/ExportMap/db/TaskDBHelper.cs b/ExportMap/db/TaskDBHelper.cs
index 4acb91e..85d97b5 100644
--- a/ExportMap/db/TaskDBHelper.cs
+++ b/ExportMap/db/TaskDBHelper.cs
@@ -12,13 +12,26 @@
     public class TaskDBHelper
     {
         /// <summary>
+        /// 鏍规嵁ID鏌ヨ
+        /// </summary>
+        public static SysTask SelectById(int id)
+        {
+            string sql = string.Format("select * from lf.sys_task where id = {0} order by id desc", id);
+
+            DataTable dt = Tools.DBHelper.GetDataTable(sql);
+            List<SysTask> list = ModelHandler.FillModel<SysTask>(dt);
+
+            return null == list || list.Count == 0 ? null : list[0];
+        }
+
+        /// <summary>
         /// 鏍规嵁ID闆嗗悎鏌ヨ
         /// </summary>
         public static List<SysTask> SelectByIds(List<int> ids)
         {
             string sql = string.Format("select * from lf.sys_task where id in ({0}) order by id desc", string.Join(",", ids.ToArray()));
 
-            DataTable dt = SQLiteHelper.GetDataTable(sql);
+            DataTable dt = Tools.DBHelper.GetDataTable(sql);
             List<SysTask> list = ModelHandler.FillModel<SysTask>(dt);
 
             return list;
diff --git a/ExportMap/export.html b/ExportMap/export.html
index 573f8ea..c713de7 100644
--- a/ExportMap/export.html
+++ b/ExportMap/export.html
@@ -177,6 +177,15 @@
         console.log(rs);
       });
     }
+
+    // 缁撴潫浠诲姟
+    function deleteTask() {
+      var data = { token: token, ids: [$("#taskId").val()], dircode: "00" };
+      ajax("Convert/DeleteTask", "POST", JSON.stringify(data), null, null, function (rs) {
+        alert("code = " + rs.code + ", msg = " + rs.msg + ", result = " + rs.result);
+        console.log(rs);
+      });
+    }
   </script>
 </head>
 <body>
@@ -205,5 +214,7 @@
   <br /><br />
   
   <input type="button" value="璇诲彇Las鍧愭爣绯�" onclick="ReadLasCs();" />
+  <input id="taskId" value="0" />
+  <input type="button" value="缁撴潫浠诲姟" onclick="deleteTask();" />
 </body>
 </html>

--
Gitblit v1.9.3