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

获取监测点修改,复用其他cid数据

parent ad031b1b
...@@ -66,16 +66,6 @@ async def post_scope_list_download(request, ...@@ -66,16 +66,6 @@ async def post_scope_list_download(request,
return ScopeListDownloadResp(rows=datas) return ScopeListDownloadResp(rows=datas)
@summary("识别记录-详情")
async def post_scope_detail1(request,
body: ScopeDetailRep) -> ScopeDetailsResp:
'''
识别详情
'''
doc_id = body.id
return await scope_detail_data(doc_id)
@summary('数据统计-录波查询-录波详情') @summary('数据统计-录波查询-录波详情')
async def post_scope_detail(req, body: ScopeDetailRep) -> ScopeDetailResp: async def post_scope_detail(req, body: ScopeDetailRep) -> ScopeDetailResp:
# 1,获取参数 # 1,获取参数
......
...@@ -8,12 +8,13 @@ from dataclasses import dataclass ...@@ -8,12 +8,13 @@ from dataclasses import dataclass
from pot_libs.common.components.fields import Cid from pot_libs.common.components.fields import Cid
from pot_libs.sanic_api import Model from pot_libs.sanic_api import Model
from pot_libs.sanic_api.column import List, Str, Opt, Int from pot_libs.sanic_api.column import List, Str, Opt, Int
from unify_api.utils.response_code import DbErr from unify_api.utils.response_code import DbErr, ParamErr
@dataclass @dataclass
class ListPointRequest(Model): class ListPointRequest(Model):
cid: Cid cid: Cid
is_power_equipment: int = Opt(Int('是否动力设备 0-否 1-是'))
@dataclass @dataclass
...@@ -54,7 +55,7 @@ class LtpRep(Model): ...@@ -54,7 +55,7 @@ class LtpRep(Model):
@dataclass @dataclass
class ListPointResponse(Model, DbErr): class ListPointResponse(Model, DbErr, ParamErr):
points: typing.List[CommonPoint] = List().items(CommonPoint) points: typing.List[CommonPoint] = List().items(CommonPoint)
inlines: typing.List[Inline] = List().items(Inline) inlines: typing.List[Inline] = List().items(Inline)
power_show_all: int = Int("电量电费页面全部按钮是否显示,0-不显示 1-显示").eg(1) power_show_all: int = Int("电量电费页面全部按钮是否显示,0-不显示 1-显示").eg(1)
......
...@@ -14,51 +14,127 @@ from unify_api.modules.common.components.list_points_cps import ( ...@@ -14,51 +14,127 @@ from unify_api.modules.common.components.list_points_cps import (
Inline, LsRep, LtpRep, LplResp, LpiResp) Inline, LsRep, LtpRep, LplResp, LpiResp)
# @summary('获取监测点,进线列表')
# async def post_list_point(req, body: ListPointRequest) -> ListPointResponse:
# cid = body.cid
# list_point, inline_list, points = [], [], {}
# sql = "SELECT pid,name,mtid,inlid,add_to_company FROM point where cid=%s"
# async with MysqlUtil() as conn:
# result = await conn.fetchall(sql, args=(cid,))
# add_to_company = []
# for res in result:
# # mtids.append(res["mtid"])
# inline_list.append({"inline_id": res["inlid"], "name": res["name"]})
# points[res["mtid"]] = res
# add_to_company.append(res["add_to_company"])
# if points:
# if len(points) == 1:
# l_sql = f"SELECT mtid,lid,ad_field from location " \
# f"where mtid = {list(points.keys())[0]}"
# else:
# l_sql = f"SELECT mtid,lid,ad_field from location " \
# f"where mtid in {tuple(points.keys())}"
# async with MysqlUtil() as conn:
# datas = await conn.fetchall(l_sql)
# for data in datas:
# if data["mtid"] in points.keys():
# temp_dict = {"temp1": "A相", "temp2": "B相", "temp3": "C相",
# "temp4": "N相", "residual_current": "default"}
# flag = temp_dict.get(data["ad_field"]) or ""
# locations_dict = {
# "item": flag,
# "location_id": data.get("lid")
# }
# if "locations" not in points[data["mtid"]]:
# points[data["mtid"]]["locations"] = [locations_dict]
# else:
# points[data["mtid"]]["locations"].append(locations_dict)
# for k, v in points.items():
# list_point.append({
# "name": v["name"], "point_id": v["pid"],
# "locations": v.get("locations") or [],
# "add_to_company": v["add_to_company"]
# })
# return ListPointResponse(
# points=list_point,
# inlines=inline_list,
# power_show_all=1 if any(add_to_company) else 0
# )
@summary('获取监测点,进线列表') @summary('获取监测点,进线列表')
async def post_list_point(req, body: ListPointRequest) -> ListPointResponse: async def post_list_point(req, body: ListPointRequest) -> ListPointResponse:
cid = body.cid cid = body.cid
list_point, inline_list, points = [], [], {} if not cid or cid < 0:
sql = "SELECT pid,name,mtid,inlid,add_to_company FROM point where cid=%s" return ListPointResponse().param_error()
is_power_equipment = body.is_power_equipment
list_point = []
points = {}
groups = {}
# 查询属于当前工厂下的监测点 + 其他工厂但是被复用到当前工厂的监测点
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_belongedto=%s or m.cid = %s"
else:
# 动力设备
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_belongedto=%s or mr.cid = %s)"
async with MysqlUtil() as conn: async with MysqlUtil() as conn:
result = await conn.fetchall(sql, args=(cid,)) result = await conn.fetchall(sql, args=(cid, cid))
add_to_company = [] # 去调拆表的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: for res in result:
# mtids.append(res["mtid"]) pid = res.get("pid")
inline_list.append({"inline_id": res["inlid"], "name": res["name"]}) points[pid] = res
points[res["mtid"]] = res
add_to_company.append(res["add_to_company"]) # 获取相应的mtid
if points: point_map_mtids = [point["mtid"] for point in result if
if len(points) == 1: point['pid'] in point_mid_map]
l_sql = f"SELECT mtid,lid,ad_field from location " \
f"where mtid = {list(points.keys())[0]}" # 根据pid获取mtd
else: sql = "SELECT id, `group`, item FROM location WHERE ( cid=%s or mtid in " \
l_sql = f"SELECT mtid,lid,ad_field from location " \ "%s ) and `type` in %s"
f"where mtid in {tuple(points.keys())}" try:
async with MysqlUtil() as conn: async with MysqlUtil() as conn:
datas = await conn.fetchall(l_sql) result = await conn.fetchall(sql, args=(
for data in datas: cid, point_map_mtids, ["temperature", "residual_current"]))
if data["mtid"] in points.keys(): for res in result:
temp_dict = {"temp1": "A相", "temp2": "B相", "temp3": "C相", id = res.get("id")
"temp4": "N相", "residual_current": "default"} group = res.get("group")
flag = temp_dict.get(data["ad_field"]) or "" item = res.get("item")
locations_dict = { groups.setdefault(group, []).append((id, item))
"item": flag, except Exception as e:
"location_id": data.get("lid") log.exception(e)
} return ListPointResponse().db_error()
if "locations" not in points[data["mtid"]]:
points[data["mtid"]]["locations"] = [locations_dict] for pid, point_info in points.items():
else: name = point_info.get("name")
points[data["mtid"]]["locations"].append(locations_dict) add_to_company = point_info["add_to_company"]
for k, v in points.items(): items = groups.get(name, [])
list_point.append({ locations = []
"name": v["name"], "point_id": v["pid"], for id, item in items:
"locations": v.get("locations") or [], comm_location = CommonLocation(location_id=id, item=item)
"add_to_company": v["add_to_company"] locations.append(comm_location)
}) 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_belongedto=%s"
inlines = await conn.fetchall(sql, args=(cid,))
inline_list = [Inline(inline_id=inline["inlid"], name=inline["name"])
for inline in inlines]
return ListPointResponse( return ListPointResponse(
points=list_point, points=list_point,
inlines=inline_list, inlines=inline_list,
power_show_all=1 if any(add_to_company) else 0 power_show_all=1 if any(
i for i in list_point if i.add_to_company == 1) else 0
) )
......
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