adio_dao.py 1.6 KB
Newer Older
lcn's avatar
lcn committed
1
from pot_libs.mysql_util.mysql_util import MysqlUtil
lcn's avatar
lcn committed
2 3 4
from pot_libs.settings import SETTING
from unify_api.modules.common.service.td_engine_service import \
    get_td_engine_data
wang.wenrong's avatar
wang.wenrong committed
5
from unify_api.utils.taos_new import parse_td_columns
lcn's avatar
lcn committed
6 7 8 9


async def get_location_dao(lids):
    location_info = {}
lcn's avatar
lcn committed
10
    sql = "SELECT lid, item, mtid, ad_type FROM location WHERE lid IN %s"
lcn's avatar
lcn committed
11 12 13 14 15 16 17
    async with MysqlUtil() as conn:
        result = await conn.fetchall(sql, args=(lids,))
        if result:
            for res in result:
                id = res.get("lid")
                item = res.get("item")
                type = res.get("ad_type")
lcn's avatar
lcn committed
18 19
                mtid = res.get("mtid")
                location_info[id] = {"item": item, "type": type, "mtid": mtid}
lcn's avatar
lcn committed
20 21 22
    return location_info


lcn's avatar
lcn committed
23 24
async def get_location_15min_dao(lid, start, end,
                                 table_name="location_15min_aiao"):
lcn's avatar
lcn committed
25
    sql = f"SELECT lid,value_max,value_max_time,value_avg,value_min," \
lcn's avatar
lcn committed
26
          f"value_min_time  FROM {table_name} WHERE lid = %s " \
lcn's avatar
lcn committed
27 28 29 30
          f"and create_time BETWEEN '{start}' and '{end}'"
    async with MysqlUtil() as conn:
        result = await conn.fetchall(sql, args=(lid,))
    return result
lcn's avatar
lcn committed
31 32 33 34 35 36


async def get_adio_current_data(mtid):
    '''
        获取安全监测实时数据
    '''
wang.wenrong's avatar
wang.wenrong committed
37
    url = f"{SETTING.stb_url}db_adio?tz=Asia/Shanghai"
lcn's avatar
lcn committed
38 39 40 41 42 43
    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 {}
wang.wenrong's avatar
wang.wenrong committed
44
    head = parse_td_columns(results)
lcn's avatar
lcn committed
45 46
    res = dict(zip(head, results['data'][0]))
    return res