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