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
9a60c699
Commit
9a60c699
authored
Jun 20, 2023
by
lcn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bug修复
parent
2fb841ab
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
77 additions
and
26 deletions
+77
-26
equip_management_pds.py
unify_api/modules/anshiu/procedures/equip_management_pds.py
+8
-10
scope_operations_serv.py
unify_api/modules/anshiu/service/scope_operations_serv.py
+4
-2
common_dao.py
unify_api/modules/common/dao/common_dao.py
+9
-0
mqtt_helper.py
unify_api/modules/device_cloud/procedures/mqtt_helper.py
+56
-14
No files found.
unify_api/modules/anshiu/procedures/equip_management_pds.py
View file @
9a60c699
...
@@ -157,18 +157,16 @@ async def get_equip_run_status(point_id):
...
@@ -157,18 +157,16 @@ async def get_equip_run_status(point_id):
async
with
MysqlUtil
()
as
conn
:
async
with
MysqlUtil
()
as
conn
:
# 是否非动力设备
# 是否非动力设备
power_equip_sql
=
"select is_power_equipment from monitor m "
\
power_equip_sql
=
"select is_power_equipment from monitor m "
\
"left join point p on m.mtid = p.mtid "
\
"left join point p on m.mtid = p.mtid "
\
"where p.pid =
%
s"
"where p.pid =
%
s"
power_equip_result
=
await
conn
.
fetchone
(
sql
=
power_equip_sql
,
power_equip_result
=
await
conn
.
fetchone
(
sql
=
power_equip_sql
,
args
=
(
point_id
,))
args
=
(
point_id
,))
if
power_equip_result
.
get
(
"is_power_equipment"
,
0
)
==
0
:
if
power_equip_result
.
get
(
"is_power_equipment"
,
0
)
==
0
:
return
2
return
2
raw_sql
=
"select count(*) run_count from scope_equip_run_record s "
\
raw_sql
=
"select (case when end_time > unix_timestamp(NOW()) then 1 "
\
"left join (select pid,max(id) max_id from "
\
"when end_time=0 then 1 else 0 end) run_count "
\
"scope_equip_run_record group by pid) sp "
\
"from scope_equip_run_record "
\
"on s.pid = sp.pid "
\
"WHERE pid =
%
s and start_time < unix_timestamp(NOW()) "
\
"WHERE s.pid=
%
s and start_time < unix_timestamp(NOW()) "
\
"order by start_time desc limit 1"
"and (end_time > unix_timestamp(NOW()) or "
\
"(end_time=0 and id=max_id)) "
result
=
await
conn
.
fetchone
(
sql
=
raw_sql
,
args
=
(
point_id
,))
result
=
await
conn
.
fetchone
(
sql
=
raw_sql
,
args
=
(
point_id
,))
return
1
if
result
.
get
(
"run_count"
)
>
0
else
0
return
1
if
result
and
result
.
get
(
"run_count"
)
else
0
unify_api/modules/anshiu/service/scope_operations_serv.py
View file @
9a60c699
import
json
import
json
import
math
import
math
from
pot_libs.aredis_util.aredis_utils
import
RedisUtils
from
pot_libs.qingstor_util.qs_client
import
QsClient
from
pot_libs.qingstor_util.qs_client
import
QsClient
from
unify_api.modules.zhiwei_u.fault_foreast.actionFile
import
actionFilemin
from
unify_api.modules.zhiwei_u.fault_foreast.actionFile
import
actionFilemin
from
unify_api.modules.zhiwei_u.fault_foreast.test
import
leakage_reg
from
unify_api.modules.zhiwei_u.fault_foreast.test
import
leakage_reg
...
@@ -152,7 +154,7 @@ async def set_scope_config_serv(pid, type, scope_type, args):
...
@@ -152,7 +154,7 @@ async def set_scope_config_serv(pid, type, scope_type, args):
'''
'''
# 先查看缓存中是否存在,如果存在直接返回
# 先查看缓存中是否存在,如果存在直接返回
redis_key
=
f
"scope_config:{pid}"
redis_key
=
f
"scope_config:{pid}"
redis_result
=
await
aredis_utils
.
RedisClient
()
.
get
(
redis_key
)
redis_result
=
await
RedisUtils
()
.
get
(
redis_key
)
log
.
info
(
f
'set_scope_config_serv redis_result:{redis_result}'
)
log
.
info
(
f
'set_scope_config_serv redis_result:{redis_result}'
)
if
redis_result
:
if
redis_result
:
raise
Exception
(
'两次操作间隔3分钟,请稍后再试。'
)
raise
Exception
(
'两次操作间隔3分钟,请稍后再试。'
)
...
@@ -218,7 +220,7 @@ async def set_scope_config_serv(pid, type, scope_type, args):
...
@@ -218,7 +220,7 @@ async def set_scope_config_serv(pid, type, scope_type, args):
# 配置下发(只有正式环境才开启)
# 配置下发(只有正式环境才开启)
await
set_mqtt_scope_config
(
pid
,
configs
,
scope_type
)
await
set_mqtt_scope_config
(
pid
,
configs
,
scope_type
)
# 将数据存入缓存中
# 将数据存入缓存中
await
aredis_utils
.
RedisClient
()
.
setex
(
redis_key
,
180
,
pid
)
await
RedisUtils
()
.
setex
(
redis_key
,
180
,
pid
)
# 保存配置信息
# 保存配置信息
new_configs
=
json
.
dumps
(
configs
)
new_configs
=
json
.
dumps
(
configs
)
update_count
=
await
set_scope_config_by_pid
(
pid
,
new_configs
)
update_count
=
await
set_scope_config_by_pid
(
pid
,
new_configs
)
...
...
unify_api/modules/common/dao/common_dao.py
View file @
9a60c699
...
@@ -79,6 +79,15 @@ async def get_location_monitor_dao(lid):
...
@@ -79,6 +79,15 @@ async def get_location_monitor_dao(lid):
return
datas
return
datas
async
def
sid_by_pid
(
pid
):
"""根据pid查询sid"""
sql
=
"select sid,meter_no from monitor m left join point p on m.mtid = "
\
"p.mtid where p.pid=
%
s "
async
with
MysqlUtil
()
as
conn
:
result
=
await
conn
.
fetchone
(
sql
,
args
=
(
pid
,))
return
result
async
def
meter_by_mids
(
mids
):
async
def
meter_by_mids
(
mids
):
"""根据mids查询meter"""
"""根据mids查询meter"""
sql
=
"select * from meter where mid in
%
s"
sql
=
"select * from meter where mid in
%
s"
...
...
unify_api/modules/device_cloud/procedures/mqtt_helper.py
View file @
9a60c699
import
pendulum
import
pendulum
from
pot_libs.logger
import
log
from
unify_api.modules.common.dao.common_dao
import
(
from
unify_api.modules.common.dao.common_dao
import
(
get_point_monitor_dao
,
get_location_monitor_dao
get_point_monitor_dao
,
get_location_monitor_dao
,
sid_by_pid
)
)
from
uuid
import
uuid4
from
uuid
import
uuid4
...
@@ -47,27 +49,67 @@ async def get_location_soe_config(event, with_params):
...
@@ -47,27 +49,67 @@ async def get_location_soe_config(event, with_params):
return
sid
,
config
return
sid
,
config
async
def
change_param_to_config
(
req_json
,
method
):
async
def
get_point_scope_config
(
event_data
,
method
=
'config'
):
'''
获取录波配置需要的参数
'''
point_id
=
event_data
.
get
(
'point_id'
)
del
event_data
[
'point_id'
]
# 根据pid获取sid
monitor_dic
=
await
sid_by_pid
(
point_id
)
if
monitor_dic
is
None
:
log
.
info
(
f
'=======no monitor of point id: {point_id}'
)
return
None
,
None
sid
=
monitor_dic
.
get
(
"sid"
)
scope_type
=
event_data
.
get
(
'scope_type'
)
del
event_data
[
'scope_type'
]
scope_trans_rule
=
{
'0.25ms'
:
'scope'
,
'0.2s'
:
'wave_200ms'
,
'2s'
:
'electric_2s'
}
scope_param
=
scope_trans_rule
.
get
(
scope_type
)
if
method
!=
'get'
and
not
scope_param
:
log
.
info
(
f
'=======no scope_param of scope_type: {scope_type}'
)
return
None
,
None
if
method
==
'config'
:
config
=
{
scope_param
:
event_data
}
else
:
config
=
scope_param
return
sid
,
config
async
def
change_param_to_config
(
req_json
,
method
,
type
=
'soe'
):
"""
"""
web参数, 转换为与装置通信的报文
web参数, 转换为与装置通信的报文
soe method: config
soe method: config
"""
"""
sid
,
config
=
None
,
None
sid
,
config
=
None
,
None
point_id
=
req_json
.
get
(
"point_id"
)
if
type
==
'scope'
:
if
point_id
is
not
None
:
sid
,
config
=
await
get_point_scope_config
(
req_json
,
method
)
sid
,
config
=
await
get_point_soe_config
(
req_json
,
with_params
=
True
)
else
:
point_id
=
req_json
.
get
(
"point_id"
)
location_id
=
req_json
.
get
(
'location_id'
)
if
point_id
is
not
None
:
if
location_id
is
not
None
:
sid
,
config
=
await
get_point_soe_config
(
req_json
,
sid
,
config
=
await
get_location_soe_config
(
req_json
,
with_params
=
True
)
with_params
=
True
)
location_id
=
req_json
.
get
(
'location_id'
)
if
location_id
is
not
None
:
sid
,
config
=
await
get_location_soe_config
(
req_json
,
with_params
=
True
)
request_data
=
{}
request_data
=
{}
if
sid
:
if
sid
:
request_id
=
str
(
uuid4
())
request_id
=
str
(
uuid4
())
request_data
=
dict
(
request_id
=
request_id
,
request_data
=
dict
(
time
=
pendulum
.
now
()
.
to_datetime_string
(),
request_id
=
request_id
,
method
=
method
,
time
=
pendulum
.
now
()
.
to_datetime_string
(),
sid
=
sid
,
data
=
config
)
method
=
method
,
sid
=
sid
)
if
method
==
'get-config'
:
request_data
[
'key'
]
=
config
elif
method
==
'config'
:
request_data
[
'data'
]
=
config
return
request_data
return
request_data
...
...
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