update
This commit is contained in:
parent
d6b91ef776
commit
8eaad30295
|
@ -77,7 +77,7 @@ def air_template(deviceId):
|
|||
|
||||
def rfid_deviceId(rfid, deviceId):
|
||||
return [
|
||||
f"insert into root.rfid(timestamp, rfid, deviceId) values(0, '{rfid}', '{deviceId}')"
|
||||
f"insert into root.rfid(rfid, deviceId) values('{rfid}', '{deviceId}')"
|
||||
]
|
||||
|
||||
|
||||
|
|
54
xumu.py
54
xumu.py
|
@ -84,17 +84,35 @@ async def rfid_query(rfid_entity: RFIDQuery):
|
|||
return BaseResponse(code=500, msg=str(e))
|
||||
|
||||
|
||||
async def has_rfid(rfid):
|
||||
try:
|
||||
sql = f"select deviceId from root.rfid where rfid='{rfid}'"
|
||||
send_json = {
|
||||
"sql": sql
|
||||
}
|
||||
r = requests.post(baseHost + queryUri, headers=headers, json=send_json)
|
||||
if r.status_code != 200:
|
||||
return BaseResponse(data=r.json(), code=404, msg="404")
|
||||
r = r.json()
|
||||
values = r["values"]
|
||||
if len(values) == 0:
|
||||
return BaseResponse(msg="No Such RFID", code=500)
|
||||
return BaseResponse(data=r)
|
||||
except Exception as e:
|
||||
return BaseResponse(code=500, msg=str(e))
|
||||
|
||||
|
||||
# 设备查询接口
|
||||
@app.post("/api/xumu/device/query")
|
||||
async def get_device(device: Device):
|
||||
@app.get("/api/xumu/device/query")
|
||||
async def get_device(iccid, deviceId):
|
||||
try:
|
||||
sql = "SELECT * FROM root.device where time>=0"
|
||||
# 检查iccid是否有值,如果有,添加到SQL语句中
|
||||
if device.iccid:
|
||||
sql += f" and iccid = '{device.iccid}'"
|
||||
if iccid:
|
||||
sql += f" and iccid = '{iccid}'"
|
||||
# 检查deviceId是否有值,如果有,添加到SQL语句中
|
||||
if device.deviceId:
|
||||
sql += f" and deviceId = '{device.deviceId}'"
|
||||
if deviceId:
|
||||
sql += f" and deviceId = '{deviceId}'"
|
||||
send_json = {
|
||||
"sql": sql
|
||||
}
|
||||
|
@ -179,17 +197,19 @@ async def process_data(request: Request):
|
|||
# 判断t是否为0,0则代表是RFID设备,需要做一个映射
|
||||
if t == 0:
|
||||
rfid = v[1]
|
||||
sql_list = rfid_deviceId(rfid, deviceId)
|
||||
sql = sql_list[0]
|
||||
send_json = {
|
||||
"sql": sql
|
||||
}
|
||||
r = requests.post(baseHost + nonQueryUri, headers=headers, json=send_json)
|
||||
if r.status_code == 200:
|
||||
r = r.json()
|
||||
if r["code"] != 200:
|
||||
return BaseResponse(code=500, msg="RFID创建映射失败", data=r)
|
||||
res.append(r)
|
||||
r = await has_rfid(rfid)
|
||||
if r.code != 200:
|
||||
sql_list = rfid_deviceId(rfid, deviceId)
|
||||
sql = sql_list[0]
|
||||
send_json = {
|
||||
"sql": sql
|
||||
}
|
||||
r = requests.post(baseHost + nonQueryUri, headers=headers, json=send_json)
|
||||
if r.status_code == 200:
|
||||
r = r.json()
|
||||
if r["code"] != 200:
|
||||
return BaseResponse(code=500, msg="RFID创建映射失败", data=r)
|
||||
res.append(r)
|
||||
send_json = {
|
||||
"devices": ["root.farm." + deviceId],
|
||||
"timestamps": [int(time.time() * 1000)],
|
||||
|
|
Loading…
Reference in New Issue