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
fd3450a0
Commit
fd3450a0
authored
May 19, 2023
by
lcn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改安电管理版
parent
91a67783
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
393 additions
and
536 deletions
+393
-536
constants.py
unify_api/constants.py
+4
-1
list_alarm_service.py
...y_api/modules/alarm_manager/service/list_alarm_service.py
+17
-11
list_alarm.py
unify_api/modules/alarm_manager/views/list_alarm.py
+36
-11
common_cps.py
unify_api/modules/common/procedures/common_cps.py
+84
-115
health_score.py
unify_api/modules/common/procedures/health_score.py
+107
-143
points.py
unify_api/modules/common/procedures/points.py
+11
-10
count_info_proxy_pds.py
..._api/modules/home_page/procedures/count_info_proxy_pds.py
+116
-187
security_info_pds.py
unify_api/modules/home_page/procedures/security_info_pds.py
+12
-54
count_info_proxy.py
unify_api/modules/home_page/views/count_info_proxy.py
+4
-3
security_info.py
unify_api/modules/home_page/views/security_info.py
+2
-1
No files found.
unify_api/constants.py
View file @
fd3450a0
...
@@ -473,4 +473,7 @@ ELECTRIC_PARAM_MAP = {
...
@@ -473,4 +473,7 @@ ELECTRIC_PARAM_MAP = {
"unbalanceI"
,
# 三相电流不平衡度
"unbalanceI"
,
# 三相电流不平衡度
"unbalanceU"
,
# 三相电压不平衡度
"unbalanceU"
,
# 三相电压不平衡度
"overPR"
"overPR"
}
}
\ No newline at end of file
CST
=
"Asia/Shanghai"
\ No newline at end of file
unify_api/modules/alarm_manager/service/list_alarm_service.py
View file @
fd3450a0
...
@@ -67,7 +67,7 @@ async def new_list_alarm_service(cid, storeys, offset, page_size, start, end,
...
@@ -67,7 +67,7 @@ async def new_list_alarm_service(cid, storeys, offset, page_size, start, end,
url
=
None
url
=
None
redirect_type
=
""
redirect_type
=
""
cid
=
int
(
res
.
get
(
"cid"
))
if
res
.
get
(
"cid"
)
else
res
.
get
(
"cid"
)
cid
=
int
(
res
.
get
(
"cid"
))
if
res
.
get
(
"cid"
)
else
res
.
get
(
"cid"
)
storey_name
=
point_storey_map
[
point_id
][
"storey_name"
]
storey_name
=
point_storey_map
[
point_id
][
"storey_name"
]
room_name
=
point_storey_map
[
point_id
][
"room_name"
]
room_name
=
point_storey_map
[
point_id
][
"room_name"
]
alarm
=
Alarm
(
alarm
=
Alarm
(
...
@@ -138,14 +138,14 @@ async def list_alarm_zdu_service(cid, point_list, page_num, page_size, start,
...
@@ -138,14 +138,14 @@ async def list_alarm_zdu_service(cid, point_list, page_num, page_size, start,
"""报警信息分页列表"""
"""报警信息分页列表"""
if
not
point_list
or
not
event_type
or
not
importance
:
if
not
point_list
or
not
event_type
or
not
importance
:
return
ListAlarmResponse
(
total
=
0
,
rows
=
[])
return
ListAlarmResponse
(
total
=
0
,
rows
=
[])
# # 1. es查询结果
# # 1. es查询结果
# es_res = await list_alarm_zdu_dao(cid, point_list, page_num, page_size,
# es_res = await list_alarm_zdu_dao(cid, point_list, page_num, page_size,
# start, end, importance, event_type)
# start, end, importance, event_type)
results
=
await
list_alarm_zdu_dao_new15
(
cid
,
point_list
,
start
,
end
,
results
=
await
list_alarm_zdu_dao_new15
(
cid
,
point_list
,
start
,
end
,
importance
,
event_type
)
importance
,
event_type
)
real_total
=
len
(
results
)
real_total
=
len
(
results
)
results
=
results
[(
page_num
-
1
)
*
page_size
,
page_num
*
page_size
]
results
=
results
[(
page_num
-
1
)
*
page_size
,
page_num
*
page_size
]
# 2. 获取工厂, 报警type对应的描述信息
# 2. 获取工厂, 报警type对应的描述信息
event_dic
=
await
company_extend_dao
(
cid
)
event_dic
=
await
company_extend_dao
(
cid
)
event_dic_map
=
{
event
[
"key"
]:
event
for
event
in
event_dic
}
event_dic_map
=
{
event
[
"key"
]:
event
for
event
in
event_dic
}
...
@@ -171,7 +171,7 @@ async def list_alarm_zdu_service(cid, point_list, page_num, page_size, start,
...
@@ -171,7 +171,7 @@ async def list_alarm_zdu_service(cid, point_list, page_num, page_size, start,
else
:
else
:
url
=
None
url
=
None
redirect_type
=
""
redirect_type
=
""
alarm
=
Alarm
(
alarm
=
Alarm
(
name
=
res
.
get
(
"name"
),
name
=
res
.
get
(
"name"
),
importance
=
res
.
get
(
"importance"
),
importance
=
res
.
get
(
"importance"
),
...
@@ -187,7 +187,7 @@ async def list_alarm_zdu_service(cid, point_list, page_num, page_size, start,
...
@@ -187,7 +187,7 @@ async def list_alarm_zdu_service(cid, point_list, page_num, page_size, start,
content
=
res
.
get
(
"message"
),
content
=
res
.
get
(
"message"
),
)
)
rows
.
append
(
alarm
)
rows
.
append
(
alarm
)
total
=
real_total
if
real_total
<
constants
.
ES_TOTAL_LIMIT
\
total
=
real_total
if
real_total
<
constants
.
ES_TOTAL_LIMIT
\
else
constants
.
ES_TOTAL_LIMIT
else
constants
.
ES_TOTAL_LIMIT
return
ListAlarmResponse
(
total
=
total
,
rows
=
rows
)
return
ListAlarmResponse
(
total
=
total
,
rows
=
rows
)
...
@@ -225,7 +225,7 @@ async def wx_list_alarm_zdu_service(cid, point_list, start, end):
...
@@ -225,7 +225,7 @@ async def wx_list_alarm_zdu_service(cid, point_list, start, end):
else
:
else
:
url
=
None
url
=
None
redirect_type
=
""
redirect_type
=
""
alarm
=
Alarm
(
alarm
=
Alarm
(
name
=
source
.
get
(
"name"
),
name
=
source
.
get
(
"name"
),
importance
=
source
.
get
(
"importance"
),
importance
=
source
.
get
(
"importance"
),
...
@@ -241,7 +241,7 @@ async def wx_list_alarm_zdu_service(cid, point_list, start, end):
...
@@ -241,7 +241,7 @@ async def wx_list_alarm_zdu_service(cid, point_list, start, end):
content
=
source
.
get
(
"message"
),
content
=
source
.
get
(
"message"
),
)
)
rows
.
append
(
alarm
)
rows
.
append
(
alarm
)
# total小程序不分页, 返回了但是不用
# total小程序不分页, 返回了但是不用
total
=
es_res
[
"hits"
][
"total"
]
total
=
es_res
[
"hits"
][
"total"
]
return
ListAlarmResponse
(
total
=
total
,
rows
=
rows
)
return
ListAlarmResponse
(
total
=
total
,
rows
=
rows
)
...
@@ -253,7 +253,10 @@ async def list_alarm_service_new15(cid, point_id, start, end, importance,
...
@@ -253,7 +253,10 @@ async def list_alarm_service_new15(cid, point_id, start, end, importance,
if
point_id
:
if
point_id
:
li
.
append
(
f
"pid={point_id}"
)
li
.
append
(
f
"pid={point_id}"
)
else
:
else
:
li
.
append
(
f
"cid={cid}"
)
if
not
isinstance
(
cid
,
list
):
cid
=
[
cid
]
cid_where
=
str
(
tuple
(
cid
))
.
replace
(
",)"
,
")"
)
li
.
append
(
f
"cid in {cid_where}"
)
if
start
and
end
:
if
start
and
end
:
li
.
append
(
f
"event_datetime BETWEEN '{start}' and '{end}'"
)
li
.
append
(
f
"event_datetime BETWEEN '{start}' and '{end}'"
)
if
importance
:
if
importance
:
...
@@ -270,7 +273,7 @@ async def list_alarm_service_new15(cid, point_id, start, end, importance,
...
@@ -270,7 +273,7 @@ async def list_alarm_service_new15(cid, point_id, start, end, importance,
li
.
append
(
f
"event_type in {str(tuple(alarm_type)).strip(',')}"
)
li
.
append
(
f
"event_type in {str(tuple(alarm_type)).strip(',')}"
)
mid_sql
=
" and "
.
join
(
li
)
mid_sql
=
" and "
.
join
(
li
)
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
)
rows
=
[]
rows
=
[]
for
data
in
datas
:
for
data
in
datas
:
...
@@ -279,7 +282,10 @@ async def list_alarm_service_new15(cid, point_id, start, end, importance,
...
@@ -279,7 +282,10 @@ async def list_alarm_service_new15(cid, point_id, start, end, importance,
type_str
=
constants
.
EVENT_TYPE_MAP
.
get
(
event_type
)
type_str
=
constants
.
EVENT_TYPE_MAP
.
get
(
event_type
)
location_id
=
data
.
get
(
"lid"
)
location_id
=
data
.
get
(
"lid"
)
es_id
=
data
.
get
(
"id"
)
es_id
=
data
.
get
(
"id"
)
if
location_id
and
(
event_type
in
constants
.
TEMP_SCOPE_URL_TYPE
):
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
url
=
"/temp_trend?doc_id=
%
s"
%
es_id
redirect_type
=
"temp_trend"
redirect_type
=
"temp_trend"
else
:
else
:
...
@@ -300,4 +306,4 @@ async def list_alarm_service_new15(cid, point_id, start, end, importance,
...
@@ -300,4 +306,4 @@ async def list_alarm_service_new15(cid, point_id, start, end, importance,
company_name
=
data
.
get
(
"fullname"
)
or
''
,
company_name
=
data
.
get
(
"fullname"
)
or
''
,
)
)
rows
.
append
(
alarm
)
rows
.
append
(
alarm
)
return
ListAlarmResponse
(
total
=
total
,
rows
=
rows
)
return
ListAlarmResponse
(
total
=
total
,
rows
=
rows
)
\ No newline at end of file
unify_api/modules/alarm_manager/views/list_alarm.py
View file @
fd3450a0
...
@@ -18,6 +18,7 @@ from unify_api.modules.alarm_manager.service.list_alarm_service import \
...
@@ -18,6 +18,7 @@ from unify_api.modules.alarm_manager.service.list_alarm_service import \
wx_list_alarm_zdu_service
,
list_alarm_service_new15
wx_list_alarm_zdu_service
,
list_alarm_service_new15
from
unify_api.modules.common.procedures.cids
import
get_cid_info
,
get_cids
,
\
from
unify_api.modules.common.procedures.cids
import
get_cid_info
,
get_cids
,
\
get_proxy_cids
get_proxy_cids
from
unify_api.modules.users.procedures.jwt_user
import
jwt_user
from
unify_api.utils
import
time_format
from
unify_api.utils
import
time_format
from
unify_api
import
constants
from
unify_api
import
constants
from
pot_libs.common.components.query
import
PageRequest
,
Equal
,
Range
,
Filter
,
\
from
pot_libs.common.components.query
import
PageRequest
,
Equal
,
Range
,
Filter
,
\
...
@@ -55,7 +56,31 @@ async def post_list_alarm(req, body: PageRequest) -> ListAlarmResponse:
...
@@ -55,7 +56,31 @@ async def post_list_alarm(req, body: PageRequest) -> ListAlarmResponse:
alarm_type
=
in_group
.
group
alarm_type
=
in_group
.
group
elif
in_group
.
field
==
'importance'
:
elif
in_group
.
field
==
'importance'
:
importance
=
in_group
.
group
importance
=
in_group
.
group
return
await
list_alarm_service_new15
(
cid
,
point_id
,
start
,
end
,
cids
=
[]
if
req
.
json
.
get
(
"product"
)
==
Product
.
AndianUManage
.
value
:
proxy_id
=
req
.
json
.
get
(
"proxy_id"
)
product
=
req
.
json
.
get
(
"product"
)
user_id
=
jwt_user
(
req
)
req_cids
=
req
.
json
.
get
(
"cids"
)
# cids = await get_cids(user_id, product)
proxy_cids
=
await
get_proxy_cids
(
user_id
,
product
,
proxy_id
)
cids
=
list
(
set
(
req_cids
)
&
set
(
proxy_cids
))
if
req
.
json
.
get
(
"product"
)
in
[
Product
.
RecognitionElectric
.
value
,
Product
.
IntelligentU
.
value
]:
if
not
cid
:
product
=
req
.
json
.
get
(
"product"
)
user_id
=
jwt_user
(
req
)
cids
=
await
get_cids
(
user_id
,
product
)
else
:
cids
=
[
cid
]
if
not
cids
and
cid
:
cids
=
[
cid
]
if
not
cids
:
raise
BusinessException
(
message
=
f
"你没有工厂权限"
)
return
await
list_alarm_service_new15
(
cids
,
point_id
,
start
,
end
,
importance
,
page_size
,
page_num
,
importance
,
page_size
,
page_num
,
alarm_type
)
alarm_type
)
...
@@ -77,19 +102,19 @@ async def post_list_alarm_bak(req, body: PageRequest) -> ListAlarmResponse:
...
@@ -77,19 +102,19 @@ async def post_list_alarm_bak(req, body: PageRequest) -> ListAlarmResponse:
ranges
=
[
_range
]
ranges
=
[
_range
]
else
:
else
:
ranges
=
[]
ranges
=
[]
# TODO:当没有选择监测点的时候,需要从req取cid,作为筛选条件
# TODO:当没有选择监测点的时候,需要从req取cid,作为筛选条件
if
req
.
json
.
get
(
"cid"
):
if
req
.
json
.
get
(
"cid"
):
cid
=
req
.
json
[
"cid"
]
cid
=
req
.
json
[
"cid"
]
equal
=
Equal
(
field
=
"cid"
,
value
=
cid
)
equal
=
Equal
(
field
=
"cid"
,
value
=
cid
)
body
.
filter
.
equals
.
append
(
equal
)
body
.
filter
.
equals
.
append
(
equal
)
if
req
.
json
.
get
(
"product"
)
==
Product
.
AndianUManage
.
value
:
if
req
.
json
.
get
(
"product"
)
==
Product
.
AndianUManage
.
value
:
proxy_id
=
req
.
json
.
get
(
"proxy_id"
)
proxy_id
=
req
.
json
.
get
(
"proxy_id"
)
product
=
req
.
json
.
get
(
"product"
)
product
=
req
.
json
.
get
(
"product"
)
user_id
=
req
.
ctx
.
user_id
user_id
=
req
.
ctx
.
user_id
req_cids
=
req
.
json
.
get
(
"cids"
)
req_cids
=
req
.
json
.
get
(
"cids"
)
# cids = await get_cids(user_id, product)
# cids = await get_cids(user_id, product)
cids
=
await
get_proxy_cids
(
user_id
,
product
,
proxy_id
)
cids
=
await
get_proxy_cids
(
user_id
,
product
,
proxy_id
)
if
req_cids
:
if
req_cids
:
...
@@ -100,7 +125,7 @@ async def post_list_alarm_bak(req, body: PageRequest) -> ListAlarmResponse:
...
@@ -100,7 +125,7 @@ async def post_list_alarm_bak(req, body: PageRequest) -> ListAlarmResponse:
else
:
else
:
in_group
=
InGroup
(
field
=
"cid"
,
group
=
cids
)
in_group
=
InGroup
(
field
=
"cid"
,
group
=
cids
)
body
.
filter
.
in_groups
.
append
(
in_group
)
body
.
filter
.
in_groups
.
append
(
in_group
)
if
req
.
json
.
get
(
"product"
)
in
[
Product
.
RecognitionElectric
.
value
,
if
req
.
json
.
get
(
"product"
)
in
[
Product
.
RecognitionElectric
.
value
,
Product
.
IntelligentU
.
value
]:
Product
.
IntelligentU
.
value
]:
req_cid
=
req
.
json
.
get
(
"cid"
)
req_cid
=
req
.
json
.
get
(
"cid"
)
...
@@ -112,14 +137,14 @@ async def post_list_alarm_bak(req, body: PageRequest) -> ListAlarmResponse:
...
@@ -112,14 +137,14 @@ async def post_list_alarm_bak(req, body: PageRequest) -> ListAlarmResponse:
cids
=
[
req_cid
]
cids
=
[
req_cid
]
in_group
=
InGroup
(
field
=
"cid"
,
group
=
cids
)
in_group
=
InGroup
(
field
=
"cid"
,
group
=
cids
)
body
.
filter
.
in_groups
.
append
(
in_group
)
body
.
filter
.
in_groups
.
append
(
in_group
)
filter
=
Filter
(
filter
=
Filter
(
equals
=
body
.
filter
.
equals
,
equals
=
body
.
filter
.
equals
,
ranges
=
ranges
,
ranges
=
ranges
,
in_groups
=
body
.
filter
.
in_groups
,
in_groups
=
body
.
filter
.
in_groups
,
keywords
=
body
.
filter
.
keywords
,
keywords
=
body
.
filter
.
keywords
,
)
)
# 重新封装PageRequest
# 重新封装PageRequest
page_request
=
PageRequest
(
page_request
=
PageRequest
(
page_size
=
body
.
page_size
,
page_num
=
body
.
page_num
,
sort
=
body
.
sort
,
page_size
=
body
.
page_size
,
page_num
=
body
.
page_num
,
sort
=
body
.
sort
,
...
@@ -127,7 +152,8 @@ async def post_list_alarm_bak(req, body: PageRequest) -> ListAlarmResponse:
...
@@ -127,7 +152,8 @@ async def post_list_alarm_bak(req, body: PageRequest) -> ListAlarmResponse:
)
)
query_body
=
EsQuery
()
.
query
(
page_request
)
query_body
=
EsQuery
()
.
query
(
page_request
)
if
not
query_body
.
get
(
"query"
):
if
not
query_body
.
get
(
"query"
):
query
=
{
"bool"
:
{
"must_not"
:
[{
"terms"
:
{
"mode.keyword"
:
[
"scope"
]}}]}}
query
=
{
"bool"
:
{
"must_not"
:
[{
"terms"
:
{
"mode.keyword"
:
[
"scope"
]}}]}}
query_body
[
"query"
]
=
query
query_body
[
"query"
]
=
query
else
:
else
:
must_not
=
[{
"terms"
:
{
"mode.keyword"
:
[
"scope"
]}}]
must_not
=
[{
"terms"
:
{
"mode.keyword"
:
[
"scope"
]}}]
...
@@ -140,7 +166,7 @@ async def post_list_alarm_bak(req, body: PageRequest) -> ListAlarmResponse:
...
@@ -140,7 +166,7 @@ async def post_list_alarm_bak(req, body: PageRequest) -> ListAlarmResponse:
log
.
warning
(
log
.
warning
(
"Can not find data on es(index:
%
s):
%
s"
%
(
index
,
query_body
))
"Can not find data on es(index:
%
s):
%
s"
%
(
index
,
query_body
))
raise
DBException
raise
DBException
cid_info_map
=
await
get_cid_info
(
all
=
True
)
cid_info_map
=
await
get_cid_info
(
all
=
True
)
rows
=
[]
rows
=
[]
for
info
in
es_results
[
"hits"
][
"hits"
]:
for
info
in
es_results
[
"hits"
][
"hits"
]:
...
@@ -181,7 +207,7 @@ async def post_list_alarm_bak(req, body: PageRequest) -> ListAlarmResponse:
...
@@ -181,7 +207,7 @@ async def post_list_alarm_bak(req, body: PageRequest) -> ListAlarmResponse:
company_name
=
cid_info_map
.
get
(
cid
,
{})
.
get
(
"fullname"
,
""
),
company_name
=
cid_info_map
.
get
(
cid
,
{})
.
get
(
"fullname"
,
""
),
)
)
rows
.
append
(
alarm
)
rows
.
append
(
alarm
)
real_total
=
es_results
[
"hits"
][
"total"
]
real_total
=
es_results
[
"hits"
][
"total"
]
total
=
real_total
if
real_total
<
constants
.
ES_TOTAL_LIMIT
else
constants
.
ES_TOTAL_LIMIT
total
=
real_total
if
real_total
<
constants
.
ES_TOTAL_LIMIT
else
constants
.
ES_TOTAL_LIMIT
return
ListAlarmResponse
(
total
=
total
,
rows
=
rows
)
return
ListAlarmResponse
(
total
=
total
,
rows
=
rows
)
...
@@ -206,7 +232,6 @@ async def post_new_list_alarm(req, body: NlaReq) -> ListAlarmResponse:
...
@@ -206,7 +232,6 @@ async def post_new_list_alarm(req, body: NlaReq) -> ListAlarmResponse:
product
)
product
)
@
summary
(
"小程序消息列表"
)
@
summary
(
"小程序消息列表"
)
async
def
post_wx_list_alarm
(
req
,
body
:
WlaReq
)
->
ListAlarmResponse
:
async
def
post_wx_list_alarm
(
req
,
body
:
WlaReq
)
->
ListAlarmResponse
:
# 1. 获取参数
# 1. 获取参数
...
...
unify_api/modules/common/procedures/common_cps.py
View file @
fd3450a0
This diff is collapsed.
Click to expand it.
unify_api/modules/common/procedures/health_score.py
View file @
fd3450a0
This diff is collapsed.
Click to expand it.
unify_api/modules/common/procedures/points.py
View file @
fd3450a0
...
@@ -21,26 +21,26 @@ async def get_points(company_ids):
...
@@ -21,26 +21,26 @@ async def get_points(company_ids):
company_point_ids_map
=
defaultdict
(
list
)
company_point_ids_map
=
defaultdict
(
list
)
for
point
in
points
:
for
point
in
points
:
company_point_ids_map
[
point
[
"cid"
]]
.
append
(
point
[
"pid"
])
company_point_ids_map
[
point
[
"cid"
]]
.
append
(
point
[
"pid"
])
point_map
=
{
i
[
"pid"
]:
i
for
i
in
points
}
point_map
=
{
i
[
"pid"
]:
i
for
i
in
points
}
point_ids
=
list
(
point_map
.
keys
())
point_ids
=
list
(
point_map
.
keys
())
pid_field
,
start_time_field
=
"pid"
,
"start_time"
pid_field
,
start_time_field
=
"pid"
,
"start_time"
sql
=
f
"SELECT pid, mid FROM change_meter_record WHERE pid in
%
s ORDER BY {pid_field}, {start_time_field}"
sql
=
f
"SELECT pid, mid FROM change_meter_record WHERE pid in
%
s ORDER BY {pid_field}, {start_time_field}"
records
=
await
conn
.
fetchall
(
sql
,
args
=
(
point_ids
,))
records
=
await
conn
.
fetchall
(
sql
,
args
=
(
point_ids
,))
newest_point_meter_relation
=
{
i
[
"pid"
]:
i
[
"mid"
]
for
i
in
records
if
newest_point_meter_relation
=
{
i
[
"pid"
]:
i
[
"mid"
]
for
i
in
records
if
i
[
"mid"
]}
i
[
"mid"
]}
valid_mids
=
list
(
newest_point_meter_relation
.
values
())
valid_mids
=
list
(
newest_point_meter_relation
.
values
())
newest_record_map
=
{
i
[
"pid"
]:
point_map
.
get
(
i
[
"pid"
])
for
i
in
records
newest_record_map
=
{
i
[
"pid"
]:
point_map
.
get
(
i
[
"pid"
])
for
i
in
records
if
i
[
"mid"
]}
if
i
[
"mid"
]}
# 根据有效的meter id查询meter参数
# 根据有效的meter id查询meter参数
async
with
MysqlUtil
()
as
conn
:
async
with
MysqlUtil
()
as
conn
:
mid_field
,
start_time_field
=
"mid"
,
"start_time"
mid_field
,
start_time_field
=
"mid"
,
"start_time"
mp_sql
=
f
"SELECT vc, mid, ctnum FROM meter_param_record WHERE mid in
%
s ORDER BY {mid_field}, {start_time_field}"
mp_sql
=
f
"SELECT vc, mid, ctnum FROM meter_param_record WHERE mid in
%
s ORDER BY {mid_field}, {start_time_field}"
mps
=
await
conn
.
fetchall
(
mp_sql
,
args
=
(
valid_mids
,))
mps
=
await
conn
.
fetchall
(
mp_sql
,
args
=
(
valid_mids
,))
meter_param_map
=
{
i
[
"mid"
]:
i
for
i
in
mps
}
meter_param_map
=
{
i
[
"mid"
]:
i
for
i
in
mps
}
for
cid
,
point_ids
in
company_point_ids_map
.
items
():
for
cid
,
point_ids
in
company_point_ids_map
.
items
():
for
point_id
in
point_ids
:
for
point_id
in
point_ids
:
if
point_id
in
newest_record_map
:
if
point_id
in
newest_record_map
:
...
@@ -56,13 +56,14 @@ async def get_points(company_ids):
...
@@ -56,13 +56,14 @@ async def get_points(company_ids):
async
def
get_points_new15
(
cids
):
async
def
get_points_new15
(
cids
):
sql
=
"SELECT p.pid,p.cid,p.inlid FROM `point` p INNER JOIN monitor m "
\
sql
=
"SELECT p.pid,p.cid,p.inlid,vc,ctnum "
\
"on m.mtid=p.mtid where p.cid in
%
s and m.demolished=0;"
"FROM `point` p INNER JOIN "
\
"monitor m on m.mtid=p.mtid where p.cid in
%
s and m.demolished=0;"
async
with
MysqlUtil
()
as
conn
:
async
with
MysqlUtil
()
as
conn
:
points
=
await
conn
.
fetchall
(
sql
,
args
=
(
cids
,))
points
=
await
conn
.
fetchall
(
sql
,
args
=
(
cids
,))
company_point_map
=
defaultdict
(
dict
)
company_point_map
=
defaultdict
(
dict
)
for
point
in
points
:
for
point
in
points
:
company_point_map
[
point
[
"cid"
]][
point
[
"pid"
]]
=
point
s
company_point_map
[
point
[
"cid"
]][
point
[
"pid"
]]
=
point
return
company_point_map
return
company_point_map
...
@@ -121,7 +122,7 @@ async def list_point(cid):
...
@@ -121,7 +122,7 @@ async def list_point(cid):
for
res
in
result
:
for
res
in
result
:
pid
=
res
.
get
(
"pid"
)
pid
=
res
.
get
(
"pid"
)
points
[
pid
]
=
res
points
[
pid
]
=
res
sql
=
"SELECT id, `group`, item FROM location WHERE cid=
%
s and `type` in
%
s"
sql
=
"SELECT id, `group`, item FROM location WHERE cid=
%
s and `type` in
%
s"
async
with
MysqlUtil
()
as
conn
:
async
with
MysqlUtil
()
as
conn
:
result
=
await
conn
.
fetchall
(
sql
,
args
=
(
result
=
await
conn
.
fetchall
(
sql
,
args
=
(
...
@@ -131,7 +132,7 @@ async def list_point(cid):
...
@@ -131,7 +132,7 @@ async def list_point(cid):
group
=
res
.
get
(
"group"
)
group
=
res
.
get
(
"group"
)
item
=
res
.
get
(
"item"
)
item
=
res
.
get
(
"item"
)
groups
.
setdefault
(
group
,
[])
.
append
((
id
,
item
))
groups
.
setdefault
(
group
,
[])
.
append
((
id
,
item
))
for
pid
,
point_info
in
points
.
items
():
for
pid
,
point_info
in
points
.
items
():
name
=
point_info
.
get
(
"name"
)
name
=
point_info
.
get
(
"name"
)
add_to_company
=
point_info
[
"add_to_company"
]
add_to_company
=
point_info
[
"add_to_company"
]
...
@@ -145,7 +146,7 @@ async def list_point(cid):
...
@@ -145,7 +146,7 @@ async def list_point(cid):
comm_point
=
{
"name"
:
name
,
"point_id"
:
pid
,
"locations"
:
locations
,
comm_point
=
{
"name"
:
name
,
"point_id"
:
pid
,
"locations"
:
locations
,
"add_to_company"
:
add_to_company
}
"add_to_company"
:
add_to_company
}
list_point
.
append
(
comm_point
)
list_point
.
append
(
comm_point
)
async
with
MysqlUtil
()
as
conn
:
async
with
MysqlUtil
()
as
conn
:
sql
=
"SELECT inlid, `name` FROM inline WHERE cid=
%
s"
sql
=
"SELECT inlid, `name` FROM inline WHERE cid=
%
s"
inlines
=
await
conn
.
fetchall
(
sql
,
args
=
(
cid
,))
inlines
=
await
conn
.
fetchall
(
sql
,
args
=
(
cid
,))
...
...
unify_api/modules/home_page/procedures/count_info_proxy_pds.py
View file @
fd3450a0
This diff is collapsed.
Click to expand it.
unify_api/modules/home_page/procedures/security_info_pds.py
View file @
fd3450a0
...
@@ -175,61 +175,19 @@ async def alarm_summary(company_ids, start, end, date_type):
...
@@ -175,61 +175,19 @@ async def alarm_summary(company_ids, start, end, date_type):
:param date_type:
:param date_type:
:return:
:return:
"""
"""
start_dt
=
datetime
.
strptime
(
start
,
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
sql
=
f
"""
end_dt
=
datetime
.
strptime
(
end
,
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
select cid,count(*) count from point_1min_event
es_start_str
=
datetime
(
year
=
start_dt
.
year
,
month
=
start_dt
.
month
,
where cid in
%
s and event_mode = 'alarm' and event_datetime >=
%
s
day
=
start_dt
.
day
)
.
strftime
(
and event_datetime <=
%
s
"
%
Y-
%
m-
%
dT
%
H:
%
M:
%
S+08:00"
group by cid
)
"""
es_end_str
=
end_dt
.
strftime
(
"
%
Y-
%
m-
%
dT
%
H:
%
M:
%
S+08:00"
)
log
.
info
(
"alarm_summary sql={}"
.
format
(
sql
))
if
date_type
==
"day"
:
async
with
MysqlUtil
()
as
conn
:
_format
=
"yyyy-MM-dd HH:mm:ss"
datas
=
await
conn
.
fetchall
(
sql
,
args
=
(
company_ids
,
start
,
end
))
_min
=
start_dt
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
print
(
f
"datas = {datas}"
)
_max
=
end_dt
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
else
:
# date_type == "month"
_format
=
"yyyy-MM-dd"
_min
=
start_dt
.
strftime
(
"
%
Y-
%
m-
%
d"
)
_max
=
end_dt
.
strftime
(
"
%
Y-
%
m-
%
d"
)
filter_list
=
[
{
"range"
:
{
"datetime"
:
{
"gte"
:
es_start_str
,
"lte"
:
es_end_str
,
}}},
{
"term"
:
{
"mode"
:
"alarm"
}},
]
filter_list
.
append
({
"terms"
:
{
"cid"
:
company_ids
}})
query_body
=
{
"query"
:
{
"bool"
:
{
"filter"
:
filter_list
}},
"size"
:
0
,
"aggs"
:
{
"cid_aggs"
:
{
"terms"
:
{
"field"
:
"cid"
,
"size"
:
10000
},
"aggs"
:
{
"date_alarms"
:
{
"date_histogram"
:
{
"field"
:
"datetime"
,
"order"
:
{
"_key"
:
"desc"
},
"min_doc_count"
:
1
,
"interval"
:
"day"
,
"format"
:
"yyyy-MM-dd"
,
"time_zone"
:
"+08:00"
,
}
}
},
}
},
}
log
.
info
(
"alarm_summary query_body={}"
.
format
(
query_body
))
async
with
EsUtil
()
as
es
:
es_result
=
await
es
.
search_origin
(
body
=
query_body
,
index
=
constants
.
POINT_1MIN_EVENT
)
print
(
f
"es_result = {es_result}"
)
buckets
=
es_result
[
"aggregations"
][
"cid_aggs"
][
"buckets"
]
or
[]
total_alarm_cnt
,
alarm_company_cnt
=
sum
(
total_alarm_cnt
,
alarm_company_cnt
=
sum
(
[
i
[
"
doc_count"
]
for
i
in
buckets
]),
len
(
bucket
s
)
[
i
[
"
count"
]
for
i
in
datas
]),
len
(
data
s
)
cid_alarmcnt_list
=
[
i
[
"
doc_count"
]
for
i
in
bucket
s
]
cid_alarmcnt_list
=
[
i
[
"
count"
]
for
i
in
data
s
]
safe_run_map
=
await
proxy_safe_run_info
(
company_ids
,
start_time_str
=
start
,
safe_run_map
=
await
proxy_safe_run_info
(
company_ids
,
start_time_str
=
start
,
end_time_str
=
end
)
end_time_str
=
end
)
...
...
unify_api/modules/home_page/views/count_info_proxy.py
View file @
fd3450a0
...
@@ -48,6 +48,7 @@ from unify_api.modules.home_page.service.count_info_service import \
...
@@ -48,6 +48,7 @@ from unify_api.modules.home_page.service.count_info_service import \
safe_run_sdu
,
safe_run_sdu_new15
safe_run_sdu
,
safe_run_sdu_new15
from
unify_api.modules.elec_charge.components.elec_charge_cps
import
\
from
unify_api.modules.elec_charge.components.elec_charge_cps
import
\
ProductProxyReq
ProductProxyReq
from
unify_api.modules.users.procedures.jwt_user
import
jwt_user
@
summary
(
"代理版首页统计信息-安电U"
)
@
summary
(
"代理版首页统计信息-安电U"
)
...
@@ -55,7 +56,7 @@ async def post_count_info_proxy(req) -> CountInfoProxyResp:
...
@@ -55,7 +56,7 @@ async def post_count_info_proxy(req) -> CountInfoProxyResp:
# 1. 获取cid_list
# 1. 获取cid_list
host
=
req
.
host
host
=
req
.
host
product
=
PRODUCT
.
get
(
host
)
product
=
PRODUCT
.
get
(
host
)
user_id
=
req
.
ctx
.
user_id
user_id
=
jwt_user
(
req
)
proxy_id
=
req
.
json
.
get
(
"proxy_id"
)
proxy_id
=
req
.
json
.
get
(
"proxy_id"
)
# cid_list = await get_cids(user_id, product)
# cid_list = await get_cids(user_id, product)
cid_list
=
await
get_proxy_cids
(
user_id
,
product
,
proxy_id
)
cid_list
=
await
get_proxy_cids
(
user_id
,
product
,
proxy_id
)
...
@@ -105,7 +106,7 @@ async def post_security_level_count(
...
@@ -105,7 +106,7 @@ async def post_security_level_count(
async
def
post_alarm_percentage_count
(
async
def
post_alarm_percentage_count
(
request
,
body
:
ProxySecurityLevelCntReq
request
,
body
:
ProxySecurityLevelCntReq
)
->
ProxyAlarmPercentageCntResp
:
)
->
ProxyAlarmPercentageCntResp
:
user_id
=
request
.
ctx
.
user_id
user_id
=
jwt_user
(
request
)
product
=
body
.
product
product
=
body
.
product
req_cid
=
body
.
cid
req_cid
=
body
.
cid
if
not
req_cid
:
if
not
req_cid
:
...
@@ -137,7 +138,7 @@ async def post_alarm_percentage_count(
...
@@ -137,7 +138,7 @@ async def post_alarm_percentage_count(
@
summary
(
"代理版本首页地图数据"
)
@
summary
(
"代理版本首页地图数据"
)
async
def
post_proxy_map_info
(
request
,
async
def
post_proxy_map_info
(
request
,
body
:
ProxySecurityLevelCntReq
)
->
ProxyIndexMapResp
:
body
:
ProxySecurityLevelCntReq
)
->
ProxyIndexMapResp
:
user_id
=
request
.
ctx
.
user_id
user_id
=
jwt_user
(
request
)
product
=
body
.
product
product
=
body
.
product
req_cid
=
body
.
cid
req_cid
=
body
.
cid
if
not
req_cid
:
if
not
req_cid
:
...
...
unify_api/modules/home_page/views/security_info.py
View file @
fd3450a0
...
@@ -23,6 +23,7 @@ from unify_api.modules.home_page.components.security_info_cps import (
...
@@ -23,6 +23,7 @@ from unify_api.modules.home_page.components.security_info_cps import (
from
unify_api.modules.home_page.procedures.security_info_pds
import
(
from
unify_api.modules.home_page.procedures.security_info_pds
import
(
alarm_summary
,
alarm_count_info_new15
,
alarm_summary
,
alarm_count_info_new15
,
)
)
from
unify_api.modules.users.procedures.jwt_user
import
jwt_user
@
summary
(
"获取首页今日或者近30天安全报警统计信息"
)
@
summary
(
"获取首页今日或者近30天安全报警统计信息"
)
...
@@ -164,7 +165,7 @@ async def post_alarm_summary(request, body: SecurityCommonReq) -> AlarmSummaryRe
...
@@ -164,7 +165,7 @@ async def post_alarm_summary(request, body: SecurityCommonReq) -> AlarmSummaryRe
if
not
req_cids
:
if
not
req_cids
:
raise
BusinessException
(
message
=
f
"暂无工厂"
)
raise
BusinessException
(
message
=
f
"暂无工厂"
)
if
product
==
Product
.
AndianUManage
.
value
:
if
product
==
Product
.
AndianUManage
.
value
:
user_id
=
request
.
ctx
.
user_id
user_id
=
jwt_user
(
request
)
# cids = await get_cids(user_id, product)
# cids = await get_cids(user_id, product)
proxy_id
=
body
.
proxy_id
proxy_id
=
body
.
proxy_id
cids
=
await
get_proxy_cids
(
user_id
,
product
,
proxy_id
)
cids
=
await
get_proxy_cids
(
user_id
,
product
,
proxy_id
)
...
...
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