From 5866f586616e48dfea53107cf6f8c3364c658951 Mon Sep 17 00:00:00 2001
From: lixin <lixinb@uniontech.com>
Date: Thu, 9 Nov 2023 17:08:00 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BB=BB=E5=8A=A1=E6=B5=81?=
 =?UTF-8?q?=E7=8A=B6=E6=80=81=E6=8E=A5=E5=8F=A3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 index.py        | 13 ++++++++++++-
 views/server.py | 31 ++++++++++++++++++++++++++++++-
 2 files changed, 42 insertions(+), 2 deletions(-)

diff --git a/index.py b/index.py
index 0c64990..059431b 100644
--- a/index.py
+++ b/index.py
@@ -4,7 +4,6 @@
 # SPDX-License-Identifier:   MulanPubL-2.0-or-later
 
 import os
-import sys
 import json
 from sysmig_agent import share
 from views import migration, server
@@ -28,6 +27,7 @@ mods = {
         'migration_details': migration.migration_details,
         'import_host_info': server.import_host_info,
         'host_info_display': server.host_info_display,
+        'sql_task': server.modify_task_stream,
         }
 
 @app.route('/import_host_info', methods=['GET', 'POST'])
@@ -52,6 +52,17 @@ def host_info_display():
         return Response(mod, content_type='application/json')
 
 
+@app.route('/sql_task', methods=['GET', 'POST'])
+def modify_task_stream():
+    """
+    修改任务流
+    :return:
+    """
+    mod = check_methods()
+    if mod:
+        return Response(mod, content_type='application/json')
+
+
 def check_methods():
     if request.method == 'POST':
         data = request.get_data()
diff --git a/views/server.py b/views/server.py
index d2ca719..a00e696 100644
--- a/views/server.py
+++ b/views/server.py
@@ -132,4 +132,33 @@ def host_info_display(data):
     res['size'] = size
 
     json_res = json.dumps(res)
-    return json_res
\ No newline at end of file
+    return json_res
+
+
+def modify_task_stream(data):
+    """
+    修改任务流状态
+    :return:
+    """
+    task_id = json.loads(data).get('task_id')
+    get_task_status_sql = "select task_status,task_stream_id from agent_task where task_id='%s';" % task_id
+    info = DBHelper().execute(get_task_status_sql).fetchone()
+    task_status = info[0]
+    task_stream_id = info[1]
+    if task_status == 0:
+        task_status = 'None'
+    elif task_status == 1:
+        task_status = 'Doing'
+    elif task_status == 2:
+        task_status = 'Done'
+    else:
+        task_status = 'Cancel'
+    time = datetime.now()
+    modify_task_status_sql = "update cur_task set task_status='%s',stream_Updatetime='%s' " \
+                             "where task_id ='%s';" % (task_status, time, task_id)
+    DBHelper().execute(modify_task_status_sql)
+
+    modify_task_stream_sql = "update task_stream set stream_status='%s',stream_Updatetime='%s' " \
+                             "where task_stream_id='%s';" % (task_status, time, task_stream_id)
+    DBHelper().execute(modify_task_stream_sql)
+    return 'success'
\ No newline at end of file
-- 
2.20.1

