Selaa lähdekoodia

设备控制更新

yf_yzl 2 vuotta sitten
vanhempi
commit
b2f978f2b2
1 muutettua tiedostoa jossa 5 lisäystä ja 3 poistoa
  1. 5 3
      smartfarming/api/views/forecast/worm_lamp.py

+ 5 - 3
smartfarming/api/views/forecast/worm_lamp.py

@@ -1,5 +1,6 @@
 import sys
 import json,os
+import logging
 from json import JSONDecodeError
 import pymysql
 from django.db.models import Sum, Max
@@ -26,6 +27,7 @@ from kedong.decoration import kedong_deco, PortError
 from smartfarming.utils import expire_time
 config_dict = settings.CONFIG
 
+logger = logging.getLogger("myapp")
 
 config = {
         'host': config_dict['bigdata']['mysql_host'],
@@ -1959,8 +1961,8 @@ def xycb_pest_chart(request):
     pest_data = []
     total_pest_num = 0
     for item in queryset:
-        device_data = json.loads(item.device_data)
         try:
+            device_data = json.loads(item.device_data)
             infr_ct = device_data['infr_ct']
             addtime = item.addtime
             pest_data.append({
@@ -1969,8 +1971,8 @@ def xycb_pest_chart(request):
             })
             total_pest_num += infr_ct
         except Exception as e:
-            continue
-
+            logger.error(f"Json 解析错误:{e}")
+            return {"total_num": 0, "pest_data": []}
     return {"total_num": total_pest_num, "pest_data": pest_data}