update
This commit is contained in:
parent
a0af0c1ab1
commit
154e539d13
22
xumu.py
22
xumu.py
|
@ -25,6 +25,7 @@ class BaseResponse(BaseModel):
|
||||||
async def video_query(username):
|
async def video_query(username):
|
||||||
return BaseResponse(data=get_video_url(username))
|
return BaseResponse(data=get_video_url(username))
|
||||||
|
|
||||||
|
|
||||||
@app.get("/api/xumu/warning")
|
@app.get("/api/xumu/warning")
|
||||||
async def get_warning(deviceId):
|
async def get_warning(deviceId):
|
||||||
try:
|
try:
|
||||||
|
@ -38,6 +39,7 @@ async def get_warning(deviceId):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return BaseResponse(code=500, msg=str(e))
|
return BaseResponse(code=500, msg=str(e))
|
||||||
|
|
||||||
|
|
||||||
@app.get("/api/xumu/device/online")
|
@app.get("/api/xumu/device/online")
|
||||||
async def device_online_query(iccid, deviceId):
|
async def device_online_query(iccid, deviceId):
|
||||||
try:
|
try:
|
||||||
|
@ -172,19 +174,33 @@ async def register(request: Request):
|
||||||
deviceId = payload["d"]
|
deviceId = payload["d"]
|
||||||
iccid = payload["cid"]
|
iccid = payload["cid"]
|
||||||
type = payload["t"]
|
type = payload["t"]
|
||||||
# 该设备是否已经创建
|
res = []
|
||||||
a_device = await get_device(iccid, deviceId)
|
# 查看设备是否已经创建
|
||||||
|
a_device = await get_device(None, deviceId)
|
||||||
if a_device.code == 200:
|
if a_device.code == 200:
|
||||||
v = a_device.data["values"]
|
v = a_device.data["values"]
|
||||||
|
t = a_device.data["timestamps"]
|
||||||
if len(v) != 0:
|
if len(v) != 0:
|
||||||
|
timestamp = t[0]
|
||||||
|
theIccid = v[0]
|
||||||
|
# 如果设备上传的注册iccid和数据库查询的iccid一致,则说明已经注册过了
|
||||||
|
if theIccid == iccid:
|
||||||
return BaseResponse(code=302, msg="该设备已经注册过了")
|
return BaseResponse(code=302, msg="该设备已经注册过了")
|
||||||
|
# 如果不一致,则直接进行更新注册
|
||||||
|
send_json = {
|
||||||
|
"sql": f"insert into root.device(timestamp, iccid, deviceId, type) values({timestamp}, '{iccid}', '{deviceId}', {type})"
|
||||||
|
}
|
||||||
|
r = requests.post(baseHost + nonQueryUri, headers=headers, json=send_json)
|
||||||
|
res.append(r.json())
|
||||||
|
else:
|
||||||
# 创建该设备
|
# 创建该设备
|
||||||
send_json = {
|
send_json = {
|
||||||
"sql": f"insert into root.device(iccid, deviceId, type) values('{iccid}', '{deviceId}', {type})"
|
"sql": f"insert into root.device(iccid, deviceId, type) values('{iccid}', '{deviceId}', {type})"
|
||||||
}
|
}
|
||||||
res = []
|
|
||||||
r = requests.post(baseHost + nonQueryUri, headers=headers, json=send_json)
|
r = requests.post(baseHost + nonQueryUri, headers=headers, json=send_json)
|
||||||
res.append(r.json())
|
res.append(r.json())
|
||||||
|
else:
|
||||||
|
return BaseResponse(code=500, msg="500 Internal error")
|
||||||
# 插入设备状态表
|
# 插入设备状态表
|
||||||
send_json = {
|
send_json = {
|
||||||
"sql": f"insert into root.farm.clientId(iccid, clientId, is_online, deviceId) values('{iccid}','{clientid}', True, '{deviceId}')"
|
"sql": f"insert into root.farm.clientId(iccid, clientId, is_online, deviceId) values('{iccid}','{clientid}', True, '{deviceId}')"
|
||||||
|
|
Loading…
Reference in New Issue