Commit 9a60c699 authored by lcn's avatar lcn

bug修复

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