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
1599f549
Commit
1599f549
authored
May 31, 2024
by
ZZH
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
monitor name support multi lang 2024-05-30
parent
2c70ab26
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
124 additions
and
57 deletions
+124
-57
constants.py
unify_api/constants.py
+22
-1
list_alarm_service.py
...y_api/modules/alarm_manager/service/list_alarm_service.py
+79
-52
common_dao.py
unify_api/modules/common/dao/common_dao.py
+7
-0
multi_lang.py
unify_api/modules/common/procedures/multi_lang.py
+16
-4
No files found.
unify_api/constants.py
View file @
1599f549
...
...
@@ -615,3 +615,24 @@ E_TYPE_LANG = {
"de_DE"
:
""
},
}
PHASE_LINE_LANG
=
{
"A相"
:
{
"en_US"
:
"Phase A"
,
"de_DE"
:
""
},
"B相"
:
{
"en_US"
:
"Phase B"
,
"de_DE"
:
""
},
"C相"
:
{
"en_US"
:
"Phase C"
,
"de_DE"
:
""
},
"N线"
:
{
"en_US"
:
"Neutral Line"
,
"de_DE"
:
""
},
}
unify_api/modules/alarm_manager/service/list_alarm_service.py
View file @
1599f549
# -*- coding:utf-8 -*-
import
json
from
unify_api
import
constants
from
unify_api.modules.alarm_manager.components.list_alarm
import
\
ListAlarmResponse
,
Alarm
...
...
@@ -11,8 +13,12 @@ from unify_api.modules.common.procedures.points import points_by_storeys
from
unify_api.modules.electric.dao.electric_dao
import
\
monitor_point_join_points
from
unify_api.utils
import
time_format
from
unify_api.modules.common.dao.common_dao
import
load_user_lang
from
unify_api.modules.common.procedures.multi_lang
import
load_event_msg
from
unify_api.modules.common.dao.common_dao
import
(
load_user_lang
,
load_monitor_names
)
from
unify_api.modules.common.procedures.multi_lang
import
(
load_event_msg
,
load_phase_line
)
async
def
new_list_alarm_service
(
cid
,
storeys
,
offset
,
page_size
,
start
,
end
,
...
...
@@ -238,69 +244,90 @@ async def wx_list_alarm_zdu_service(cid, point_list, start, end):
return
ListAlarmResponse
(
total
=
len
(
results
),
rows
=
rows
)
async
def
pack_alarm_records
(
records
,
pid
,
lang
):
alarm_recs
,
mtr_names
=
[],
{}
if
lang
!=
"zh_CN"
:
mtids
=
[
r
[
"mtid"
]
for
r
in
records
]
mtr_names
=
await
load_monitor_names
(
mtids
,
lang
)
for
r
in
records
:
event_type
=
r
.
get
(
"event_type"
)
event_duration
=
r
.
get
(
"event_duration"
)
type_str
=
constants
.
EVENT_TYPE_MAP
.
get
(
event_type
)
es_id
=
r
.
get
(
"id"
)
if
pid
and
r
.
get
(
"event_mode"
)
==
"scope"
:
url
,
redirect_type
=
f
"/scope_details?doc_id={es_id}"
,
"scope"
elif
r
.
get
(
"lid"
)
and
event_type
in
constants
.
TEMP_SCOPE_URL_TYPE
:
url
,
redirect_type
=
f
"/temp_trend?doc_id={es_id}"
,
"temp_trend"
else
:
url
,
redirect_type
=
None
,
""
mtr_name
=
r
.
get
(
"name"
)
if
lang
==
"zh_CN"
:
event_msg
=
r
.
get
(
"message"
)
else
:
event_param
=
r
[
"event_param"
]
if
event_param
:
event_param
=
json
.
loads
(
r
[
"event_param"
])
event_msg
=
load_event_msg
(
event_type
,
event_param
,
lang
)
if
not
event_msg
:
event_msg
=
r
.
get
(
"message"
)
phase_line
=
load_phase_line
(
mtr_name
,
lang
)
name
=
mtr_names
[
r
[
"mtid"
]]
mtr_name
=
f
"{name}{phase_line}"
if
phase_line
else
name
alarm
=
Alarm
(
name
=
mtr_name
,
importance
=
r
.
get
(
"importance"
),
date_time
=
str
(
r
.
get
(
"event_datetime"
)),
type
=
event_type
,
type_name
=
type_str
,
description
=
event_msg
,
redirect_type
=
redirect_type
,
es_id
=
es_id
,
url
=
url
,
event_duration
=
round
(
event_duration
)
if
isinstance
(
event_duration
,
float
)
else
event_duration
,
company_name
=
r
.
get
(
"fullname"
)
or
''
,
)
alarm_recs
.
append
(
alarm
)
return
alarm_recs
async
def
list_alarm_service
(
cid
,
user_id
,
point_id
,
start
,
end
,
importance
,
page_size
,
page_num
,
alarm_type
):
li
=
[
"event_mode!='scope'"
]
conds
=
[
"event_mode!='scope'"
]
if
point_id
:
li
.
append
(
f
"pid={point_id}"
)
conds
.
append
(
f
"pid={point_id}"
)
else
:
if
not
isinstance
(
cid
,
list
):
cid
=
[
cid
]
cid_where
=
str
(
tuple
(
cid
))
.
replace
(
",)"
,
")"
)
li
.
append
(
f
"cid in {cid_where}"
)
conds
.
append
(
f
"cid in {cid_where}"
)
if
start
and
end
:
li
.
append
(
f
"event_datetime BETWEEN '{start}' and '{end}'"
)
conds
.
append
(
f
"event_datetime BETWEEN '{start}' and '{end}'"
)
if
importance
:
if
len
(
importance
)
==
1
:
li
.
append
(
f
"importance={importance[0]}"
)
conds
.
append
(
f
"importance={importance[0]}"
)
else
:
li
.
append
(
f
"importance in {str(tuple(importance)).strip(',')}"
)
conds
.
append
(
f
"importance in {str(tuple(importance)).strip(',')}"
)
else
:
li
.
append
(
"importance in (1, 2, 3)"
)
conds
.
append
(
"importance in (1, 2, 3)"
)
if
alarm_type
:
if
len
(
alarm_type
)
==
1
:
li
.
append
(
f
"event_type='{alarm_type[0]}'"
)
conds
.
append
(
f
"event_type='{alarm_type[0]}'"
)
else
:
li
.
append
(
f
"event_type in {str(tuple(alarm_type)).strip(',')}"
)
mid_sql
=
" and "
.
join
(
li
)
total
=
await
get_total_list_alarm_dao
(
mid_sql
)
mid_sql2
=
" and "
.
join
([
"point_1min_event."
+
i
for
i
in
li
])
datas
=
await
get_list_alarm_dao
(
mid_sql2
,
page_size
,
page_num
)
lang
=
await
load_user_lang
(
user_id
)
rows
=
[]
for
data
in
datas
:
event_type
=
data
.
get
(
"event_type"
)
event_duration
=
data
.
get
(
"event_duration"
)
type_str
=
constants
.
EVENT_TYPE_MAP
.
get
(
event_type
)
location_id
=
data
.
get
(
"lid"
)
es_id
=
data
.
get
(
"id"
)
if
point_id
and
data
.
get
(
"event_mode"
)
==
"scope"
:
url
=
"/scope_details?doc_id=
%
s"
%
es_id
redirect_type
=
"scope"
elif
location_id
and
type
in
constants
.
TEMP_SCOPE_URL_TYPE
:
url
=
"/temp_trend?doc_id=
%
s"
%
es_id
redirect_type
=
"temp_trend"
else
:
url
=
None
redirect_type
=
""
conds
.
append
(
f
"event_type in {str(tuple(alarm_type)).strip(',')}"
)
if
lang
==
"zh_CN"
:
event_msg
=
data
.
get
(
"message"
)
else
:
event_msg
=
load_event_msg
(
event_type
,
data
[
"event_param"
],
lang
)
alarm
=
Alarm
(
name
=
data
.
get
(
"name"
),
importance
=
data
.
get
(
"importance"
),
date_time
=
str
(
data
.
get
(
"event_datetime"
)),
type
=
event_type
,
type_name
=
type_str
,
description
=
event_msg
,
redirect_type
=
redirect_type
,
es_id
=
es_id
,
url
=
url
,
event_duration
=
round
(
event_duration
)
if
isinstance
(
event_duration
,
float
)
else
event_duration
,
company_name
=
data
.
get
(
"fullname"
)
or
''
,
)
rows
.
append
(
alarm
)
return
ListAlarmResponse
(
total
=
total
,
rows
=
rows
)
total
=
await
get_total_list_alarm_dao
(
" AND "
.
join
(
conds
))
conds_str
=
" AND "
.
join
([
"point_1min_event."
+
i
for
i
in
conds
])
alarm_lst
=
await
get_list_alarm_dao
(
conds_str
,
page_size
,
page_num
)
lang
=
await
load_user_lang
(
user_id
)
alarm_records
=
await
pack_alarm_records
(
alarm_lst
,
point_id
,
lang
)
return
ListAlarmResponse
(
total
=
total
,
rows
=
alarm_records
)
unify_api/modules/common/dao/common_dao.py
View file @
1599f549
...
...
@@ -357,3 +357,10 @@ async def load_point_pttl_mean(start, end, pid):
async
with
MysqlUtil
()
as
conn
:
datas
=
await
conn
.
fetchall
(
sql
,
args
=
(
pid
,))
return
datas
async
def
load_monitor_names
(
mtids
,
lang
):
sql
=
f
"SELECT mtid, {lang} FROM power_iot.monitor_name WHERE mtid IN
%
s;"
async
with
MysqlUtil
()
as
conn
:
return
{
r
[
"mtid"
]:
r
[
lang
]
for
r
in
await
conn
.
fetchall
(
sql
,
(
tuple
(
mtids
),))}
unify_api/modules/common/procedures/multi_lang.py
View file @
1599f549
...
...
@@ -3,9 +3,8 @@
DATE:2024/5/30 11:34
"""
import
json
from
unify_api.constants
import
E_TYPE_LANG
from
pot_libs.logger
import
log
from
unify_api.constants
import
E_TYPE_LANG
,
PHASE_LINE_LANG
def
load_event_msg
(
e_type
,
event_param
,
lang
):
...
...
@@ -16,4 +15,17 @@ def load_event_msg(e_type, event_param, lang):
if
not
msg_fmt
:
return
""
return
msg_fmt
.
format
(
**
json
.
loads
(
event_param
))
return
msg_fmt
.
format
(
**
event_param
)
def
load_phase_line
(
mtr_name
,
lang
):
lst
=
[]
try
:
lst
=
mtr_name
.
split
(
"_"
)
except
Exception
as
e
:
log
.
error
(
f
"load_phase_line error, mtr_name:{mtr_name}, {e}"
)
finally
:
if
len
(
lst
)
>
1
:
return
PHASE_LINE_LANG
.
get
(
lst
[
-
1
],
{})
.
get
(
lang
)
return
""
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