Commit 0c29e639 authored by lcn's avatar lcn

bug修复

parent 8441b0f6
...@@ -50,23 +50,24 @@ async def query_location_1min_index(date_start, date_end, mtid, ...@@ -50,23 +50,24 @@ async def query_location_1min_index(date_start, date_end, mtid,
return results return results
async def get_search_scope(cid, pid, start, end): async def get_search_scope(cid, pid, start, end, limit, offset):
where_list = [f"pid = {pid}"] where = f" event_mode='scope'"
args = ()
if cid: if cid:
where_list.append(f"cid in %s") where += f" and cid in %s"
args = (cid,)
if pid:
where += f" and pid = {pid}"
if start and end: if start and end:
where_list.append( where += f" and event_datetime >= '{start}' and event_datetime <=" \
f"event_datetime >= '{start}' and event_datetime <='{end}' ") f"'{end}' "
where_str = " and ".join(where_list) sql = f"select * from point_1min_event where {where} " \
sql = f"select * from point_1min_event where {where_str} " \ f"ORDER BY event_datetime desc limit {limit} offset {offset}"
f"and event_mode='scope' " \ total_sql = f"select count(*) count from point_1min_event where {where}"
f"ORDER BY event_datetime desc limit 5000"
async with MysqlUtil() as conn: async with MysqlUtil() as conn:
if cid: data = await conn.fetchall(sql, args=args) or []
data = await conn.fetchall(sql, args=(cid,)) total = await conn.fetch_value(total_sql, args=args) or 0
else: return data, total
data = await conn.fetchall(sql)
return data
async def query_search_scope(cid, pid, page_num, page_size, async def query_search_scope(cid, pid, page_num, page_size,
...@@ -136,15 +137,15 @@ async def query_search_scope(cid, pid, page_num, page_size, ...@@ -136,15 +137,15 @@ async def query_search_scope(cid, pid, page_num, page_size,
return data, total return data, total
async def get_scope_pids(pids, start, end): async def get_scope_pids(pids, start, end, limit=20, offset=0):
where_str = f"event_mode='scope' and pid in {pids}"
if start and end: if start and end:
where_str = f"pid in {pids} and event_datetime>={start} and " \ where_str += f" and event_datetime>={start} and event_datetime<={end}"
f"event_datetime<={end}" sql = f"select * from point_1min_event where {where_str} " \
else: f"ORDER BY event_datetime desc limit {limit} offset {offset}"
where_str = f"pid in {pids}" total_sql = f"select count(*) count from point_1min_event where" \
sql = f"select * from point_1min_event where {where_str} and " \ f" {where_str}"
f"event_mode='scope' " \
f"ORDER BY event_datetime desc limit 5000"
async with MysqlUtil() as conn: async with MysqlUtil() as conn:
data = await conn.fetchall(sql) data = await conn.fetchall(sql) or []
return data total = await conn.fetch_value(total_sql) or 0
return data, total
...@@ -4,7 +4,8 @@ import io ...@@ -4,7 +4,8 @@ import io
import pandas as pd import pandas as pd
from pot_libs.qingstor_util.qs_client import QsClient from pot_libs.qingstor_util.qs_client import QsClient
from unify_api.modules.zhiwei_u.procedures.scope_operations_pds import get_event_info_by_event_id, get_scope_info_pds from unify_api.modules.zhiwei_u.procedures.scope_operations_pds import \
get_event_info_by_event_id, get_scope_info_pds
from unify_api.modules.zhiwei_u.fault_foreast.actionFile import actionFilemin from unify_api.modules.zhiwei_u.fault_foreast.actionFile import actionFilemin
from unify_api.modules.zhiwei_u import config from unify_api.modules.zhiwei_u import config
from unify_api.utils import time_format from unify_api.utils import time_format
...@@ -45,21 +46,16 @@ async def search_scope_service(prod_id, cid, pid, sid, page_num, page_size, ...@@ -45,21 +46,16 @@ async def search_scope_service(prod_id, cid, pid, sid, page_num, page_size,
pids_datas = await sid_to_order_dao(sid) pids_datas = await sid_to_order_dao(sid)
pids = [data["pid"] for data in pids_datas] pids = [data["pid"] for data in pids_datas]
# todo databases should be point_1min_scope, not point_1min_event # todo databases should be point_1min_scope, not point_1min_event
scope_datas = await get_scope_pids(pids, start, end) datas, total = await get_scope_pids(pids, start, end, page_size,
start_num)
datas = scope_datas[start_num: start_num+page_size]
total = len(scope_datas)
# datas = await query_search_scope_pids(pids, page_num, page_size,
# start, end)
else: else:
if prod_id and not cid and not pid: if prod_id and not cid and not pid:
cid_list = await select_cids_by_prod_id(prod_id) cid_list = await select_cids_by_prod_id(prod_id)
cid = [c["cid"] for c in cid_list] cid = [c["cid"] for c in cid_list]
elif cid: elif cid:
cid = [cid] cid = [cid]
scope_datas = await get_search_scope(cid, pid, start, end) datas, total = await get_search_scope(cid, pid, start, end, page_size,
datas = scope_datas[start_num: start_num + page_size] start_num)
total = len(scope_datas)
if not datas: if not datas:
return SearchScopeResq(total=0, rows=[]) return SearchScopeResq(total=0, rows=[])
...@@ -108,7 +104,6 @@ async def load_context(url): ...@@ -108,7 +104,6 @@ async def load_context(url):
async def scope_detail_service(id, wave_range, download=None, user_id=None): async def scope_detail_service(id, wave_range, download=None, user_id=None):
# 1.根据es_id查询point_1min_event对应的point属性 # 1.根据es_id查询point_1min_event对应的point属性
try: try:
mysql_results = await get_event_info_by_event_id(id) mysql_results = await get_event_info_by_event_id(id)
...@@ -146,7 +141,6 @@ async def scope_detail_service(id, wave_range, download=None, user_id=None): ...@@ -146,7 +141,6 @@ async def scope_detail_service(id, wave_range, download=None, user_id=None):
return ScopeDetailsResponse().db_error() return ScopeDetailsResponse().db_error()
if not mysql_results: if not mysql_results:
alarm = Alarm(check_dt=check_dt, pid=point_id, cid=cid, alarm = Alarm(check_dt=check_dt, pid=point_id, cid=cid,
point=point_name, sid=point["sid"], message=message, point=point_name, sid=point["sid"], message=message,
prod_id=company["product"], prod_id=company["product"],
...@@ -166,10 +160,12 @@ async def scope_detail_service(id, wave_range, download=None, user_id=None): ...@@ -166,10 +160,12 @@ async def scope_detail_service(id, wave_range, download=None, user_id=None):
source = mysql_results source = mysql_results
scope_type = source.get("fault_type") scope_type = source.get("fault_type")
fault_type = config.EVENT_TYPE_MAP.get(scope_type) fault_type = config.EVENT_TYPE_MAP.get(scope_type)
date_time = datetime.datetime.strftime(source.get("datetime"), "%Y-%m-%d %H:%M:%S") date_time = datetime.datetime.strftime(source.get("datetime"),
"%Y-%m-%d %H:%M:%S")
position = list(json.loads(source.get("result")).keys()) position = list(json.loads(source.get("result")).keys())
position_tmp = [ position_tmp = [
pos + "相" if len(pos) == 1 else pos + "线" if len(pos) == 2 else '' for pos + "相" if len(pos) == 1 else pos + "线" if len(pos) == 2 else ''
for
pos in position] pos in position]
position_tmp = [p for p in position_tmp if p] # 去掉空字符串 position_tmp = [p for p in position_tmp if p] # 去掉空字符串
position_str = "|".join(position_tmp) position_str = "|".join(position_tmp)
...@@ -240,7 +236,7 @@ async def scope_detail_service(id, wave_range, download=None, user_id=None): ...@@ -240,7 +236,7 @@ async def scope_detail_service(id, wave_range, download=None, user_id=None):
else: else:
result = "" result = ""
for r in res: for r in res:
result += "%s : %0.0f%%;" % (r[0], r[1]*100) result += "%s : %0.0f%%;" % (r[0], r[1] * 100)
except Exception as e: except Exception as e:
result = "" result = ""
log.error(f"actionFile error:{e}") log.error(f"actionFile error:{e}")
......
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