yf_yzl 2 лет назад
Родитель
Сommit
e4e631aacc

+ 3 - 2
formal

@@ -53,8 +53,8 @@
      "6": "监控"
   },
   "image_url": {
-    "image":"http://60.14.40.10:8000",
-    "discern": "http://60.14.40.10:8000"
+    "image":"http://60.14.40.10:8002",
+    "discern": "http://60.14.40.10:8002"
   },
   "camera": {
     "lc_addr": "https://openapi.lechange.cn/openapi/bindDeviceLive",
@@ -65,6 +65,7 @@
     "lc_controler": "https://openapi.lechange.cn/openapi/controlMovePTZ",
     "lc_modify_live_plan": "https://openapi.lechange.cn/openapi/modifyLivePlan",
     "lc_modify_live_plan_status": "https://openapi.lechange.cn/modifyLivePlanStatus", 
+    "lc_local_record": "https://openapi.lechange.cn/openapi/queryLocalRecords",
     "lc_kit_token": "https://openapi.lechange.cn/openapi/getKitToken", 
     "ys_open": "https://open.ys7.com/api/lapp/live/video/open",
     "ys_get": "https://open.ys7.com/api/lapp/live/address/get"

+ 27 - 2
smartfarming/api/views/camera/camera_manage.py

@@ -17,7 +17,7 @@ from smartfarming.models.sim_card import MongoMsg_Conf
 from smartfarming.models.device import MongoDevice
 from smartfarming.models.camera import MongoCameraPhoto, MongoCameraData, MongoCameraAccount
 from smartfarming.serializers.device_serializers import DeviceSerializers
-from smartfarming.utils import bindDeviceLive, getLive, controlMove, modify_live_time, off_on_live, setDeviceSnap, getKitToken
+from smartfarming.utils import bindDeviceLive, getLive, controlMove, modify_live_time, off_on_live, setDeviceSnap, getKitToken, getRecord
 from kedong.tools import RedisPool
 from kedong.decoration import kedong_deco, PortError
 
@@ -503,7 +503,7 @@ def camera_photo(request):
 
 
 @kedong_deco(login_required=True)
-def get_camera_dh_token(request):
+def get_camera_dh_tokens(request):
     """ 
     获取大华相机token 
     参数:
@@ -529,3 +529,28 @@ def get_camera_dh_token(request):
     return like_token_data
 
 
+@kedong_deco(login_required=True)
+def get_camera_dh_token(request):
+    """ 
+    获取大华相机token 
+    参数:
+    device_id                必传(string)                   设备号
+    """
+    device_id = request.POST.get("device_id")
+    if not device_id:
+        raise PortError("","参数缺失")
+    camera_query = MongoCameraData.objects.filter(device_id=device_id).first()
+    if not camera_query:
+        raise PortError("","未找到此设备")
+    camera_account_query = MongoCameraAccount.objects.filter(id=camera_query.account_id).first()
+    if not camera_account_query:
+        raise PortError("","此设备未绑定监控账号")
+    if camera_account_query.account_type == 0:
+        raise PortError('', '海康监控暂不支持获取token')
+    if device_id.find("-") != -1:
+        channelNo = device_id.split("-")[1]
+        device_id = device_id.split("-")[0]
+    appId = camera_account_query.app_key
+    appSecret = camera_account_query.app_secret
+    like_token_data = getRecord(appId, appSecret,device_id,channelNo)
+    return like_token_data

+ 2 - 311
smartfarming/api/views/forecast/send_control.py

@@ -1,7 +1,5 @@
 import requests
 import json
-from json import JSONDecodeError
-
 from requests.auth import HTTPBasicAuth
 from smartfarming.api.views.forecast.all_dict import insect_dict,get_siminfo,get_simsinfo
 from kedong.decoration import kedong_deco, PortError
@@ -23,7 +21,6 @@ def device_control_info(request):
         raise PortError('cmd',"参数缺失")
     if not d_id:
         raise PortError('d_id', "参数缺失")
-
     if MongoDeviceConfig.objects.filter(d_id=d_id,cmd=cmd).exists():
         d_config = MongoDeviceConfig.objects.get(d_id=d_id,cmd=cmd)
         try:
@@ -37,209 +34,15 @@ def device_control_info(request):
         return d_config
     else:
         raise PortError(d_id, "配置未上传")
-
-
-def user_device_control(request):
-    """
-    用户远程控制设备下发(用于对接)
-    参数:
-    device_type_id              必传                          设备类型  2杀虫灯,3测报灯,4智能性诱,7孢子仪 5气象站, 14色诱测报灯 12吸虫塔
-    device_id                   必传                          设备号
-    config                      必传                          设备控制参数
-    username                    必传                          用户名
-
-    config 说明:
-        测报灯:{'ts': 0, 'tpl': 5, 'tt': 6, 'collt': 10, 'datt': 20, 'htim': 10, 'et': 6, 'st': 20, 'hst': 85, 'tph': 70, 'imgres': 0}
-        测报灯拍照:takephoto
-}
-
-     具体说明太长          对接口问我要
-    """
-    #测报灯  下发主题  /yfkj/cbd/sub/+imei
-    #杀虫灯  下发主题  /yfkj/scd/sub/+imei
-    #性诱设备  下发主题 yfkj/xycb/s2c/+imei
-    #孢子仪  下发主题 /yfkj/bzy/s2c/+imei
-    # myuid = request.myuser.uid
-    # user_type = request.user_type
-    post_info = request.POST
-    username = post_info.get("username")
-    ip = request.META.get('REMOTE_ADDR')
-    try:
-        check_username = DeviceUser.objects.get(real_name=username)
-    except:
-        raise PortError('username', "用户名不存在")
-
-    if check_username.user_type == 3:
-        raise PortError('', "控制异常,请联系上级")
-
-    
-    
-    device_type_id = post_info.get("device_type_id", '')
-    device_id = post_info.get("device_id", '')
-    if not device_id:
-        raise PortError('device_id',"参数缺失")
-    devices = Device.objects.all()
-   
-    try:
-        device = devices.get(device_id=device_id)
-    except:
-        raise PortError("device_id","没有此设备")
-
-    if not check_username.user_type == 1 and device.device_expire == "1":
-        raise PortError("device_id","设备已过期")
     
-    config = post_info.get("config", '')
-    # cmd = post_info.get("cmd", '')
-    payload = {}
-    # if work_type == "0":
-    #     payload = {"cmd": "workmode", "ext": {"asleep": "1", "common": "0", "power": "0"}}
-    # elif work_type == "1":
-    #     payload = {"cmd": "workmode", "ext": {"asleep": "0", "common": "1", "power": "0"}}
-    # elif work_type == "2":
-    #     payload = {"cmd": "workmode", "ext": {"asleep": "0", "common": "0", "power": "1"}}
-
-    if config:
-        if config == "takephoto":
-            payload["cmd"] = "takephoto"
-        else:
-            try:
-                config = json.loads(config)
-            except  JSONDecodeError as e:
-                config = eval(config)
-            except:
-                raise PortError('',"参数类型错误")
-            payload["cmd"] = "paramconf"
-            payload["ext"] = config
-    else:
-        raise PortError('',"缺少config参数")
-
-    topic = ""
-    if not device_type_id:
-        raise PortError('device_type_id',"参数缺失")
-    if int(device_type_id) == 3:
-        topic = "/yfkj/cbd/sub/%s"%device.device_id
-    else:
-        raise PortError('device_type_id',"参数超出范围")
-
-    payload = json.dumps(payload)
-    cmds = {"topic":topic,"payload":payload,"qos":1}
-
-    content = "设备类型:%s,下发:%s"
-    operation_log(check_username.uid, content % (device_type_id, payload), device.device_id, 0, ip)
-    res = rp(cmds)
-    if res.status_code == 200:
-        return True
-
-
-def user_get_device_config(request):
-    """
-    查询设备配置信息/设备监测最新数据  (用于对接)
-    参数:
-    device_type_id                  必传                         设备类型  3测报灯
-    device_id                       必传                         设备号
-    control_type                    必传                         操作类型  data 读取设备数据信息
-    username                        必传                         用户名
-    """
-    #测报灯  下发主题  /yfkj/cbd/sub/+imei
-    #杀虫灯  下发主题  /yfkj/scd/sub/+imei
-    #性诱设备  下发主题 yfkj/xycb/s2c/+imei
-    #孢子仪  下发主题 /yfkj/bzy/s2c/+imei
-    # uid = request.myuser.uid
-    # user_type = request.user_type
-    # if user_type == 3:
-    #     raise PortError('', "控制异常,请联系上级")
-    
-    post_info = request.POST
-    device_type_id = post_info.get("device_type_id", '')
-    device_id = post_info.get("device_id", '')
-    if not device_id:
-        raise PortError('device_id', "参数缺失")
-    username = post_info.get("username")
-    ip = request.META.get('REMOTE_ADDR')
-    try:
-        check_username = DeviceUser.objects.get(real_name=username)
-    except:
-        raise PortError('username', "用户名不存在")
-    devices = Device.objects.all()
-    device = devices.get(device_id=device_id)
-
-    # myuser_type = request.user_type
-    if not check_username.user_type == 1 and device.device_expire == "1":
-        raise PortError('', "该设备已到期")
-
-
-    control_type = post_info.get("control_type", '')
-    if not control_type:
-        raise PortError('control_type',"参数缺失")
-    payload = {
-        "cmd": "read",
-        "ext":control_type
-    }
-    topic = ""
-    if not device_type_id:
-        raise PortError('device_type_id', "参数缺失")
-    if int(device_type_id) == 3:
-        topic = "/yfkj/cbd/sub/%s" % device.device_id
-    else:
-        raise PortError('device_type_id', "参数超出范围")
-    # elif int(device_type_id) == 2:
-    #     topic = "/yfkj/scd/sub/%s" % device.device_id
-    # elif int(device_type_id) == 4:
-    #     topic = "/yfkj/xycb/s2c/%s" % device.device_id
-    # elif int(device_type_id) == 5:
-    #     topic = "/yfkj/qxz/sub/%s" % device.device_id
-    #     payload = {
-    #     "cmd": "read",
-    #     "ext": {"type": control_type}
-    # }
-    # elif int(device_type_id) == 7:
-    #     topic = "/yfkj/bzy/s2c/%s" % device.device_id
-    # elif int(device_type_id) == 9:
-    #     topic = "/yfkj/tccbd/sub/%s" % device.device_id
-    # elif int(device_type_id) == 14:
-    #     topic = "yfkj/color/s2c/%s" % device.device_id
-    #     payload = {"cmd":"read","ext":"data"}
-    # elif int(device_type_id) == 8:
-    #     topic = "/yfkj/xyv3/s2c/%s" % device.device_id
-    cmd = {"topic": topic, "payload": json.dumps(payload), "qos": 1}    
-    res = requests.post("%s"%config_dict['mqtt_config']["http"], json=cmd,
-                        auth=HTTPBasicAuth(config_dict['mqtt_config']["user"], config_dict['mqtt_config']["secret_key"]))
-
-    if res.status_code == 200:
-        return True
-    else:
-        return False
-
 
 @kedong_deco(login_required=True)
 def device_control(request):
-    """
-    设备下发控制
-    参数:
-    device_type_id              必传                         设备类型  2杀虫灯,3测报灯,4智能性诱,7孢子仪 5气象站, 14色诱测报灯 12吸虫塔
-    d_id                        必传                         设备自增id
-    config                      非必传                        设备控制参数
-    work_type                   非必传                        工作模式时 必传 0节能 1常规  2加强
-    cmd                         非必传                        下发服务器配置使用 setnet
-    device_name                 必传                          设备名称
-
-    config 说明:
-        测报灯:{'ts': 0, 'tpl': 5, 'tt': 6, 'collt': 10, 'datt': 20, 'htim': 10, 'et': 6, 'st': 20, 'hst': 85, 'tph': 70, 'imgres': 0}
-        孢子仪:{'datt': 0, 'drop_time': 0, 'imgres': 0, 'set_temp': 25, 'coll_time': ['7-9', '10-11', Ellipsis], 'cul_time': 24, 'wind_sw': 0}
-        杀虫灯:{'timctrl': 1, 'et': 22, 'st': 20}
-        色诱测报灯: {'cmd': 'photoconf','ext': {'start': '18','end': '22','freq': '20'}   下发设置工作时间
-}
-
-                具体说明太长          对接口问我要
-    """
+    # 设备下发控制
     #测报灯  下发主题  /yfkj/cbd/sub/+imei
     #杀虫灯  下发主题  /yfkj/scd/sub/+imei
     #性诱设备  下发主题 yfkj/xycb/s2c/+imei
     #孢子仪  下发主题 /yfkj/bzy/s2c/+imei
-    myuid = request.myuser.uid
-    user_type = request.user_type
-    if user_type == 3:
-        raise PortError('', "控制异常,请联系上级")
     post_info = request.POST
     device_type_id = post_info.get("device_type_id", '')
     d_id = post_info.get("d_id", '')
@@ -253,13 +56,11 @@ def device_control(request):
         device = devices.get(id=int(d_id))
     except:
         raise PortError("d_id","没有此设备")
-
-    if not user_type == 1 and device.device_expire == "1":
+    if device.device_expire == "1":
         raise PortError("d_id","设备已过期")
     if device_name:
         device.device_name = device_name
         device.save()
-    
     config = post_info.get("config", '')
     cmd = post_info.get("cmd", '')
     payload = {}
@@ -269,11 +70,9 @@ def device_control(request):
         payload = {"cmd": "workmode", "ext": {"asleep": "0", "common": "1", "power": "0"}}
     elif work_type == "2":
         payload = {"cmd": "workmode", "ext": {"asleep": "0", "common": "0", "power": "1"}}
-
     if config:
         try:
             config = json.loads(config)
-
         except:
             raise PortError('',"参数类型错误")
     if not work_type:
@@ -281,7 +80,6 @@ def device_control(request):
             raise PortError('config', "参数缺失")
         payload["cmd"] = "paramconf"
         payload["ext"] = config
-
     if req == "ctr_clear":
         payload = {"cmd": "ctr_clear"}
     topic = ""
@@ -295,7 +93,6 @@ def device_control(request):
         topic = "/yfkj/xycb/s2c/%s"%device.device_id
     elif int(device_type_id) in [5, 8]:
         topic = "/yfkj/qxz/sub/%s"%device.device_id
-
         timeout = config.get("timeout","")
         content = config.get("content","")
         interval = config.get("interval","")
@@ -307,12 +104,10 @@ def device_control(request):
             }
             cmds = {"topic": topic, "payload": payload, "qos": 1}
             content = "气象站:%s,下发:%s"
-            rp(cmds)
         if interval:
             payload["cmd"] = "config"
             payload["ext"] = {"interval":interval}
             cmds = {"topic": topic, "payload": payload, "qos": 1}
-            rp(cmds)
         return True
     elif int(device_type_id) == 7:
         topic = "/yfkj/bzy/s2c/%s"%device.device_id
@@ -333,7 +128,6 @@ def device_control(request):
         }
     payload = json.dumps(payload)
     cmds = {"topic":topic,"payload":payload,"qos":1}
-
     content = "设备类型:%s,下发:%s"
     # TODO 大数据平台转发
     print(cmds)
@@ -352,95 +146,6 @@ def clear_insects_permission(request):
     return data
 
 
-
-def clear_insects(request):
-    """
-    杀虫灯批量一键自清虫
-    """
-    uid = request.myuser.uid
-    myuser = request.myuser
-    device_query =  Device.devices(uid=uid,myuser=myuser)
-    scd_query = device_query.filter(device_type_id=2)
-    scd_imei_list = [i.device_id for i in scd_query]
-    for i in scd_imei_list:
-        topic = "/yfkj/scd/sub/%s" % i
-        payload = json.dumps({"cmd": "ctr_clear"})
-        cmds = {"topic":topic,"payload":payload,"qos":1}
-        try:
-            res = rp(cmds)
-            if res.status_code != 200:
-                return False
-        except:
-            return False
-    return True
-
-
-
-def scd_device_control(request):
-    """
-    杀虫灯批量下发控制接口
-    参数:
-    imei_list                   必传                         设备imei号 为选中的设备下发
-    config                      必传                       设备控制参数
-      
-    config 说明:
-        杀虫灯:{"st":"20","et":"2","ds":"0","ts":"0","tt":"4","dattim":"30","clt":"120"}
-
-    下发成功后返回值:
-    "data": [],
-    下发未成功返回值:
-     "data": [
-        "863488050761140"                                   下发未成功设备号
-    ],
-}
-    """
-    #测报灯  下发主题  /yfkj/cbd/sub/+imei
-    #杀虫灯  下发主题  /yfkj/scd/sub/+imei
-    #性诱设备  下发主题 yfkj/xycb/s2c/+imei
-    #孢子仪  下发主题 /yfkj/bzy/s2c/+imei
-    imei_list = request.POST.get("imei_list")
-
-    config = request.POST.get("config", '')
-    uid = request.myuser.uid
-    myuser = request.myuser
-
-    if not config:
-        raise PortError("config","配置信息未传")
-    if not imei_list:
-        raise PortError("imei_list","设备列表未传")
-    
-    try:
-        config = json.loads(config)
-    except:
-        raise PortError('',"参数类型错误")
-    data = []
-    payload = {}
-    payload["cmd"] = "paramconf"
-    payload["ext"] = config
-    payload = json.dumps(payload)
-
-    device_ids = json.loads(imei_list)
-    device_query =  Device.devices(uid=uid,myuser=myuser)
-    scd_query = device_query.filter(device_type_id=2)
-    scd_list = [i.device_id for i in scd_query]
-    
-    for i in device_ids:
-        if i in scd_list:
-            topic = "/yfkj/scd/sub/%s" % i
-            cmds = {"topic":topic,"payload":payload,"qos":1}
-            try:
-                res = rp(cmds)
-                if res.status_code == 200:
-                    pass
-                else:
-                    data.append(i)
-            except:
-                data.append(i)
-        else:
-            raise PortError('permission error',"%s设备非用户账户下"%i)
-    return data      
-
-
 @kedong_deco(login_required=True)
 def get_device_config(request):
     """
