|
@@ -74,10 +74,9 @@ class QxzDeviceDetailView(APIView):
|
|
|
serializer = DeviceDetailSerializer(data=request.query_params)
|
|
serializer = DeviceDetailSerializer(data=request.query_params)
|
|
|
serializer.is_valid(raise_exception=True)
|
|
serializer.is_valid(raise_exception=True)
|
|
|
request_data = serializer.validated_data
|
|
request_data = serializer.validated_data
|
|
|
- start_time, device_id = request_data["start_timestamp"], request_data["device_id"]
|
|
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
conf_wheres = {
|
|
conf_wheres = {
|
|
|
- "device_id":device_id,
|
|
|
|
|
|
|
+ "device_id":request_data["device_id"],
|
|
|
}
|
|
}
|
|
|
conf_m = MongoDBTools(db_name='smartfarming', table_name='sa_qxz_conf')
|
|
conf_m = MongoDBTools(db_name='smartfarming', table_name='sa_qxz_conf')
|
|
|
conf_data = conf_m.find_one(wheres=conf_wheres)
|
|
conf_data = conf_m.find_one(wheres=conf_wheres)
|
|
@@ -86,15 +85,25 @@ class QxzDeviceDetailView(APIView):
|
|
|
conf_data.pop("device_id")
|
|
conf_data.pop("device_id")
|
|
|
conf_data.pop("uptime")
|
|
conf_data.pop("uptime")
|
|
|
conf_data = dict(sorted(conf_data.items(), key=lambda e:int(e[0].split("e")[1])))
|
|
conf_data = dict(sorted(conf_data.items(), key=lambda e:int(e[0].split("e")[1])))
|
|
|
- result = {"conf":conf_data,"items":[]}
|
|
|
|
|
|
|
+ result = {"conf":conf_data,"total_counts":0,"items":[]}
|
|
|
|
|
|
|
|
data_m = MongoDBTools(db_name='smartfarming', table_name='sa_qxz_data')
|
|
data_m = MongoDBTools(db_name='smartfarming', table_name='sa_qxz_data')
|
|
|
- data_wheres = {
|
|
|
|
|
- "device_id": device_id,
|
|
|
|
|
- "uptime": {"$gt":start_time}
|
|
|
|
|
- }
|
|
|
|
|
- data = data_m.find_many(wheres=data_wheres)
|
|
|
|
|
-
|
|
|
|
|
|
|
+ if request_data["req"] == "new":
|
|
|
|
|
+ data_wheres = {
|
|
|
|
|
+ "device_id": request_data["device_id"]
|
|
|
|
|
+ }
|
|
|
|
|
+ data = data_m.find_many(wheres=data_wheres,skip=request_data["offset"],limit=request_data["page_size"])
|
|
|
|
|
+ else:
|
|
|
|
|
+ data_wheres = {
|
|
|
|
|
+ "device_id": request_data["device_id"],
|
|
|
|
|
+ "uptime": {
|
|
|
|
|
+ "$gt": request_data["start_timestamp"],
|
|
|
|
|
+ "$lte": request_data["end_timestamp"]
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ data = data_m.find_many(wheres=data_wheres,is_reverse=False,skip=(request_data["page"]-1)*request_data["page_size"],limit=request_data["page_size"])
|
|
|
|
|
+ total_counts = data.count()
|
|
|
|
|
+ result["total_counts"] = total_counts
|
|
|
for item in data:
|
|
for item in data:
|
|
|
item.pop("id")
|
|
item.pop("id")
|
|
|
item.pop("device_id")
|
|
item.pop("device_id")
|
|
@@ -153,12 +162,11 @@ class ScdDeviceDetailView(APIView):
|
|
|
serializer = DeviceDetailSerializer(data=request.query_params)
|
|
serializer = DeviceDetailSerializer(data=request.query_params)
|
|
|
serializer.is_valid(raise_exception=True)
|
|
serializer.is_valid(raise_exception=True)
|
|
|
request_data = serializer.validated_data
|
|
request_data = serializer.validated_data
|
|
|
- start_time, device_id = request_data["start_timestamp"], request_data["device_id"]
|
|
|
|
|
|
|
|
|
|
uid = request.user
|
|
uid = request.user
|
|
|
scd_dict_cache = default_cache.get(str(uid)+"_scd_list")
|
|
scd_dict_cache = default_cache.get(str(uid)+"_scd_list")
|
|
|
if scd_dict_cache:
|
|
if scd_dict_cache:
|
|
|
- d_id = scd_dict_cache[device_id]
|
|
|
|
|
|
|
+ d_id = scd_dict_cache[request_data["device_id"]]
|
|
|
else:
|
|
else:
|
|
|
"""避免缓存失效"""
|
|
"""避免缓存失效"""
|
|
|
wheres = {
|
|
wheres = {
|
|
@@ -178,27 +186,38 @@ class ScdDeviceDetailView(APIView):
|
|
|
for item in data:
|
|
for item in data:
|
|
|
scd_dict_cache[item["device_id"]]=item["id"]
|
|
scd_dict_cache[item["device_id"]]=item["id"]
|
|
|
default_cache.set(str(uid)+"_scd_list", scd_dict_cache,60*5)
|
|
default_cache.set(str(uid)+"_scd_list", scd_dict_cache,60*5)
|
|
|
- d_id = scd_dict_cache[device_id]
|
|
|
|
|
|
|
+ d_id = scd_dict_cache[request_data["device_id"]]
|
|
|
|
|
|
|
|
- result = []
|
|
|
|
|
-
|
|
|
|
|
- data_m = MongoDBTools(db_name='smartfarming', table_name='sa_device_scd_data')
|
|
|
|
|
- data_wheres = {
|
|
|
|
|
- "device_id": d_id,
|
|
|
|
|
- "addtime": {"$gt":start_time}
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ result = {"total_counts":0,"items":[]}
|
|
|
data_project = {
|
|
data_project = {
|
|
|
"addtime": "$addtime",
|
|
"addtime": "$addtime",
|
|
|
"device_data": "$device_data"
|
|
"device_data": "$device_data"
|
|
|
}
|
|
}
|
|
|
- data = data_m.find_many(wheres=data_wheres,options=data_project)
|
|
|
|
|
-
|
|
|
|
|
|
|
+ data_m = MongoDBTools(db_name='smartfarming', table_name='sa_device_scd_data')
|
|
|
|
|
+ if request_data["req"] == "new":
|
|
|
|
|
+ data_wheres = {
|
|
|
|
|
+ "device_id": d_id
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ data = data_m.find_many(wheres=data_wheres,options=data_project,skip=request_data["offset"],limit=request_data["page_size"])
|
|
|
|
|
+ else:
|
|
|
|
|
+ data_wheres = {
|
|
|
|
|
+ "device_id": d_id,
|
|
|
|
|
+ "addtime": {
|
|
|
|
|
+ "$gt": request_data["start_timestamp"],
|
|
|
|
|
+ "$lte": request_data["end_timestamp"]
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ data = data_m.find_many(wheres=data_wheres,options=data_project,is_reverse=False,skip=(request_data["page"]-1)*request_data["page_size"],limit=request_data["page_size"])
|
|
|
|
|
+ total_counts = data.count()
|
|
|
|
|
+ result["total_counts"] = total_counts
|
|
|
|
|
+
|
|
|
for item in data:
|
|
for item in data:
|
|
|
try:
|
|
try:
|
|
|
device_data = json.loads(item["device_data"])
|
|
device_data = json.loads(item["device_data"])
|
|
|
except:
|
|
except:
|
|
|
device_data = ast.literal_eval(item["device_data"])
|
|
device_data = ast.literal_eval(item["device_data"])
|
|
|
- result.append({"uptime":item["addtime"],"item_data":device_data})
|
|
|
|
|
|
|
+ result["items"].append({"uptime":item["addtime"],"item_data":device_data})
|
|
|
return Response(result)
|
|
return Response(result)
|
|
|
|
|
|
|
|
|
|
|
|
@@ -252,12 +271,11 @@ class CbdDeviceDetailView(APIView):
|
|
|
serializer = DeviceDetailSerializer(data=request.query_params)
|
|
serializer = DeviceDetailSerializer(data=request.query_params)
|
|
|
serializer.is_valid(raise_exception=True)
|
|
serializer.is_valid(raise_exception=True)
|
|
|
request_data = serializer.validated_data
|
|
request_data = serializer.validated_data
|
|
|
- start_time, device_id = request_data["start_timestamp"], request_data["device_id"]
|
|
|
|
|
|
|
|
|
|
uid = request.user
|
|
uid = request.user
|
|
|
cbd_dict_cache = default_cache.get(str(uid)+"_cbd_list")
|
|
cbd_dict_cache = default_cache.get(str(uid)+"_cbd_list")
|
|
|
if cbd_dict_cache:
|
|
if cbd_dict_cache:
|
|
|
- d_id = cbd_dict_cache[device_id]["d_id"]
|
|
|
|
|
|
|
+ d_id = cbd_dict_cache[request_data["device_id"]]["d_id"]
|
|
|
else:
|
|
else:
|
|
|
"""避免缓存失效"""
|
|
"""避免缓存失效"""
|
|
|
wheres = {
|
|
wheres = {
|
|
@@ -278,27 +296,39 @@ class CbdDeviceDetailView(APIView):
|
|
|
for item in data:
|
|
for item in data:
|
|
|
cbd_dict_cache[item["device_id"]]={"d_id":item["id"],"disable":item["disable"]}
|
|
cbd_dict_cache[item["device_id"]]={"d_id":item["id"],"disable":item["disable"]}
|
|
|
default_cache.set(str(uid)+"_cbd_list", cbd_dict_cache,60*5)
|
|
default_cache.set(str(uid)+"_cbd_list", cbd_dict_cache,60*5)
|
|
|
- d_id = cbd_dict_cache[device_id]["d_id"]
|
|
|
|
|
|
|
+ d_id = cbd_dict_cache[request_data["device_id"]]["d_id"]
|
|
|
|
|
|
|
|
- result = []
|
|
|
|
|
|
|
+ result = {"total_counts":0,"items":[]}
|
|
|
|
|
|
|
|
data_m = MongoDBTools(db_name='smartfarming', table_name='sa_device_cbd_data')
|
|
data_m = MongoDBTools(db_name='smartfarming', table_name='sa_device_cbd_data')
|
|
|
- data_wheres = {
|
|
|
|
|
- "device_id": d_id,
|
|
|
|
|
- "addtime": {"$gt":start_time}
|
|
|
|
|
- }
|
|
|
|
|
|
|
+
|
|
|
data_project = {
|
|
data_project = {
|
|
|
"addtime": "$addtime",
|
|
"addtime": "$addtime",
|
|
|
"device_data": "$device_data"
|
|
"device_data": "$device_data"
|
|
|
}
|
|
}
|
|
|
- data = data_m.find_many(wheres=data_wheres,options=data_project)
|
|
|
|
|
|
|
+ if request_data["req"] == "new":
|
|
|
|
|
+ data_wheres = {
|
|
|
|
|
+ "device_id": d_id
|
|
|
|
|
+ }
|
|
|
|
|
+ data = data_m.find_many(wheres=data_wheres,options=data_project,skip=request_data["offset"],limit=request_data["page_size"])
|
|
|
|
|
+ else:
|
|
|
|
|
+ data_wheres = {
|
|
|
|
|
+ "device_id": d_id,
|
|
|
|
|
+ "addtime": {
|
|
|
|
|
+ "$gt": request_data["start_timestamp"],
|
|
|
|
|
+ "$lte": request_data["end_timestamp"]
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ data = data_m.find_many(wheres=data_wheres,options=data_project,is_reverse=False,skip=(request_data["page"]-1)*request_data["page_size"],limit=request_data["page_size"])
|
|
|
|
|
+ total_counts = data.count()
|
|
|
|
|
+ result["total_counts"] = total_counts
|
|
|
|
|
|
|
|
for item in data:
|
|
for item in data:
|
|
|
try:
|
|
try:
|
|
|
device_data = json.loads(item["device_data"])
|
|
device_data = json.loads(item["device_data"])
|
|
|
except:
|
|
except:
|
|
|
device_data = ast.literal_eval(item["device_data"])
|
|
device_data = ast.literal_eval(item["device_data"])
|
|
|
- result.append({"uptime":item["addtime"],"item_data":device_data})
|
|
|
|
|
|
|
+ result["items"].append({"uptime":item["addtime"],"item_data":device_data})
|
|
|
return Response(result)
|
|
return Response(result)
|
|
|
|
|
|
|
|
|
|
|
|
@@ -311,13 +341,12 @@ class CbdDevicePhotoView(APIView):
|
|
|
serializer = DeviceDetailSerializer(data=request.query_params)
|
|
serializer = DeviceDetailSerializer(data=request.query_params)
|
|
|
serializer.is_valid(raise_exception=True)
|
|
serializer.is_valid(raise_exception=True)
|
|
|
request_data = serializer.validated_data
|
|
request_data = serializer.validated_data
|
|
|
- start_time, device_id = request_data["start_timestamp"], request_data["device_id"]
|
|
|
|
|
|
|
|
|
|
uid = request.user
|
|
uid = request.user
|
|
|
cbd_dict_cache = default_cache.get(str(uid)+"_cbd_list")
|
|
cbd_dict_cache = default_cache.get(str(uid)+"_cbd_list")
|
|
|
if cbd_dict_cache:
|
|
if cbd_dict_cache:
|
|
|
- d_id = cbd_dict_cache[device_id]["d_id"]
|
|
|
|
|
- disable = cbd_dict_cache[device_id]["disable"]
|
|
|
|
|
|
|
+ d_id = cbd_dict_cache[request_data["device_id"]]["d_id"]
|
|
|
|
|
+ disable = cbd_dict_cache[request_data["device_id"]]["disable"]
|
|
|
else:
|
|
else:
|
|
|
"""避免缓存失效"""
|
|
"""避免缓存失效"""
|
|
|
wheres = {
|
|
wheres = {
|
|
@@ -338,15 +367,11 @@ class CbdDevicePhotoView(APIView):
|
|
|
for item in data:
|
|
for item in data:
|
|
|
cbd_dict_cache[item["device_id"]]={"d_id":item["id"],"disable":item["disable"]}
|
|
cbd_dict_cache[item["device_id"]]={"d_id":item["id"],"disable":item["disable"]}
|
|
|
default_cache.set(str(uid)+"_cbd_list", cbd_dict_cache,60*5)
|
|
default_cache.set(str(uid)+"_cbd_list", cbd_dict_cache,60*5)
|
|
|
- d_id = cbd_dict_cache[device_id]["d_id"]
|
|
|
|
|
- disable = cbd_dict_cache[device_id]["disable"]
|
|
|
|
|
|
|
+ d_id = cbd_dict_cache[request_data["device_id"]]["d_id"]
|
|
|
|
|
+ disable = cbd_dict_cache[request_data["device_id"]]["disable"]
|
|
|
|
|
|
|
|
- result = []
|
|
|
|
|
|
|
+ result = {"total_counts":0,"items":[]}
|
|
|
data_m = MongoDBTools(db_name='smartfarming', table_name='sa_device_cbdphoto')
|
|
data_m = MongoDBTools(db_name='smartfarming', table_name='sa_device_cbdphoto')
|
|
|
- data_wheres = {
|
|
|
|
|
- "device_id": str(d_id),
|
|
|
|
|
- "addtime": {"$gt":start_time}
|
|
|
|
|
- }
|
|
|
|
|
if disable == 1:
|
|
if disable == 1:
|
|
|
data_project = {
|
|
data_project = {
|
|
|
"addtime": "$addtime",
|
|
"addtime": "$addtime",
|
|
@@ -359,7 +384,23 @@ class CbdDevicePhotoView(APIView):
|
|
|
"addtime": "$addtime",
|
|
"addtime": "$addtime",
|
|
|
"addr": "$addr"
|
|
"addr": "$addr"
|
|
|
}
|
|
}
|
|
|
- data = data_m.find_many(wheres=data_wheres,options=data_project)
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if request_data["req"] == "new":
|
|
|
|
|
+ data_wheres = {
|
|
|
|
|
+ "device_id": str(d_id)
|
|
|
|
|
+ }
|
|
|
|
|
+ data = data_m.find_many(wheres=data_wheres,options=data_project,skip=request_data["offset"],limit=request_data["page_size"])
|
|
|
|
|
+ else:
|
|
|
|
|
+ data_wheres = {
|
|
|
|
|
+ "device_id": str(d_id),
|
|
|
|
|
+ "addtime": {
|
|
|
|
|
+ "$gt": request_data["start_timestamp"],
|
|
|
|
|
+ "$lte": request_data["end_timestamp"]
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ data = data_m.find_many(wheres=data_wheres,options=data_project,is_reverse=False,skip=(request_data["page"]-1)*request_data["page_size"],limit=request_data["page_size"])
|
|
|
|
|
+ total_counts = data.count()
|
|
|
|
|
+ result["total_counts"] = total_counts
|
|
|
for item in data:
|
|
for item in data:
|
|
|
item_data = {}
|
|
item_data = {}
|
|
|
addr = item["addr"]
|
|
addr = item["addr"]
|
|
@@ -386,7 +427,7 @@ class CbdDevicePhotoView(APIView):
|
|
|
item_data["Result_image"] = Result_image
|
|
item_data["Result_image"] = Result_image
|
|
|
item_data["Result"] = Result
|
|
item_data["Result"] = Result
|
|
|
|
|
|
|
|
- result.append(item_data)
|
|
|
|
|
|
|
+ result["items"].append(item_data)
|
|
|
return Response(result)
|
|
return Response(result)
|
|
|
|
|
|
|
|
|
|
|
|
@@ -438,12 +479,11 @@ class BzyDeviceDetailView(APIView):
|
|
|
serializer = DeviceDetailSerializer(data=request.query_params)
|
|
serializer = DeviceDetailSerializer(data=request.query_params)
|
|
|
serializer.is_valid(raise_exception=True)
|
|
serializer.is_valid(raise_exception=True)
|
|
|
request_data = serializer.validated_data
|
|
request_data = serializer.validated_data
|
|
|
- start_time, device_id = request_data["start_timestamp"], request_data["device_id"]
|
|
|
|
|
|
|
|
|
|
uid = request.user
|
|
uid = request.user
|
|
|
bzy_dict_cache = default_cache.get(str(uid)+"_bzy_list")
|
|
bzy_dict_cache = default_cache.get(str(uid)+"_bzy_list")
|
|
|
if bzy_dict_cache:
|
|
if bzy_dict_cache:
|
|
|
- d_id = bzy_dict_cache[device_id]
|
|
|
|
|
|
|
+ d_id = bzy_dict_cache[request_data["device_id"]]
|
|
|
else:
|
|
else:
|
|
|
"""避免缓存失效"""
|
|
"""避免缓存失效"""
|
|
|
wheres = {
|
|
wheres = {
|
|
@@ -463,27 +503,39 @@ class BzyDeviceDetailView(APIView):
|
|
|
for item in data:
|
|
for item in data:
|
|
|
bzy_dict_cache[item["device_id"]]=item["id"]
|
|
bzy_dict_cache[item["device_id"]]=item["id"]
|
|
|
default_cache.set(str(uid)+"_bzy_list", bzy_dict_cache,60*5)
|
|
default_cache.set(str(uid)+"_bzy_list", bzy_dict_cache,60*5)
|
|
|
- d_id = bzy_dict_cache[device_id]
|
|
|
|
|
|
|
+ d_id = bzy_dict_cache[request_data["device_id"]]
|
|
|
|
|
|
|
|
- result = []
|
|
|
|
|
|
|
+ result = {"total_counts":0,"items":[]}
|
|
|
|
|
|
|
|
data_m = MongoDBTools(db_name='smartfarming', table_name='sa_device_bzy_data')
|
|
data_m = MongoDBTools(db_name='smartfarming', table_name='sa_device_bzy_data')
|
|
|
- data_wheres = {
|
|
|
|
|
- "device_id": d_id,
|
|
|
|
|
- "addtime": {"$gt":start_time}
|
|
|
|
|
- }
|
|
|
|
|
data_project = {
|
|
data_project = {
|
|
|
"addtime": "$addtime",
|
|
"addtime": "$addtime",
|
|
|
"device_data": "$device_data"
|
|
"device_data": "$device_data"
|
|
|
}
|
|
}
|
|
|
- data = data_m.find_many(wheres=data_wheres,options=data_project)
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if request_data["req"] == "new":
|
|
|
|
|
+ data_wheres = {
|
|
|
|
|
+ "device_id": d_id
|
|
|
|
|
+ }
|
|
|
|
|
+ data = data_m.find_many(wheres=data_wheres,options=data_project,skip=request_data["offset"],limit=request_data["page_size"])
|
|
|
|
|
+ else:
|
|
|
|
|
+ data_wheres = {
|
|
|
|
|
+ "device_id": d_id,
|
|
|
|
|
+ "addtime": {
|
|
|
|
|
+ "$gt": request_data["start_timestamp"],
|
|
|
|
|
+ "$lte": request_data["end_timestamp"]
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ data = data_m.find_many(wheres=data_wheres,options=data_project,is_reverse=False,skip=(request_data["page"]-1)*request_data["page_size"],limit=request_data["page_size"])
|
|
|
|
|
+ total_counts = data.count()
|
|
|
|
|
+ result["total_counts"] = total_counts
|
|
|
|
|
|
|
|
for item in data:
|
|
for item in data:
|
|
|
try:
|
|
try:
|
|
|
device_data = json.loads(item["device_data"])
|
|
device_data = json.loads(item["device_data"])
|
|
|
except:
|
|
except:
|
|
|
device_data = ast.literal_eval(item["device_data"])
|
|
device_data = ast.literal_eval(item["device_data"])
|
|
|
- result.append({"uptime":item["addtime"],"item_data":device_data})
|
|
|
|
|
|
|
+ result["items"].append({"uptime":item["addtime"],"item_data":device_data})
|
|
|
return Response(result)
|
|
return Response(result)
|
|
|
|
|
|
|
|
|
|
|
|
@@ -496,12 +548,11 @@ class BzyDevicePhotoView(APIView):
|
|
|
serializer = DeviceDetailSerializer(data=request.query_params)
|
|
serializer = DeviceDetailSerializer(data=request.query_params)
|
|
|
serializer.is_valid(raise_exception=True)
|
|
serializer.is_valid(raise_exception=True)
|
|
|
request_data = serializer.validated_data
|
|
request_data = serializer.validated_data
|
|
|
- start_time, device_id = request_data["start_timestamp"], request_data["device_id"]
|
|
|
|
|
|
|
|
|
|
uid = request.user
|
|
uid = request.user
|
|
|
bzy_dict_cache = default_cache.get(str(uid)+"_bzy_list")
|
|
bzy_dict_cache = default_cache.get(str(uid)+"_bzy_list")
|
|
|
if bzy_dict_cache:
|
|
if bzy_dict_cache:
|
|
|
- d_id = bzy_dict_cache[device_id]
|
|
|
|
|
|
|
+ d_id = bzy_dict_cache[request_data["device_id"]]
|
|
|
else:
|
|
else:
|
|
|
"""避免缓存失效"""
|
|
"""避免缓存失效"""
|
|
|
wheres = {
|
|
wheres = {
|
|
@@ -521,20 +572,31 @@ class BzyDevicePhotoView(APIView):
|
|
|
for item in data:
|
|
for item in data:
|
|
|
bzy_dict_cache[item["device_id"]]=item["id"]
|
|
bzy_dict_cache[item["device_id"]]=item["id"]
|
|
|
default_cache.set(str(uid)+"_bzy_list", bzy_dict_cache,60*5)
|
|
default_cache.set(str(uid)+"_bzy_list", bzy_dict_cache,60*5)
|
|
|
- d_id = bzy_dict_cache[device_id]
|
|
|
|
|
|
|
+ d_id = bzy_dict_cache[request_data["device_id"]]
|
|
|
|
|
|
|
|
- result = []
|
|
|
|
|
|
|
+ result = {"total_counts":0,"items":[]}
|
|
|
|
|
|
|
|
data_m = MongoDBTools(db_name='smartfarming', table_name='sa_device_bzyphoto')
|
|
data_m = MongoDBTools(db_name='smartfarming', table_name='sa_device_bzyphoto')
|
|
|
- data_wheres = {
|
|
|
|
|
- "device_id": str(d_id),
|
|
|
|
|
- "addtime": {"$gt":start_time}
|
|
|
|
|
- }
|
|
|
|
|
data_project = {
|
|
data_project = {
|
|
|
"addtime": "$addtime",
|
|
"addtime": "$addtime",
|
|
|
"addr": "$addr"
|
|
"addr": "$addr"
|
|
|
}
|
|
}
|
|
|
- data = data_m.find_many(wheres=data_wheres,options=data_project)
|
|
|
|
|
|
|
+ if request_data["req"] == "new":
|
|
|
|
|
+ data_wheres = {
|
|
|
|
|
+ "device_id": str(d_id)
|
|
|
|
|
+ }
|
|
|
|
|
+ data = data_m.find_many(wheres=data_wheres,options=data_project,skip=request_data["offset"],limit=request_data["page_size"])
|
|
|
|
|
+ else:
|
|
|
|
|
+ data_wheres = {
|
|
|
|
|
+ "device_id": str(d_id),
|
|
|
|
|
+ "addtime": {
|
|
|
|
|
+ "$gt": request_data["start_timestamp"],
|
|
|
|
|
+ "$lte": request_data["end_timestamp"]
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ data = data_m.find_many(wheres=data_wheres,options=data_project,is_reverse=False,skip=(request_data["page"]-1)*request_data["page_size"],limit=request_data["page_size"])
|
|
|
|
|
+ total_counts = data.count()
|
|
|
|
|
+ result["total_counts"] = total_counts
|
|
|
|
|
|
|
|
for item in data:
|
|
for item in data:
|
|
|
if item["addr"].startswith("http"):
|
|
if item["addr"].startswith("http"):
|
|
@@ -544,7 +606,7 @@ class BzyDevicePhotoView(APIView):
|
|
|
else:
|
|
else:
|
|
|
Image = settings.CONFIG["image_url"]["bzy_img_forward"] + "/" + item["addr"]
|
|
Image = settings.CONFIG["image_url"]["bzy_img_forward"] + "/" + item["addr"]
|
|
|
|
|
|
|
|
- result.append({"uptime":item["addtime"],"Image":Image})
|
|
|
|
|
|
|
+ result["items"].append({"uptime":item["addtime"],"Image":Image})
|
|
|
return Response(result)
|
|
return Response(result)
|
|
|
|
|
|
|
|
|
|
|
|
@@ -596,12 +658,11 @@ class XycbDeviceDetailView(APIView):
|
|
|
serializer = DeviceDetailSerializer(data=request.query_params)
|
|
serializer = DeviceDetailSerializer(data=request.query_params)
|
|
|
serializer.is_valid(raise_exception=True)
|
|
serializer.is_valid(raise_exception=True)
|
|
|
request_data = serializer.validated_data
|
|
request_data = serializer.validated_data
|
|
|
- start_time, device_id = request_data["start_timestamp"], request_data["device_id"]
|
|
|
|
|
|
|
|
|
|
uid = request.user
|
|
uid = request.user
|
|
|
xycb_dict_cache = default_cache.get(str(uid)+"_xycb_list")
|
|
xycb_dict_cache = default_cache.get(str(uid)+"_xycb_list")
|
|
|
if xycb_dict_cache:
|
|
if xycb_dict_cache:
|
|
|
- d_id = xycb_dict_cache[device_id]
|
|
|
|
|
|
|
+ d_id = xycb_dict_cache[request_data["device_id"]]
|
|
|
else:
|
|
else:
|
|
|
"""避免缓存失效"""
|
|
"""避免缓存失效"""
|
|
|
wheres = {
|
|
wheres = {
|
|
@@ -621,27 +682,39 @@ class XycbDeviceDetailView(APIView):
|
|
|
for item in data:
|
|
for item in data:
|
|
|
xycb_dict_cache[item["device_id"]]=item["id"]
|
|
xycb_dict_cache[item["device_id"]]=item["id"]
|
|
|
default_cache.set(str(uid)+"_scd_list", xycb_dict_cache,60*5)
|
|
default_cache.set(str(uid)+"_scd_list", xycb_dict_cache,60*5)
|
|
|
- d_id = xycb_dict_cache[device_id]
|
|
|
|
|
|
|
+ d_id = xycb_dict_cache[request_data["device_id"]]
|
|
|
|
|
|
|
|
- result = []
|
|
|
|
|
|
|
+ result = {"total_counts":0,"items":[]}
|
|
|
|
|
|
|
|
data_m = MongoDBTools(db_name='smartfarming', table_name='sa_device_xycb_data')
|
|
data_m = MongoDBTools(db_name='smartfarming', table_name='sa_device_xycb_data')
|
|
|
- data_wheres = {
|
|
|
|
|
- "device_id": d_id,
|
|
|
|
|
- "addtime": {"$gt":start_time}
|
|
|
|
|
- }
|
|
|
|
|
data_project = {
|
|
data_project = {
|
|
|
"addtime": "$addtime",
|
|
"addtime": "$addtime",
|
|
|
"device_data": "$device_data"
|
|
"device_data": "$device_data"
|
|
|
}
|
|
}
|
|
|
- data = data_m.find_many(wheres=data_wheres,options=data_project)
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if request_data["req"] == "new":
|
|
|
|
|
+ data_wheres = {
|
|
|
|
|
+ "device_id": d_id
|
|
|
|
|
+ }
|
|
|
|
|
+ data = data_m.find_many(wheres=data_wheres,options=data_project,skip=request_data["offset"],limit=request_data["page_size"])
|
|
|
|
|
+ else:
|
|
|
|
|
+ data_wheres = {
|
|
|
|
|
+ "device_id": d_id,
|
|
|
|
|
+ "addtime": {
|
|
|
|
|
+ "$gt": request_data["start_timestamp"],
|
|
|
|
|
+ "$lte": request_data["end_timestamp"]
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ data = data_m.find_many(wheres=data_wheres,options=data_project,is_reverse=False,skip=(request_data["page"]-1)*request_data["page_size"],limit=request_data["page_size"])
|
|
|
|
|
+ total_counts = data.count()
|
|
|
|
|
+ result["total_counts"] = total_counts
|
|
|
|
|
|
|
|
for item in data:
|
|
for item in data:
|
|
|
try:
|
|
try:
|
|
|
device_data = json.loads(item["device_data"])
|
|
device_data = json.loads(item["device_data"])
|
|
|
except:
|
|
except:
|
|
|
device_data = ast.literal_eval(item["device_data"])
|
|
device_data = ast.literal_eval(item["device_data"])
|
|
|
- result.append({"uptime":item["addtime"],"item_data":device_data})
|
|
|
|
|
|
|
+ result["items"].append({"uptime":item["addtime"],"item_data":device_data})
|
|
|
return Response(result)
|
|
return Response(result)
|
|
|
|
|
|
|
|
|
|
|
|
@@ -693,12 +766,11 @@ class XctDeviceDetailView(APIView):
|
|
|
serializer = DeviceDetailSerializer(data=request.query_params)
|
|
serializer = DeviceDetailSerializer(data=request.query_params)
|
|
|
serializer.is_valid(raise_exception=True)
|
|
serializer.is_valid(raise_exception=True)
|
|
|
request_data = serializer.validated_data
|
|
request_data = serializer.validated_data
|
|
|
- start_time, device_id = request_data["start_timestamp"], request_data["device_id"]
|
|
|
|
|
|
|
|
|
|
uid = request.user
|
|
uid = request.user
|
|
|
xct_dict_cache = default_cache.get(str(uid)+"_xct_list")
|
|
xct_dict_cache = default_cache.get(str(uid)+"_xct_list")
|
|
|
if xct_dict_cache:
|
|
if xct_dict_cache:
|
|
|
- d_id = xct_dict_cache[device_id]
|
|
|
|
|
|
|
+ d_id = xct_dict_cache[request_data["device_id"]]
|
|
|
else:
|
|
else:
|
|
|
"""避免缓存失效"""
|
|
"""避免缓存失效"""
|
|
|
wheres = {
|
|
wheres = {
|
|
@@ -718,27 +790,39 @@ class XctDeviceDetailView(APIView):
|
|
|
for item in data:
|
|
for item in data:
|
|
|
xct_dict_cache[item["device_id"]]=item["id"]
|
|
xct_dict_cache[item["device_id"]]=item["id"]
|
|
|
default_cache.set(str(uid)+"_xct_list", xct_dict_cache,60*5)
|
|
default_cache.set(str(uid)+"_xct_list", xct_dict_cache,60*5)
|
|
|
- d_id = xct_dict_cache[device_id]
|
|
|
|
|
|
|
+ d_id = xct_dict_cache[request_data["device_id"]]
|
|
|
|
|
|
|
|
- result = []
|
|
|
|
|
|
|
+ result = {"total_counts":0,"items":[]}
|
|
|
|
|
|
|
|
data_m = MongoDBTools(db_name='smartfarming', table_name='sa_device_xct_data')
|
|
data_m = MongoDBTools(db_name='smartfarming', table_name='sa_device_xct_data')
|
|
|
- data_wheres = {
|
|
|
|
|
- "device_id": d_id,
|
|
|
|
|
- "addtime": {"$gt":start_time}
|
|
|
|
|
- }
|
|
|
|
|
data_project = {
|
|
data_project = {
|
|
|
"addtime": "$addtime",
|
|
"addtime": "$addtime",
|
|
|
"device_data": "$device_data"
|
|
"device_data": "$device_data"
|
|
|
}
|
|
}
|
|
|
- data = data_m.find_many(wheres=data_wheres,options=data_project)
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if request_data["req"] == "new":
|
|
|
|
|
+ data_wheres = {
|
|
|
|
|
+ "device_id": d_id
|
|
|
|
|
+ }
|
|
|
|
|
+ data = data_m.find_many(wheres=data_wheres,options=data_project,skip=request_data["offset"],limit=request_data["page_size"])
|
|
|
|
|
+ else:
|
|
|
|
|
+ data_wheres = {
|
|
|
|
|
+ "device_id": d_id,
|
|
|
|
|
+ "addtime": {
|
|
|
|
|
+ "$gt": request_data["start_timestamp"],
|
|
|
|
|
+ "$lte": request_data["end_timestamp"]
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ data = data_m.find_many(wheres=data_wheres,options=data_project,is_reverse=False,skip=(request_data["page"]-1)*request_data["page_size"],limit=request_data["page_size"])
|
|
|
|
|
+ total_counts = data.count()
|
|
|
|
|
+ result["total_counts"] = total_counts
|
|
|
|
|
|
|
|
for item in data:
|
|
for item in data:
|
|
|
try:
|
|
try:
|
|
|
device_data = json.loads(item["device_data"])
|
|
device_data = json.loads(item["device_data"])
|
|
|
except:
|
|
except:
|
|
|
device_data = ast.literal_eval(item["device_data"])
|
|
device_data = ast.literal_eval(item["device_data"])
|
|
|
- result.append({"uptime":item["addtime"],"item_data":device_data})
|
|
|
|
|
|
|
+ result["items"].append({"uptime":item["addtime"],"item_data":device_data})
|
|
|
return Response(result)
|
|
return Response(result)
|
|
|
|
|
|
|
|
|
|
|
|
@@ -751,12 +835,11 @@ class XctDevicePhotoView(APIView):
|
|
|
serializer = DeviceDetailSerializer(data=request.query_params)
|
|
serializer = DeviceDetailSerializer(data=request.query_params)
|
|
|
serializer.is_valid(raise_exception=True)
|
|
serializer.is_valid(raise_exception=True)
|
|
|
request_data = serializer.validated_data
|
|
request_data = serializer.validated_data
|
|
|
- start_time, device_id = request_data["start_timestamp"], request_data["device_id"]
|
|
|
|
|
|
|
|
|
|
uid = request.user
|
|
uid = request.user
|
|
|
xct_dict_cache = default_cache.get(str(uid)+"_xct_list")
|
|
xct_dict_cache = default_cache.get(str(uid)+"_xct_list")
|
|
|
if xct_dict_cache:
|
|
if xct_dict_cache:
|
|
|
- d_id = xct_dict_cache[device_id]
|
|
|
|
|
|
|
+ d_id = xct_dict_cache[request_data["device_id"]]
|
|
|
else:
|
|
else:
|
|
|
"""避免缓存失效"""
|
|
"""避免缓存失效"""
|
|
|
wheres = {
|
|
wheres = {
|
|
@@ -776,22 +859,33 @@ class XctDevicePhotoView(APIView):
|
|
|
for item in data:
|
|
for item in data:
|
|
|
xct_dict_cache[item["device_id"]]=item["id"]
|
|
xct_dict_cache[item["device_id"]]=item["id"]
|
|
|
default_cache.set(str(uid)+"_xct_list", xct_dict_cache,60*5)
|
|
default_cache.set(str(uid)+"_xct_list", xct_dict_cache,60*5)
|
|
|
- d_id = xct_dict_cache[device_id]
|
|
|
|
|
|
|
+ d_id = xct_dict_cache[request_data["device_id"]]
|
|
|
|
|
|
|
|
- result = []
|
|
|
|
|
|
|
+ result = {"total_counts":0,"itmes":[]}
|
|
|
|
|
|
|
|
data_m = MongoDBTools(db_name='smartfarming', table_name='sa_device_xct_photo')
|
|
data_m = MongoDBTools(db_name='smartfarming', table_name='sa_device_xct_photo')
|
|
|
- data_wheres = {
|
|
|
|
|
- "device_id": str(d_id),
|
|
|
|
|
- "addtime": {"$gt":start_time}
|
|
|
|
|
- }
|
|
|
|
|
data_project = {
|
|
data_project = {
|
|
|
"addtime": "$addtime",
|
|
"addtime": "$addtime",
|
|
|
"addr": "$addr",
|
|
"addr": "$addr",
|
|
|
"indentify_photo":"$indentify_photo",
|
|
"indentify_photo":"$indentify_photo",
|
|
|
"indentify_result":"$indentify_result"
|
|
"indentify_result":"$indentify_result"
|
|
|
}
|
|
}
|
|
|
- data = data_m.find_many(wheres=data_wheres,options=data_project)
|
|
|
|
|
|
|
+ if request_data["req"] == "new":
|
|
|
|
|
+ data_wheres = {
|
|
|
|
|
+ "device_id": str(d_id)
|
|
|
|
|
+ }
|
|
|
|
|
+ data = data_m.find_many(wheres=data_wheres,options=data_project,skip=request_data["offset"],limit=request_data["page_size"])
|
|
|
|
|
+ else:
|
|
|
|
|
+ data_wheres = {
|
|
|
|
|
+ "device_id": str(d_id),
|
|
|
|
|
+ "addtime": {
|
|
|
|
|
+ "$gt": request_data["start_timestamp"],
|
|
|
|
|
+ "$lte": request_data["end_timestamp"]
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ data = data_m.find_many(wheres=data_wheres,options=data_project,is_reverse=False,skip=(request_data["page"]-1)*request_data["page_size"],limit=request_data["page_size"])
|
|
|
|
|
+ total_counts = data.count()
|
|
|
|
|
+ result["total_counts"] = total_counts
|
|
|
|
|
|
|
|
for item in data:
|
|
for item in data:
|
|
|
if item["addr"].startswith("http"):
|
|
if item["addr"].startswith("http"):
|
|
@@ -814,5 +908,5 @@ class XctDevicePhotoView(APIView):
|
|
|
Result_image = settings.CONFIG["image_url"]["xct_img_result_forward"] + "/" + indentify_photo
|
|
Result_image = settings.CONFIG["image_url"]["xct_img_result_forward"] + "/" + indentify_photo
|
|
|
else:
|
|
else:
|
|
|
Result_image = "0"
|
|
Result_image = "0"
|
|
|
- result.append({"uptime":item["addtime"],"Image":Image,"Result_image":Result_image,"Result":Result})
|
|
|
|
|
|
|
+ result["itmes"].append({"uptime":item["addtime"],"Image":Image,"Result_image":Result_image,"Result":Result})
|
|
|
return Response(result)
|
|
return Response(result)
|