Commit 81c24bd9 authored by lcn's avatar lcn

修改tdengine写法

parent 4bb601d6
......@@ -438,3 +438,11 @@ DOWNLOAD_ORDER = "filedata/zhiweiu/order"
SMS_LOGIN_TEMPLATE = "SMS_222195119"
SMS_SIGN_NAME = "清科优能"
TDENGINE_CHILD_SUBFIX_LIST = {
"db_appliance": "app",
"db_soe": "soe",
"db_scope": "scp",
"db_adio": "adi",
"db_electric": "ele",
}
\ No newline at end of file
......@@ -36,7 +36,7 @@ async def storey_by_cid(cid):
async def query_points_by_storey(storeys):
"""根据storey_id查询point_id和room_name"""
sql = "SELECT s.storey_id,s.storey_name,s.point_id,s.room_name,m.mtid," \
"p.ctnum from storey_room_map s LEFT JOIN point p " \
"p.ctnum,p.cid from storey_room_map s LEFT JOIN point p " \
"on p.pid=s.point_id LEFT JOIN monitor m on m.mtid=p.mtid " \
"where s.storey_id in %s and m.demolished=0 " \
"order by s.storey_id, s.room_name"
......
......@@ -3,7 +3,7 @@ from pot_libs.mysql_util.mysql_util import MysqlUtil
async def monitor_point_join_by_points(points):
"""monitor和point关联"""
sql = "SELECT m.mtid,p.ctnum,m.name, m.m_type, p.pid " \
sql = "SELECT m.mtid,p.ctnum,m.name, m.m_type, p.pid,p.cid " \
"FROM monitor m inner join point p on m.mtid = p.mtid " \
"WHERE p.pid in %s and m.demolished = 0 order by field(p.pid,{})".\
format(str(points).replace("[", "").replace("]", ""))
......
......@@ -227,20 +227,20 @@ async def qual_current_data(point_mid):
return ret_dic
async def elec_current_data_new15(mtids):
async def elec_current_data_new15(mtids, cid):
res_map = {}
url = f"{SETTING.stb_url}db_electric"
sql = f""
for mtid in mtids:
table_name = f"mt{mtid}_ele"
if len(sql) > 0:
sql += " union all "
sql += f"select last_row(*) from {table_name}"
sql = f"""
select tbname,last_row(*) from electric_stb
where cpyid={cid}
group by tbname
"""
is_succ, results = await get_td_engine_data(url, sql)
if is_succ:
head = [re.findall(r'last_row\((.*)\)', i)[0] if "(" in i else i
for i in results["head"]]
for res in results["data"]:
data = dict(zip(head, res))
res_map[data["mtid"]] = data
if data["mtid"] in mtids:
res_map[data["mtid"]] = data
return res_map
......@@ -38,11 +38,12 @@ async def elec_current_storeys_service(storeys):
point_list = await points_by_storeys(storeys)
# mtids
mtids = [i.get("mtid") for i in point_list]
cid = point_list[0]['cid'] if len(point_list) > 0 else 0
# 2.获取mid, ctnum
# point_mid = await batch_get_wiring_type(points)
# # 3. 获取redis数据
# res = await elec_current_data(point_mid)
res = await elec_current_data_new15(mtids)
res = await elec_current_data_new15(mtids, cid)
# 4. 返回数据
elec_data = {}
for info in point_list:
......@@ -128,7 +129,8 @@ async def qual_current_storeys_service(storeys):
# # 3. 获取redis数据
# res = await qual_current_data(point_mid)
mtids = [point["mtid"] for point in point_list if point["mtid"]]
res = await elec_current_data_new15(mtids)
cid = point_list[0]['cid'] if len(point_list) > 0 else 0
res = await elec_current_data_new15(mtids, cid)
# 4. 返回数据
qual_data = {}
for info in point_list:
......@@ -210,7 +212,8 @@ async def elec_card_level_service(point_list):
# # 3. 获取redis数据
# res_redis = await elec_current_data(point_mid)
mtids = [monitor["mtid"] for monitor in monitor_point_list if monitor["mtid"]]
results = await elec_current_data_new15(mtids)
cid = monitor_point_list[0]['cid'] if len(monitor_point_list) > 0 else 0
results = await elec_current_data_new15(mtids, cid)
# 4. 返回数据
ret_data = {
"inline": [],
......@@ -303,7 +306,8 @@ async def qual_current_level_service(point_list):
# res_redis = await qual_current_data(point_mid)
mtids = [monitor["mtid"] for monitor in monitor_point_list if
monitor["mtid"]]
res = await elec_current_data_new15(mtids)
cid = monitor_point_list[0]['cid'] if len(monitor_point_list) > 0 else 0
res = await elec_current_data_new15(mtids, cid)
# 4. 返回数据
ret_data = {
"inline": [],
......
......@@ -550,13 +550,11 @@ async def current_load_new15(cid):
from unify_api.modules.common.service.td_engine_service import \
get_td_engine_data
url = f"{SETTING.stb_url}db_electric"
monitors = await monitor_by_cid(cid)
sql = f""
for monitor in monitors:
table_name = f"mt{monitor.get('mtid')}_ele"
if len(sql) > 0:
sql += " union all "
sql += f"select last_row(*) from {table_name}"
sql = f"""
select last_row(*) from electric_stb
where cpyid={cid}
group by tbname
"""
is_succ, results = await get_td_engine_data(url, sql)
now_tt = int(time.time())
if is_succ:
......
......@@ -189,13 +189,11 @@ async def health_ctl_rate_service_new15(cid):
real_tt = now_ts
total = 0
url = f"{SETTING.stb_url}db_electric"
monitors = await monitor_by_cid(cid)
sql = f""
for monitor in monitors:
table_name = f"mt{monitor.get('mtid')}_ele"
if len(sql) > 0:
sql += " union all "
sql += f"select last_row(*) from {table_name}"
sql = f"""
select last_row(*) from electric_stb
where cpyid={cid}
group by tbname
"""
is_succ, results = await get_td_engine_data(url, sql)
time_str = time_format.get_datetime_str(real_tt)
if is_succ:
......
......@@ -106,14 +106,11 @@ async def stb_data_longgang_service(user_id, type):
token = get_token()
stb_url = f"{SETTING.stb_url}{db_name[type]['super']}"
monitor_datas = await points_monitor_by_cid(cids)
sql = f""
for monitor_data in monitor_datas:
table_name = f"mt{monitor_data.get('mtid')}_{db_name[type]['suffix']}"
if len(sql) > 0:
sql += " union all "
sql += f"select last_row(*) from {table_name}"
sql = f"""
select last_row(*) from electric_stb
where cpyid = {cids[0]}
group by tbname
"""
resp_str, status = await AioHttpUtils().post_data(
stb_url, data=sql, timeout=50,
headers={"Authorization": f"Basic {token}"}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment