scope_operations_dao.py 2.12 KB
Newer Older
wang.wenrong's avatar
wang.wenrong committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
from pot_libs.mysql_util.mysql_util import MysqlUtil


async def get_scope_event_by_event_id(event_id):
    """
    获取录波报警详情
    :param event_id:
    :return:
    """
    sql = f"""
        select pe.*,m.sid from point_1min_event pe
        left join monitor m on pe.mtid = m.mtid
        where pe.event_id =%s
    """

    async with MysqlUtil() as conn:
        result = await conn.fetchone(sql, args=(event_id,))
    return result


async def get_scope_detail_by_pid(pid, event_datetime):
    """
    获取录波详情
    :param pid:
    :param event_datetime:
    :return:
    """
    sql = f"""
        select * from point_1min_scope
        where pid =%s and create_time=%s
    """

    async with MysqlUtil() as conn:
        result = await conn.fetchone(sql, args=(pid, event_datetime))
    return result


async def get_threshold_by_mtid(mtid):
    """
    根据mtid获取阈值
    :param mtid:
    :return:
    """
    sql = f"""
        select threshold from soe_config_record  scr
        left join location l on  scr.lid = l.lid
        where l.ad_type='residual_current' and scr.etype='overResidualCurrent'
        and l.mtid=%s
    """
    async with MysqlUtil() as conn:
        threshold = await conn.fetch_value(sql, args=(mtid,))
    return threshold
wang.wenrong's avatar
wang.wenrong committed
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78


async def get_scope_url_by_pid(mtid, start_dt, end_dt):
    """
    获取录波详情
    :param pid:
    :param event_datetime:
    :return:
    """
    sql = f"""
        SELECT
            url, 
        DATE_FORMAT(create_time, '%Y-%m-%d %H:%i:%s') datetime
        FROM
            point_1min_scope 
        WHERE
            create_time > '{start_dt}' 
            AND create_time < '{end_dt}' 
            AND mtid = {mtid} 
            AND scope_g = '2s'

    """

    async with MysqlUtil() as conn:
        result = await conn.fetchall(sql,)
    return result
wang.wenrong's avatar
wang.wenrong committed
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94


async def get_e_type_by_event_type(event_type):
    sql = f"""
        SELECT 
        `name` type
        FROM
            event_type 
        WHERE
            e_type = '{event_type}'
        
            """

    async with MysqlUtil() as conn:
        result = await conn.fetchone(sql,)
    return result