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
07d65473
Commit
07d65473
authored
Aug 25, 2022
by
lcn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
BUG修复
parent
46311c41
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
82 additions
and
5 deletions
+82
-5
adio_dao.py
unify_api/modules/adio/dao/adio_dao.py
+22
-2
adio.py
unify_api/modules/adio/views/adio.py
+57
-1
common_dao.py
unify_api/modules/common/dao/common_dao.py
+3
-2
No files found.
unify_api/modules/adio/dao/adio_dao.py
View file @
07d65473
from
pot_libs.mysql_util.mysql_util
import
MysqlUtil
from
pot_libs.settings
import
SETTING
from
unify_api.modules.common.service.td_engine_service
import
\
get_td_engine_data
async
def
get_location_dao
(
lids
):
location_info
=
{}
sql
=
"SELECT lid, item, ad_type FROM location WHERE lid IN
%
s"
sql
=
"SELECT lid, item,
mtid,
ad_type FROM location WHERE lid IN
%
s"
async
with
MysqlUtil
()
as
conn
:
result
=
await
conn
.
fetchall
(
sql
,
args
=
(
lids
,))
if
result
:
...
...
@@ -11,7 +14,8 @@ async def get_location_dao(lids):
id
=
res
.
get
(
"lid"
)
item
=
res
.
get
(
"item"
)
type
=
res
.
get
(
"ad_type"
)
location_info
[
id
]
=
{
"item"
:
item
,
"type"
:
type
}
mtid
=
res
.
get
(
"mtid"
)
location_info
[
id
]
=
{
"item"
:
item
,
"type"
:
type
,
"mtid"
:
mtid
}
return
location_info
...
...
@@ -22,3 +26,19 @@ async def get_location_15min_dao(lid, start, end):
async
with
MysqlUtil
()
as
conn
:
result
=
await
conn
.
fetchall
(
sql
,
args
=
(
lid
,))
return
result
async
def
get_adio_current_data
(
mtid
):
'''
获取安全监测实时数据
'''
url
=
f
"{SETTING.stb_url}db_adio"
sql
=
f
"select last_row(*) from mt{mtid}_adi"
is_success
,
results
=
await
get_td_engine_data
(
url
,
sql
)
if
not
is_success
:
return
{}
if
not
results
[
'data'
]:
return
{}
head
=
results
[
'head'
]
res
=
dict
(
zip
(
head
,
results
[
'data'
][
0
]))
return
res
unify_api/modules/adio/views/adio.py
View file @
07d65473
...
...
@@ -27,7 +27,7 @@ from unify_api.modules.adio.components.adio import (
)
from
pot_libs.common.components.query
import
PageRequest
,
Range
,
Equal
,
Filter
from
unify_api.modules.adio.dao.adio_dao
import
get_location_dao
,
\
get_location_15min_dao
get_location_15min_dao
,
get_adio_current_data
@
summary
(
"返回安全监测历史曲线"
)
...
...
@@ -120,6 +120,62 @@ async def post_adio_current(req, body: PageRequest) -> AdioCurrentResponse:
except
:
log
.
warning
(
"para exception, in_groups is NULL, no location_id"
)
return
AdioCurrentResponse
(
temperature
=
[],
residual_current
=
[])
# location_ids
location_group
=
in_group
.
group
if
not
location_group
:
log
.
warning
(
"para exception, in_groups is NULL, no location_id"
)
return
AdioCurrentResponse
(
temperature
=
[],
residual_current
=
[])
# 读取location表信息
location_info
=
await
get_location_dao
(
location_group
)
if
not
location_info
:
log
.
warning
(
"location_id error location_info empty"
)
return
AdioCurrentResponse
(
temperature
=
[],
residual_current
=
[])
# 获取mtid信息
mtid
=
list
(
location_info
.
values
())[
0
][
'mtid'
]
# 读取tdengine里面的数据
aido_data
=
await
get_adio_current_data
(
mtid
)
if
not
aido_data
:
return
AdioCurrentResponse
(
temperature
=
[],
residual_current
=
[])
temperature
=
[]
residual_current
=
[]
trans_field
=
{
"A相"
:
"temp1"
,
"B相"
:
"temp2"
,
"C相"
:
"temp3"
,
"N线"
:
"temp4"
}
for
location_id
,
item_info
in
location_info
.
items
():
time_str
=
aido_data
.
get
(
'ts'
)[:
19
]
item
=
item_info
.
get
(
"item"
,
""
)
if
item_info
.
get
(
"type"
)
==
"residual_current"
:
adio_current
=
AdioCurrent
(
type
=
"residual_current"
,
item
=
"漏电流"
,
real_time
=
time_str
,
value
=
aido_data
.
get
(
"residual_current"
)
)
residual_current
.
append
(
adio_current
)
else
:
type_filed
=
trans_field
.
get
(
item
)
adio_current
=
AdioCurrent
(
type
=
"temperature"
,
item
=
item
,
real_time
=
time_str
,
value
=
aido_data
.
get
(
type_filed
),
)
temperature
.
append
(
adio_current
)
return
AdioCurrentResponse
(
temperature
=
temperature
,
residual_current
=
residual_current
)
@
summary
(
"返回安全监测实时参数(老的)"
)
@
description
(
"包含温度和漏电流(老的)"
)
@
examples
(
adio_current_example
)
async
def
post_adio_current_bak
(
req
,
body
:
PageRequest
)
->
AdioCurrentResponse
:
try
:
in_group
=
body
.
filter
.
in_groups
[
0
]
except
:
log
.
warning
(
"para exception, in_groups is NULL, no location_id"
)
return
AdioCurrentResponse
(
temperature
=
[],
residual_current
=
[])
# location_ids
location_group
=
in_group
.
group
...
...
unify_api/modules/common/dao/common_dao.py
View file @
07d65473
...
...
@@ -71,9 +71,10 @@ async def mid_by_pid(pid):
async
def
get_point_monitor_dao
(
pid
):
sql
=
"SELECT m.meter_no,m.sid,p.ctr,p.ptr,p.ctnum,p.vc,p.tc,p.imax "
\
sql
=
"SELECT m.meter_no,m.mtid,m.sid,"
\
"p.ctr,p.ptr,p.ctnum,p.vc,p.tc,p.imax"
\
"FROM `point` p INNER JOIN monitor m on m.mtid=p.mtid "
\
"where p.pid=
%
s
limit 1;
"
"where p.pid=
%
s
and m.demolished = 0
"
async
with
MysqlUtil
()
as
conn
:
datas
=
await
conn
.
fetchone
(
sql
,
args
=
(
pid
,))
return
datas
...
...
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