|
@@ -0,0 +1,105 @@
|
|
|
+# -*- encoding: utf-8 -*-
|
|
|
+"""
|
|
|
+@File : SerialNumberCheckController.py
|
|
|
+@Time : 2024/6/20 13:33
|
|
|
+@Author : stephen
|
|
|
+@Email : zhangdongming@asj6.wecom.work
|
|
|
+@Software: PyCharm
|
|
|
+"""
|
|
|
+import time
|
|
|
+
|
|
|
+from django.http import QueryDict
|
|
|
+from django.views import View
|
|
|
+
|
|
|
+from Ansjer.config import LOGGER
|
|
|
+from Model.models import SerialNumberCheckLog
|
|
|
+from Object.ResponseObject import ResponseObject
|
|
|
+
|
|
|
+
|
|
|
+class SerialNumberView(View):
|
|
|
+ def get(self, request, *args, **kwargs):
|
|
|
+ request.encoding = 'utf-8'
|
|
|
+ operation = kwargs.get('operation')
|
|
|
+ return self.validation(request.GET, request, operation)
|
|
|
+
|
|
|
+ def post(self, request, *args, **kwargs):
|
|
|
+ request.encoding = 'utf-8'
|
|
|
+ operation = kwargs.get('operation')
|
|
|
+ return self.validation(request.POST, request, operation)
|
|
|
+
|
|
|
+ def delete(self, request, *args, **kwargs):
|
|
|
+ request.encoding = 'utf-8'
|
|
|
+ operation = kwargs.get('operation')
|
|
|
+ delete = QueryDict(request.body)
|
|
|
+ if not delete:
|
|
|
+ delete = request.GET
|
|
|
+ return self.validation(delete, request, operation)
|
|
|
+
|
|
|
+ def put(self, request, *args, **kwargs):
|
|
|
+ request.encoding = 'utf-8'
|
|
|
+ operation = kwargs.get('operation')
|
|
|
+ put = QueryDict(request.body)
|
|
|
+ return self.validation(put, request, operation)
|
|
|
+
|
|
|
+ def validation(self, request_dict, request, operation):
|
|
|
+ response = ResponseObject('cn')
|
|
|
+ if operation == 'serialNumberCheck':
|
|
|
+ return self.save_serial_number_log(request_dict, response)
|
|
|
+
|
|
|
+ @classmethod
|
|
|
+ def save_serial_number_log(cls, request_dict, response):
|
|
|
+ """
|
|
|
+ 保存APP扫码工具排查序列号重复日志
|
|
|
+ @param request_dict: 序列号、手机型号、类型
|
|
|
+ @param response: 响应类
|
|
|
+ @return:
|
|
|
+ """
|
|
|
+ serial_no = request_dict.get("serialNo", None)
|
|
|
+ phone_model = request_dict.get("phoneModel", None)
|
|
|
+ if not serial_no:
|
|
|
+ return response.json(444)
|
|
|
+ p_type = int(request_dict.get('type', 0))
|
|
|
+ n_time = int(time.time())
|
|
|
+ try:
|
|
|
+ dict_type = {'1': '三乡总装', '2': '三乡包装', '3': '三乡返工', '4': '三乡管理', '5': '珠海包装', '6': '珠海管理'}
|
|
|
+ first_serial = serial_no[:6]
|
|
|
+ # 查询当前工位是否扫过序列号
|
|
|
+ first_serial_qs = SerialNumberCheckLog.objects.filter(serial_number=first_serial)
|
|
|
+ # 工位类型,1:三乡总装,2:三乡包装,3:三乡返工,4:三乡管理,5:珠海包装
|
|
|
+ if p_type == 4 or p_type == 6:
|
|
|
+ first_serial_qs = first_serial_qs.filter(type=5) if p_type == 6 else first_serial_qs.exclude(type=5)
|
|
|
+ first_serial_qs = first_serial_qs.order_by('type', '-created_time')
|
|
|
+ if not first_serial_qs.exists():
|
|
|
+ return response.json(173)
|
|
|
+ logs = []
|
|
|
+ # 管理分类可查询当前序列号扫码记录
|
|
|
+ for item in first_serial_qs:
|
|
|
+ log_dict = {'fullSerialNumber': item.full_serial_number, 'count': item.count, 'type': item.type,
|
|
|
+ 'createdTime': item.created_time, 'stationName': dict_type[str(item.type)],
|
|
|
+ 'phoneModel': item.phone_model}
|
|
|
+ logs.append(log_dict)
|
|
|
+ result = {'logs': logs}
|
|
|
+ return response.json(0, result)
|
|
|
+ first_serial_qs = first_serial_qs.filter(type=p_type)
|
|
|
+ if first_serial_qs.exists():
|
|
|
+ # APP扫码工具记录+1
|
|
|
+ params = {'serial_number': first_serial, 'created_time': n_time,
|
|
|
+ 'full_serial_number': serial_no, 'type': p_type, 'phone_model': phone_model}
|
|
|
+ SerialNumberCheckLog.objects.create(**params)
|
|
|
+ # 返回当前序列号数据结构
|
|
|
+ log_dict = {'fullSerialNumber': first_serial_qs[0].full_serial_number,
|
|
|
+ 'count': first_serial_qs[0].count, 'type': first_serial_qs[0].type,
|
|
|
+ 'createdTime': first_serial_qs[0].created_time,
|
|
|
+ 'stationName': dict_type[str(first_serial_qs[0].type)],
|
|
|
+ 'phoneModel': first_serial_qs[0].phone_model}
|
|
|
+ result = {'logs': [log_dict]}
|
|
|
+ return response.json(174, result)
|
|
|
+ else:
|
|
|
+ params = {'serial_number': first_serial, 'created_time': n_time,
|
|
|
+ 'full_serial_number': serial_no, 'type': p_type, 'phone_model': phone_model}
|
|
|
+ SerialNumberCheckLog.objects.create(**params)
|
|
|
+ return response.json(0)
|
|
|
+ except Exception as e:
|
|
|
+ LOGGER.error('APP扫码工具保存日志异常:errLine:{}, errMsg:{}'
|
|
|
+ .format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
+ return response.json(5)
|