Răsfoiți Sursa

56完善用户信息查看

Lan 1 săptămână în urmă
părinte
comite
b0b54142dd
61 a modificat fișierele cu 191 adăugiri și 5 ștergeri
  1. BIN
      backend/api/__pycache__/__init__.cpython-310.pyc
  2. BIN
      backend/api/__pycache__/admin.cpython-310.pyc
  3. BIN
      backend/api/__pycache__/api_alert.cpython-310.pyc
  4. BIN
      backend/api/__pycache__/api_calculate.cpython-310.pyc
  5. BIN
      backend/api/__pycache__/api_graph.cpython-310.pyc
  6. BIN
      backend/api/__pycache__/api_graphicFile.cpython-310.pyc
  7. BIN
      backend/api/__pycache__/api_prepare.cpython-310.pyc
  8. BIN
      backend/api/__pycache__/api_rawDataTrans.cpython-310.pyc
  9. BIN
      backend/api/__pycache__/api_results.cpython-310.pyc
  10. BIN
      backend/api/__pycache__/api_system.cpython-310.pyc
  11. BIN
      backend/api/__pycache__/api_taskFile.cpython-310.pyc
  12. BIN
      backend/api/__pycache__/api_user.cpython-310.pyc
  13. BIN
      backend/api/__pycache__/apps.cpython-310.pyc
  14. BIN
      backend/api/__pycache__/scheduler.cpython-310.pyc
  15. BIN
      backend/api/__pycache__/serializers.cpython-310.pyc
  16. BIN
      backend/api/__pycache__/tokenAuthentication.cpython-310.pyc
  17. BIN
      backend/api/__pycache__/urls.cpython-310.pyc
  18. BIN
      backend/api/__pycache__/utils.cpython-310.pyc
  19. 62 0
      backend/api/api_graphicFile.py
  20. 40 0
      backend/api/api_taskFile.py
  21. 57 1
      backend/api/api_user.py
  22. BIN
      backend/api/migrations/__pycache__/0001_initial.cpython-310.pyc
  23. BIN
      backend/api/migrations/__pycache__/0002_alter_user_options_user_last_login.cpython-310.pyc
  24. BIN
      backend/api/migrations/__pycache__/0003_view_file.cpython-310.pyc
  25. BIN
      backend/api/migrations/__pycache__/0004_rename_display_name_user_displayname_file_usage.cpython-310.pyc
  26. BIN
      backend/api/migrations/__pycache__/0005_file_associate_file_content.cpython-310.pyc
  27. BIN
      backend/api/migrations/__pycache__/0006_alter_file_associate.cpython-310.pyc
  28. BIN
      backend/api/migrations/__pycache__/0007_fileinfo.cpython-310.pyc
  29. BIN
      backend/api/migrations/__pycache__/0008_mission_result.cpython-310.pyc
  30. BIN
      backend/api/migrations/__pycache__/0009_alter_fileinfo_file_alter_mission_name.cpython-310.pyc
  31. BIN
      backend/api/migrations/__pycache__/0010_algorithm_plan.cpython-310.pyc
  32. BIN
      backend/api/migrations/__pycache__/0011_result_plan_result_state.cpython-310.pyc
  33. BIN
      backend/api/migrations/__pycache__/0012_result_edgefile_result_nodefile_alter_result_plan.cpython-310.pyc
  34. BIN
      backend/api/migrations/__pycache__/0013_remove_result_state_alter_file_usage.cpython-310.pyc
  35. BIN
      backend/api/migrations/__pycache__/0014_result_progress.cpython-310.pyc
  36. BIN
      backend/api/migrations/__pycache__/0015_mission_state.cpython-310.pyc
  37. BIN
      backend/api/migrations/__pycache__/0016_alter_result_edgefile_alter_result_nodefile.cpython-310.pyc
  38. BIN
      backend/api/migrations/__pycache__/0017_graph_graphtoken.cpython-310.pyc
  39. BIN
      backend/api/migrations/__pycache__/0018_rename_edgemap_graph_edges_and_more.cpython-310.pyc
  40. BIN
      backend/api/migrations/__pycache__/0019_alter_graph_user.cpython-310.pyc
  41. BIN
      backend/api/migrations/__pycache__/0020_alert_systemperformance.cpython-310.pyc
  42. BIN
      backend/api/migrations/__pycache__/0021_rename_indicator_alert_metric.cpython-310.pyc
  43. BIN
      backend/api/migrations/__pycache__/__init__.cpython-310.pyc
  44. BIN
      backend/api/models/__pycache__/__init__.cpython-310.pyc
  45. BIN
      backend/api/models/__pycache__/alert.cpython-310.pyc
  46. BIN
      backend/api/models/__pycache__/algorithm.cpython-310.pyc
  47. BIN
      backend/api/models/__pycache__/file.cpython-310.pyc
  48. BIN
      backend/api/models/__pycache__/graph.cpython-310.pyc
  49. BIN
      backend/api/models/__pycache__/mission.cpython-310.pyc
  50. BIN
      backend/api/models/__pycache__/plan.cpython-310.pyc
  51. BIN
      backend/api/models/__pycache__/result.cpython-310.pyc
  52. BIN
      backend/api/models/__pycache__/system.cpython-310.pyc
  53. BIN
      backend/api/models/__pycache__/user.cpython-310.pyc
  54. BIN
      backend/api/models/__pycache__/view.cpython-310.pyc
  55. 21 3
      backend/api/models/file.py
  56. 11 1
      backend/api/urls.py
  57. BIN
      backend/backend/__pycache__/__init__.cpython-310.pyc
  58. BIN
      backend/backend/__pycache__/settings.cpython-310.pyc
  59. BIN
      backend/backend/__pycache__/urls.cpython-310.pyc
  60. BIN
      backend/backend/__pycache__/wsgi.cpython-310.pyc
  61. BIN
      backend/db.sqlite3

