Commit e9a86df4 authored by lcn's avatar lcn

bug修复

parent 43ef9b36
......@@ -8,12 +8,19 @@ from unify_api.modules.zhiwei_u.components.scope_operations_cps import \
from pot_libs.mysql_util.mysql_util import MysqlUtil
async def scope_by_sql(mid_sql):
sql = f"select * from point_1min_scope where {mid_sql} order by " \
f"create_time desc limit 500"
async def scope_by_sql(mid_sql, offset, limit):
scope_event_type = ['over_gap_cur', 'over_gap_i', 'over_gap_pttl',
'over_gap_u', 'over_res_cur', 'over_rms_i',
'over_rms_pttl', 'over_rms_u', 'under_rms_u']
sql = f"select * from point_1min_scope where {mid_sql} " \
f"and fault_type in %s" \
f"order by create_time desc limit {limit} offset {offset}"
count_sql = f"select count(*) count from point_1min_scope where" \
f" {mid_sql} and fault_type in %s"
async with MysqlUtil() as conn:
data = await conn.fetchall(sql)
return data
data = await conn.fetchall(sql, args=(scope_event_type,))
count = await conn.fetch_value(count_sql, args=(scope_event_type,))
return data, count
async def detail_data_by_es(pid, create_time):
......
......@@ -18,7 +18,7 @@ from pot_libs.common.components.responses import success_res
from unify_api.utils.response_code import RET
async def scope_record_service(cid, point_id, page_num, page_size, start, end):
async def scope_record_service(cid, point_id, offset, limit, start, end):
li = [f"cid={cid}"]
if point_id:
if len(point_id) == 1:
......@@ -28,15 +28,12 @@ async def scope_record_service(cid, point_id, page_num, page_size, start, end):
if start and end:
li.append(f"create_time BETWEEN '{start}' and '{end}'")
mid_sql = " and ".join(li)
datas = await scope_by_sql(mid_sql)
total = len(datas)
datas, total = await scope_by_sql(mid_sql, offset, limit)
# 获取监测点名称
point_dict = await get_point_dict(cid)
# 动态漏电流阈值
rows = []
if datas:
start = (page_num - 1) * page_size
datas = datas[start: start + page_num]
for data in datas:
# 漏电流
if data["fault_type"] in ("over_res_cur", "overResidualCurrent"):
......
......@@ -14,7 +14,8 @@ async def post_scope_record(req, body: ScopeRecordReq) -> ScopeRecordResp:
end = body.end
page_size = body.page_size
page_num = body.page_num
return await scope_record_service(cid, point_id, page_num, page_size,
return await scope_record_service(cid, point_id,
(page_num - 1) * page_size, page_size,
start, end)
......
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