This commit is contained in:
xyj 2024-03-04 16:07:52 +08:00
parent fd0618b83f
commit 64bce5815b
2 changed files with 19 additions and 5 deletions

View File

@ -141,6 +141,13 @@ def create_register_sql(iccid, deviceId, type):
return send_json return send_json
def has_device_status_sql(clientid):
send_json = {
"sql": f"select * from root.farm.clientId where clientId='{clientid}')"
}
return send_json
def insert_device_status_sql(iccid, clientid, deviceId): def insert_device_status_sql(iccid, clientid, deviceId):
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}')"
@ -332,7 +339,8 @@ def insert_to_warning_sql(deviceId, v, t):
v.append("室外天气湿度偏高") v.append("室外天气湿度偏高")
elif air_humidity <= air_humidity_threshold[0]: elif air_humidity <= air_humidity_threshold[0]:
v.append("室外天气湿度偏低") v.append("室外天气湿度偏低")
v.append("室内外温度偏高或偏低,需根据环境采取适当措施,如提供遮蔽和防晒、保持适宜的室内温度、增加保暖措施、提供饮水等。") v.append(
"室内外温度偏高或偏低,需根据环境采取适当措施,如提供遮蔽和防晒、保持适宜的室内温度、增加保暖措施、提供饮水等。")
elif t == 2: elif t == 2:
# danqi 氮气 # danqi 氮气
v.append("氮气浓度偏高") v.append("氮气浓度偏高")

View File

@ -161,7 +161,13 @@ async def register(request: Request):
send_json = create_register_sql(iccid, deviceId, type) send_json = create_register_sql(iccid, deviceId, type)
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())
# TODO 插入设备状态表,如果状态表有,那么不插入设备表,如果状态表没有,则插入 # 插入设备状态表,如果状态表有,那么不插入设备表,如果状态表没有,则插入
send_json = has_device_status_sql(clientid)
r = requests.post(baseHost + queryUri, headers=headers, json=send_json)
if r.status_code != 200:
return BaseResponse(data=r.json(), code=500, msg="500 Internal Error")
data = r.json()
if len(data["values"]) == 0:
send_json = insert_device_status_sql(iccid, clientid, deviceId) send_json = insert_device_status_sql(iccid, clientid, deviceId)
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())