|
|
@@ -3,6 +3,8 @@ import logging
|
|
|
import datetime
|
|
|
from operator import itemgetter
|
|
|
from django.db.models import Q, Sum, Count
|
|
|
+from django.db.models.functions import Cast
|
|
|
+from djongo import models
|
|
|
from django.conf import settings
|
|
|
from rest_framework.views import APIView
|
|
|
from rest_framework.response import Response
|
|
|
@@ -20,6 +22,7 @@ from smartfarming.models.device import MongoDevice
|
|
|
from smartfarming.models.ascend import MongoBase
|
|
|
|
|
|
|
|
|
+
|
|
|
logger = logging.getLogger("myapp")
|
|
|
|
|
|
class LandPlanInfoAPIView(APIView):
|
|
|
@@ -39,7 +42,7 @@ class LandPlanInfoAPIView(APIView):
|
|
|
queryset = queryset.filter(addtime__gte=start_timestamp, addtime__lte=end_timestatmp)
|
|
|
if plan:
|
|
|
ids_lst = MongoPlantInfo.objects.filter(plantname__icontains=plan).values_list("id", flat=True)
|
|
|
- queryset = queryset.filter(plan_ids__in = ids_lst)
|
|
|
+ queryset = queryset.filter(id__in = ids_lst)
|
|
|
total_obj = queryset.count()
|
|
|
paginator = Paginator(queryset, page_size)
|
|
|
page_obj = paginator.get_page(page_num)
|
|
|
@@ -48,7 +51,7 @@ class LandPlanInfoAPIView(APIView):
|
|
|
# 获取最近5年年份列表
|
|
|
current_year = datetime.datetime.now().year
|
|
|
year_list = [year for year in range(current_year, current_year - 6, -1)]
|
|
|
- year_value = LandPlanInfo.objects.all().exclude(recovery_time=0).values_list("addtime", flat=True).order_by("-addtime")
|
|
|
+ year_value = LandPlanInfo.objects.all().exclude(recovery_time=0).values_list("recovery_time", flat=True).order_by("-recovery_time")
|
|
|
years = []
|
|
|
for year in year_value:
|
|
|
y = datetime.datetime.fromtimestamp(year).year
|
|
|
@@ -67,7 +70,8 @@ class LandPlanInfoAPIView(APIView):
|
|
|
end_timestatmp = datetime.datetime(i, 12,31,23,59).timestamp()
|
|
|
plan_totals = LandPlanInfo.objects.filter(
|
|
|
recovery_time__gte=start_timestamp,
|
|
|
- recovery_time__lte=end_timestatmp).exclude(recovery_time=0).values("plan_id").annotate(total=Sum("recovery_kg")).order_by("plan_id").values_list("plan_id", "total")
|
|
|
+ recovery_time__lte=end_timestatmp).exclude(recovery_time=0).values("plan_id").annotate(
|
|
|
+ total=Sum(Cast('recovery_kg', output_field=models.FloatField()))).order_by("plan_id").values_list("plan_id", "total")
|
|
|
# 作物 id:总质量
|
|
|
inners = {}
|
|
|
for k in plan_totals:
|