Просмотр исходного кода

优化扫码工具返回结果,新增插座接口

zhangdongming 2 лет назад
Родитель
Сommit
5e3e963b30

+ 2 - 1
Ansjer/server_urls/loocam_url.py

@@ -9,7 +9,7 @@
 from django.urls import re_path
 
 from Controller.SensorGateway import GatewayFamilyRoomController, SubDeviceController, GatewayFamilyMemberController, \
-    EquipmentFamilyController, GatewayDeviceController, SmartSceneController
+    EquipmentFamilyController, GatewayDeviceController, SmartSceneController, SmartSocketController
 
 urlpatterns = [
     re_path(r'^sensor/gateway/(?P<operation>.*)$', EquipmentFamilyController.EquipmentFamilyView.as_view()),
@@ -19,4 +19,5 @@ urlpatterns = [
     re_path(r'^gateway/subdevice/(?P<operation>.*)$', SubDeviceController.GatewaySubDeviceView.as_view()),
     re_path(r'^gateway/device/info/(?P<operation>.*)$', GatewayDeviceController.GatewayDeviceView.as_view()),
     re_path(r'^smartscene/(?P<operation>.*)$', SmartSceneController.SmartSceneView.as_view()),
+    re_path(r'^open/socket/(?P<operation>.*)$', SmartSocketController.SmartSocketView.as_view()),
 ]

+ 1 - 0
Ansjer/urls.py

@@ -248,6 +248,7 @@ urlpatterns = [
     re_path(r'^api/device/share/(?P<operation>.*)$', UserDeviceShareController.UserDeviceShareView.as_view()),
     re_path(r'^app/sensor/gateway/(?P<operation>.*)$', EquipmentFamilyController.EquipmentFamilyView.as_view()),
     re_path(r'^loocam/', include("Ansjer.server_urls.loocam_url")),
+    re_path(r'^api/loocam/', include("Ansjer.server_urls.loocam_url")),
     re_path(r'^unicom/', include("Ansjer.server_urls.unicom_url")),
     re_path(r'^algorithm-shop/', include("Ansjer.server_urls.algorithm_shop_url")),
     re_path(r'^kvs/', include("Ansjer.server_urls.kvs_url")),

+ 68 - 0
Controller/SensorGateway/SmartSocketController.py

@@ -0,0 +1,68 @@
+# -*- encoding: utf-8 -*-
+"""
+@File    : SmartSocketController.py
+@Time    : 2023/3/17 11:52
+@Author  : stephen
+@Email   : zhangdongming@asj6.wecom.work
+@Software: PyCharm
+"""
+import time
+
+from django.http import QueryDict
+from django.views import View
+
+from Model.models import SocketInfo
+from Object.ResponseObject import ResponseObject
+
+
+class SmartSocketView(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 == 'getSocketDetails':
+            return self.getSocketDetails(request_dict, response)
+
+    @classmethod
+    def getSocketDetails(cls, request_dict, response):
+        return response.json(0)
+
+    @staticmethod
+    def save_socket_switch(device_id, serial_number, status, type_switch=0):
+        if not device_id:
+            return False
+        socket_info_qs = SocketInfo.objects.filter(device_id=device_id, type_switch=type_switch)
+        now_time = int(time.time())
+        if not socket_info_qs.exists():
+            socket_dict = {"device_id": device_id,
+                           "serial_number": serial_number,
+                           "status": status,
+                           "type_switch": type_switch,
+                           "created_time": now_time,
+                           "updated_time": now_time}
+            SocketInfo.objects.create(**socket_dict)
+        if socket_info_qs.first().status == status:
+            return True
+        pass

+ 12 - 4
Controller/TestApi.py

@@ -19,7 +19,6 @@ import cv2
 from botocore import client
 from django.db import transaction
 
-from Ansjer.cn_config.config_formal import CONFIG_INFO
 from Ansjer.config import CONFIG_INFO
 from Controller.DeviceConfirmRegion import Device_Region
 from Object.AWS.AmazonS3Util import AmazonS3Util
@@ -163,7 +162,7 @@ class testView(View):
         elif operation == 'serial-repetition':  # 用与测试序列号重复接口
             response = ResponseObject('cn')
             return self.serial_repetition_test(request_dict, response)
-        elif operation == 'getSerialNumberInfo':  # 序列号信息查询
+        elif operation == 'getSerialNumberInfo':  # 序列号查重
             return self.getSerialNumberInfo(request_dict, response)
         elif operation == 'get-serial-details':  # 序列号信息查询
             return self.get_serial_details(request_dict, response, request)
@@ -172,8 +171,12 @@ class testView(View):
 
     @classmethod
     def serial_repetition_test(cls, request_dict, response):
+        """
+        专用于生产扫码排查序列号重复,辅助接口
+        """
         try:
             serial_no = request_dict.get('serialNo', None)
+            phone_model = request_dict.get('phoneModel', None)
             if not serial_no:
                 return response.json(444)
             with transaction.atomic():
@@ -184,11 +187,16 @@ class testView(View):
                 serial_qs = TestSerialRepetition.objects.filter(serial_number=serial_no)
                 if not serial_qs.exists():
                     n_time = int(time.time())
-                    params = {'serial_number': serial_no, 'created_time': n_time}
+                    params = {'serial_number': serial_no,
+                              'created_time': n_time,
+                              'phone_model': phone_model}
                     TestSerialRepetition.objects.create(**params)
                     return response.json(0)
                 else:
-                    return response.json(174)
+                    result = {'serialNumber': serial_qs.first().serial_number,
+                              'phoneModel': serial_qs.first().phone_model,
+                              'createdTime': serial_qs.first().created_time}
+                    return response.json(174, result)
         except Exception as e:
             logging.info('异常错误,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
             return response.json(178, e)

+ 1 - 0
Model/models.py

@@ -3368,6 +3368,7 @@ class TestSerialRepetition(models.Model):
     id = models.AutoField(primary_key=True, verbose_name='自增id')
     serial_number = models.CharField(blank=True, unique=True, db_index=True, max_length=20, default='',
                                      verbose_name='序列号')
+    phone_model = models.CharField(max_length=64, default='', verbose_name='手机型号')
     created_time = models.IntegerField(default=0, verbose_name='创建时间')
 
     class Meta: