|
@@ -1,6 +1,7 @@
|
|
|
import json
|
|
|
import time
|
|
|
|
|
|
+from django.core.paginator import Paginator
|
|
|
from django.db import transaction
|
|
|
from django.views import View
|
|
|
|
|
@@ -31,6 +32,12 @@ class ProblemEntryView(View):
|
|
|
return self.query_event_subcategory(request_dict, response)
|
|
|
elif operation == 'queryDeviceScheme':
|
|
|
return self.query_device_scheme(request_dict, response)
|
|
|
+ elif operation == 'ProductProblemList':
|
|
|
+ return self.product_problem_list(request_dict, response)
|
|
|
+ elif operation == 'editProductProblemStatus':
|
|
|
+ return self.edit_product_problem_status(request_dict, response)
|
|
|
+ else:
|
|
|
+ return response.json(414)
|
|
|
|
|
|
@staticmethod
|
|
|
def add_product_problem(request_dict, response):
|
|
@@ -169,4 +176,103 @@ class ProblemEntryView(View):
|
|
|
|
|
|
except Exception as e:
|
|
|
print(e)
|
|
|
- return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
+ return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def product_problem_list(request_dict, response):
|
|
|
+ device_id = request_dict.get("deviceId", None)
|
|
|
+ storage_code = request_dict.get("storageCode", None)
|
|
|
+ event_code = request_dict.get("eventCode", None)
|
|
|
+ status = request_dict.get("status", None)
|
|
|
+ page = request_dict.get("page", 1)
|
|
|
+ pageSize = request_dict.get("pageSize", 10)
|
|
|
+
|
|
|
+ # 1. 先查询ProductTroubleshoot表
|
|
|
+ product_troubleshoot_qs = ProductTroubleshoot.objects.all()
|
|
|
+ if device_id:
|
|
|
+ product_troubleshoot_qs = product_troubleshoot_qs.filter(device_id=device_id)
|
|
|
+ if storage_code:
|
|
|
+ product_troubleshoot_qs = product_troubleshoot_qs.filter(storage_code__contains=storage_code)
|
|
|
+ if event_code:
|
|
|
+ product_troubleshoot_qs = product_troubleshoot_qs.filter(event_code__contains=event_code)
|
|
|
+ if status:
|
|
|
+ product_troubleshoot_qs = product_troubleshoot_qs.filter(status=status)
|
|
|
+
|
|
|
+ paginator = Paginator(product_troubleshoot_qs.order_by('id'), pageSize)
|
|
|
+ product_trouble_page = paginator.page(page)
|
|
|
+
|
|
|
+ # 获取当前页的数据列表
|
|
|
+ product_trouble_list = list(product_trouble_page.object_list.values(
|
|
|
+ 'id',
|
|
|
+ 'date_time',
|
|
|
+ 'device_type',
|
|
|
+ 'device_id',
|
|
|
+ 'storage_code',
|
|
|
+ 'event_code',
|
|
|
+ 'status',
|
|
|
+ 'remark',
|
|
|
+ ))
|
|
|
+
|
|
|
+ # 2. 收集所有storage_code用于批量查询ProductsScheme表
|
|
|
+ storage_codes = [item['storage_code'] for item in product_trouble_list if item['storage_code']]
|
|
|
+ product_schemes = ProductsScheme.objects.filter(storage_code__in=storage_codes)
|
|
|
+
|
|
|
+ # 3. 创建映射字典并拼接字段
|
|
|
+ scheme_info_dict = {}
|
|
|
+ for scheme in product_schemes:
|
|
|
+ # 拼接需要的字段,过滤掉空值
|
|
|
+ fields_to_join = [
|
|
|
+ scheme.flash,
|
|
|
+ scheme.ddr,
|
|
|
+ scheme.main_controller,
|
|
|
+ scheme.wifi,
|
|
|
+ scheme.four_g,
|
|
|
+ scheme.ad,
|
|
|
+ scheme.sensor,
|
|
|
+ scheme.customer_code,
|
|
|
+ scheme.phy,
|
|
|
+ ]
|
|
|
+
|
|
|
+ # 过滤掉None和空字符串,然后用逗号连接
|
|
|
+ joined_info = '+'.join(filter(None, fields_to_join))
|
|
|
+ scheme_info_dict[scheme.storage_code] = joined_info
|
|
|
+
|
|
|
+ # 4. 将拼接后的信息添加到原数据中
|
|
|
+ for item in product_trouble_list:
|
|
|
+ storage_code = item['storage_code']
|
|
|
+ item['product_scheme_info'] = scheme_info_dict.get(storage_code, '')
|
|
|
+
|
|
|
+ data = {
|
|
|
+ "list": product_trouble_list,
|
|
|
+ "total": paginator.count,
|
|
|
+ }
|
|
|
+ return response.json(0, data)
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def edit_product_problem_status(request_dict, response):
|
|
|
+ try:
|
|
|
+ record_id = request_dict.get("id", None)
|
|
|
+ new_status = request_dict.get("status", None)
|
|
|
+
|
|
|
+ if not all([record_id, new_status]):
|
|
|
+ return response.json(444)
|
|
|
+
|
|
|
+ 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"]
|
|
|
+
|
|
|
+ troubleshoot_record.save()
|
|
|
+
|
|
|
+ return response.json(0)
|
|
|
+
|
|
|
+
|
|
|
+ except Exception as e:
|
|
|
+ print(e)
|
|
|
+ return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
+
|