Commit 4bb601d6 authored by lcn's avatar lcn

修改tdengine写法

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