@@ -454,11 +159,6 @@ def get_device_config(request):
     #杀虫灯  下发主题  /yfkj/scd/sub/+imei
     #性诱设备  下发主题 yfkj/xycb/s2c/+imei
     #孢子仪  下发主题 /yfkj/bzy/s2c/+imei
-    # uid = request.myuser.uid
-    # user_type = request.user_type
-    # if user_type == 3:
-    #     raise PortError('', "控制异常,请联系上级")
-    imei_list = ["866950041980524","866950041980458","866950041975045","866950041941286","866950041941203","866950041980425","866950041941377"]
     post_info = request.POST
     device_type_id = post_info.get("device_type_id", '')
     d_id = post_info.get("d_id", '')
@@ -502,15 +202,6 @@ def get_device_config(request):
         payload = {"cmd":"read","ext":"data"}
     elif int(device_type_id) == 8:
         topic = "/yfkj/xyv3/s2c/%s" % device.device_id
-    if device.device_id in imei_list:
-        topic = "yfkj/xycb/s2c/%s" % device.device_id
-        cmd = {"topic": topic, "payload": json.dumps(payload), "qos": 1}
-    #     res = requests.post("http://www.yfzhwlw.com:8080/api/v2/mqtt/publish",
-    #                     data=json.dumps(cmd, indent=1), auth=HTTPBasicAuth("admin", "yfkj_6019"))
-    # else:
-    #     cmd = {"topic": topic, "payload": json.dumps(payload), "qos": 1}    
-    #     res = requests.post("%s"%config_dict['mqtt_config']["http"], json=cmd,
-    #                         auth=HTTPBasicAuth(config_dict['mqtt_config']["user"], config_dict['mqtt_config']["secret_key"]))
     # TODO 暂时处理调用http接口
     code = 200
     if code == 200:

