From 25bf0a51088fa0d0acdc39c6096cc45d699f63a1 Mon Sep 17 00:00:00 2001
From: zhaoqingang <zhaoqg0118@163.com>
Date: 星期四, 13 二月 2025 10:53:23 +0800
Subject: [PATCH] merge master

---
 app/models/session_model.py        |    1 
 app/service/ragflow.py             |    4 
 app/api/chat.py                    |   13 
 app/service/difyService.py         |    4 
 app/api/agent.py                   |   31 +++
 app/config/env_conf/resource.json  |  376 ++++++++++++++++++------------------
 app/api/auth.py                    |    4 
 app/init_config/init_run_data.py   |   21 +
 app/config/env_conf/admin.yaml     |   12 +
 app/service/session.py             |    9 
 app/api/files.py                   |    2 
 app/service/v2/initialize_data.py  |   39 +++
 app/config/env_conf/menu_conf.json |   29 --
 13 files changed, 314 insertions(+), 231 deletions(-)

diff --git a/app/api/agent.py b/app/api/agent.py
index 0fb5f10..fd31c96 100644
--- a/app/api/agent.py
+++ b/app/api/agent.py
@@ -233,6 +233,7 @@
                     tmp_data["question"] = i.get("content")
                 elif i.get("role") == "assistant":
                     if isinstance(i.get("content"), dict):
+                        content = i.get("content", {})
                         tmp_data["answer"] = i.get("content", {}).get("answer")
                         if "file_name" in i.get("content", {}):
                             tmp_data["files"] = [{"file_name": i.get("content", {}).get("file_name"),
@@ -242,6 +243,36 @@
 
                         if "download_url" in i.get("content", {}):
                             tmp_data["download_url"] = i.get("content", {}).get("download_url")
+                        if "node_list" in content:
+                            node_dict = {
+                                "node_data": [],
+                                # {"title": "鍘婚櫎鍐椾綑",  # 鑺傜偣鍚嶇О "status": "succeeded",  # 鑺傜偣鐘舵��"created_at": 1735817337,  # 寮�濮嬫椂闂�"finished_at": 1735817337,  # 缁撴潫鏃堕棿"error": ""  # 閿欒鏃ュ織}
+                                "total_tokens": 0,  # 鑺辫垂token鏁�
+                                "created_at": 0,  # 寮�濮嬫椂闂�
+                                "finished_at": 0,  # 缁撴潫鏃堕棿
+                                "elapsed_time": 0,  # 缁撴潫鏃堕棿
+                                "status": "succeeded",  # 宸ヤ綔娴佺姸鎬�
+                                "error": "",  # 閿欒鏃ュ織
+                            }
+                            for node in content["node_list"]:
+                                if node.get("event") == "node_finished":
+                                    node_dict["node_data"].append({
+                                        "title": node.get("data", {}).get("title", ""),
+                                        "status": node.get("data", {}).get("status", ""),
+                                        "created_at": node.get("data", {}).get("created_at", 0),
+                                        "finished_at": node.get("data", {}).get("finished_at", 0),
+                                        "node_type": node.get("data", {}).get("node_type", 0),
+                                        "elapsed_time": node.get("data", {}).get("elapsed_time", 0),
+                                        "error": node.get("data", {}).get("error", ""),
+                                    })
+                                elif node.get("event") == "workflow_finished":
+                                    node_dict["total_tokens"] = node.get("data", {}).get("total_tokens", 0)
+                                    node_dict["created_at"] = node.get("data", {}).get("created_at", 0)
+                                    node_dict["finished_at"] = node.get("data", {}).get("finished_at", 0)
+                                    node_dict["status"] = node.get("data", {}).get("status", "")
+                                    node_dict["error"] = node.get("data", {}).get("error", "")
+                                    node_dict["elapsed_time"] = node.get("data", {}).get("elapsed_time", 0)
+                            tmp_data["workflow"] = node_dict
                     else:
                         tmp_data["answer"] = i.get("content")
                     data.append(tmp_data)
diff --git a/app/api/auth.py b/app/api/auth.py
index da59d89..b43e9d1 100644
--- a/app/api/auth.py
+++ b/app/api/auth.py
@@ -126,14 +126,16 @@
             continue
         try:
             name = login_data.username
+            email = ""
             app_password = login_data.password
             user_app = await UserAppDao(db).get_data_by_id(user.id, app["id"])
             if user_app:
                 name  = user_app.username
+                email  = user_app.email
                 app_password = user_app.decrypted_password(user_app.password)
             else:
                 await update_user_info(db, user.id)
-            token = await service.login(name, app_password)
+            token = await service.login(name, app_password,email=email)
             token_dict[app["id"]] = token
         except Exception as e:
             return Response(code=500, msg=f"Failed to login with {app['id']}: {str(e)}")
diff --git a/app/api/chat.py b/app/api/chat.py
index 6980d10..2c03a58 100644
--- a/app/api/chat.py
+++ b/app/api/chat.py
@@ -1,6 +1,5 @@
 import json
 import re
-import uuid
 from copy import deepcopy
 
 from fastapi import WebSocket, WebSocketDisconnect, APIRouter, Depends
@@ -231,7 +230,8 @@
                         question,
                         agent_id,
                         AgentType.BASIC,
-                        current_user.id
+                        current_user.id,
+                        {"role": "user", "content": question}
                     )
                 except Exception as e:
                     logger.error(e)
@@ -345,7 +345,8 @@
                                 question,
                                 agent_id,
                                 AgentType.DIFY,
-                                current_user.id
+                                current_user.id,
+                                {"role": "user", "content": question}
                             )
                             conversation_id = session.conversation_id
                         except Exception as e:
@@ -806,7 +807,7 @@
                                         result = {"message": f"鍐呴儴閿欒锛� {e2}", "type": "close"}
                                         await websocket.send_json(result)
                                         print(f"Error process message of ragflow: {e2}")
-                elif agent.type == "documentIa":
+                elif chat_type == "documentIa":
                     token = DfTokenDao(db).get_token_by_id(DOCUMENT_IA_QUESTIONS)
                     # print(token)
                     if not token:
