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
ad54c5f9
Commit
ad54c5f9
authored
Jun 04, 2024
by
ZZH
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
list point support mult lang 2024-06-04
parent
6c411fe4
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
89 additions
and
101 deletions
+89
-101
constants.py
unify_api/constants.py
+1
-1
multi_lang.py
unify_api/modules/common/procedures/multi_lang.py
+2
-2
list_point_service.py
unify_api/modules/common/service/list_point_service.py
+57
-2
list_point.py
unify_api/modules/common/views/list_point.py
+11
-79
open_data_service.py
unify_api/modules/shidianu/service/open_data_service.py
+18
-17
No files found.
unify_api/constants.py
View file @
ad54c5f9
...
...
@@ -603,7 +603,7 @@ WG_TOPIC = ["tsp", "water", "water_bromake", "ws"]
OSS_NEWS
=
"filedata/official_web/news_info"
E_TYPE_LANG
=
{
E_TYPE_
MSG_
LANG
=
{
"power_quality_low"
:
{
"en_US"
:
"The power quality is low, and there may be substandard electrical appliances present"
,
"de_DE"
:
""
...
...
unify_api/modules/common/procedures/multi_lang.py
View file @
ad54c5f9
...
...
@@ -4,14 +4,14 @@ DATE:2024/5/30 11:34
"""
from
pot_libs.logger
import
log
from
unify_api.constants
import
E_TYPE_LANG
,
PHASE_LINE_LANG
,
E_TYPE_NAME_LANG
from
unify_api.constants
import
E_TYPE_
MSG_
LANG
,
PHASE_LINE_LANG
,
E_TYPE_NAME_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
)
msg_fmt
=
E_TYPE_
MSG_
LANG
.
get
(
e_type
,
{})
.
get
(
lang
)
if
not
msg_fmt
:
return
""
...
...
unify_api/modules/common/service/list_point_service.py
View file @
ad54c5f9
from
unify_api.modules.common.components.list_points_cps
import
LsRep
,
\
LtpRep
,
LplResp
,
LpiResp
# -*- coding:utf-8 -*-
from
unify_api.modules.common.dao.common_dao
import
storey_by_cid
,
\
tsp_by_cid
,
monitor_point_join
,
inline_zdu_all_by_cid
from
unify_api.modules.common.dao.level_dao
import
transformer_by_cid
,
\
feeder_by_cid
,
power_dist_by_cid
,
inline_zdu_by_cid
,
device_level_by_cid
from
unify_api.modules.common.procedures.list_point_pds
import
\
monitor_map_point_location
from
pot_libs.mysql_util.mysql_util
import
MysqlUtil
from
unify_api.modules.common.components.list_points_cps
import
(
ListPointRequest
,
ListPointResponse
,
CommonPoint
,
CommonLocation
,
Inline
,
LsRep
,
LtpRep
,
LplResp
,
LpiResp
)
from
unify_api.modules.common.dao.common_dao
import
(
load_user_lang
,
load_monitor_names
)
async
def
list_storey_service
(
cid
):
...
...
@@ -88,3 +98,48 @@ async def list_point_inline_service(cid):
inlines
=
[{
"name"
:
inline
[
"name"
],
"inline_id"
:
inline
[
"inlid"
]}
for
inline
in
inline_zdu_dic
]
return
LpiResp
(
inlines
=
inlines
)
async
def
load_list_point
(
user_id
,
cid
):
sql
=
"SELECT p.pid, p.mtid, m.name, p.add_to_company FROM point p "
\
"INNER JOIN monitor m ON p.mtid=m.mtid "
\
"WHERE m.demolished=0 AND m.cid=
%
s;"
async
with
MysqlUtil
()
as
conn
:
points
=
{
r
[
"mtid"
]:
r
for
r
in
await
conn
.
fetchall
(
sql
,
(
cid
,))}
if
not
points
:
return
ListPointResponse
(
points
=
[],
inlines
=
[],
power_show_all
=
0
)
locs
=
{
mtid
:
[]
for
mtid
in
list
(
points
.
keys
())}
sql
=
f
"SELECT ln.lid, ln.item, ln.mtid "
\
f
"FROM location ln INNER JOIN monitor mr on ln.mtid = mr.mtid "
\
f
"WHERE mr.demolished=0 AND mr.cid=
%
s"
for
r
in
await
conn
.
fetchall
(
sql
,
(
cid
,)):
mtid
,
lid
,
item
=
r
[
"mtid"
],
r
[
"lid"
],
r
[
"item"
]
loc_item
=
CommonLocation
(
location_id
=
lid
,
item
=
item
)
if
mtid
not
in
locs
:
locs
[
mtid
]
=
[
loc_item
]
else
:
locs
[
mtid
]
.
append
(
loc_item
)
list_point
=
[]
lang
=
await
load_user_lang
(
user_id
)
mtr_names
=
await
load_monitor_names
(
list
(
points
.
keys
()),
lang
)
for
mtid
,
point
in
points
.
items
():
pid
,
p_name
=
point
[
"pid"
],
point
.
get
(
"name"
,
""
)
add_to_company
=
point
[
"add_to_company"
]
mtr_name
=
mtr_names
.
get
(
mtid
,
p_name
)
p_item
=
CommonPoint
(
name
=
mtr_name
,
point_id
=
pid
,
locations
=
locs
.
get
(
mtid
,
{}),
add_to_company
=
add_to_company
)
list_point
.
append
(
p_item
)
sql
=
"SELECT inlid, `name` FROM inline WHERE cid=
%
s"
inline_list
=
[
Inline
(
inline_id
=
r
[
"inlid"
],
name
=
r
[
"name"
])
for
r
in
await
conn
.
fetchall
(
sql
,
(
cid
,))]
return
ListPointResponse
(
points
=
list_point
,
inlines
=
inline_list
,
power_show_all
=
1
if
any
(
i
for
i
in
list_point
if
i
.
add_to_company
==
1
)
else
0
)
unify_api/modules/common/views/list_point.py
View file @
ad54c5f9
# -*- coding:utf-8 -*-
from
pot_libs.logger
import
log
from
pot_libs.sanic_api
import
summary
from
pot_libs.mysql_util.mysql_util
import
MysqlUtil
from
unify_api.modules.common.components.common_cps
import
CidReq
from
unify_api.modules.common.procedures.points
import
point_to_mid
from
unify_api.modules.common.service.list_point_service
import
\
list_storey_service
,
list_tsp_point_service
,
list_point_level_service
,
\
list_point_inline_service
from
unify_api.modules.common.service.list_point_service
import
(
list_storey_service
,
list_tsp_point_service
,
list_point_level_service
,
list_point_inline_service
,
load_list_point
)
from
unify_api.modules.common.components.list_points_cps
import
(
ListPointRequest
,
ListPointResponse
,
CommonPoint
,
CommonLocation
,
Inline
,
LsRep
,
LtpRep
,
LplResp
,
LpiResp
)
Inline
,
LsRep
,
LtpRep
,
LplResp
,
LpiResp
)
from
unify_api.modules.users.procedures.jwt_user
import
jwt_user
@
summary
(
'获取监测点,进线列表'
)
...
...
@@ -19,81 +23,9 @@ async def post_list_point(req, body: ListPointRequest) -> ListPointResponse:
cid
=
body
.
cid
if
not
cid
or
cid
<
0
:
return
ListPointResponse
()
.
param_error
()
is_power_equipment
=
body
.
is_power_equipment
list_point
=
[]
points
=
{}
groups
=
{}
sql
=
"SELECT p.pid,p.mtid, p.name, p.add_to_company FROM point p "
\
"left join monitor m on p.mtid = m.mtid "
\
"left join monitor_reuse mr on p.mtid = mr.mtid "
\
"WHERE m.demolished = 0 and (p.cid=
%
s or mr.cid =
%
s) "
# 查询属于当前工厂下的监测点 + 其他工厂但是被复用到当前工厂的监测点
if
is_power_equipment
:
# 动力设备
sql
+=
" and m.is_power_equipment = 1 "
async
with
MysqlUtil
()
as
conn
:
result
=
await
conn
.
fetchall
(
sql
,
args
=
(
cid
,
cid
))
if
not
result
:
return
ListPointResponse
(
points
=
list_point
,
inlines
=
[],
power_show_all
=
0
)
# 去调拆表的POINT
point_ids
=
[
point
[
"pid"
]
for
point
in
result
]
point_mid_map
,
point_count
=
await
point_to_mid
(
point_ids
)
result
=
[
point
for
point
in
result
if
point
[
"pid"
]
in
point_mid_map
]
for
res
in
result
:
pid
=
res
.
get
(
"pid"
)
points
[
pid
]
=
res
# 获取相应的mtid
point_map_mtids
=
[
point
[
"mtid"
]
for
point
in
result
if
point
[
'pid'
]
in
point_mid_map
]
# 根据pid获取mtd
sql
=
"SELECT ln.lid, mr.`name` `group`, ln.item FROM location ln LEFT JOIN"
\
" monitor mr on ln.mtid = mr.mtid WHERE ( ln.cid=
%
s or ln.mtid in "
\
"
%
s ) and ln.`ad_type` in
%
s"
try
:
async
with
MysqlUtil
()
as
conn
:
result
=
await
conn
.
fetchall
(
sql
,
args
=
(
cid
,
point_map_mtids
,
[
"temperature"
,
"residual_current"
]))
for
res
in
result
:
id
=
res
.
get
(
"lid"
)
group
=
res
.
get
(
"group"
)
item
=
res
.
get
(
"item"
)
groups
.
setdefault
(
group
,
[])
.
append
((
id
,
item
))
except
Exception
as
e
:
log
.
exception
(
e
)
return
ListPointResponse
()
.
db_error
()
for
pid
,
point_info
in
points
.
items
():
name
=
point_info
.
get
(
"name"
)
add_to_company
=
point_info
[
"add_to_company"
]
items
=
groups
.
get
(
name
,
[])
locations
=
[]
for
id
,
item
in
items
:
comm_location
=
CommonLocation
(
location_id
=
id
,
item
=
item
)
locations
.
append
(
comm_location
)
comm_point
=
CommonPoint
(
name
=
name
,
point_id
=
pid
,
locations
=
locations
,
add_to_company
=
add_to_company
)
list_point
.
append
(
comm_point
)
async
with
MysqlUtil
()
as
conn
:
sql
=
"SELECT inlid, `name` FROM inline WHERE cid=
%
s"
inlines
=
await
conn
.
fetchall
(
sql
,
args
=
(
cid
,))
inline_list
=
[
Inline
(
inline_id
=
inline
[
"inlid"
],
name
=
inline
[
"name"
])
for
inline
in
inlines
]
return
ListPointResponse
(
points
=
list_point
,
inlines
=
inline_list
,
power_show_all
=
1
if
any
(
i
for
i
in
list_point
if
i
.
add_to_company
==
1
)
else
0
)
user_id
=
jwt_user
(
req
)
return
await
load_list_point
(
user_id
,
cid
)
@
summary
(
'获取楼层-识电u'
)
...
...
unify_api/modules/shidianu/service/open_data_service.py
View file @
ad54c5f9
...
...
@@ -108,23 +108,24 @@ async def stb_data_longgang_service(user_id, d_type):
async
def
get_power
(
user_id
,
cids
):
user_info
=
await
get_user_product_auth
(
user_id
)
if
isinstance
(
cids
,
list
):
if
user_info
and
user_info
.
get
(
"cid_ext"
):
cid_ext
=
json
.
loads
(
user_info
[
"cid_ext"
])
for
cid
in
cids
:
user_cid_power
=
cid_ext
.
get
(
str
(
cid
),
""
)
if
not
user_cid_power
or
(
4
not
in
user_cid_power
):
return
False
return
True
return
False
elif
isinstance
(
cids
,
int
):
if
user_info
and
user_info
.
get
(
"cid_ext"
):
cid_ext
=
json
.
loads
(
user_info
[
"cid_ext"
])
user_cid_power
=
cid_ext
.
get
(
str
(
cids
),
""
)
if
user_cid_power
and
(
4
in
user_cid_power
):
return
True
return
False
return
False
# user_info = await get_user_product_auth(user_id)
# if isinstance(cids, list):
# if user_info and user_info.get("cid_ext"):
# cid_ext = json.loads(user_info["cid_ext"])
# for cid in cids:
# user_cid_power = cid_ext.get(str(cid), "")
# if not user_cid_power or (4 not in user_cid_power):
# return False
# return True
# return False
# elif isinstance(cids, int):
# if user_info and user_info.get("cid_ext"):
# cid_ext = json.loads(user_info["cid_ext"])
# user_cid_power = cid_ext.get(str(cids), "")
# if user_cid_power and (4 in user_cid_power):
# return True
# return False
def
get_token
():
...
...
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