|
@@ -1,5 +1,5 @@
|
|
|
from django.core.paginator import Paginator
|
|
from django.core.paginator import Paginator
|
|
|
-import time
|
|
|
|
|
|
|
+import logging
|
|
|
import datetime
|
|
import datetime
|
|
|
from operator import itemgetter
|
|
from operator import itemgetter
|
|
|
from django.db.models import Q, Sum, Count
|
|
from django.db.models import Q, Sum, Count
|
|
@@ -20,6 +20,8 @@ from smartfarming.models.device import MongoDevice
|
|
|
from smartfarming.models.ascend import MongoBase
|
|
from smartfarming.models.ascend import MongoBase
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+logger = logging.getLogger("myapp")
|
|
|
|
|
+
|
|
|
class LandPlanInfoAPIView(APIView):
|
|
class LandPlanInfoAPIView(APIView):
|
|
|
|
|
|
|
|
def post(self, request):
|
|
def post(self, request):
|
|
@@ -118,6 +120,7 @@ class PlanNameAPIView(APIView):
|
|
|
plans = MongoPlantInfo.objects.filter(is_delete=1, id__in=plan_ids).values_list("plantname", flat=True).distinct()
|
|
plans = MongoPlantInfo.objects.filter(is_delete=1, id__in=plan_ids).values_list("plantname", flat=True).distinct()
|
|
|
return Response({"code": 0, "msg": "success", "data": plans})
|
|
return Response({"code": 0, "msg": "success", "data": plans})
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
|
|
|
+ logger.error(e)
|
|
|
return Response({"code": 0, "msg": "success", "data": []})
|
|
return Response({"code": 0, "msg": "success", "data": []})
|
|
|
|
|
|
|
|
|
|
|
|
@@ -125,24 +128,28 @@ class PlanAreaAPIView(APIView):
|
|
|
|
|
|
|
|
def post(self, request):
|
|
def post(self, request):
|
|
|
# 种植面积与作物个数统计
|
|
# 种植面积与作物个数统计
|
|
|
- land_plan_ids = LandPlanInfo.objects.filter(status="采收").filter(recovery_kg=0).values("land_id", "plan_id")
|
|
|
|
|
- plan_land = []
|
|
|
|
|
- plans = []
|
|
|
|
|
- plan_area = 0
|
|
|
|
|
- for i in land_plan_ids:
|
|
|
|
|
- landarea = MongoLandInfo.objects.get(id=i.get("land_id")).landarea
|
|
|
|
|
- plant = MongoPlantInfo.objects.get(id=i.get("plan_id"))
|
|
|
|
|
- plantname = f"{plant.plantname}({plant.planttype})"
|
|
|
|
|
- plan_land.append(
|
|
|
|
|
- {
|
|
|
|
|
- "name": plantname,
|
|
|
|
|
- "value": round(float(landarea), 2)
|
|
|
|
|
- }
|
|
|
|
|
- )
|
|
|
|
|
- plans.append(plantname) if plantname not in plans else None
|
|
|
|
|
- plan_area += round(float(landarea), 2)
|
|
|
|
|
- return Response({"code": 0, "msg": "success", "data": {"lands_area": round(plan_area, 2), "plans_count": len(plans), "p_list": plan_land}})
|
|
|
|
|
-
|
|
|
|
|
|
|
+ try:
|
|
|
|
|
+ land_plan_ids = LandPlanInfo.objects.filter(status="采收").filter(recovery_kg=0).values("land_id", "plan_id")
|
|
|
|
|
+ plan_land = []
|
|
|
|
|
+ plans = []
|
|
|
|
|
+ plan_area = 0
|
|
|
|
|
+ for i in land_plan_ids:
|
|
|
|
|
+ landarea = MongoLandInfo.objects.get(id=i.get("land_id")).landarea
|
|
|
|
|
+ plant = MongoPlantInfo.objects.get(id=i.get("plan_id"))
|
|
|
|
|
+ plantname = f"{plant.plantname}({plant.planttype})"
|
|
|
|
|
+ plan_land.append(
|
|
|
|
|
+ {
|
|
|
|
|
+ "name": plantname,
|
|
|
|
|
+ "value": round(float(landarea), 2)
|
|
|
|
|
+ }
|
|
|
|
|
+ )
|
|
|
|
|
+ plans.append(plantname) if plantname not in plans else None
|
|
|
|
|
+ plan_area += round(float(landarea), 2)
|
|
|
|
|
+ return Response({"code": 0, "msg": "success", "data": {"lands_area": round(plan_area, 2), "plans_count": len(plans), "p_list": plan_land}})
|
|
|
|
|
+ except Exception as e:
|
|
|
|
|
+ logger.error(e)
|
|
|
|
|
+ return Response({"code": 0, "msg": "请检查数据"})
|
|
|
|
|
+
|
|
|
|
|
|
|
|
class DeviceCountAPIView(APIView):
|
|
class DeviceCountAPIView(APIView):
|
|
|
|
|
|
|
@@ -194,6 +201,7 @@ class RecentPestCountAPIView(APIView):
|
|
|
result = {m[0]:m[1] for m in result[-10:]}
|
|
result = {m[0]:m[1] for m in result[-10:]}
|
|
|
return Response({"code": 0, "msg": "success", "data": result})
|
|
return Response({"code": 0, "msg": "success", "data": result})
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
|
|
|
+ logger.error(e)
|
|
|
return Response({"code": 2, "msg": "数据有误,请核查"})
|
|
return Response({"code": 2, "msg": "数据有误,请核查"})
|
|
|
|
|
|
|
|
|
|
|
|
@@ -239,7 +247,7 @@ class AlermNewsAPIView(APIView):
|
|
|
data.append(i)
|
|
data.append(i)
|
|
|
return Response({"code": 0,"msg":"success", "data": data})
|
|
return Response({"code": 0,"msg":"success", "data": data})
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
|
- print(e)
|
|
|
|
|
|
|
+ logger.error(e)
|
|
|
return Response({"code": 2, "msg": "获取数据失败"})
|
|
return Response({"code": 2, "msg": "获取数据失败"})
|
|
|
|
|
|
|
|
class APPAlarmAPIView(APIView):
|
|
class APPAlarmAPIView(APIView):
|
|
@@ -292,6 +300,7 @@ class QxzCameraUpdate(APIView):
|
|
|
ca_obj.save()
|
|
ca_obj.save()
|
|
|
return Response({"code": 0,"msg":"success"})
|
|
return Response({"code": 0,"msg":"success"})
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
|
|
|
+ logger.error(e)
|
|
|
return Response({"code": 2,"msg":"失败"})
|
|
return Response({"code": 2,"msg":"失败"})
|
|
|
|
|
|
|
|
|
|
|
|
@@ -299,8 +308,20 @@ class KeDongOverAPIView(APIView):
|
|
|
|
|
|
|
|
def post(self, request):
|
|
def post(self, request):
|
|
|
# 我的信息
|
|
# 我的信息
|
|
|
- country_count = CountryModel.objects.all().count()
|
|
|
|
|
- area = MongoBase.objects.all().first().base_area
|
|
|
|
|
- device = MongoDevice.objects.all().count()
|
|
|
|
|
- return Response({"code": 0,"msg":"success", "data": {"country_count": country_count, "area": area, "device": device}})
|
|
|
|
|
|
|
+ try:
|
|
|
|
|
+ country_count = CountryModel.objects.all().count()
|
|
|
|
|
+ area = MongoBase.objects.all().first().base_area
|
|
|
|
|
+ device = MongoDevice.objects.all().count()
|
|
|
|
|
+ return Response({
|
|
|
|
|
+ "code": 0,
|
|
|
|
|
+ "msg":"success",
|
|
|
|
|
+ "data": {
|
|
|
|
|
+ "country_count": country_count,
|
|
|
|
|
+ "area": area,
|
|
|
|
|
+ "device": device
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ except Exception as e:
|
|
|
|
|
+ logger.error(e)
|
|
|
|
|
+ return Response({"code": 2,"msg":"失败"})
|
|
|
|
|
|