Commit 21b257c1 authored by lcn's avatar lcn

bug修复

parent d2c161bf
......@@ -23,39 +23,41 @@ async def post_list_point(req, body: ListPointRequest) -> ListPointResponse:
list_point = []
points = {}
groups = {}
sql = "SELECT p.pid,p.mtid, p.name, p.add_to_company FROM point p " \
"left join monitor m on p.mtid = m.mtid " \
"left join monitor_reuse mr on p.mtid = mr.mtid " \
"WHERE m.demolished = 0 and (p.cid=%s or mr.cid = %s) "
# 查询属于当前工厂下的监测点 + 其他工厂但是被复用到当前工厂的监测点
if not is_power_equipment:
sql = "SELECT p.pid,p.mtid, p.name, p.add_to_company FROM point p " \
"left join monitor_reuse m on p.mtid = m.mtid " \
"WHERE p.cid=%s or m.cid = %s"
else:
if is_power_equipment:
# 动力设备
sql = "SELECT p.pid,p.mtid, p.name, p.add_to_company FROM point p " \
"left join monitor m on p.mtid = m.mtid " \
"left join monitor_reuse mr on p.mtid = mr.mtid " \
"WHERE m.demolished = 0 and m.is_power_equipment = 1 and (" \
"p.cid=%s or mr.cid = %s)"
sql += " and m.is_power_equipment = 1 "
async with MysqlUtil() as conn:
result = await conn.fetchall(sql, args=(cid, cid))
if not result:
return ListPointResponse(
points=list_point,
inlines=[],
power_show_all=0
)
# 去调拆表的POINT
point_ids = [point["pid"] for point in result]
point_mid_map, point_count = await point_to_mid(point_ids)
result = [point for point in result if point["pid"] in point_mid_map]
for res in result:
pid = res.get("pid")
points[pid] = res
# 获取相应的mtid
point_map_mtids = [point["mtid"] for point in result if
point['pid'] in point_mid_map]
# 根据pid获取mtd
sql = "SELECT ln.lid, mr.`name` `group`, ln.item FROM location ln LEFT JOIN" \
" monitor mr on ln.mtid = mr.mtid WHERE ( ln.cid=%s or ln.mtid in " \
"%s ) and ln.`ad_type` in %s"
try:
async with MysqlUtil() as conn:
result = await conn.fetchall(sql, args=(
......@@ -68,7 +70,7 @@ async def post_list_point(req, body: ListPointRequest) -> ListPointResponse:
except Exception as e:
log.exception(e)
return ListPointResponse().db_error()
for pid, point_info in points.items():
name = point_info.get("name")
add_to_company = point_info["add_to_company"]
......@@ -80,7 +82,7 @@ async def post_list_point(req, body: ListPointRequest) -> ListPointResponse:
comm_point = CommonPoint(name=name, point_id=pid, locations=locations,
add_to_company=add_to_company)
list_point.append(comm_point)
async with MysqlUtil() as conn:
sql = "SELECT inlid, `name` FROM inline WHERE cid=%s"
inlines = await conn.fetchall(sql, args=(cid,))
......
......@@ -75,12 +75,11 @@ async def get_elec_mtid_sid_by_cid(cid):
async def load_add_to_compy_ids(cid):
if not isinstance(cid, (list, tuple)):
cid = [cid]
symbol = "in" if isinstance(cid, (list, tuple)) else "="
db = SETTING.mysql_db
sql = f"SELECT monitor.mtid, monitor.sid FROM {db}.monitor " \
f"INNER JOIN {db}.point ON point.mtid=monitor.mtid " \
f"WHERE monitor.cid in %s AND point.add_to_company=1 " \
f"WHERE monitor.cid {symbol} %s AND point.add_to_company=1 " \
f"AND monitor.demolished=0;"
async with MysqlUtil() as conn:
ids = await conn.fetchall(sql, (cid,))
......
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