+ 3 - 1
smartfarming/urls.py

@@ -53,7 +53,8 @@ from smartfarming.views.device import (
     DeviceListInfoAPIView,
     DeviceListAPIView,
     DeviceChangeAPIView,
-    DeviceListAPIView
+    DeviceListAPIView,
+    QxzDeviceAddAPIViw
 )
 
 from smartfarming.views.knowledge import (
@@ -130,6 +131,7 @@ urlpatterns = [
     path("weekend_add", PlanWeekendAddAPIView.as_view()),  # 生成周期增加
     path("weekend_delete", PlanWeekendDelete.as_view()),  # 生成周期删除
     path("device_add", CbdScdXyDeviceSaveAPIView.as_view()),  # 增加设备及数据接口  【提供给大数据平台】
+    path("qxz_add", QxzDeviceAddAPIViw.as_view()),  # 增加气象站数据接口  【提供给大数据平台】
     path("device_info", DeviceListInfoAPIView.as_view()), # 设备信息列表
     path("device", DeviceListAPIView.as_view()), # 设备列表(用于一张图)
     path("device_update", DeviceChangeAPIView.as_view()), # 设备更新

+ 22 - 0
smartfarming/utils.py

@@ -438,6 +438,7 @@ def off_on_live(appId,appSecret,liveToken,status):
 def setDeviceSnap(appId,appSecret,deviceId,channelId="0"):
     # 抓图接口
     url = config.get("camera").get("lc_device_snap_enhanced")
+    url = config.get("camera").get("lc_device_snap")
     time,nonce,sign,token = device_config(appId, appSecret)
     if not token:
         return {"msg": "抓图失败"}
@@ -473,6 +474,27 @@ def getKitToken(appId,appSecret,deviceId,channelId="0"):
     like_token_data = requests.post(url,json=data)
     return like_token_data.json()
 
+def getRecord(appId,appSecret,deviceId,channelId="0"):
+    url = config.get("camera").get("lc_local_record")
+    time,nonce,sign,token = device_config(appId, appSecret)
+    if not token:
+        return {"result":{"code":"1"}}
+    data = {
+        "system":{"ver":"1.0","appId":appId,"sign":sign,"time":time,"nonce":nonce},
+        "id":nonce,
+        "params":{
+            "deviceId":deviceId,
+            "channelId":channelId,
+            "token":token, 
+            "beginTime":"2023-07-19 00:00:00", 
+            "endTime": "2023-07-25 00:00:00",
+            "type": "All",
+            "count": 100
+        }
+    }
+    record_token_data = requests.post(url,json=data)
+    return record_token_data.json()
+
 
 if __name__ == "__main__":
     t = get_recent_month(1)

+ 52 - 39
smartfarming/views/counts_views.py

@@ -57,45 +57,58 @@ class LandPlanInfoAPIView(APIView):
                 years.append(y)
         years.reverse()
         # 获取最近5年的作物ID
-        end = datetime.datetime(int(years[-1]) -5, 12,31,23,59).timestamp()
-        start = datetime.datetime(int(years[-1]), 12,31,23,59).timestamp()
-        plan_ids = LandPlanInfo.objects.filter(addtime__gte=end, addtime__lte=start).exclude(recovery_time=0).distinct().values_list("plan_id", flat=True).order_by("plan_id")
-        counts = []
-        # 组织具体数据
-        for i in years:
-            start_timestamp = datetime.datetime(i, 1,1,0,0).timestamp()
-            end_timestatmp = datetime.datetime(i, 12,31,23,59).timestamp()
-            plan_totals = LandPlanInfo.objects.filter(
-                addtime__gte=start_timestamp, 
-                addtime__lte=end_timestatmp).exclude(recovery_time=0).values("plan_id").annotate(total=Sum("recovery_kg")).order_by("plan_id").values_list("plan_id", "total")
-            inners = {}
-            for k in plan_totals:
-                inners[str(k[0])] = k[1]
-            pid =[]
-            for j in plan_ids:
-                pid.append(inners.get(str(j), 0))
-            counts.append(pid)
-        transpose_matrix = [[row[i] for row in counts] for i in range(len(counts[0]))]
-        plannames = []
-        # 组织农作物
-        for p in plan_ids:
-            plan_obj = MongoPlantInfo.objects.filter(id=p)
-            if plan_obj:
-                planname = plan_obj.first().plantname +"-"+ plan_obj.first().planttype
-            else:
-                planname = ""
-            plannames.append(planname)
-        return Response({
-            "code": 0, 
-            "msg": "success", 
-            "data": serializers.data, 
-            "count": total_obj, 
-            "charts": {
-                "years": years,
-                "data": transpose_matrix,
-                "plan": plannames
-            }
-        })
+        if years:
+            end = datetime.datetime(int(years[-1]) -5, 12,31,23,59).timestamp()
+            start = datetime.datetime(int(years[-1]), 12,31,23,59).timestamp()
+            plan_ids = LandPlanInfo.objects.filter(addtime__gte=end, addtime__lte=start).exclude(recovery_time=0).distinct().values_list("plan_id", flat=True).order_by("plan_id")
+            counts = []
+            # 组织具体数据
+            for i in years:
+                start_timestamp = datetime.datetime(i, 1,1,0,0).timestamp()
+                end_timestatmp = datetime.datetime(i, 12,31,23,59).timestamp()
+                plan_totals = LandPlanInfo.objects.filter(
+                    addtime__gte=start_timestamp, 
+                    addtime__lte=end_timestatmp).exclude(recovery_time=0).values("plan_id").annotate(total=Sum("recovery_kg")).order_by("plan_id").values_list("plan_id", "total")
+                inners = {}
+                for k in plan_totals:
+                    inners[str(k[0])] = k[1]
+                pid =[]
+                for j in plan_ids:
+                    pid.append(inners.get(str(j), 0))
+                counts.append(pid)
+            transpose_matrix = [[row[i] for row in counts] for i in range(len(counts[0]))]
+            plannames = []
+            # 组织农作物
+            for p in plan_ids:
+                plan_obj = MongoPlantInfo.objects.filter(id=p)
+                if plan_obj:
+                    planname = plan_obj.first().plantname +"-"+ plan_obj.first().planttype
+                else:
+                    planname = ""
+                plannames.append(planname)
+            return Response({
+                "code": 0, 
+                "msg": "success", 
+                "data": serializers.data, 
+                "count": total_obj, 
+                "charts": {
+                    "years": years,
+                    "data": transpose_matrix,
+                    "plan": plannames
+                }
+            })
+        else:
+            return Response({
+                "code": 0, 
+                "msg": "success", 
+                "data": [], 
+                "count": 0, 
+                "charts": {
+                    "years": [],
+                    "data": [],
+                    "plan": []
+                }
+            })
 
 
 class PlanNameAPIView(APIView):

+ 1 - 0
test

@@ -67,6 +67,7 @@
       "lc_controler": "https://openapi.lechange.cn/openapi/controlMovePTZ",
       "lc_modify_live_plan": "https://openapi.lechange.cn/openapi/modifyLivePlan",
       "lc_modify_live_plan_status": "https://openapi.lechange.cn/modifyLivePlanStatus", 
+      "lc_local_record": "https://openapi.lechange.cn/openapi/queryLocalRecords",
       "lc_kit_token": "https://openapi.lechange.cn/openapi/getKitToken", 
       "ys_open": "https://open.ys7.com/api/lapp/live/video/open",
       "ys_get": "https://open.ys7.com/api/lapp/live/address/get"