BIN
backend/api/__pycache__/__init__.cpython-310.pyc


BIN
backend/api/__pycache__/admin.cpython-310.pyc


BIN
backend/api/__pycache__/api_alert.cpython-310.pyc


BIN
backend/api/__pycache__/api_calculate.cpython-310.pyc


BIN
backend/api/__pycache__/api_graph.cpython-310.pyc


BIN
backend/api/__pycache__/api_graphicFile.cpython-310.pyc


BIN
backend/api/__pycache__/api_prepare.cpython-310.pyc


BIN
backend/api/__pycache__/api_rawDataTrans.cpython-310.pyc


BIN
backend/api/__pycache__/api_results.cpython-310.pyc


BIN
backend/api/__pycache__/api_system.cpython-310.pyc


BIN
backend/api/__pycache__/api_taskFile.cpython-310.pyc


BIN
backend/api/__pycache__/api_user.cpython-310.pyc


BIN
backend/api/__pycache__/apps.cpython-310.pyc


BIN
backend/api/__pycache__/scheduler.cpython-310.pyc


BIN
backend/api/__pycache__/serializers.cpython-310.pyc


BIN
backend/api/__pycache__/tokenAuthentication.cpython-310.pyc


BIN
backend/api/__pycache__/urls.cpython-310.pyc


BIN
backend/api/__pycache__/utils.cpython-310.pyc


+ 62 - 0
backend/api/api_graphicFile.py

