Commit d9c6073c authored by ZZH's avatar ZZH

support multi lang 2024-05-30

parent cf293000
......@@ -494,3 +494,124 @@ S030_TOPIC = ["electric", "soe", "scope", "adio", "scope", "appliance",
WG_TOPIC = ["tsp", "water", "water_bromake", "ws"]
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
......@@ -11,6 +11,8 @@ 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
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):
return ListAlarmResponse(total=len(results), rows=rows)
async def list_alarm_service(cid, point_id, start, end, importance, page_size,
page_num, alarm_type):
async def list_alarm_service(cid, user_id, point_id, start, end, importance,
page_size, page_num, alarm_type):
li = ["event_mode!='scope'"]
if 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,
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")
......@@ -280,13 +283,18 @@ async def list_alarm_service(cid, point_id, start, end, importance, page_size,
else:
url = None
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(
name=data.get("name"),
importance=data.get("importance"),
date_time=str(data.get("event_datetime")),
type=event_type,
type_name=type_str,
description=data.get("message"),
description=event_msg,
redirect_type=redirect_type,
es_id=es_id,
url=url,
......
......@@ -7,17 +7,17 @@ from pot_libs.utils.exc_util import BusinessException
from unify_api.constants import Product
from unify_api.modules.alarm_manager.components.alarm_static_cps import NlaReq, \
WlaReq, LazReq
from unify_api.modules.alarm_manager.service.list_alarm_service import \
new_list_alarm_service, wx_list_alarm_service, list_alarm_zdu_service, \
from unify_api.modules.alarm_manager.service.list_alarm_service import (
new_list_alarm_service, wx_list_alarm_service, list_alarm_zdu_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 pot_libs.common.components.query import PageRequest
from unify_api.modules.alarm_manager.components.list_alarm import (
ListAlarmResponse, ListAlarmReq,
Alarm,
list_alarm_example, WlazReq,
ListAlarmResponse, ListAlarmReq, Alarm, list_alarm_example, WlazReq,
)
......@@ -74,7 +74,7 @@ async def post_list_alarm(req, body: PageRequest) -> ListAlarmResponse:
cids = [cid]
if not cids:
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,
alarm_type)
......
import json
from pot_libs.mysql_util.mysql_util import MysqlUtil
from pot_libs.logger import log
......@@ -279,6 +281,12 @@ async def user_by_user_id(user_id):
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):
sql = "SELECT * FROM user where phone_number = %s and is_delete=0"
async with MysqlUtil() as conn:
......
# -*- 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))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment