|
|
@@ -55,7 +55,7 @@ class CbdScdXyDeviceSaveAPIView(APIView):
|
|
|
model = MongoSCDData
|
|
|
elif device_type_id == 3:
|
|
|
model = MongoCBDData
|
|
|
- elif device_type_id == 8:
|
|
|
+ elif device_type_id == 4:
|
|
|
model = MongoXYCBData
|
|
|
# 在设备信息表中查找是否有数据,如果没有数据则增加
|
|
|
device_name = device_type_zh.get(str(device_type_id))
|
|
|
@@ -64,19 +64,26 @@ class CbdScdXyDeviceSaveAPIView(APIView):
|
|
|
defaults={
|
|
|
"device_id": device_id,
|
|
|
"device_type_id": device_type_id,
|
|
|
- "device_name": device_name,
|
|
|
"addtime": now
|
|
|
}
|
|
|
)
|
|
|
if is_created:
|
|
|
- logger.info(f"{device_type} 设备 {device_id} 入库成功")
|
|
|
+ device.device_name = device_name
|
|
|
+ device.save()
|
|
|
+ logger.warning(f"新设备:{device_type} {device_id} 入库成功")
|
|
|
# 获取数据并更新设备
|
|
|
if cmd == "data":
|
|
|
ext = payload.get("ext")
|
|
|
if ext:
|
|
|
+ # 获取设备上报的时间,同步设备
|
|
|
+ try:
|
|
|
+ stamp = ext.get("stamp")
|
|
|
+ uptime = int((datetime.datetime.strptime(stamp, "%Y%m%d%H%M%S")).timestamp())
|
|
|
+ except Exception as e:
|
|
|
+ logger.error(f"同步设备时间失败:{device_id} {e}")
|
|
|
# 增加设备数据
|
|
|
model.objects.create(
|
|
|
- device_id = device_id,
|
|
|
+ device_id = device.id,
|
|
|
device_data = str(ext),
|
|
|
addtime = now
|
|
|
)
|
|
|
@@ -84,10 +91,10 @@ class CbdScdXyDeviceSaveAPIView(APIView):
|
|
|
lat = ext.get("lat")
|
|
|
dver_num = ext.get("dver")
|
|
|
device.device_status = 1
|
|
|
- device.uptime = now
|
|
|
+ device.uptime = uptime
|
|
|
if dver_num:
|
|
|
device.dver_num = dver_num
|
|
|
- if lng and lat and dver_num:
|
|
|
+ if lng and lat and dver_num and device.gps != 0:
|
|
|
device.lng = lng
|
|
|
device.lat = lat
|
|
|
# 根据经纬度获取省市级
|