@@ -828,7 +829,8 @@
                                 question,
                                 agent_id,
                                 AgentType.DIFY,
-                                current_user.id
+                                current_user.id,
+                                {"role": "user", "content": question}
                             )
                             conversation_id = session.conversation_id
                         except Exception as e:
@@ -929,7 +931,6 @@
                                 result = {"message": f"鍐呴儴閿欒锛� {e2}", "type": "close"}
                                 await websocket.send_json(result)
                                 print(f"Error process message of ragflow: {e2}")
-
 
             # 鍚姩浠诲姟澶勭悊瀹㈡埛绔秷鎭�
             tasks = [
diff --git a/app/api/files.py b/app/api/files.py
index c9f0524..db8936b 100644
--- a/app/api/files.py
+++ b/app/api/files.py
@@ -118,7 +118,7 @@
                 raise HTTPException(status_code=500, detail=str(e))
         elif agent.chat_type == "reportWorkflow" or agent.chat_type == "documentIa" or agent.chat_type == "paperTalk":
             token_dict = {
-                "reportWorkflow": DOCUMENT_TO_REPORT,
+                "reportWorkflow": DOCUMENT_TO_REPORT_TITLE,
                 "documentIa": DOCUMENT_IA_QUESTIONS,
                 "paperTalk": DOCUMENT_TO_PAPER,
             }
diff --git a/app/config/env_conf/admin.yaml b/app/config/env_conf/admin.yaml
new file mode 100644
index 0000000..3821bfd
--- /dev/null
+++ b/app/config/env_conf/admin.yaml
@@ -0,0 +1,12 @@
+smart_server:
+  account: administer
+  password: basic@2025
+
+ragflow_app:
+  id: 2c039666c29d11efa4670242ac1b0006
+  account: admin@example.com
+  password: basic@2025
+
+dify_app:
+  account: admin@mail.com
+  password: basic@2025
\ No newline at end of file
diff --git a/app/config/env_conf/menu_conf.json b/app/config/env_conf/menu_conf.json
index fac6e33..c8750b2 100644
--- a/app/config/env_conf/menu_conf.json
+++ b/app/config/env_conf/menu_conf.json
@@ -1,23 +1,6 @@
 {
   "data": [
     {
-      "id": 10,
-      "title": "鎶ュ憡鐢熸垚",
-      "icon": "2",
-      "img": "/src/assets/index/2.png",
-      "desc": "鍩轰簬鎮ㄥ垱寤虹殑鎶ュ憡鏍煎紡鍜岀煡璇嗗簱涓殑鏂囨。鍐呭锛屽揩閫熺敓鎴愬畾鍒舵姤鍛婏紝骞舵敮鎸佷竴閿笅杞姐��",
-      "describe": "鍩轰簬鎮ㄥ垱寤虹殑鎶ュ憡鏍煎紡鍜岀煡璇嗗簱涓殑鏂囨。鍐呭锛屽揩閫熺敓鎴愬畾鍒舵姤鍛婏紝骞舵敮鎸佷竴閿笅杞姐��",
-      "rank": 100,
-      "dialog": [
-        {
-          "id": "80ee430a-e396-48c4-a12c-7c7cdf5eda51",
-          "chat_id": "80ee430a-e396-48c4-a12c-7c7cdf5eda51",
-          "chat_type": "report",
-          "agentType": 2
-        }
-      ]
-    },
-    {
       "id": 1,
       "title": "鎶ヨ〃鍚堝苟",
       "icon": "6",
@@ -155,7 +138,7 @@
     },
     {
       "id": 9,
-      "title": "鏂囨。鎶ュ憡",
+      "title": "鎶ュ憡鐢熸垚",
       "icon": "2",
       "img": "/src/assets/index/2.png",
       "desc": "鍩轰簬鎮ㄥ垱寤虹殑鎶ュ憡鏍煎紡鍜屼笂浼犵殑鏂囨。鍐呭锛屽揩閫熺敓鎴愬畾鍒舵姤鍛婏紝骞舵敮鎸佷竴閿笅杞姐��",
@@ -163,13 +146,19 @@
       "rank": 91,
       "dialog": [
         {
-          "id": "72a69e47-458d-47f9-b534-1859e5da244f",
+          "id": "87b8e17c-594d-424f-b9f8-0b56036904c9",
           "chat_id": "basic_report_clean",
           "chat_type": "reportWorkflow",
           "agentType": 4
         },
         {
-          "id": "6eda0700-6273-488d-a97c-88d315bd9d8f",
+          "id": "61d26deb-9371-4f9c-b61b-b9f9a24a9188",
+          "chat_id": "basic_report_clean",
+          "chat_type": "reportWorkflow",
+          "agentType": 4
+        },
+        {
+          "id": "d6eea92d-444a-4658-b9e7-9ab7bd5cb19d",
           "chat_id": "basic_report_clean",
           "chat_type": "reportWorkflow",
           "agentType": 4
diff --git a/app/config/env_conf/resource.json b/app/config/env_conf/resource.json
index 2530c6d..b0cb111 100644
--- a/app/config/env_conf/resource.json
+++ b/app/config/env_conf/resource.json
@@ -1,8 +1,8 @@
 [
   {
     "id": "1eed48e2-d510-42f2-9495-bc299bae237b",
-    "created_at": "8/8/2024 19:21:42",
-    "updated_at": "8/8/2024 19:21:42",
+    "created_at": "26/12/2024 18:45:57",
+    "updated_at": "26/12/2024 18:45:57",
     "name": "root",
     "url": "root",
     "path": null,
@@ -15,14 +15,14 @@
     "resource_type_id": "3",
     "resource_id": null,
     "status": "1",
-    "hidden": null,
+    "hidden": 0,
     "children": [
       {
-        "id": "76e81844-c3a6-4ea0-882f-150be2987d9d",
-        "created_at": "23/12/2024 09:50:31",
-        "updated_at": "23/12/2024 09:50:31",
+        "id": "8eadbabd-cf55-469b-ad74-4f9fc80631a1",
+        "created_at": "10/1/2025 18:48:05",
+        "updated_at": "10/1/2025 18:48:05",
         "name": "鏅鸿兘浣撹鎯�",
-        "url": "/intelligent/detail",
+        "url": "DifyDetail",
         "path": "/intelligent/detail",
         "perms": "system:intelligent:detail",
         "description": "",
@@ -32,14 +32,31 @@
         "canbdeeleted": null,
         "resource_type_id": "3",
         "resource_id": "1eed48e2-d510-42f2-9495-bc299bae237b",
-        "status": "2",
+        "status": "1",
         "hidden": 0
       },
-
+      {
+        "id": "21e90633-bb76-4419-8925-c20b9ccd33f1",
+        "created_at": "10/1/2025 18:48:05",
+        "updated_at": "10/1/2025 18:48:05",
+        "name": "鐭ヨ瘑搴撹鎯�",
+        "url": "KnowledgeDetail",
+        "path": "/knowledge/detail",
+        "perms": "system:knowledge:detail",
+        "description": "",
+        "icon": "",
+        "seq": 0,
+        "target": null,
+        "canbdeeleted": null,
+        "resource_type_id": "3",
+        "resource_id": "1eed48e2-d510-42f2-9495-bc299bae237b",
+        "status": "1",
+        "hidden": 0
+      },
       {
         "id": "3750795c-404b-488b-8080-89c037b4a187",
-        "created_at": "18/12/2024 19:20:09",
-        "updated_at": "20/12/2024 11:38:54",
+        "created_at": "26/12/2024 18:45:57",
+        "updated_at": "26/12/2024 18:45:57",
         "name": "灏忔暟",
         "url": "Xiaoshu",
         "path": "/xiaoshu",
@@ -56,8 +73,8 @@
       },
       {
         "id": "3ea0f0b8-5160-4005-91d6-7c6650a5934c",
-        "created_at": "20/12/2024 11:38:54",
-        "updated_at": "20/12/2024 11:38:54",
+        "created_at": "26/12/2024 18:45:57",
+        "updated_at": "26/12/2024 18:45:57",
         "name": "浼氳瘽鍘嗗彶",
         "url": "ConversationHistory",
         "path": "/chat/history",
@@ -74,8 +91,8 @@
       },
       {
         "id": "6469b565-908a-4771-a9e3-1cf8651b26f4",
-        "created_at": "12/9/2024 08:01:13",
-        "updated_at": "20/12/2024 11:38:54",
+        "created_at": "26/12/2024 18:45:57",
+        "updated_at": "26/12/2024 18:45:57",
         "name": "浼氳瘽",
         "url": "ConversationQA",
         "path": "/chat/qa",
@@ -88,12 +105,12 @@
         "resource_type_id": "0",
         "resource_id": "1eed48e2-d510-42f2-9495-bc299bae237b",
         "status": "1",
-        "hidden": null
+        "hidden": 0
       },
       {
         "id": "6b3640d2-6142-4dce-b09b-ce11f9e6c89c",
-        "created_at": "20/12/2024 11:38:54",
-        "updated_at": "20/12/2024 11:38:54",
+        "created_at": "26/12/2024 18:45:57",
+        "updated_at": "26/12/2024 18:45:57",
         "name": "浼氳瘽杩涜涓�",
         "url": "ConversationQA",
         "path": "/chat/qa",
@@ -110,8 +127,8 @@
       },
       {
         "id": "6da7445a-5980-4380-ab1d-75021c1dd269",
-        "created_at": "18/12/2024 19:20:09",
-        "updated_at": "20/12/2024 11:38:54",
+        "created_at": "26/12/2024 18:45:57",
+        "updated_at": "26/12/2024 18:45:57",
         "name": "鏅鸿兘浣�",
         "url": "Intelligent",
         "path": "/intelligent",
@@ -127,9 +144,27 @@
         "hidden": 0
       },
       {
+        "id": "a4931c80-c890-4142-a698-87940c937b57",
+        "created_at": "26/12/2024 18:45:57",
+        "updated_at": "26/12/2024 18:45:57",
+        "name": "浼氳瘽闈㈡澘",
+        "url": "ConversationBoard",
+        "path": "/chat/board",
+        "perms": "system:conversation:board",
+        "description": "",
+        "icon": "",
+        "seq": 0,
+        "target": null,
+        "canbdeeleted": null,
+        "resource_type_id": "3",
+        "resource_id": "1eed48e2-d510-42f2-9495-bc299bae237b",
+        "status": "1",
+        "hidden": 0
+      },
+      {
         "id": "9fb9456c-1000-485e-9cbb-905d951b86c1",
-        "created_at": "18/12/2024 19:20:09",
-        "updated_at": "20/12/2024 11:38:54",
+        "created_at": "26/12/2024 18:45:57",
+        "updated_at": "26/12/2024 18:45:57",
         "name": "鐭ヨ瘑搴撶鐞�",
         "url": "Knowledge",
         "path": "/knowledge",
@@ -145,27 +180,9 @@
         "hidden": 0,
         "children": [
           {
-            "id": "2d1c2831-79f4-4817-b79f-be4e49687bd1",
-            "created_at": "19/12/2024 10:08:40",
-            "updated_at": "24/12/2024 19:15:20",
-            "name": "鐭ヨ瘑搴撹鎯�",
-            "url": "KnowledgeDetail",
-            "path": "detail",
-            "perms": "system:knowledge:detail",
-            "description": "",
-            "icon": "",
-            "seq": 0,
-            "target": null,
-            "canbdeeleted": null,
-            "resource_type_id": "3",
-            "resource_id": "9fb9456c-1000-485e-9cbb-905d951b86c1",
-            "status": "1",
-            "hidden": 0
-          },
-          {
             "id": "242060f6-741e-423a-8634-2f7ece1f0c6d",
-            "created_at": "19/12/2024 10:08:40",
-            "updated_at": "24/12/2024 19:15:20",
+            "created_at": "26/12/2024 18:45:57",
+            "updated_at": "26/12/2024 18:45:57",
             "name": "鐭ヨ瘑搴撳垹闄�",
             "url": "-",
             "path": "-",
@@ -182,8 +199,8 @@
           },
           {
             "id": "25722c9e-63fe-4c80-8c05-5fcb9fb58d01",
-            "created_at": "19/12/2024 10:08:40",
-            "updated_at": "24/12/2024 19:15:20",
+            "created_at": "26/12/2024 18:45:57",
+            "updated_at": "26/12/2024 18:45:57",
             "name": "鐭ヨ瘑搴撴柊澧�",
             "url": "-",
             "path": "-",
@@ -197,31 +214,31 @@
             "resource_id": "9fb9456c-1000-485e-9cbb-905d951b86c1",
             "status": "0",
             "hidden": 0
+          },
+          {
+            "id": "91be8704-d6ac-4941-ab9b-02ebfd9c56a3",
+            "created_at": "10/1/2025 17:51:51",
+            "updated_at": "10/1/2025 18:48:05",
+            "name": "鏂囨。涓婁紶",
+            "url": "-",
+            "path": "-",
+            "perms": "system:knowledgeLib:upload",
+            "description": "",
+            "icon": "",
+            "seq": 0,
+            "target": null,
+            "canbdeeleted": null,
+            "resource_type_id": "1",
+            "resource_id": "9fb9456c-1000-485e-9cbb-905d951b86c1",
+            "status": "1",
+            "hidden": 0
           }
         ]
       },
       {
-        "id": "a4931c80-c890-4142-a698-87940c937b57",
-        "created_at": "20/12/2024 11:38:54",
-        "updated_at": "20/12/2024 11:38:54",
-        "name": "浼氳瘽闈㈡澘",
-        "url": "ConversationBoard",
-        "path": "/chat/board",
-        "perms": "system:conversation:board",
-        "description": "",
-        "icon": "",
-        "seq": 0,
-        "target": null,
-        "canbdeeleted": null,
-        "resource_type_id": "3",
-        "resource_id": "1eed48e2-d510-42f2-9495-bc299bae237b",
-        "status": "1",
-        "hidden": 0
-      },
-      {
         "id": "online",
-        "created_at": "25/8/2015 10:34:53",
-        "updated_at": "20/12/2024 11:38:54",
+        "created_at": "26/12/2024 18:45:57",
+        "updated_at": "26/12/2024 18:45:57",
         "name": "妯″瀷绠$悊",
         "url": "Model",
         "path": "/model",
@@ -234,12 +251,12 @@
         "resource_type_id": "0",
         "resource_id": "1eed48e2-d510-42f2-9495-bc299bae237b",
         "status": "1",
-        "hidden": null
+        "hidden": 0
       },
       {
         "id": "xtgl",
-        "created_at": "25/8/2015 10:34:53",
-        "updated_at": "20/12/2024 11:38:54",
+        "created_at": "26/12/2024 18:45:57",
+        "updated_at": "26/12/2024 18:45:57",
         "name": "鏉冮檺绠$悊",
         "url": "layout/LayoutPermission",
         "path": "/permission",
@@ -252,12 +269,12 @@
         "resource_type_id": "0",
         "resource_id": "1eed48e2-d510-42f2-9495-bc299bae237b",
         "status": "1",
-        "hidden": null,
+        "hidden": 0,
         "children": [
           {
             "id": "0642e4a6-3d48-4635-ba2a-bf4e39c351ed",
-            "created_at": "28/10/2024 07:38:41",
-            "updated_at": "18/12/2024 20:05:23",
+            "created_at": "26/12/2024 18:45:57",
+            "updated_at": "26/12/2024 18:45:57",
             "name": "鐢ㄦ埛缁勭鐞�",
             "url": "PermissionGroup",
             "path": "/permission/group",
@@ -270,12 +287,12 @@
             "resource_type_id": "0",
             "resource_id": "xtgl",
             "status": "1",
-            "hidden": null,
+            "hidden": 0,
             "children": [
               {
                 "id": "0bcb1f37-f87e-4f47-ba72-a2e194884b8f",
-                "created_at": "28/10/2024 07:41:16",
-                "updated_at": "18/12/2024 15:09:28",
+                "created_at": "26/12/2024 18:45:57",
+                "updated_at": "26/12/2024 18:45:57",
                 "name": "缂栬緫鐢ㄦ埛缁�",
                 "url": "/base/syuser!update",
                 "path": "",
@@ -288,13 +305,12 @@
                 "resource_type_id": "1",
                 "resource_id": "0642e4a6-3d48-4635-ba2a-bf4e39c351ed",
                 "status": "1",
-                "hidden": null
+                "hidden": 0
               },
-
               {
                 "id": "2648f4bd-b5d5-4a34-8b9c-128fd970b014",
-                "created_at": "18/12/2024 15:09:28",
-                "updated_at": "18/12/2024 15:09:28",
+                "created_at": "26/12/2024 18:45:57",
+                "updated_at": "26/12/2024 18:45:57",
                 "name": "鐢ㄦ埛缁勬垚鍛樼鐞�",
                 "url": "-",
                 "path": "",
@@ -309,11 +325,10 @@
                 "status": "1",
                 "hidden": 0
               },
-
               {
                 "id": "3daf1a03-c0c9-4ebd-935d-fe46561971fb",
-                "created_at": "28/10/2024 07:46:14",
-                "updated_at": "28/10/2024 07:46:41",
+                "created_at": "26/12/2024 18:45:57",
+                "updated_at": "26/12/2024 18:45:57",
                 "name": "鐢ㄦ埛缁勫垪琛�",
                 "url": "/base/syuser!grid",
                 "path": null,
@@ -326,32 +341,12 @@
                 "resource_type_id": "1",
                 "resource_id": "0642e4a6-3d48-4635-ba2a-bf4e39c351ed",
                 "status": "1",
-                "hidden": null
-              },
-
-              {
-                "id": "72fe917f-70ee-4cbf-8c21-f1852f3ef037",
-                "created_at": "18/12/2024 15:09:28",
-                "updated_at": "19/12/2024 16:08:38",
-                "name": "鐢ㄦ埛缁勬潈闄愮鐞�",
-                "url": "-",
-                "path": "",
-                "perms": "system:group:permissionConfig",
-                "description": "",
-                "icon": "",
-                "seq": 0,
-                "target": null,
-                "canbdeeleted": null,
-                "resource_type_id": "1",
-                "resource_id": "0642e4a6-3d48-4635-ba2a-bf4e39c351ed",
-                "status": "1",
                 "hidden": 0
               },
-
               {
                 "id": "5d9ab44e-488c-4dd8-8688-56650393fab1",
-                "created_at": "18/12/2024 11:35:02",
-                "updated_at": "18/12/2024 11:35:02",
+                "created_at": "26/12/2024 18:45:57",
+                "updated_at": "26/12/2024 18:45:57",
                 "name": "鍒犻櫎鐢ㄦ埛缁�",
                 "url": "-",
                 "path": "",
@@ -366,11 +361,28 @@
                 "status": "1",
                 "hidden": 0
               },
-
+              {
+                "id": "72fe917f-70ee-4cbf-8c21-f1852f3ef037",
+                "created_at": "26/12/2024 18:45:57",
+                "updated_at": "10/1/2025 18:48:05",
+                "name": "鐢ㄦ埛缁勬潈闄愮鐞�",
+                "url": "-",
+                "path": "-",
+                "perms": "system:group:permissionConfig",
+                "description": "",
+                "icon": "",
+                "seq": 0,
+                "target": null,
+                "canbdeeleted": null,
+                "resource_type_id": "1",
+                "resource_id": "0642e4a6-3d48-4635-ba2a-bf4e39c351ed",
+                "status": "1",
+                "hidden": 0
+              },
               {
                 "id": "f2b2c9be-1c39-4416-b3c7-21891fc28f84",
-                "created_at": "28/10/2024 07:56:04",
-                "updated_at": "28/10/2024 07:56:04",
+                "created_at": "26/12/2024 18:45:57",
+                "updated_at": "26/12/2024 18:45:57",
                 "name": "娣诲姞鐢ㄦ埛缁�",
                 "url": "/base/sygroup!save",
                 "path": null,
@@ -383,14 +395,14 @@
                 "resource_type_id": "1",
                 "resource_id": "0642e4a6-3d48-4635-ba2a-bf4e39c351ed",
                 "status": "1",
-                "hidden": null
+                "hidden": 0
               }
             ]
           },
           {
             "id": "jggl",
-            "created_at": "25/8/2015 10:34:53",
-            "updated_at": "18/12/2024 20:05:23",
+            "created_at": "26/12/2024 18:45:57",
+            "updated_at": "26/12/2024 18:45:57",
             "name": "鏈烘瀯绠$悊",
             "url": "PermissionOrganization",
             "path": "/permission/org",
@@ -403,12 +415,12 @@
             "resource_type_id": "0",
             "resource_id": "xtgl",
             "status": "1",
-            "hidden": null,
+            "hidden": 0,
             "children": [
               {
                 "id": "jgbj",
-                "created_at": "25/8/2015 10:34:53",
-                "updated_at": "25/5/2022 00:39:56",
+                "created_at": "26/12/2024 18:45:57",
+                "updated_at": "26/12/2024 18:45:57",
                 "name": "缂栬緫鏈烘瀯",
                 "url": "/base/syorganization!update",
                 "path": null,
@@ -421,12 +433,12 @@
                 "resource_type_id": "1",
                 "resource_id": "jggl",
                 "status": "1",
-                "hidden": null
+                "hidden": 0
               },
               {
                 "id": "jglb",
-                "created_at": "25/8/2015 10:34:53",
-                "updated_at": "28/11/2016 14:09:52",
+                "created_at": "26/12/2024 18:45:57",
+                "updated_at": "26/12/2024 18:45:57",
                 "name": "鏈烘瀯鍒楄〃",
                 "url": "/base/syorganization!treeGrid",
                 "path": null,
@@ -439,12 +451,12 @@
                 "resource_type_id": "1",
                 "resource_id": "jggl",
                 "status": "1",
-                "hidden": null
+                "hidden": 0
               },
               {
                 "id": "jgsc",
-                "created_at": "25/8/2015 10:34:53",
-                "updated_at": "18/12/2024 11:35:02",
+                "created_at": "26/12/2024 18:45:57",
+                "updated_at": "26/12/2024 18:45:57",
                 "name": "鍒犻櫎鏈烘瀯",
                 "url": "/base/syorganization!delete",
                 "path": "",
@@ -457,12 +469,12 @@
                 "resource_type_id": "1",
                 "resource_id": "jggl",
                 "status": "1",
-                "hidden": null
+                "hidden": 0
               },
               {
                 "id": "jgtj",
-                "created_at": "25/8/2015 10:34:53",
-                "updated_at": "25/8/2015 10:34:53",
+                "created_at": "26/12/2024 18:45:57",
+                "updated_at": "26/12/2024 18:45:57",
                 "name": "娣诲姞鏈烘瀯",
                 "url": "/base/syorganization!save",
                 "path": null,
@@ -475,14 +487,14 @@
                 "resource_type_id": "1",
                 "resource_id": "jggl",
                 "status": "1",
-                "hidden": null
+                "hidden": 0
               }
             ]
           },
           {
             "id": "jsgl",
-            "created_at": "25/8/2015 10:34:53",
-            "updated_at": "18/12/2024 20:05:23",
+            "created_at": "26/12/2024 18:45:57",
+            "updated_at": "26/12/2024 18:45:57",
             "name": "瑙掕壊绠$悊",
             "url": "PermissionRole",
             "path": "/permission/role",
@@ -495,12 +507,12 @@
             "resource_type_id": "0",
             "resource_id": "xtgl",
             "status": "1",
-            "hidden": null,
+            "hidden": 0,
             "children": [
               {
                 "id": "00b61433-a5cd-46e9-a867-2e249dd310f4",
-                "created_at": "18/12/2024 11:35:02",
-                "updated_at": "18/12/2024 11:35:02",
+                "created_at": "26/12/2024 18:45:57",
+                "updated_at": "26/12/2024 18:45:57",
                 "name": "瑙掕壊鏉冮檺閰嶇疆",
                 "url": "-",
                 "path": "",
@@ -517,8 +529,8 @@
               },
               {
                 "id": "f9947112-c8e4-42cd-ba3a-2612eb373564",
-                "created_at": "18/12/2024 11:35:02",
-                "updated_at": "18/12/2024 11:35:02",
+                "created_at": "26/12/2024 18:45:57",
+                "updated_at": "26/12/2024 18:45:57",
                 "name": "瑙掕壊閮ㄩ棬閰嶇疆",
                 "url": "-",
                 "path": "",
@@ -535,8 +547,8 @@
               },
               {
                 "id": "jsbj",
-                "created_at": "25/8/2015 10:34:53",
-                "updated_at": "25/8/2015 10:34:53",
+                "created_at": "26/12/2024 18:45:57",
+                "updated_at": "26/12/2024 18:45:57",
                 "name": "缂栬緫瑙掕壊",
                 "url": "/base/syrole!update",
                 "path": null,
@@ -549,12 +561,12 @@
                 "resource_type_id": "1",
                 "resource_id": "jsgl",
                 "status": "1",
-                "hidden": null
+                "hidden": 0
               },
               {
                 "id": "jslb",
-                "created_at": "25/8/2015 10:34:53",
-                "updated_at": "25/8/2015 10:34:53",
+                "created_at": "26/12/2024 18:45:57",
+                "updated_at": "26/12/2024 18:45:57",
                 "name": "瑙掕壊鍒楄〃",
                 "url": "/base/syrole!grid",
                 "path": null,
@@ -567,12 +579,12 @@
                 "resource_type_id": "1",
                 "resource_id": "jsgl",
                 "status": "1",
-                "hidden": null
+                "hidden": 0
               },
               {
                 "id": "jssc",
-                "created_at": "25/8/2015 10:34:53",
-                "updated_at": "18/12/2024 11:35:02",
+                "created_at": "26/12/2024 18:45:57",
+                "updated_at": "26/12/2024 18:45:57",
                 "name": "鍒犻櫎瑙掕壊",
                 "url": "/base/syrole!delete",
                 "path": "",
@@ -585,12 +597,12 @@
                 "resource_type_id": "1",
                 "resource_id": "jsgl",
                 "status": "1",
-                "hidden": null
+                "hidden": 0
               },
               {
                 "id": "jstj",
-                "created_at": "25/8/2015 10:34:53",
-                "updated_at": "25/8/2015 10:34:53",
+                "created_at": "26/12/2024 18:45:57",
+                "updated_at": "26/12/2024 18:45:57",
                 "name": "娣诲姞瑙掕壊",
                 "url": "/base/syrole!save",
                 "path": null,
@@ -603,15 +615,14 @@
                 "resource_type_id": "1",
                 "resource_id": "jsgl",
                 "status": "1",
-                "hidden": null
+                "hidden": 0
               }
             ]
           },
-
           {
             "id": "yhgl",
-            "created_at": "25/8/2015 10:34:53",
-            "updated_at": "18/12/2024 20:05:23",
+            "created_at": "26/12/2024 18:45:57",
+            "updated_at": "26/12/2024 18:45:57",
             "name": "鐢ㄦ埛绠$悊",
             "url": "PermissionAccount",
             "path": "/permission/account",
@@ -624,12 +635,12 @@
             "resource_type_id": "0",
             "resource_id": "xtgl",
             "status": "1",
-            "hidden": null,
+            "hidden": 0,
             "children": [
               {
                 "id": "07417a54-4afc-45ec-84ee-c59baf7d45b4",
-                "created_at": "18/12/2024 11:35:02",
-                "updated_at": "18/12/2024 11:35:02",
+                "created_at": "26/12/2024 18:45:57",
+                "updated_at": "26/12/2024 18:45:57",
                 "name": "鐢ㄦ埛瑙掕壊",
                 "url": "-",
                 "path": "",
@@ -644,11 +655,10 @@
                 "status": "1",
                 "hidden": 0
               },
-
               {
                 "id": "a06316f1-b7e4-48b8-80c8-49b1dbb79c4a",
-                "created_at": "18/12/2024 11:35:02",
-                "updated_at": "18/12/2024 11:35:02",
+                "created_at": "26/12/2024 18:45:57",
+                "updated_at": "26/12/2024 18:45:57",
                 "name": "閲嶅埗瀵嗙爜",
                 "url": "-",
                 "path": "",
@@ -663,11 +673,10 @@
                 "status": "0",
                 "hidden": 0
               },
-
               {
                 "id": "e368cae2-96b6-46e5-b537-946a8dc5ede6",
-                "created_at": "18/12/2024 11:35:02",
-                "updated_at": "18/12/2024 11:35:02",
+                "created_at": "26/12/2024 18:45:57",
+                "updated_at": "26/12/2024 18:45:57",
                 "name": "閮ㄩ棬閰嶇疆",
                 "url": "-",
                 "path": "",
@@ -682,11 +691,10 @@
                 "status": "1",
                 "hidden": 0
               },
-
               {
                 "id": "yhbj",
-                "created_at": "25/8/2015 10:34:53",
-                "updated_at": "25/8/2015 10:34:53",
+                "created_at": "26/12/2024 18:45:57",
+                "updated_at": "26/12/2024 18:45:57",
                 "name": "缂栬緫鐢ㄦ埛",
                 "url": "/base/syuser!update",
                 "path": null,
@@ -699,13 +707,12 @@
                 "resource_type_id": "1",
                 "resource_id": "yhgl",
                 "status": "1",
-                "hidden": null
+                "hidden": 0
               },
-
               {
                 "id": "yhlb",
-                "created_at": "25/8/2015 10:34:53",
-                "updated_at": "25/8/2015 10:34:53",
+                "created_at": "26/12/2024 18:45:57",
+                "updated_at": "26/12/2024 18:45:57",
                 "name": "鐢ㄦ埛鍒楄〃",
                 "url": "/base/syuser!grid",
                 "path": null,
@@ -718,13 +725,12 @@
                 "resource_type_id": "1",
                 "resource_id": "yhgl",
                 "status": "1",
-                "hidden": null
+                "hidden": 0
               },
-
               {
                 "id": "yhsc",
-                "created_at": "25/8/2015 10:34:53",
-                "updated_at": "18/12/2024 11:35:02",
+                "created_at": "26/12/2024 18:45:57",
+                "updated_at": "26/12/2024 18:45:57",
                 "name": "鍒犻櫎鐢ㄦ埛",
                 "url": "/base/syuser!delete",
                 "path": "",
@@ -737,13 +743,12 @@
                 "resource_type_id": "1",
                 "resource_id": "yhgl",
                 "status": "1",
-                "hidden": null
+                "hidden": 0
               },
-
               {
                 "id": "yhtj",
-                "created_at": "25/8/2015 10:34:53",
-                "updated_at": "25/8/2015 10:34:53",
+                "created_at": "26/12/2024 18:45:57",
+                "updated_at": "26/12/2024 18:45:57",
                 "name": "娣诲姞鐢ㄦ埛",
                 "url": "/base/syuser!save",
                 "path": null,
@@ -756,14 +761,14 @@
                 "resource_type_id": "1",
                 "resource_id": "yhgl",
                 "status": "1",
-                "hidden": null
+                "hidden": 0
               }
             ]
           },
           {
             "id": "zygl",
-            "created_at": "25/8/2015 10:34:53",
-            "updated_at": "18/12/2024 20:05:23",
+            "created_at": "26/12/2024 18:45:57",
+            "updated_at": "26/12/2024 18:45:57",
             "name": "璧勬簮绠$悊",
             "url": "PermissionResource",
             "path": "/permission/resource",
@@ -776,12 +781,12 @@
             "resource_type_id": "0",
             "resource_id": "xtgl",
             "status": "1",
-            "hidden": null,
+            "hidden": 0,
             "children": [
               {
                 "id": "zybj",
-                "created_at": "25/8/2015 10:34:53",
-                "updated_at": "5/9/2024 03:14:57",
+                "created_at": "26/12/2024 18:45:57",
+                "updated_at": "26/12/2024 18:45:57",
                 "name": "缂栬緫璧勬簮",
                 "url": "/base/syresource!update",
                 "path": null,
@@ -794,13 +799,12 @@
                 "resource_type_id": "1",
                 "resource_id": "zygl",
                 "status": "1",
-                "hidden": null
+                "hidden": 0
               },
-
               {
                 "id": "zylb",
-                "created_at": "25/8/2015 10:34:53",
-                "updated_at": "18/12/2024 11:35:02",
+                "created_at": "26/12/2024 18:45:57",
+                "updated_at": "26/12/2024 18:45:57",
                 "name": "璧勬簮鍒楄〃",
                 "url": "/base/syresource!treeGrid",
                 "path": "",
@@ -813,13 +817,12 @@
                 "resource_type_id": "1",
                 "resource_id": "zygl",
                 "status": "1",
-                "hidden": null
+                "hidden": 0
               },
-
               {
                 "id": "zysc",
-                "created_at": "25/8/2015 10:34:53",
-                "updated_at": "18/12/2024 11:35:02",
+                "created_at": "26/12/2024 18:45:57",
+                "updated_at": "26/12/2024 18:45:57",
                 "name": "鍒犻櫎璧勬簮",
                 "url": "/base/syresource!delete",
                 "path": "",
@@ -832,13 +835,12 @@
                 "resource_type_id": "1",
                 "resource_id": "zygl",
                 "status": "1",
-                "hidden": null
+                "hidden": 0
               },
-
               {
                 "id": "zytj",
-                "created_at": "25/8/2015 10:34:53",
-                "updated_at": "25/8/2015 10:34:53",
+                "created_at": "26/12/2024 18:45:57",
+                "updated_at": "26/12/2024 18:45:57",
                 "name": "娣诲姞璧勬簮",
                 "url": "/base/syresource!save",
                 "path": null,
@@ -851,7 +853,7 @@
                 "resource_type_id": "1",
                 "resource_id": "zygl",
                 "status": "1",
-                "hidden": null
+                "hidden": 0
               }
             ]
           }
@@ -859,4 +861,4 @@
       }
     ]
   }
-]
+]
\ No newline at end of file
diff --git a/app/init_config/init_run_data.py b/app/init_config/init_run_data.py
index 8bcff03..02283f4 100644
--- a/app/init_config/init_run_data.py
+++ b/app/init_config/init_run_data.py
@@ -1,17 +1,22 @@
 from app.models.base_model import SessionLocal
 from app.service.v2.initialize_data import dialog_menu_sync, default_group_sync, default_role_sync, app_register_sync, \
-    basic_agent_sync, admin_account_sync
-from app.task.fetch_agent import sync_resources_from_json
+    basic_agent_sync, admin_account_sync, admin_user_sync
 
 
 async def sync_default_data():
     db = SessionLocal()
-    await dialog_menu_sync(db)  # 灏忔暟
-    await default_group_sync(db) # 榛樿缁�
-    await default_role_sync(db) # 榛樿瑙掕壊
-    await app_register_sync(db) # 娉ㄥ唽鐨勫簲鐢�
-    await basic_agent_sync(db) # 寮�鍙戠殑agent
-    await admin_account_sync(db) # 瓒呯璐﹀彿
+    try:
+        await dialog_menu_sync(db)  # 灏忔暟
+        await default_group_sync(db)  # 榛樿缁�
+        await default_role_sync(db)  # 榛樿瑙掕壊
+        await app_register_sync(db)  # 娉ㄥ唽鐨勫簲鐢�
+        await basic_agent_sync(db)  # 寮�鍙戠殑agent
+        await admin_account_sync(db)  #
+        await admin_user_sync(db)  #
+    except Exception as e:
+        print(e)
+    finally:
+        db.close()
     # await default_role_sync(db)  # 椤甸潰璧勬簮閰嶇疆淇℃伅
     # await default_role_sync(db)  # 榛樿鐨勮鑹茶祫婧�
 
diff --git a/app/models/session_model.py b/app/models/session_model.py
index d91a2b1..5765a44 100644
--- a/app/models/session_model.py
+++ b/app/models/session_model.py
@@ -33,6 +33,7 @@
             'name': self.name,
             'agent_type': self.agent_type,
             'agent_id': self.agent_id,
+            'workflow': self.workflow if self.workflow else 0,
             'create_date': self.create_date.strftime("%Y-%m-%d %H:%M:%S"),
             'update_date': self.update_date.strftime("%Y-%m-%d %H:%M:%S"),
         }
diff --git a/app/service/difyService.py b/app/service/difyService.py
index 3c67d09..21117e8 100644
--- a/app/service/difyService.py
+++ b/app/service/difyService.py
@@ -72,9 +72,9 @@
             # print(response.text)
             return self._handle_response(response)
 
-    async def login(self, username: str, password: str, remember_me=True, invite_token:str="") -> str:
+    async def login(self, username: str, password: str, remember_me=True, invite_token:str="", email="") -> str:
         # password = RagflowCrypto(settings.PUBLIC_KEY, settings.PRIVATE_KEY).encrypt(password)
-        data = {"email": f"{username}@basic.com", "password": password, "remember_me": remember_me, "invite_token": invite_token,
+        data = {"email":email if email else f"{username}@basic.com", "password": password, "remember_me": remember_me, "invite_token": invite_token,
          "language": "zh-Hans"}
 
         async with httpx.AsyncClient() as client:
diff --git a/app/service/ragflow.py b/app/service/ragflow.py
index f10902f..08cc26f 100644
--- a/app/service/ragflow.py
+++ b/app/service/ragflow.py
@@ -48,13 +48,13 @@
                 raise Exception(f"Ragflow registration failed: {response.text}")
             return self._handle_response(response)
 
-    async def login(self, username: str, password: str) -> str:
+    async def login(self, username: str, password: str, email="") -> str:
         password = RagflowCrypto(settings.PUBLIC_KEY, settings.PRIVATE_KEY).encrypt(password)
         async with httpx.AsyncClient() as client:
             response = await client.post(
                 f"{self.base_url}/v1/user/login",
                 headers={'Content-Type': 'application/json'},
-                json={"email": f"{username}@example.com", "password": password}
+                json={"email": email if email else f"{username}@example.com", "password": password}
             )
             if response.status_code != 200:
                 raise Exception(f"Ragflow login failed: {response.text}")
diff --git a/app/service/session.py b/app/service/session.py
index 37a7fe7..034eb50 100644
--- a/app/service/session.py
+++ b/app/service/session.py
@@ -12,8 +12,10 @@
     def __init__(self, db: Session):
         self.db = db
 
-    def create_session(self, session_id: str, name: str, agent_id: str, agent_type: AgentType, user_id: int,
-                       message: dict = None, workflow_type: int = 0) -> Type[SessionModel] | SessionModel:
+
+    def create_session(self, session_id: str, name: str, agent_id: str, agent_type: AgentType, user_id: int, message: dict = None, workflow_type: int = 0) -> Type[
+                                                                                                                    SessionModel] | SessionModel:
+
         """
         鍒涘缓涓�涓柊鐨勪細璇濊褰曘��
 
@@ -30,6 +32,7 @@
             message = {"role": "user", "content": name}
         existing_session = self.get_session_by_id(session_id)
         if existing_session:
+            # existing_session.add_message({"role": "user", "content": name})
             existing_session.add_message(message)
             existing_session.update_date = current_time()
             self.db.commit()
@@ -43,7 +46,7 @@
             agent_type=agent_type,
             tenant_id=user_id,
             workflow=workflow_type,
-            message=json.dumps([message])
+            message = json.dumps([message])
         )
         self.db.add(new_session)
         self.db.commit()
diff --git a/app/service/v2/initialize_data.py b/app/service/v2/initialize_data.py
index c3e295f..e315b4a 100644
--- a/app/service/v2/initialize_data.py
+++ b/app/service/v2/initialize_data.py
@@ -3,9 +3,12 @@
 import os
 
 import yaml
+from passlib.context import CryptContext
+
 
 from Log import logger
-from app.config.const import DIFY, ENV_CONF_PATH
+# from app.api import pwd_context
+from app.config.const import DIFY, ENV_CONF_PATH, RAGFLOW
 from app.models import MenuCapacityModel, WebMenuModel, GroupModel, RoleModel, DialogModel, UserModel, UserAppModel, \
     cipher_suite, UserTokenModel
 from app.service.auth import UserAppDao
@@ -16,6 +19,8 @@
 from app.service.v2.app_register import AppRegisterDao
 from app.config.config import settings
 from app.utils.password_handle import generate_password
+
+pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
 
 
 async def dialog_menu_sync(db):
@@ -252,4 +257,36 @@
         db.commit()
     except Exception as e:
         print(e)
+        db.rollback()
+async def admin_user_sync(db):
+    try:
+        config = {}
+        with open(os.path.join(ENV_CONF_PATH, "admin.yaml"), 'r', encoding='utf-8') as file:
+            # 鍔犺浇JSON鏁版嵁
+            config = yaml.safe_load(file)
+        # print(config)
+        db_user = db.query(UserModel).filter(UserModel.username == config["smart_server"]["account"]).first()
+        if db_user:
+            print("admin_user_sync: 鐢ㄦ埛宸茬粡瀛樺湪锛�")
+            return
+        register_dict = {}
+
+        for app in [RAGFLOW, DIFY]:
+            register_dict[app] = {"id": config[app].get("id", "123"), "name": config[app]["account"],
+                                        "pwd":config[app]["password"],
+                                        "email": config[app]["account"]}
+
+        # 瀛樺偍鐢ㄦ埛淇℃伅
+        hashed_password = pwd_context.hash(config["smart_server"]["password"])
+        user_model = UserModel(username=config["smart_server"]["account"], hashed_password=hashed_password, email="",
+                               phone="", login_name="", sync_flag="", creator=0, permission="admin")
+        db.add(user_model)
+        db.commit()
+        db.refresh(user_model)
+        u_id = user_model.id
+        user_app_dao = UserAppDao(db)
+        for k, v in register_dict.items():
+            await user_app_dao.update_and_insert_data(v.get("name"), user_model.encrypted_password(v.get("pwd")), v.get("email"), u_id, str(v.get("id")), k)
+    except Exception as e:
+        print(e)
         db.rollback()
\ No newline at end of file

--
Gitblit v1.8.0