Commit 9a60c699 authored by lcn's avatar lcn

bug修复

parent 2fb841ab
......@@ -157,18 +157,16 @@ async def get_equip_run_status(point_id):
async with MysqlUtil() as conn:
# 是否非动力设备
power_equip_sql = "select is_power_equipment from monitor m " \
"left join point p on m.mtid = p.mtid " \
"where p.pid = %s"
"left join point p on m.mtid = p.mtid " \
"where p.pid = %s"
power_equip_result = await conn.fetchone(sql=power_equip_sql,
args=(point_id,))
if power_equip_result.get("is_power_equipment", 0) == 0:
return 2
raw_sql = "select count(*) run_count from scope_equip_run_record s " \
"left join (select pid,max(id) max_id from " \
"scope_equip_run_record group by pid) sp " \
"on s.pid = sp.pid " \
"WHERE s.pid= %s and start_time < unix_timestamp(NOW()) " \
"and (end_time > unix_timestamp(NOW()) or " \
"(end_time=0 and id=max_id)) "
raw_sql = "select (case when end_time > unix_timestamp(NOW()) then 1 " \
"when end_time=0 then 1 else 0 end) run_count " \
"from scope_equip_run_record " \
"WHERE pid = %s and start_time < unix_timestamp(NOW()) " \
"order by start_time desc limit 1"
result = await conn.fetchone(sql=raw_sql, args=(point_id,))
return 1 if result.get("run_count") > 0 else 0
return 1 if result and result.get("run_count") else 0
import json
import math
from pot_libs.aredis_util.aredis_utils import RedisUtils
from pot_libs.qingstor_util.qs_client import QsClient
from unify_api.modules.zhiwei_u.fault_foreast.actionFile import actionFilemin
from unify_api.modules.zhiwei_u.fault_foreast.test import leakage_reg
......@@ -152,7 +154,7 @@ async def set_scope_config_serv(pid, type, scope_type, args):
'''
# 先查看缓存中是否存在,如果存在直接返回
redis_key = f"scope_config:{pid}"
redis_result = await aredis_utils.RedisClient().get(redis_key)
redis_result = await RedisUtils().get(redis_key)
log.info(f'set_scope_config_serv redis_result:{redis_result}')
if redis_result:
raise Exception('两次操作间隔3分钟,请稍后再试。')
......@@ -218,7 +220,7 @@ async def set_scope_config_serv(pid, type, scope_type, args):
# 配置下发(只有正式环境才开启)
await set_mqtt_scope_config(pid, configs, scope_type)
# 将数据存入缓存中
await aredis_utils.RedisClient().setex(redis_key, 180, pid)
await RedisUtils().setex(redis_key, 180, pid)
# 保存配置信息
new_configs = json.dumps(configs)
update_count = await set_scope_config_by_pid(pid, new_configs)
......
......@@ -79,6 +79,15 @@ async def get_location_monitor_dao(lid):
return datas
async def sid_by_pid(pid):
"""根据pid查询sid"""
sql = "select sid,meter_no from monitor m left join point p on m.mtid = " \
"p.mtid where p.pid=%s "
async with MysqlUtil() as conn:
result = await conn.fetchone(sql, args=(pid,))
return result
async def meter_by_mids(mids):
"""根据mids查询meter"""
sql = "select * from meter where mid in %s"
......
import pendulum
from pot_libs.logger import log
from unify_api.modules.common.dao.common_dao import (
get_point_monitor_dao, get_location_monitor_dao
get_point_monitor_dao, get_location_monitor_dao, sid_by_pid
)
from uuid import uuid4
......@@ -47,27 +49,67 @@ async def get_location_soe_config(event, with_params):
return sid, config
async def change_param_to_config(req_json, method):
async def get_point_scope_config(event_data, method='config'):
'''
获取录波配置需要的参数
'''
point_id = event_data.get('point_id')
del event_data['point_id']
# 根据pid获取sid
monitor_dic = await sid_by_pid(point_id)
if monitor_dic is None:
log.info(f'=======no monitor of point id: {point_id}')
return None, None
sid = monitor_dic.get("sid")
scope_type = event_data.get('scope_type')
del event_data['scope_type']
scope_trans_rule = {'0.25ms': 'scope', '0.2s': 'wave_200ms',
'2s': 'electric_2s'}
scope_param = scope_trans_rule.get(scope_type)
if method != 'get' and not scope_param:
log.info(f'=======no scope_param of scope_type: {scope_type}')
return None, None
if method == 'config':
config = {
scope_param: event_data
}
else:
config = scope_param
return sid, config
async def change_param_to_config(req_json, method, type='soe'):
"""
web参数, 转换为与装置通信的报文
soe method: config
"""
sid, config = None, None
point_id = req_json.get("point_id")
if point_id is not None:
sid, config = await get_point_soe_config(req_json, with_params=True)
location_id = req_json.get('location_id')
if location_id is not None:
sid, config = await get_location_soe_config(req_json, with_params=True)
if type == 'scope':
sid, config = await get_point_scope_config(req_json, method)
else:
point_id = req_json.get("point_id")
if point_id is not None:
sid, config = await get_point_soe_config(req_json,
with_params=True)
location_id = req_json.get('location_id')
if location_id is not None:
sid, config = await get_location_soe_config(req_json,
with_params=True)
request_data = {}
if sid:
request_id = str(uuid4())
request_data = dict(request_id=request_id,
time=pendulum.now().to_datetime_string(),
method=method,
sid=sid, data=config)
request_data = dict(
request_id=request_id,
time=pendulum.now().to_datetime_string(),
method=method,
sid=sid)
if method == 'get-config':
request_data['key'] = config
elif method == 'config':
request_data['data'] = config
return request_data
......
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