Commit 07d65473 authored by lcn's avatar lcn

BUG修复

parent 46311c41
from pot_libs.mysql_util.mysql_util import MysqlUtil from pot_libs.mysql_util.mysql_util import MysqlUtil
from pot_libs.settings import SETTING
from unify_api.modules.common.service.td_engine_service import \
get_td_engine_data
async def get_location_dao(lids): async def get_location_dao(lids):
location_info = {} location_info = {}
sql = "SELECT lid, item, ad_type FROM location WHERE lid IN %s" sql = "SELECT lid, item, mtid, ad_type FROM location WHERE lid IN %s"
async with MysqlUtil() as conn: async with MysqlUtil() as conn:
result = await conn.fetchall(sql, args=(lids,)) result = await conn.fetchall(sql, args=(lids,))
if result: if result:
...@@ -11,7 +14,8 @@ async def get_location_dao(lids): ...@@ -11,7 +14,8 @@ async def get_location_dao(lids):
id = res.get("lid") id = res.get("lid")
item = res.get("item") item = res.get("item")
type = res.get("ad_type") type = res.get("ad_type")
location_info[id] = {"item": item, "type": type} mtid = res.get("mtid")
location_info[id] = {"item": item, "type": type, "mtid": mtid}
return location_info return location_info
...@@ -22,3 +26,19 @@ async def get_location_15min_dao(lid, start, end): ...@@ -22,3 +26,19 @@ async def get_location_15min_dao(lid, start, end):
async with MysqlUtil() as conn: async with MysqlUtil() as conn:
result = await conn.fetchall(sql, args=(lid,)) result = await conn.fetchall(sql, args=(lid,))
return result return result
async def get_adio_current_data(mtid):
'''
获取安全监测实时数据
'''
url = f"{SETTING.stb_url}db_adio"
sql = f"select last_row(*) from mt{mtid}_adi"
is_success, results = await get_td_engine_data(url, sql)
if not is_success:
return {}
if not results['data']:
return {}
head = results['head']
res = dict(zip(head, results['data'][0]))
return res
...@@ -27,7 +27,7 @@ from unify_api.modules.adio.components.adio import ( ...@@ -27,7 +27,7 @@ from unify_api.modules.adio.components.adio import (
) )
from pot_libs.common.components.query import PageRequest, Range, Equal, Filter from pot_libs.common.components.query import PageRequest, Range, Equal, Filter
from unify_api.modules.adio.dao.adio_dao import get_location_dao, \ from unify_api.modules.adio.dao.adio_dao import get_location_dao, \
get_location_15min_dao get_location_15min_dao, get_adio_current_data
@summary("返回安全监测历史曲线") @summary("返回安全监测历史曲线")
...@@ -120,6 +120,62 @@ async def post_adio_current(req, body: PageRequest) -> AdioCurrentResponse: ...@@ -120,6 +120,62 @@ async def post_adio_current(req, body: PageRequest) -> AdioCurrentResponse:
except: except:
log.warning("para exception, in_groups is NULL, no location_id") log.warning("para exception, in_groups is NULL, no location_id")
return AdioCurrentResponse(temperature=[], residual_current=[]) return AdioCurrentResponse(temperature=[], residual_current=[])
# location_ids
location_group = in_group.group
if not location_group:
log.warning("para exception, in_groups is NULL, no location_id")
return AdioCurrentResponse(temperature=[], residual_current=[])
# 读取location表信息
location_info = await get_location_dao(location_group)
if not location_info:
log.warning("location_id error location_info empty")
return AdioCurrentResponse(temperature=[], residual_current=[])
# 获取mtid信息
mtid = list(location_info.values())[0]['mtid']
# 读取tdengine里面的数据
aido_data = await get_adio_current_data(mtid)
if not aido_data:
return AdioCurrentResponse(temperature=[], residual_current=[])
temperature = []
residual_current = []
trans_field = {"A相": "temp1", "B相": "temp2", "C相": "temp3",
"N线": "temp4"}
for location_id, item_info in location_info.items():
time_str = aido_data.get('ts')[:19]
item = item_info.get("item", "")
if item_info.get("type") == "residual_current":
adio_current = AdioCurrent(
type="residual_current",
item="漏电流",
real_time=time_str,
value=aido_data.get("residual_current")
)
residual_current.append(adio_current)
else:
type_filed = trans_field.get(item)
adio_current = AdioCurrent(
type="temperature",
item=item,
real_time=time_str,
value=aido_data.get(type_filed),
)
temperature.append(adio_current)
return AdioCurrentResponse(temperature=temperature,
residual_current=residual_current)
@summary("返回安全监测实时参数(老的)")
@description("包含温度和漏电流(老的)")
@examples(adio_current_example)
async def post_adio_current_bak(req, body: PageRequest) -> AdioCurrentResponse:
try:
in_group = body.filter.in_groups[0]
except:
log.warning("para exception, in_groups is NULL, no location_id")
return AdioCurrentResponse(temperature=[], residual_current=[])
# location_ids # location_ids
location_group = in_group.group location_group = in_group.group
......
...@@ -71,9 +71,10 @@ async def mid_by_pid(pid): ...@@ -71,9 +71,10 @@ async def mid_by_pid(pid):
async def get_point_monitor_dao(pid): async def get_point_monitor_dao(pid):
sql = "SELECT m.meter_no,m.sid,p.ctr,p.ptr,p.ctnum,p.vc,p.tc,p.imax " \ sql = "SELECT m.meter_no,m.mtid,m.sid," \
"p.ctr,p.ptr,p.ctnum,p.vc,p.tc,p.imax" \
"FROM `point` p INNER JOIN monitor m on m.mtid=p.mtid " \ "FROM `point` p INNER JOIN monitor m on m.mtid=p.mtid " \
"where p.pid=%s limit 1;" "where p.pid=%s and m.demolished = 0"
async with MysqlUtil() as conn: async with MysqlUtil() as conn:
datas = await conn.fetchone(sql, args=(pid,)) datas = await conn.fetchone(sql, args=(pid,))
return datas return datas
......
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