Commit 4bb601d6 authored by lcn's avatar lcn

修改tdengine写法

parent e7df191b
......@@ -29,8 +29,7 @@ def test_td_engine():
url = f"{SETTING.stb_url}db_electric"
print(token)
h = {"Authorization": f"Basic {token}"}
sql = f"select last_row(*) from electric_stb where cpyid =204 " \
f"group by tbname"
sql = f"select last_row(*) from mt1332_ele where pid=1395"
r = requests.post(url, data=sql, headers=h)
print(r.status_code)
print(r.content)
......
......@@ -230,9 +230,12 @@ async def qual_current_data(point_mid):
async def elec_current_data_new15(mtids):
res_map = {}
url = f"{SETTING.stb_url}db_electric"
table_name = [f"mt{mtid}_ele" for mtid in mtids]
sql = f'select last_row(*) from electric_stb ' \
f'where TBNAME IN {tuple(table_name)} group by tbname'
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}"
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
......
......@@ -875,7 +875,7 @@ async def elec_current_service_new15(point_id):
mtid = meter_info["mtid"]
# 获取子表中的实时数据
url = f"{SETTING.stb_url}db_electric"
sql = f"select last(*) from mt{mtid}_ele where pid={point_id}"
sql = f"select last_row(*) from mt{mtid}_ele where pid={point_id}"
is_succ, results = await get_td_engine_data(url, sql)
if not is_succ:
return '',{}
......
......@@ -879,7 +879,7 @@ async def post_qual_current(req, body: PageRequest) -> QualCurrentResponse:
mtid = meter_info["mtid"]
# 获取子表中的实时数据
url = f"{SETTING.stb_url}db_electric"
sql = f"select last(*) from mt{mtid}_ele where pid={point_id}"
sql = f"select last_row(*) from mt{mtid}_ele where pid={point_id}"
is_succ, results = await get_td_engine_data(url, sql)
log.info(f"is_succ:{is_succ}")
if is_succ:
......
......@@ -14,7 +14,8 @@ from unify_api import constants
from unify_api.constants import Importance, EVENT_TYPE_MAP, SDU_ALARM_LIST
from unify_api.modules.alarm_manager.dao.list_static_dao import \
sdu_alarm_importance_dao, alarm_aggs_importance
from unify_api.modules.common.dao.common_dao import monitor_point_join
from unify_api.modules.common.dao.common_dao import monitor_point_join, \
monitor_by_cid
from unify_api.modules.common.procedures.common_utils import get_electric_index
from unify_api.modules.common.procedures.points import get_points, \
proxy_points, get_points_num
......@@ -549,8 +550,13 @@ 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"
sql = f"select last_row(*) from electric_stb where cpyid ={cid} " \
f"group by tbname"
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}"
is_succ, results = await get_td_engine_data(url, sql)
now_tt = int(time.time())
if is_succ:
......
import json
import time
import re
from unify_api.modules.common.dao.common_dao import monitor_by_cid
from unify_api.utils.common_utils import round_2
from pot_libs.logger import log
from pot_libs.settings import SETTING
......@@ -187,8 +189,13 @@ async def health_ctl_rate_service_new15(cid):
real_tt = now_ts
total = 0
url = f"{SETTING.stb_url}db_electric"
sql = f"select last_row(*) from electric_stb where cpyid ={cid} " \
f"group by tbname"
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}"
is_succ, results = await get_td_engine_data(url, sql)
time_str = time_format.get_datetime_str(real_tt)
if is_succ:
......
......@@ -9,8 +9,8 @@ from unify_api.modules.shidianu.components.open_data_cps import (
)
from unify_api.modules.alarm_manager.components.list_alarm import \
ListAlarmResponse, Alarm
from unify_api.modules.common.dao.common_dao import meter_by_mids,\
monitor_point_storey_join_in
from unify_api.modules.common.dao.common_dao import meter_by_mids, \
monitor_point_storey_join_in, points_monitor_by_cid
from unify_api.modules.common.procedures.points import point_to_mid
from unify_api.modules.shidianu.dao.open_data_dao import \
get_user_product_auth, result_longgang_by_cid, monitor_point_company
......@@ -87,9 +87,9 @@ async def basic_info_longgang_service(user_id, page_size, page_num):
async def stb_data_longgang_service(user_id, type):
db_name = {
"soe": "db_soe",
"electric": "db_electric",
"appliance": "db_appliance"
"soe": {"super": "db_soe", "suffix": "soe"},
"electric": {"super": "db_electric", "suffix": "ele"},
"appliance": {"super": "db_appliance", "suffix": "app"}
}
if type not in db_name.keys():
return success_res(code=4002, msg="type错误")
......@@ -105,10 +105,15 @@ async def stb_data_longgang_service(user_id, type):
return success_res(code=4001, msg="您没有权限访问")
token = get_token()
stb_url = f"{SETTING.stb_url}{db_name[type]}"
table_name = f"{type}_stb"
sql = f"select last_row(*) from {table_name} " \
f"where cpyid in {tuple(cids)} group by tbname"
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}"
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