Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
Automat
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
冯佳佳
Automat
Commits
d3ba2a0e
Commit
d3ba2a0e
authored
Jan 13, 2022
by
Aeolus
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
5d7a8203
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
129 additions
and
46 deletions
+129
-46
models/models.py
+7
-6
myapps/pc_management/api/machine_portal.py
+122
-39
myapps/pc_management/api/place_portal.py
+0
-1
No files found.
models/models.py
View file @
d3ba2a0e
...
...
@@ -57,7 +57,7 @@ class AdminMachine(Base):
user_id
=
Column
(
INTEGER
(
11
),
nullable
=
False
)
user_no
=
Column
(
String
(
25
,
'utf8mb4_unicode_ci'
),
nullable
=
False
)
machine_no
=
Column
(
INTEGER
(
11
),
nullable
=
False
)
status
=
Column
(
INTEGER
(
1
),
nullable
=
False
)
status
=
Column
(
INTEGER
(
1
),
default
=
1
,
nullable
=
False
)
created_at
=
Column
(
DateTime
,
nullable
=
False
,
server_default
=
text
(
"CURRENT_TIMESTAMP"
))
updated_at
=
Column
(
DateTime
,
nullable
=
False
,
server_default
=
text
(
"CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
))
...
...
@@ -130,9 +130,10 @@ class Machine(Base):
id
=
Column
(
INTEGER
(
10
),
primary_key
=
True
)
machine_no
=
Column
(
String
(
20
,
'utf8mb4_unicode_ci'
),
nullable
=
False
,
unique
=
True
,
comment
=
'机柜编号'
)
qrcode_no
=
Column
(
String
(
20
,
'utf8mb4_unicode_ci'
),
nullable
=
False
,
unique
=
True
,
comment
=
'二维码编号'
)
mac
=
Column
(
String
(
30
,
'utf8mb4_unicode_ci'
),
nullable
=
False
,
unique
=
True
,
comment
=
'mac'
)
power
=
Column
(
TINYINT
(
3
),
nullable
=
False
,
server_default
=
text
(
"'0'"
),
comment
=
'电量'
)
device_id
=
Column
(
String
(
45
,
'utf8mb4_unicode_ci'
),
unique
=
True
)
qrcode_no
=
Column
(
String
(
20
,
'utf8mb4_unicode_ci'
),
unique
=
True
,
comment
=
'二维码编号'
)
mac
=
Column
(
String
(
30
,
'utf8mb4_unicode_ci'
),
unique
=
True
,
comment
=
'mac'
)
power
=
Column
(
TINYINT
(
3
),
server_default
=
text
(
"'0'"
),
comment
=
'电量'
)
short_address
=
Column
(
VARCHAR
(
45
))
address
=
Column
(
String
(
191
,
'utf8mb4_unicode_ci'
),
comment
=
'机柜位置'
)
place_id
=
Column
(
INTEGER
(
10
),
nullable
=
False
)
...
...
@@ -140,10 +141,10 @@ class Machine(Base):
position
=
Column
(
String
(
20
,
'utf8mb4_unicode_ci'
),
comment
=
'机柜位置坐标'
)
hatch_number
=
Column
(
TINYINT
(
3
),
nullable
=
False
,
server_default
=
text
(
"'0'"
),
comment
=
'机柜的仓口数量'
)
type
=
Column
(
TINYINT
(
3
),
nullable
=
False
,
server_default
=
text
(
"'1'"
),
comment
=
'机柜类型1正常'
)
status
=
Column
(
TINYINT
(
1
),
server_default
=
text
(
"'1'"
),
comment
=
'状态:
1正常-1删除'
)
status
=
Column
(
TINYINT
(
1
),
default
=
text
(
"'0'"
),
comment
=
'状态: 0未激活
1正常-1删除'
)
created_at
=
Column
(
TIMESTAMP
,
nullable
=
False
,
server_default
=
text
(
"CURRENT_TIMESTAMP"
))
updated_at
=
Column
(
TIMESTAMP
,
nullable
=
False
,
server_default
=
text
(
"CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
))
command_time
=
Column
(
INTEGER
(
1
),
nullable
=
False
)
command_time
=
Column
(
INTEGER
(
1
),
nullable
=
False
,
server_default
=
text
(
"'1'"
)
)
class
MachineProduction
(
Base
):
...
...
myapps/pc_management/api/machine_portal.py
View file @
d3ba2a0e
...
...
@@ -14,7 +14,7 @@ from flask import Blueprint, g, request, jsonify
from
models.base_model
import
db
from
models.models
import
AdminMachine
,
Machine
from
utils.error_code
import
NO_PLACE
_ERROR
from
utils.error_code
import
MACHINE_NOT_EXIST
_ERROR
from
utils.my_response
import
BaseResponse
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -22,88 +22,171 @@ logger = logging.getLogger(__name__)
machine_route
=
Blueprint
(
'machine'
,
__name__
)
@machine_route.route
(
"machine_list"
,
methods
=
[
"
GE
T"
])
@machine_route.route
(
"machine_list"
,
methods
=
[
"
POS
T"
])
def
run_machine_list
():
"""
:return:
"""
json_data
=
request
.
get_json
()
page
=
json_data
.
get
(
"page"
,
None
)
page_size
=
json_data
.
get
(
"pageSize"
,
None
)
keyword
=
json_data
.
get
(
"keyword"
,
None
)
admin
=
g
.
user
admin_machine_list
=
AdminMachine
.
query
.
filter_by
(
admin_no
=
admin
.
id
,
status
=
1
)
.
all
()
if
admin_machine_list
:
machine_no_list
=
[
i
.
machine_no
for
i
in
admin_machine_list
]
else
:
return
BaseResponse
(
data
=
[])
select_sql
=
"""select machine.id, machine.machine_no, machine.device_id, machine.qrcode_no,machine.status,
machine.mac, machine.power, machine.hatch_number, machine.type,machine.place_id,
place.place_name
"""
count_sql
=
"select count(machine.id) as total_count"
from_sql
=
""" from machine left join place on machine.place_id = place.id
where machine.machine_no in ( select machine_no from admin_machine where
admin_machine.user_id = {user_id} and admin_machine.status = 1)
"""
.
format
(
user_id
=
admin
.
id
)
machine_list
=
db
.
session
.
query
(
Machine
)
.
filter
(
Machine
.
id
.
in_
(
machine_no_list
))
.
all
()
where_sql
=
" "
if
keyword
:
where_sql
+=
"""
and CONCAT(machine.machine_no,machine.qrcode_no) LIKE '
%
{keyword}
%
'
if
machine_list
:
machine_data_list
=
[
{
"machine_name"
:
i
.
machine_name
,
"machine_id"
:
i
.
id
,
"address"
:
i
.
address
,
"parent_id"
:
i
.
parent_id
}
for
i
in
machine_list
]
return
BaseResponse
(
data
=
machine_data_list
)
"""
.
format
(
keyword
=
keyword
)
order_sql
=
" ORDER BY machine.id ASC, machine.status ASC"
limit_sql
=
" LIMIT {offset} , {page_size} "
.
format
(
offset
=
(
page
-
1
)
*
page_size
,
page_size
=
page_size
)
count_result
=
db
.
session
.
execute
(
count_sql
+
from_sql
+
where_sql
)
.
fetchone
()
if
not
count_result
:
return
BaseResponse
(
data
=
{
"list"
:
[],
"page"
:
page
,
"pageSize"
:
page_size
,
"total_count"
:
0
})
else
:
return
BaseResponse
(
data
=
[])
total_count
=
count_result
.
total_count
result
=
db
.
session
.
execute
(
select_sql
+
from_sql
+
where_sql
+
order_sql
+
limit_sql
)
.
fetchall
()
return_data
=
[]
for
info
in
result
:
return_data
.
append
(
{
"machine_no"
:
info
.
machine_no
,
"device_id"
:
info
.
device_id
,
"place_name"
:
info
.
place_name
,
"mac"
:
info
.
mac
,
"power"
:
info
.
power
,
"hatch_number"
:
info
.
hatch_number
,
"type"
:
info
.
type
,
"status"
:
info
.
status
,
"place_id"
:
info
.
place_id
})
return
BaseResponse
({
"list"
:
return_data
,
"page"
:
page
,
"pageSize"
:
page_size
,
"total_count"
:
total_count
})
@machine_route.route
(
"add_machine"
,
methods
=
[
"GET"
])
@machine_route.route
(
"add_machine"
,
methods
=
[
"POST"
])
def
run_add_machine
():
"""
:return:
"""
json_data
=
request
.
get_json
()
machine_name
=
json_data
[
"machine_name"
]
address
=
json_data
.
get
(
"address"
,
""
)
parent_id
=
json_data
.
get
(
"parent_id"
,
0
)
machine_no
=
json_data
[
"machine_no"
]
address
=
json_data
.
get
(
"address"
,
None
)
device_id
=
json_data
.
get
(
"device_id"
,
None
)
qrcode_no
=
json_data
.
get
(
"qrcode_no"
,
None
)
mac
=
json_data
.
get
(
"mac"
,
None
)
power
=
json_data
.
get
(
"power"
,
None
)
hatch_number
=
json_data
.
get
(
"hatch_number"
,
None
)
place_id
=
json_data
.
get
(
"place_id"
,
None
)
type
=
json_data
.
get
(
"type"
,
1
)
machine_model
=
Machine
()
machine_model
.
machine_name
=
machine_name
machine_model
.
machine_no
=
machine_no
machine_model
.
device_id
=
device_id
machine_model
.
qrcode_no
=
qrcode_no
machine_model
.
mac
=
mac
machine_model
.
power
=
power
machine_model
.
place_id
=
place_id
machine_model
.
address
=
address
machine_model
.
parent_id
=
parent_id
machine_model
.
mch_platform
=
1
machine_model
.
hatch_number
=
hatch_number
machine_model
.
type
=
type
db
.
session
.
add
(
machine_model
)
admin_machine
=
AdminMachine
()
admin_machine
.
user_id
=
g
.
user
.
id
admin_machine
.
user_no
=
g
.
user
.
user_no
admin_machine
.
machine_no
=
machine_model
.
machine_no
db
.
session
.
add
(
admin_machine
)
db
.
session
.
commit
()
return
BaseResponse
()
@machine_route.route
(
"edit_machine"
,
methods
=
[
"
GE
T"
])
@machine_route.route
(
"edit_machine"
,
methods
=
[
"
POS
T"
])
def
run_edit_machine
():
"""
:return:
"""
json_data
=
request
.
get_json
()
id
=
json_data
[
"id"
]
machine_name
=
json_data
.
get
(
"machine_name"
,
""
)
address
=
json_data
.
get
(
"address"
,
""
)
parent_id
=
json_data
.
get
(
"parent_id"
,
0
)
machine_no
=
json_data
[
"machine_no"
]
address
=
json_data
.
get
(
"address"
,
None
)
device_id
=
json_data
.
get
(
"device_id"
,
None
)
qrcode_no
=
json_data
.
get
(
"qrcode_no"
,
None
)
mac
=
json_data
.
get
(
"mac"
,
None
)
power
=
json_data
.
get
(
"power"
,
None
)
hatch_number
=
json_data
.
get
(
"hatch_number"
,
None
)
place_id
=
json_data
.
get
(
"place_id"
,
None
)
type
=
json_data
.
get
(
"type"
,
None
)
status
=
json_data
.
get
(
"status"
,
None
)
machine_model
=
Machine
.
query
.
filter_by
(
id
=
id
)
.
first
()
machine_model
.
machine_name
=
machine_name
machine_model
=
Machine
.
query
.
filter_by
(
machine_no
=
machine_no
)
.
first
()
if
not
machine_model
:
return
jsonify
(
MACHINE_NOT_EXIST_ERROR
)
if
device_id
:
machine_model
.
device_id
=
device_id
if
qrcode_no
:
machine_model
.
qrcode_no
=
qrcode_no
if
mac
:
machine_model
.
mac
=
mac
if
power
:
machine_model
.
power
=
power
if
place_id
:
machine_model
.
place_id
=
place_id
if
address
:
machine_model
.
address
=
address
machine_model
.
parent_id
=
parent_id
if
hatch_number
:
machine_model
.
hatch_number
=
hatch_number
if
type
:
machine_model
.
type
=
type
if
status
:
machine_model
.
status
=
status
db
.
session
.
add
(
machine_model
)
db
.
session
.
commit
()
return
BaseResponse
()
@machine_route.route
(
"machine_detail"
,
methods
=
[
"
GE
T"
])
@machine_route.route
(
"machine_detail"
,
methods
=
[
"
POS
T"
])
def
get_machine_detail
():
"""
:return:
"""
json_data
=
request
.
get_json
()
id
=
json_data
[
"id"
]
machine_model
=
Machine
.
query
.
filter_by
(
id
=
id
)
.
first
()
if
machine_model
:
return
jsonify
({
"machine_name"
:
machine_model
.
machine_name
,
"address"
:
machine_model
.
address
,
"parent_id"
:
machine_model
.
parent_id
,
"status"
:
machine_model
.
status
,
})
else
:
return
jsonify
(
NO_PLACE_ERROR
)
machine_no
=
json_data
[
"machine_no"
]
admin
=
g
.
user
select_sql
=
"""select machine.id, machine.machine_no, machine.device_id, machine.qrcode_no,machine.status,
machine.mac, machine.power, machine.hatch_number, machine.type,machine.place_id,
place.place_name
"""
from_sql
=
""" from machine left join place on machine.place_id = place.id
where machine.machine_no in ( select machine_no from admin_machine where
admin_machine.user_id = {user_id} and admin_machine.status = 1)
"""
.
format
(
user_id
=
admin
.
id
)
where_sql
=
" and machine.machine_no = {}"
.
format
(
machine_no
)
result
=
db
.
session
.
execute
(
select_sql
+
from_sql
+
where_sql
)
.
fetchall
()
if
not
result
or
len
(
result
)
!=
1
:
return
jsonify
(
MACHINE_NOT_EXIST_ERROR
)
info
=
result
[
0
]
return
BaseResponse
(
data
=
{
"machine_no"
:
info
.
machine_no
,
"device_id"
:
info
.
device_id
,
"place_name"
:
info
.
place_name
,
"mac"
:
info
.
mac
,
"power"
:
info
.
power
,
"hatch_number"
:
info
.
hatch_number
,
"type"
:
info
.
type
,
"status"
:
info
.
status
,
"place_id"
:
info
.
place_id
})
myapps/pc_management/api/place_portal.py
View file @
d3ba2a0e
...
...
@@ -88,7 +88,6 @@ def run_add_place():
admin_place
.
user_id
=
g
.
user
.
id
admin_place
.
user_no
=
g
.
user
.
user_no
admin_place
.
place_id
=
place_model
.
id
admin_place
.
place_id
=
place_model
.
id
db
.
session
.
add
(
admin_place
)
db
.
session
.
commit
()
return
BaseResponse
()
...
...
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