Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
U
unify_api2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
chaonan
unify_api2
Commits
fd317f5f
Commit
fd317f5f
authored
May 15, 2023
by
wang.wenrong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
获取监测点修改,复用其他cid数据
parent
ad031b1b
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
115 additions
and
48 deletions
+115
-48
scope_operations.py
unify_api/modules/anshiu/views/scope_operations.py
+0
-10
list_points_cps.py
unify_api/modules/common/components/list_points_cps.py
+3
-2
list_point.py
unify_api/modules/common/views/list_point.py
+112
-36
No files found.
unify_api/modules/anshiu/views/scope_operations.py
View file @
fd317f5f
...
...
@@ -66,16 +66,6 @@ async def post_scope_list_download(request,
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
(
'数据统计-录波查询-录波详情'
)
async
def
post_scope_detail
(
req
,
body
:
ScopeDetailRep
)
->
ScopeDetailResp
:
# 1,获取参数
...
...
unify_api/modules/common/components/list_points_cps.py
View file @
fd317f5f
...
...
@@ -8,12 +8,13 @@ from dataclasses import dataclass
from
pot_libs.common.components.fields
import
Cid
from
pot_libs.sanic_api
import
Model
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
class
ListPointRequest
(
Model
):
cid
:
Cid
is_power_equipment
:
int
=
Opt
(
Int
(
'是否动力设备 0-否 1-是'
))
@
dataclass
...
...
@@ -54,7 +55,7 @@ class LtpRep(Model):
@
dataclass
class
ListPointResponse
(
Model
,
DbErr
):
class
ListPointResponse
(
Model
,
DbErr
,
ParamErr
):
points
:
typing
.
List
[
CommonPoint
]
=
List
()
.
items
(
CommonPoint
)
inlines
:
typing
.
List
[
Inline
]
=
List
()
.
items
(
Inline
)
power_show_all
:
int
=
Int
(
"电量电费页面全部按钮是否显示,0-不显示 1-显示"
)
.
eg
(
1
)
...
...
unify_api/modules/common/views/list_point.py
View file @
fd317f5f
...
...
@@ -14,51 +14,127 @@ from unify_api.modules.common.components.list_points_cps import (
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
(
'获取监测点,进线列表'
)
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"
if
not
cid
or
cid
<
0
:
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
:
result
=
await
conn
.
fetchall
(
sql
,
args
=
(
cid
,))
add_to_company
=
[]
result
=
await
conn
.
fetchall
(
sql
,
args
=
(
cid
,
cid
))
# 去调拆表的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
:
# 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())}"
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 id, `group`, item FROM location WHERE ( cid=
%
s or mtid in "
\
"
%
s ) and `type` in
%
s"
try
:
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"
]
})
result
=
await
conn
.
fetchall
(
sql
,
args
=
(
cid
,
point_map_mtids
,
[
"temperature"
,
"residual_current"
]))
for
res
in
result
:
id
=
res
.
get
(
"id"
)
group
=
res
.
get
(
"group"
)
item
=
res
.
get
(
"item"
)
groups
.
setdefault
(
group
,
[])
.
append
((
id
,
item
))
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"
]
items
=
groups
.
get
(
name
,
[])
locations
=
[]
for
id
,
item
in
items
:
comm_location
=
CommonLocation
(
location_id
=
id
,
item
=
item
)
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
(
points
=
list_point
,
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
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment