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
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
131 additions
and
48 deletions
+131
-48
models/models.py
+7
-6
myapps/pc_management/api/machine_portal.py
+124
-41
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):
...
@@ -57,7 +57,7 @@ class AdminMachine(Base):
user_id
=
Column
(
INTEGER
(
11
),
nullable
=
False
)
user_id
=
Column
(
INTEGER
(
11
),
nullable
=
False
)
user_no
=
Column
(
String
(
25
,
'utf8mb4_unicode_ci'
),
nullable
=
False
)
user_no
=
Column
(
String
(
25
,
'utf8mb4_unicode_ci'
),
nullable
=
False
)
machine_no
=
Column
(
INTEGER
(
11
),
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"
))
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"
))
updated_at
=
Column
(
DateTime
,
nullable
=
False
,
server_default
=
text
(
"CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
))
...
@@ -130,9 +130,10 @@ class Machine(Base):
...
@@ -130,9 +130,10 @@ class Machine(Base):
id
=
Column
(
INTEGER
(
10
),
primary_key
=
True
)
id
=
Column
(
INTEGER
(
10
),
primary_key
=
True
)
machine_no
=
Column
(
String
(
20
,
'utf8mb4_unicode_ci'
),
nullable
=
False
,
unique
=
True
,
comment
=
'机柜编号'
)
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
=
'二维码编号'
)
device_id
=
Column
(
String
(
45
,
'utf8mb4_unicode_ci'
),
unique
=
True
)
mac
=
Column
(
String
(
30
,
'utf8mb4_unicode_ci'
),
nullable
=
False
,
unique
=
True
,
comment
=
'mac'
)
qrcode_no
=
Column
(
String
(
20
,
'utf8mb4_unicode_ci'
),
unique
=
True
,
comment
=
'二维码编号'
)
power
=
Column
(
TINYINT
(
3
),
nullable
=
False
,
server_default
=
text
(
"'0'"
),
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
))
short_address
=
Column
(
VARCHAR
(
45
))
address
=
Column
(
String
(
191
,
'utf8mb4_unicode_ci'
),
comment
=
'机柜位置'
)
address
=
Column
(
String
(
191
,
'utf8mb4_unicode_ci'
),
comment
=
'机柜位置'
)
place_id
=
Column
(
INTEGER
(
10
),
nullable
=
False
)
place_id
=
Column
(
INTEGER
(
10
),
nullable
=
False
)
...
@@ -140,10 +141,10 @@ class Machine(Base):
...
@@ -140,10 +141,10 @@ class Machine(Base):
position
=
Column
(
String
(
20
,
'utf8mb4_unicode_ci'
),
comment
=
'机柜位置坐标'
)
position
=
Column
(
String
(
20
,
'utf8mb4_unicode_ci'
),
comment
=
'机柜位置坐标'
)
hatch_number
=
Column
(
TINYINT
(
3
),
nullable
=
False
,
server_default
=
text
(
"'0'"
),
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正常'
)
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"
))
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"
))
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
):
class
MachineProduction
(
Base
):
...
...
myapps/pc_management/api/machine_portal.py
View file @
d3ba2a0e
...
@@ -14,7 +14,7 @@ from flask import Blueprint, g, request, jsonify
...
@@ -14,7 +14,7 @@ from flask import Blueprint, g, request, jsonify
from
models.base_model
import
db
from
models.base_model
import
db
from
models.models
import
AdminMachine
,
Machine
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
from
utils.my_response
import
BaseResponse
logger
=
logging
.
getLogger
(
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
...
@@ -22,88 +22,171 @@ logger = logging.getLogger(__name__)
...
@@ -22,88 +22,171 @@ logger = logging.getLogger(__name__)
machine_route
=
Blueprint
(
'machine'
,
__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
():
def
run_machine_list
():
"""
"""
:return:
: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
=
g
.
user
admin_machine_list
=
AdminMachine
.
query
.
filter_by
(
admin_no
=
admin
.
id
,
status
=
1
)
.
all
()
select_sql
=
"""select machine.id, machine.machine_no, machine.device_id, machine.qrcode_no,machine.status,
if
admin_machine_list
:
machine.mac, machine.power, machine.hatch_number, machine.type,machine.place_id,
machine_no_list
=
[
i
.
machine_no
for
i
in
admin_machine_list
]
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
)
where_sql
=
" "
if
keyword
:
where_sql
+=
"""
and CONCAT(machine.machine_no,machine.qrcode_no) LIKE '
%
{keyword}
%
'
"""
.
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
:
else
:
return
BaseResponse
(
data
=
[])
total_count
=
count_result
.
total_count
machine_list
=
db
.
session
.
query
(
Machine
)
.
filter
(
Machine
.
id
.
in_
(
machine_no_list
))
.
all
()
result
=
db
.
session
.
execute
(
select_sql
+
from_sql
+
where_sql
+
order_sql
+
limit_sql
)
.
fetch
all
()
if
machine_list
:
return_data
=
[]
machine_data_list
=
[
for
info
in
result
:
{
"machine_name"
:
i
.
machine_name
,
"machine_id"
:
i
.
id
,
"address"
:
i
.
address
,
"parent_id"
:
i
.
parent_id
}
for
i
in
return_data
.
append
(
machine_list
]
{
"machine_no"
:
info
.
machine_no
,
"device_id"
:
info
.
device_id
,
"place_name"
:
info
.
place_name
,
return
BaseResponse
(
data
=
machine_data_list
)
"mac"
:
info
.
mac
,
"power"
:
info
.
power
,
"hatch_number"
:
info
.
hatch_number
,
"type"
:
info
.
type
,
else
:
"status"
:
info
.
status
,
"place_id"
:
info
.
place_id
return
BaseResponse
(
data
=
[]
)
}
)
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
():
def
run_add_machine
():
"""
"""
:return:
:return:
"""
"""
json_data
=
request
.
get_json
()
json_data
=
request
.
get_json
()
machine_name
=
json_data
[
"machine_name"
]
machine_no
=
json_data
[
"machine_no"
]
address
=
json_data
.
get
(
"address"
,
""
)
address
=
json_data
.
get
(
"address"
,
None
)
parent_id
=
json_data
.
get
(
"parent_id"
,
0
)
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
()
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
.
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
)
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
()
db
.
session
.
commit
()
return
BaseResponse
()
return
BaseResponse
()
@machine_route.route
(
"edit_machine"
,
methods
=
[
"
GE
T"
])
@machine_route.route
(
"edit_machine"
,
methods
=
[
"
POS
T"
])
def
run_edit_machine
():
def
run_edit_machine
():
"""
"""
:return:
:return:
"""
"""
json_data
=
request
.
get_json
()
json_data
=
request
.
get_json
()
id
=
json_data
[
"id"
]
machine_no
=
json_data
[
"machine_no"
]
machine_name
=
json_data
.
get
(
"machine_name"
,
""
)
address
=
json_data
.
get
(
"address"
,
None
)
address
=
json_data
.
get
(
"address"
,
""
)
device_id
=
json_data
.
get
(
"device_id"
,
None
)
parent_id
=
json_data
.
get
(
"parent_id"
,
0
)
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
)
status
=
json_data
.
get
(
"status"
,
None
)
machine_model
=
Machine
.
query
.
filter_by
(
id
=
id
)
.
first
()
machine_model
=
Machine
.
query
.
filter_by
(
machine_no
=
machine_no
)
.
first
()
machine_model
.
machine_name
=
machine_name
if
not
machine_model
:
machine_model
.
address
=
address
return
jsonify
(
MACHINE_NOT_EXIST_ERROR
)
machine_model
.
parent_id
=
parent_id
machine_model
.
status
=
status
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
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
.
add
(
machine_model
)
db
.
session
.
commit
()
db
.
session
.
commit
()
return
BaseResponse
()
return
BaseResponse
()
@machine_route.route
(
"machine_detail"
,
methods
=
[
"
GE
T"
])
@machine_route.route
(
"machine_detail"
,
methods
=
[
"
POS
T"
])
def
get_machine_detail
():
def
get_machine_detail
():
"""
"""
:return:
:return:
"""
"""
json_data
=
request
.
get_json
()
json_data
=
request
.
get_json
()
id
=
json_data
[
"id"
]
machine_no
=
json_data
[
"machine_no"
]
machine_model
=
Machine
.
query
.
filter_by
(
id
=
id
)
.
first
()
admin
=
g
.
user
if
machine_model
:
select_sql
=
"""select machine.id, machine.machine_no, machine.device_id, machine.qrcode_no,machine.status,
return
jsonify
({
"machine_name"
:
machine_model
.
machine_name
,
machine.mac, machine.power, machine.hatch_number, machine.type,machine.place_id,
"address"
:
machine_model
.
address
,
place.place_name
"parent_id"
:
machine_model
.
parent_id
,
"""
"status"
:
machine_model
.
status
,
})
from_sql
=
""" from machine left join place on machine.place_id = place.id
else
:
where machine.machine_no in ( select machine_no from admin_machine where
return
jsonify
(
NO_PLACE_ERROR
)
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():
...
@@ -88,7 +88,6 @@ def run_add_place():
admin_place
.
user_id
=
g
.
user
.
id
admin_place
.
user_id
=
g
.
user
.
id
admin_place
.
user_no
=
g
.
user
.
user_no
admin_place
.
user_no
=
g
.
user
.
user_no
admin_place
.
place_id
=
place_model
.
id
admin_place
.
place_id
=
place_model
.
id
admin_place
.
place_id
=
place_model
.
id
db
.
session
.
add
(
admin_place
)
db
.
session
.
add
(
admin_place
)
db
.
session
.
commit
()
db
.
session
.
commit
()
return
BaseResponse
()
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