@@ -0,0 +1,62 @@
+from django.http import HttpResponse
+
+from rest_framework.views import APIView
+
+from api.models import Graph , User
+from api.utils import *
+
+class GraphicSelectAPI(APIView):
+    def get(self , request):
+        user = request.user
+        print(user)
+        graphics = []
+        if(user.identity == 'admin'):
+            graphiclist = Graph.objects.all()
+            print(graphiclist)
+            for graph in graphiclist:
+                graphics.append({
+                    "id": graph.id,
+                    "nodes": graph.nodes,
+                    "type": graph.type,
+                    "edges": graph.edges,
+                    "createTime": graph.create_time,
+                    "updateTime": graph.update_time,
+                    "resultId": graph.result_id,
+                    "userId": graph.user_id 
+                })
+        else:
+            graphiclist = Graph.objects.filter(user_id = user.id)
+            for graph in graphiclist:
+                graphics.append({
+                    "id": graph.id,
+                    "nodes": graph.nodes,
+                    "type": graph.type,
+                    "edges": graph.edges,
+                    "createTime": graph.create_time,
+                    "updateTime": graph.update_time,
+                    "resultId": graph.result_id,
+                    "userId": graph.user_id 
+                })
+        return success(message = "图形数据查询成功" , 
+                        data = graphics , code = 200)
+    
+
+class GraphicDownloadAPI(APIView):
+    def post(self, request):
+        try:
+            print(request.data)
+            graph = Graph.objects.get(id = request.data.get("id"))
+            print(graph)
+        except Graph.DoesNotExist:
+            return failed(message = "文件不存在", status=404)
+
+        # 创建CSV响应
+        response = HttpResponse(content_type='text/csv')
+        response['Content-Disposition'] = f'attachment; filename="{graph.name}.csv"'
+        
+        # 写入CSV内容,假设file.content是CSV格式的字符串
+        response.write(graph.nodes)
+        
+        return success(message = "图形数据下载成功" , 
+                        data = response , code = 200)
+

+ 40 - 0
backend/api/api_taskFile.py

@@ -0,0 +1,40 @@
+from rest_framework.views import APIView
+from api.models import Mission , User
+from api.utils import *
+
+class TaskSelectAPI(APIView):
+        authentication_classes = []
+        permission_classes = []
+
+        def post(self , request):
+            print(request.data.get('username'))
+            user = User.objects.get(username = request.data.get('username'))
+            tasks = []
+            if(user.identity == 'admin'):
+                tasklist = Mission.objects.all()
+                for file in tasklist:
+                    tasks.append({
+                        "id": file.id,
+                        "name": file.name,
+                        "nodeFileId": file.nodeFile_id,
+                        "createTime": file.create_time,
+                        "updateTime": file.update_time,
+                        "state": file.state,
+                        "userId": file.user_id,
+                        "edgeFileId": file.edgeFile_id 
+                    })
+            else:
+                tasklist = Mission.objects.filter(user_id = user.id) 
+                for file in tasklist:
+                    tasks.append({
+                        "id": file.id,
+                        "name": file.name,
+                        "nodeFileId": file.nodeFile_id,
+                        "createTime": file.create_time,
+                        "updateTime": file.update_time,
+                        "userId": file.user_id,
+                        "edgeFileId": file.edgeFile_id 
+                    })
+            return success(message = "任务数据查询成功" , 
+                           data = tasks , code = 200)
+    

+ 57 - 1
backend/api/api_user.py

@@ -6,6 +6,8 @@ from .serializers import UserRegisterSerializer
 
 from django.middleware.csrf import get_token
 from django.contrib.auth import login
+from api.models import User
+from django.contrib.auth.hashers import make_password , check_password
 
 from api.utils import *
 
@@ -81,4 +83,58 @@ class getDashboard(APIView):
         return Response({
             'data': 'yes'
         })
-        
+
+
+#查询用户信息
+class UserSelectAPI(APIView):
+    def get(self, request):
+        user = request.user
+        return success(message="查询用户信息成功", data = {
+                'username': user.username,
+                'displayname': user.displayname,
+                'createtime': user.create_time,
+                'identity': user.identity,
+                'lastlogin': user.last_login
+            }, code=200)
+    
+#修改用户信息
+class UserUpdateAPI(APIView):
+    def post(self, request):
+        try:
+            user = request.user
+            user.username = request.data.get('username')
+            user.displayname = request.data.get('displayname')
+            user.identity = request.data.get('identity')
+            user.save()
+            return success(message="修改用户信息成功", data = {
+                'username': user.username,
+                'displayname': user.displayname,
+                'createtime': user.create_time,
+                'identity': user.identity,
+                'lastlogin': user.last_login
+            }, code=200)
+        except Exception as e:
+            return failed(message="修改用户信息失败", code=400)
+    
+#修改用户密码
+class PassUpdateAPI(APIView):
+    def post(self, request):
+        try:
+            user = request.user
+            password = make_password(
+                request.data.get("oldPassword"),
+                salt='vrviewer',
+                hasher='pbkdf2_sha256'
+            )
+            if(check_password(request.data.get("oldPassword") , user.password)):
+                user.password = make_password(
+                request.data.get("newPassword"),
+                salt='vrviewer',
+                hasher='pbkdf2_sha256'
+                )
+                user.save()
+                return success(message="用户密码修改成功", code=200)
+            else:
+                return failed(message="用户密码修改失败,原密码错误", code=400)
+        except Exception as e:
+            return failed(message="用户密码修改失败", code=400)

