Browse Source

产品问题审批

linhaohong 2 months ago
parent
commit
f18f21e085
1 changed files with 31 additions and 7 deletions
  1. 31 7
      AdminController/ProblemEntryManagementController.py

+ 31 - 7
AdminController/ProblemEntryManagementController.py

@@ -6,8 +6,9 @@ from django.db import transaction
 from django.views import View
 
 from Ansjer.test.util.email_log import response
-from Model.models import DeviceScheme, ProductTroubleshoot, AbnormalEventCode, ProductsScheme
+from Model.models import DeviceScheme, ProductTroubleshoot, AbnormalEventCode, ProductsScheme, AbnormalEvent
 from Object.ResponseObject import ResponseObject
+from Service.CommonService import CommonService
 
 
 class ProblemEntryView(View):
@@ -198,7 +199,7 @@ class ProblemEntryView(View):
         if status:
             product_troubleshoot_qs = product_troubleshoot_qs.filter(status=status)
 
-        paginator = Paginator(product_troubleshoot_qs.order_by('id'), pageSize)
+        paginator = Paginator(product_troubleshoot_qs.order_by('status', '-id'), pageSize)
         product_trouble_page = paginator.page(page)
 
         # 获取当前页的数据列表
@@ -248,6 +249,7 @@ class ProblemEntryView(View):
         }
         return response.json(0, data)
 
+
     @staticmethod
     def edit_product_problem_status(request_dict, response):
         try:
@@ -257,20 +259,42 @@ class ProblemEntryView(View):
             if not all([record_id, new_status]):
                 return response.json(444)
 
+            new_status = int(new_status)
             try:
                 troubleshoot_record = ProductTroubleshoot.objects.get(id=record_id)
             except ProductTroubleshoot.DoesNotExist:
                 return response.json(173)
 
+            # 更新状态
             troubleshoot_record.status = new_status
-
-            if "remark" in request_dict:
-                troubleshoot_record.remark = request_dict["remark"]
-
+            updated_time = int(time.time())
             troubleshoot_record.save()
 
-            return response.json(0)
+            # 如果是审批通过状态(1),创建异常事件
+            if new_status == 1:
+                device_id = troubleshoot_record.device_id
+                device_type = troubleshoot_record.device_type
+
+                # 获取UID
+                uid = device_id if device_type == 2 else CommonService.get_uid_by_serial_number(device_id)
+
+                # 获取设备型号
+                device_model = 0
+                device_scheme = DeviceScheme.objects.filter(serial_number=device_id).first()
+                if device_scheme:
+                    device_model = device_scheme.device_type
+
+                # 创建异常事件
+                AbnormalEvent.objects.create(
+                    uid=uid,
+                    event_code=troubleshoot_record.event_code,
+                    device_type=device_model,
+                    content=troubleshoot_record.remark,
+                    report_type=1,
+                    created_time=int(time.time())
+                )
 
+            return response.json(0)  # 成功
 
         except Exception as e:
             print(e)