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
d9c6073c
Commit
d9c6073c
authored
May 30, 2024
by
ZZH
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support multi lang 2024-05-30
parent
cf293000
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
169 additions
and
13 deletions
+169
-13
constants.py
unify_api/constants.py
+121
-0
list_alarm_service.py
...y_api/modules/alarm_manager/service/list_alarm_service.py
+11
-3
list_alarm.py
unify_api/modules/alarm_manager/views/list_alarm.py
+10
-10
common_dao.py
unify_api/modules/common/dao/common_dao.py
+8
-0
multi_lang.py
unify_api/modules/common/procedures/multi_lang.py
+19
-0
No files found.
unify_api/constants.py
View file @
d9c6073c
...
@@ -494,3 +494,124 @@ S030_TOPIC = ["electric", "soe", "scope", "adio", "scope", "appliance",
...
@@ -494,3 +494,124 @@ S030_TOPIC = ["electric", "soe", "scope", "adio", "scope", "appliance",
WG_TOPIC
=
[
"tsp"
,
"water"
,
"water_bromake"
,
"ws"
]
WG_TOPIC
=
[
"tsp"
,
"water"
,
"water_bromake"
,
"ws"
]
OSS_NEWS
=
"filedata/official_web/news_info"
OSS_NEWS
=
"filedata/official_web/news_info"
E_TYPE_LANG
=
{
"power_quality_low"
:
{
"en_US"
:
"The power quality is low, and there may be substandard electrical appliances present"
,
"de_DE"
:
""
},
"illegal_ele_app"
:
{
"en_US"
:
"There is an unauthorized appliance connected and in use, suspected to be {appliance}"
,
"de_DE"
:
""
},
"ele_overload"
:
{
"en_US"
:
"The line load rate has exceeded 80
%
, with the highest reaching {max}
%
"
,
"de_DE"
:
""
},
"overI"
:
{
"en_US"
:
"The current on phase {phase} has been exceeding the rated current by {threshold}
%
for {duration} seconds, reaching a maximum of {max}A"
,
"de_DE"
:
""
},
"overU"
:
{
"en_US"
:
"The voltage on the {branch} has been exceeding the rated voltage by {threshold}
%
for {duration} seconds, reaching a maximum of {max}V"
,
"de_DE"
:
""
},
"overPR"
:
{
"en_US"
:
"Load rate exceeds {threshold}
%
, reaching {cur}
%
"
,
"de_DE"
:
""
},
"overResidualCurrent"
:
{
"en_US"
:
"The leakage current has exceeded {threshold} mA, reaching {cur} mA"
,
"de_DE"
:
""
},
"overTemp"
:
{
"en_US"
:
"The temperature has exceeded {threshold}°C, reaching {cur}°C"
,
"de_DE"
:
""
},
"overTempRange15min"
:
{
"en_US"
:
"The temperature rise exceeds {threshold}°C within 15 minutes, reaching {cur}°C"
,
"de_DE"
:
""
},
"overTempRange1min"
:
{
"en_US"
:
"The temperature rise within 1 minute has exceeded {threshold}°C, reaching {cur}°C"
,
"de_DE"
:
""
},
"overTempTrendDaily"
:
{
"en_US"
:
"The temperature forecast for today predicts that the temperature at {time_str} may exceed {threshold}°C, reaching {cur}°C"
,
"de_DE"
:
""
},
"overTempTrendQuarterly"
:
{
"en_US"
:
"The real-time temperature forecast for today suggests that the temperature at {time_str} may exceed {threshold}°C, reaching {cur}°C"
,
"de_DE"
:
""
},
"overTHDI"
:
{
"en_US"
:
"The total harmonic distortion (THD) of the {phase}-phase current exceeds the limit of {threshold}A, reaching {cur}A"
,
"de_DE"
:
""
},
"overTHDU"
:
{
"en_US"
:
"The total harmonic distortion (THD) of the voltage in phase {phase} has exceeded the limit of {threshold}
%
, reaching {cur}
%
"
,
"de_DE"
:
""
},
"unbalanceI"
:
{
"en_US"
:
"The three-phase current unbalance has been sustained for {duration} seconds exceeding {threshold}
%
, with the highest reaching {max}
%
"
,
"de_DE"
:
""
},
"unbalanceU"
:
{
"en_US"
:
"The three-phase voltage unbalance has been exceeding {threshold}
%
for {duration} seconds, with the highest reaching {max}"
,
"de_DE"
:
""
},
"under_rms_u"
:
{
"en_US"
:
""
,
"de_DE"
:
""
},
"underPhasePF"
:
{
"en_US"
:
"The power factor of phase {phase} has been below {threshold} for {duration} seconds, reaching a minimum of {min}"
,
"de_DE"
:
""
},
"underTotalPF"
:
{
"en_US"
:
"The three-phase total power factor has been below {threshold} for {duration} seconds, reaching a minimum of {min}"
,
"de_DE"
:
""
},
"underU"
:
{
"en_US"
:
"The voltage on branch {branch} has been below the rated voltage by {threshold}
%
for {duration} seconds, reaching a minimum of {min}V"
,
"de_DE"
:
""
},
"over_gap_cur"
:
{
"en_US"
:
""
,
"de_DE"
:
""
},
"over_gap_i"
:
{
"en_US"
:
""
,
"de_DE"
:
""
},
"over_gap_pttl"
:
{
"en_US"
:
""
,
"de_DE"
:
""
},
"over_gap_u"
:
{
"en_US"
:
""
,
"de_DE"
:
""
},
"over_res_cur"
:
{
"en_US"
:
""
,
"de_DE"
:
""
},
"over_rms_i"
:
{
"en_US"
:
""
,
"de_DE"
:
""
},
"over_rms_pttl"
:
{
"en_US"
:
""
,
"de_DE"
:
""
},
"over_rms_u"
:
{
"en_US"
:
""
,
"de_DE"
:
""
},
}
\ No newline at end of file
unify_api/modules/alarm_manager/service/list_alarm_service.py
View file @
d9c6073c
...
@@ -11,6 +11,8 @@ from unify_api.modules.common.procedures.points import points_by_storeys
...
@@ -11,6 +11,8 @@ from unify_api.modules.common.procedures.points import points_by_storeys
from
unify_api.modules.electric.dao.electric_dao
import
\
from
unify_api.modules.electric.dao.electric_dao
import
\
monitor_point_join_points
monitor_point_join_points
from
unify_api.utils
import
time_format
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
async
def
new_list_alarm_service
(
cid
,
storeys
,
offset
,
page_size
,
start
,
end
,
async
def
new_list_alarm_service
(
cid
,
storeys
,
offset
,
page_size
,
start
,
end
,
...
@@ -236,8 +238,8 @@ async def wx_list_alarm_zdu_service(cid, point_list, start, end):
...
@@ -236,8 +238,8 @@ async def wx_list_alarm_zdu_service(cid, point_list, start, end):
return
ListAlarmResponse
(
total
=
len
(
results
),
rows
=
rows
)
return
ListAlarmResponse
(
total
=
len
(
results
),
rows
=
rows
)
async
def
list_alarm_service
(
cid
,
point_id
,
start
,
end
,
importance
,
page_siz
e
,
async
def
list_alarm_service
(
cid
,
user_id
,
point_id
,
start
,
end
,
importanc
e
,
page_num
,
alarm_type
):
page_
size
,
page_
num
,
alarm_type
):
li
=
[
"event_mode!='scope'"
]
li
=
[
"event_mode!='scope'"
]
if
point_id
:
if
point_id
:
li
.
append
(
f
"pid={point_id}"
)
li
.
append
(
f
"pid={point_id}"
)
...
@@ -264,6 +266,7 @@ async def list_alarm_service(cid, point_id, start, end, importance, page_size,
...
@@ -264,6 +266,7 @@ async def list_alarm_service(cid, point_id, start, end, importance, page_size,
total
=
await
get_total_list_alarm_dao
(
mid_sql
)
total
=
await
get_total_list_alarm_dao
(
mid_sql
)
mid_sql2
=
" and "
.
join
([
"point_1min_event."
+
i
for
i
in
li
])
mid_sql2
=
" and "
.
join
([
"point_1min_event."
+
i
for
i
in
li
])
datas
=
await
get_list_alarm_dao
(
mid_sql2
,
page_size
,
page_num
)
datas
=
await
get_list_alarm_dao
(
mid_sql2
,
page_size
,
page_num
)
lang
=
await
load_user_lang
(
user_id
)
rows
=
[]
rows
=
[]
for
data
in
datas
:
for
data
in
datas
:
event_type
=
data
.
get
(
"event_type"
)
event_type
=
data
.
get
(
"event_type"
)
...
@@ -280,13 +283,18 @@ async def list_alarm_service(cid, point_id, start, end, importance, page_size,
...
@@ -280,13 +283,18 @@ async def list_alarm_service(cid, point_id, start, end, importance, page_size,
else
:
else
:
url
=
None
url
=
None
redirect_type
=
""
redirect_type
=
""
if
lang
==
"zh_CN"
:
event_msg
=
data
.
get
(
"message"
)
else
:
event_msg
=
load_event_msg
(
event_type
,
data
[
"event_param"
],
lang
)
alarm
=
Alarm
(
alarm
=
Alarm
(
name
=
data
.
get
(
"name"
),
name
=
data
.
get
(
"name"
),
importance
=
data
.
get
(
"importance"
),
importance
=
data
.
get
(
"importance"
),
date_time
=
str
(
data
.
get
(
"event_datetime"
)),
date_time
=
str
(
data
.
get
(
"event_datetime"
)),
type
=
event_type
,
type
=
event_type
,
type_name
=
type_str
,
type_name
=
type_str
,
description
=
data
.
get
(
"message"
)
,
description
=
event_msg
,
redirect_type
=
redirect_type
,
redirect_type
=
redirect_type
,
es_id
=
es_id
,
es_id
=
es_id
,
url
=
url
,
url
=
url
,
...
...
unify_api/modules/alarm_manager/views/list_alarm.py
View file @
d9c6073c
...
@@ -7,17 +7,17 @@ from pot_libs.utils.exc_util import BusinessException
...
@@ -7,17 +7,17 @@ from pot_libs.utils.exc_util import BusinessException
from
unify_api.constants
import
Product
from
unify_api.constants
import
Product
from
unify_api.modules.alarm_manager.components.alarm_static_cps
import
NlaReq
,
\
from
unify_api.modules.alarm_manager.components.alarm_static_cps
import
NlaReq
,
\
WlaReq
,
LazReq
WlaReq
,
LazReq
from
unify_api.modules.alarm_manager.service.list_alarm_service
import
\
from
unify_api.modules.alarm_manager.service.list_alarm_service
import
(
new_list_alarm_service
,
wx_list_alarm_service
,
list_alarm_zdu_service
,
\
new_list_alarm_service
,
wx_list_alarm_service
,
list_alarm_zdu_service
,
wx_list_alarm_zdu_service
,
list_alarm_service
wx_list_alarm_zdu_service
,
list_alarm_service
from
unify_api.modules.common.procedures.cids
import
get_cid_info
,
get_cids
,
\
)
get_proxy_cids
from
unify_api.modules.common.procedures.cids
import
(
get_cid_info
,
get_cids
,
get_proxy_cids
)
from
unify_api.modules.users.procedures.jwt_user
import
jwt_user
from
unify_api.modules.users.procedures.jwt_user
import
jwt_user
from
pot_libs.common.components.query
import
PageRequest
from
pot_libs.common.components.query
import
PageRequest
from
unify_api.modules.alarm_manager.components.list_alarm
import
(
from
unify_api.modules.alarm_manager.components.list_alarm
import
(
ListAlarmResponse
,
ListAlarmReq
,
ListAlarmResponse
,
ListAlarmReq
,
Alarm
,
list_alarm_example
,
WlazReq
,
Alarm
,
list_alarm_example
,
WlazReq
,
)
)
...
@@ -74,7 +74,7 @@ async def post_list_alarm(req, body: PageRequest) -> ListAlarmResponse:
...
@@ -74,7 +74,7 @@ async def post_list_alarm(req, body: PageRequest) -> ListAlarmResponse:
cids
=
[
cid
]
cids
=
[
cid
]
if
not
cids
:
if
not
cids
:
raise
BusinessException
(
message
=
f
"你没有工厂权限"
)
raise
BusinessException
(
message
=
f
"你没有工厂权限"
)
return
await
list_alarm_service
(
cids
,
point_id
,
start
,
end
,
return
await
list_alarm_service
(
cids
,
user_id
,
point_id
,
start
,
end
,
importance
,
page_size
,
page_num
,
importance
,
page_size
,
page_num
,
alarm_type
)
alarm_type
)
...
...
unify_api/modules/common/dao/common_dao.py
View file @
d9c6073c
import
json
from
pot_libs.mysql_util.mysql_util
import
MysqlUtil
from
pot_libs.mysql_util.mysql_util
import
MysqlUtil
from
pot_libs.logger
import
log
from
pot_libs.logger
import
log
...
@@ -279,6 +281,12 @@ async def user_by_user_id(user_id):
...
@@ -279,6 +281,12 @@ async def user_by_user_id(user_id):
return
user_dic
return
user_dic
async
def
load_user_lang
(
user_id
):
async
with
MysqlUtil
()
as
conn
:
sql
=
"SELECT lang FROM user WHERE user_id=
%
s;"
return
await
conn
.
fetch_value
(
sql
,
(
user_id
,))
async
def
user_by_phone_number
(
phone
):
async
def
user_by_phone_number
(
phone
):
sql
=
"SELECT * FROM user where phone_number =
%
s and is_delete=0"
sql
=
"SELECT * FROM user where phone_number =
%
s and is_delete=0"
async
with
MysqlUtil
()
as
conn
:
async
with
MysqlUtil
()
as
conn
:
...
...
unify_api/modules/common/procedures/multi_lang.py
0 → 100644
View file @
d9c6073c
# -*- coding:utf-8 -*-
"""
DATE:2024/5/30 11:34
"""
import
json
from
unify_api.constants
import
E_TYPE_LANG
def
load_event_msg
(
e_type
,
event_param
,
lang
):
if
not
event_param
:
return
""
msg_fmt
=
E_TYPE_LANG
.
get
(
e_type
,
{})
.
get
(
lang
)
if
not
msg_fmt
:
return
""
return
msg_fmt
.
format
(
**
json
.
loads
(
event_param
))
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