Commit c21ef2cd authored by wang.wenrong's avatar wang.wenrong

equipment-details-mysql

parent 14562472
......@@ -126,12 +126,12 @@ async def monitor_point_storey_join_in(cid, page_num, page_size):
return monitor_point_storey_list
async def meter_param_by_mid(mid):
async def meter_param_by_mid(mtid):
"""根据mid查询meter, 参数固定不要再增加"""
sql = "select ctr,ptr,ctnum,vc,tc,imax from meter_param_record " \
"where mid=%s order by start_time desc limit 1"
sql = "select ctr,ptr,ctnum,vc,tc,imax from point " \
"where mtid=%s order by create_time desc limit 1"
async with MysqlUtil() as conn:
meter_param_dic = await conn.fetchone(sql, args=(mid,))
meter_param_dic = await conn.fetchone(sql, args=(mtid,))
return meter_param_dic
......
......@@ -13,33 +13,22 @@ async def get_wiring_type(point_id):
:return: ctnum, mid
"""
ctnum = None
mid = None
mtid = None
if not point_id:
log.error("para error point_id:%s exception" % point_id)
return ctnum, mid
return ctnum, mtid
# 根据point_id去change_meter_record查询最新的mid
sql = "SELECT mid FROM change_meter_record WHERE pid=%s " \
"ORDER BY start_time DESC LIMIT 1"
sql = "SELECT mtid FROM point WHERE pid=%s "
async with MysqlUtil() as conn:
result = await conn.fetchone(sql, args=(point_id,))
if result:
mid = result.get("mid")
mtid = result.get("mtid")
if not mid:
return ctnum, mid
# 2. 根据mid去meter_param_record查最新ctnum
sql = "SELECT ctnum FROM meter_param_record WHERE mid=%s " \
"ORDER BY start_time DESC LIMIT 1"
async with MysqlUtil() as conn:
result = await conn.fetchone(sql, args=(mid,))
if result:
ctnum = result.get("ctnum")
return ctnum, mid
if not mtid:
return ctnum, mtid
return ctnum, mtid
async def get_wiring_type_new15(pid):
......
......@@ -10,42 +10,59 @@ from unify_api.constants import EVENT_TYPE_UNIT_MAP
async def alarm_setting_pds(pid, locations):
"""获取报警设置"""
sql_point = "SELECT alarm_setting.id, alarm_setting.type, " \
"event_type.name, event_type.importance, " \
"threshold, duration, alarm_setting.enable " \
"FROM alarm_setting INNER JOIN event_type " \
"ON alarm_setting.`type`=event_type.`id` " \
"WHERE point_id=%s"
sql_location = "SELECT location.item, " \
"location.type as location_type, " \
"alarm_setting.id, alarm_setting.type, " \
"event_type.name, event_type.importance, " \
"threshold, duration, alarm_setting.enable " \
"FROM alarm_setting INNER JOIN event_type " \
"ON alarm_setting.`type`=event_type.`id` " \
"INNER JOIN location " \
"on location.id=alarm_setting.location_id " \
"WHERE location_id IN %s"
sql_point = f"""
SELECT
sd.id,
sd.etype,
et.`NAME`,
sd.threshold,
sd.duration,
sd.importance,
sd.`enable`
FROM
soe_config_record sd
INNER JOIN event_type et ON sd.etype = et.e_type
WHERE
sd.pid = %s
"""
sql_location = """
SELECT
ln.item,
ln.ad_type AS location_ytpe,
sd.id,
sd.etype,
et.`name`,
sd.importance,
sd.threshold,
sd.duration,
sd.`enable`
FROM
soe_config_record sd
INNER JOIN event_type et ON sd.etype = et.e_type
INNER JOIN location ln ON ln.lid = sd.lid
WHERE
sd.lid IN %s
"""
async with MysqlUtil() as conn:
res_point = await conn.fetchall(sql_point, args=(
pid,)) if pid else {}
res_point = await conn.fetchall(sql_point, args=(pid,)) if pid else {}
res_location = await conn.fetchall(sql_location, args=(
tuple(locations),)) if locations else {}
tuple(locations)), ) if locations else {}
alarm_list = []
for res in res_point:
name = res.get("name")
id_ = res.get("id")
threshold = res.get("threshold")
duration = res.get("duration")
enable = res.get("enable")
event_type = res.get("type")
name = res.get("name", "")
id_ = res.get("id", "")
threshold = res.get("threshold", "")
duration = res.get("duration", "")
enable = res.get("enable", "")
event_type = res.get("type", "")
p_dic = {
"id": id_,
"type": name if name is not None else "",
"threshold": threshold if threshold is not None else "",
"duration": duration if duration is not None else "",
"enable": enable if enable is not None else "",
"type": name,
"threshold": threshold,
"duration": duration,
"enable": enable,
"unit": EVENT_TYPE_UNIT_MAP[event_type]
}
alarm_list.append(p_dic)
......@@ -53,16 +70,16 @@ async def alarm_setting_pds(pid, locations):
name = (res.get("item") + res.get("name")) if res.get(
"item") != "default" else res.get("name"),
id_ = res.get("id")
threshold = res.get("threshold")
duration = res.get("duration")
enable = res.get("enable")
event_type = res.get("type")
threshold = res.get("threshold", "")
duration = res.get("duration", "")
enable = res.get("enable", "")
event_type = res.get("type", "")
lo_dic = {
"id": id_,
"type": name if name is not None else "",
"threshold": threshold if threshold is not None else "",
"duration": duration if duration is not None else "",
"enable": enable if enable is not None else "",
"type": name,
"threshold": threshold,
"duration": duration,
"enable": enable,
"unit": EVENT_TYPE_UNIT_MAP[event_type]
}
alarm_list.append(lo_dic)
......
......@@ -139,10 +139,10 @@ async def equipment_details_mysql_service(sid, mtid):
alarm_list = await alarm_setting_pds(point_id, locations)
# 2. 额定电压, 额定电流
ct, pt, rated_voltage, rated_current = "", "", "", ""
ctnum, mid = await get_wiring_type(point_id)
ctnum, mtid = await get_wiring_type(point_id)
# 装置已安装逻辑:有mid且ptr、ctr有值
if mid:
meter_param_dic = await meter_param_by_mid(mid)
if mtid:
meter_param_dic = await meter_param_by_mid(mtid)
if meter_param_dic:
ct = meter_param_dic.get("ctr")
ct = ct if ct is not None else ""
......
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