BIN
backend/api/migrations/__pycache__/0001_initial.cpython-310.pyc


BIN
backend/api/migrations/__pycache__/0002_alter_user_options_user_last_login.cpython-310.pyc


BIN
backend/api/migrations/__pycache__/0003_view_file.cpython-310.pyc


BIN
backend/api/migrations/__pycache__/0004_rename_display_name_user_displayname_file_usage.cpython-310.pyc


BIN
backend/api/migrations/__pycache__/0005_file_associate_file_content.cpython-310.pyc


BIN
backend/api/migrations/__pycache__/0006_alter_file_associate.cpython-310.pyc


BIN
backend/api/migrations/__pycache__/0007_fileinfo.cpython-310.pyc


BIN
backend/api/migrations/__pycache__/0008_mission_result.cpython-310.pyc


BIN
backend/api/migrations/__pycache__/0009_alter_fileinfo_file_alter_mission_name.cpython-310.pyc


BIN
backend/api/migrations/__pycache__/0010_algorithm_plan.cpython-310.pyc


BIN
backend/api/migrations/__pycache__/0011_result_plan_result_state.cpython-310.pyc


BIN
backend/api/migrations/__pycache__/0012_result_edgefile_result_nodefile_alter_result_plan.cpython-310.pyc


BIN
backend/api/migrations/__pycache__/0013_remove_result_state_alter_file_usage.cpython-310.pyc


BIN
backend/api/migrations/__pycache__/0014_result_progress.cpython-310.pyc


BIN
backend/api/migrations/__pycache__/0015_mission_state.cpython-310.pyc


BIN
backend/api/migrations/__pycache__/0016_alter_result_edgefile_alter_result_nodefile.cpython-310.pyc


BIN
backend/api/migrations/__pycache__/0017_graph_graphtoken.cpython-310.pyc


BIN
backend/api/migrations/__pycache__/0018_rename_edgemap_graph_edges_and_more.cpython-310.pyc


BIN
backend/api/migrations/__pycache__/0019_alter_graph_user.cpython-310.pyc


BIN
backend/api/migrations/__pycache__/0020_alert_systemperformance.cpython-310.pyc


BIN
backend/api/migrations/__pycache__/0021_rename_indicator_alert_metric.cpython-310.pyc


BIN
backend/api/migrations/__pycache__/__init__.cpython-310.pyc


BIN
backend/api/models/__pycache__/__init__.cpython-310.pyc


BIN
backend/api/models/__pycache__/alert.cpython-310.pyc


BIN
backend/api/models/__pycache__/algorithm.cpython-310.pyc


BIN
backend/api/models/__pycache__/file.cpython-310.pyc


BIN
backend/api/models/__pycache__/graph.cpython-310.pyc


BIN
backend/api/models/__pycache__/mission.cpython-310.pyc


BIN
backend/api/models/__pycache__/plan.cpython-310.pyc


BIN
backend/api/models/__pycache__/result.cpython-310.pyc


BIN
backend/api/models/__pycache__/system.cpython-310.pyc


BIN
backend/api/models/__pycache__/user.cpython-310.pyc


BIN
backend/api/models/__pycache__/view.cpython-310.pyc


+ 21 - 3
backend/api/models/file.py

@@ -4,6 +4,7 @@ import csv
 from api.utils import *
 import json
 from random import randint
