Pārlūkot izejas kodu

根据通道号筛选电池电量

zhangdongming 2 nedēļas atpakaļ
vecāks
revīzija
99c97a0ff3
1 mainītis faili ar 6 papildinājumiem un 0 dzēšanām
  1. 6 0
      Controller/UserDevice/DeviceReportController.py

+ 6 - 0
Controller/UserDevice/DeviceReportController.py

@@ -57,6 +57,7 @@ class DeviceReportView(View):
             return self.get_battery_capacity_list(userID, request, request_dict, response)
         elif operation == 'getWakeSleepData':
             return self.get_wake_sleep_data(userID, request_dict, response)
+        return response.json(414)
 
     @classmethod
     def get_wake_sleep_data(cls, userID, request_dict, response):
@@ -72,6 +73,7 @@ class DeviceReportView(View):
             uid = request_dict.get('device_id', None)
             if not uid:
                 return response.json(444)
+            channel = int(request_dict.get('channel', 1))
             current_time = int(time.time())
             SECONDS_PER_DAY = 24 * 60 * 60  # 单日秒数常量
 
@@ -84,6 +86,7 @@ class DeviceReportView(View):
 
             seven_days_stats = DeviceDailyReport.objects.filter(
                 device_id=uid,
+                channel=channel,
                 report_time__range=(seven_days_ago, current_time)  # 时间范围查询
             ).aggregate(
                 total_human_detection=Coalesce(Sum('human_detection'), Value(0)),
@@ -95,6 +98,7 @@ class DeviceReportView(View):
             # region 30天明细数据(按时间倒序)
             thirty_days_details = DeviceDailyReport.objects.filter(
                 device_id=uid,
+                channel=channel,
                 report_time__gte=thirty_days_ago,
                 report_time__lte=current_time
             ).order_by('-report_time').values_list(
@@ -134,6 +138,7 @@ class DeviceReportView(View):
             device_id = request_dict.get('device_id')
             if not device_id:
                 return response.json(444, "设备ID不能为空")
+            channel = int(request_dict.get('channel', 1))
 
             tz_offset = float(request_dict.get('tz', 0))
             if not (-12 <= tz_offset <= 14):
@@ -160,6 +165,7 @@ class DeviceReportView(View):
             # 查询数据库
             records = DeviceDailyReport.objects.filter(
                 device_id=device_id,
+                channel=channel,
                 type=1,
                 report_time__gte=start_utc,
                 report_time__lt=end_utc