Sfoglia il codice sorgente

查询设备明细

linhaohong 1 anno fa
parent
commit
ec7aac48b1

+ 73 - 1
AdminController/CloudServiceManage/AgentDeviceController.py

@@ -49,4 +49,76 @@ class AgentDeviceView(View):
 
     def validation(self, request_dict, request, operation):
 
-        pass
+        pass
+        language = request_dict.get('language', 'en')
+        response = ResponseObject(language, 'pc')
+        # 订单结算界面
+        if operation == 'XXXXX':
+            pass
+        else:
+            tko = TokenObject(
+                request.META.get('HTTP_AUTHORIZATION'),
+                returntpye='pc')
+            if tko.code != 0:
+                return response.json(tko.code)
+            response.lang = tko.lang
+            userID = tko.userID
+            if operation == 'getAgentDevice':
+                return self.get_agent_device(userID, request_dict, response)
+            else:
+                return response.json(444, 'operation')
+
+    def get_agent_device(self, userID, request_dict, response):
+        """
+        查询设备明细
+        @param userID: userID
+        @param request_dict: 请求参数
+        @param request_dict ac_id: 代理商id
+        @param request_dict device_name: 设备名字
+        @param request_dict status: 设备类型
+        @param request_dict serial_number: 设备9位序列号
+        @param response: 响应对象
+        @return:
+        """
+        device_name = request_dict.get('device_name', None)
+        status = request_dict.get('status', None)
+        serial_number = request_dict.get('serial_number', None)
+
+        agent_customer_info = AgentCustomerInfo.objects.filter(user_id=userID).first()
+        if agent_customer_info is None:
+            return response.json(104, 'Agent customer not found')
+
+        ac_id = agent_customer_info.id
+
+        try:
+            agent_device_qs = AgentDevice.objects.filter(ac_id=ac_id)
+
+            if device_name:
+                # 根据device_name查询对应的type值
+                device_types = DeviceTypeModel.objects.filter(name=device_name).values_list('type', flat=True)
+                agent_device_qs = agent_device_qs.filter(type__in=device_types)
+
+            if status:
+                agent_device_qs = agent_device_qs.filter(status=status)
+
+            if serial_number:
+                agent_device_qs = agent_device_qs.filter(serial_number=serial_number)
+
+            # 构造返回列表
+            device_list = []
+            for device in agent_device_qs:
+                device_type = DeviceTypeModel.objects.filter(type=device.type).first()
+                device_name = device_type.name if device_type else device.type
+                device_list.append({
+                    'id': device.id,
+                    'ac_id': device.ac_id,
+                    'status': device.status,
+                    'serial_number': device.serial_number,
+                    'device_name': device_name,
+                    'at_time': device.at_time,
+                })
+
+            return response.json(0, {'list': device_list})
+        except Exception as e:
+            print(e)
+            return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))