+import logging
 
 types = [
     ('csv', 'csv'),
@@ -21,8 +22,7 @@ contents = [
     ('edge', 'edge'),
 ]
 
-
-
+logger = logging.getLogger("file-model")
 
 class FileManager(models.Manager):
     def getHistory(self, user):
@@ -36,7 +36,7 @@ class FileManager(models.Manager):
             try:
                 size = os.path.getsize(path)
             except FileNotFoundError:
-                print("未找到对应文件,现将记录删除1", fileId, file.name)
+                print("未找到对应文件,现将记录删除", fileId, file.name)
                 self.get(id=fileId).delete()
                 continue
             except Exception as error:
@@ -49,12 +49,30 @@ class FileManager(models.Manager):
             else:
                 size = size / 1024
                 size = f"{size:.2f} KB"
+            if file.content == 'node':
+                missions = file.own_missions_node.all()
+                fileInfo = {
+                    '节点总数': file.own_file_info.nodes,
+                    'S节点数': file.own_file_info.sNodes,
+                    'D节点数': file.own_file_info.dNodes,
+                    'I节点数': file.own_file_info.iNodes,
+                }
+            elif file.content == 'edge':
+                missions = file.own_missions_edge.all()
+                fileInfo = {
+                    '边总数': file.own_file_info.edges,
+                }
+            else:
+                logger.error(f"获取历史文件出错,文件格式错误 content: {file.content}")
+                return FAILED
             history.append({
                 'id': file.id,
                 'name': file.name,
                 'uploadTime': file.update_time,
                 'size': size,
                 'content': file.content,
+                'missions': [{'id': mission.id, 'name': mission.name} for mission in missions],
+                'fileInfo': fileInfo,
             })
         return history
         # except Exception as error:

+ 11 - 1
backend/api/urls.py

@@ -1,5 +1,5 @@
 from django.urls import path
-from .api_user import UserRegisterAPI, UserLoginAPI
+from .api_user import UserRegisterAPI, UserLoginAPI, UserUpdateAPI , UserSelectAPI , PassUpdateAPI
 from .api_user import getDashboard
 from .api_prepare import UploadFileAPI, PlanAPI, InputFileAPI, MissionsAPI
 from .api_calculate import CalculateAPI
@@ -9,6 +9,9 @@ from .api_graph import GenerateGraph, ViewGraphByToken
 from .api_alert import AlertAPI, AlertCheck
 from .api_system import SystemPerformanceAPI
 
+from .api_graphicFile import GraphicSelectAPI , GraphicDownloadAPI
+from .api_taskFile import TaskSelectAPI
+
 urlpatterns = [
     path('register/', UserRegisterAPI.as_view(), name='user_register_api'),
     path('login/', UserLoginAPI.as_view(), name='user_login_api'),
@@ -25,4 +28,11 @@ urlpatterns = [
     path('systemPerformance/', SystemPerformanceAPI.as_view(), name="system_performance_api"),
     path('inputFile/', InputFileAPI.as_view(), name='input_file_api'),
     path('missions/', MissionsAPI.as_view(), name="missions_api"),
+
+    path('selectUser/', UserSelectAPI.as_view(), name='user_select_api'),
+    path('updateUser/', UserUpdateAPI.as_view(), name='user_update_api'),
+    path('updatePass/', PassUpdateAPI.as_view(), name='pass_update_api'),
+    path('selectGraphic/' , GraphicSelectAPI.as_view() , name = "graphic_select_api"),
+    path('selectTask/' , TaskSelectAPI.as_view() , name = "task_select_api"),
+    path('downloadGraphic/' , GraphicDownloadAPI.as_view() , name = "download_graphic_api")
 ]

BIN
backend/backend/__pycache__/__init__.cpython-310.pyc


BIN
backend/backend/__pycache__/settings.cpython-310.pyc


BIN
backend/backend/__pycache__/urls.cpython-310.pyc


BIN
backend/backend/__pycache__/wsgi.cpython-310.pyc


BIN
backend/db.sqlite3