This commit is contained in:
xyj 2024-01-25 14:54:28 +08:00
parent d6b91ef776
commit 8eaad30295
2 changed files with 38 additions and 18 deletions

View File

@ -77,7 +77,7 @@ def air_template(deviceId):
def rfid_deviceId(rfid, deviceId): def rfid_deviceId(rfid, deviceId):
return [ return [
f"insert into root.rfid(timestamp, rfid, deviceId) values(0, '{rfid}', '{deviceId}')" f"insert into root.rfid(rfid, deviceId) values('{rfid}', '{deviceId}')"
] ]

32
xumu.py
View File

@ -84,17 +84,35 @@ async def rfid_query(rfid_entity: RFIDQuery):
return BaseResponse(code=500, msg=str(e)) 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") @app.get("/api/xumu/device/query")
async def get_device(device: Device): async def get_device(iccid, deviceId):
try: try:
sql = "SELECT * FROM root.device where time>=0" sql = "SELECT * FROM root.device where time>=0"
# 检查iccid是否有值如果有添加到SQL语句中 # 检查iccid是否有值如果有添加到SQL语句中
if device.iccid: if iccid:
sql += f" and iccid = '{device.iccid}'" sql += f" and iccid = '{iccid}'"
# 检查deviceId是否有值如果有添加到SQL语句中 # 检查deviceId是否有值如果有添加到SQL语句中
if device.deviceId: if deviceId:
sql += f" and deviceId = '{device.deviceId}'" sql += f" and deviceId = '{deviceId}'"
send_json = { send_json = {
"sql": sql "sql": sql
} }
@ -179,6 +197,8 @@ async def process_data(request: Request):
# 判断t是否为00则代表是RFID设备需要做一个映射 # 判断t是否为00则代表是RFID设备需要做一个映射
if t == 0: if t == 0:
rfid = v[1] rfid = v[1]
r = await has_rfid(rfid)
if r.code != 200:
sql_list = rfid_deviceId(rfid, deviceId) sql_list = rfid_deviceId(rfid, deviceId)
sql = sql_list[0] sql = sql_list[0]
send_json = { send_json = {