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
7b2fe02d
Commit
7b2fe02d
authored
Jan 08, 2022
by
yanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
e64c0af3
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
81 additions
and
51 deletions
+81
-51
models/models.py
+0
-1
myapps/management/api/login.py
+5
-5
myapps/management/api/machine_portal.py
+50
-24
myapps/management/api/tallyman_portal.py
+26
-21
No files found.
models/models.py
View file @
7b2fe02d
...
...
@@ -363,7 +363,6 @@ class Management(Base):
user_no
=
Column
(
String
(
25
,
'utf8mb4_unicode_ci'
),
nullable
=
False
,
unique
=
True
)
user_name
=
Column
(
String
(
255
,
'utf8mb4_unicode_ci'
),
nullable
=
False
)
phone
=
Column
(
String
(
255
,
'utf8mb4_unicode_ci'
),
nullable
=
False
,
unique
=
True
)
key
=
Column
(
String
(
255
,
'utf8mb4_unicode_ci'
),
nullable
=
False
,
unique
=
True
)
level
=
Column
(
INTEGER
(
1
),
nullable
=
False
,
comment
=
'1:补货员'
)
status
=
Column
(
INTEGER
(
1
),
nullable
=
False
,
comment
=
'1:正常 2:删除'
)
_password_hash_
=
Column
(
String
(
255
,
'utf8mb4_unicode_ci'
))
...
...
myapps/management/api/login.py
View file @
7b2fe02d
...
...
@@ -32,23 +32,23 @@ def login():
if
phone_result
.
check_password
(
password
)
==
True
:
load_dotenv
(
dotenv_path
=
env_path
,
verbose
=
True
,
override
=
True
)
SECRET_KEY
=
os
.
getenv
(
'SECRET_KEY'
)
token
=
generate_jwt
({
"user_
no"
:
'SK000007'
},
time
.
time
()
+
6000
,
SECRET_KEY
)
token
=
generate_jwt
({
"user_
id"
:
phone_result
.
id
},
time
.
time
()
+
6000
,
SECRET_KEY
)
date
=
{
"token"
:
token
,
"success"
:
True
"token"
:
token
,
"success"
:
True
}
return
BaseResponse
(
data
=
date
)
else
:
return
BaseResponse
(
**
PASSWORD_ERROR
)
#用户id登录
#
用户id登录
user_result
=
Management
.
query
.
filter_by
(
user_no
=
number
,
status
=
1
)
.
first
()
if
user_result
:
# 进行密码验证
if
user_result
.
check_password
(
password
)
==
True
:
load_dotenv
(
dotenv_path
=
env_path
,
verbose
=
True
,
override
=
True
)
SECRET_KEY
=
os
.
getenv
(
'SECRET_KEY'
)
token
=
generate_jwt
({
"user_
no"
:
'SK000007'
},
time
.
time
()
+
6000
,
SECRET_KEY
)
token
=
generate_jwt
({
"user_
id"
:
user_result
.
id
},
time
.
time
()
+
6000
,
SECRET_KEY
)
date
=
{
"token"
:
token
,
"success"
:
True
...
...
myapps/management/api/machine_portal.py
View file @
7b2fe02d
#!usr/bin/env python
# -*- coding:utf-8 _*-
import
os
import
json
import
logging
import
re
import
time
from
flask
import
Blueprint
,
request
,
jsonify
,
g
from
models.base_model
import
db
from
utils.my_response
import
BaseResponse
from
models.models
import
Machine
,
Hatch
,
Place
from
utils.error_code
import
MACHINE_NOT_EXIST_ERROR
,
NO_PLACE_ERROR
from
models.models
import
Machine
,
Hatch
,
Place
,
Management
from
utils.error_code
import
MACHINE_NOT_EXIST_ERROR
,
NO_PLACE_ERROR
,
TOKEN_NOT_VALID_ERROR
from
utils.jwt_util
import
verify_jwt
logger
=
logging
.
getLogger
(
__name__
)
# 创建蓝图
machine_query_route
=
Blueprint
(
'machine'
,
__name__
)
...
...
@@ -100,35 +100,61 @@ def query():
# 机器查询machine_query
@machine_query_route.route
(
"machine_query"
,
methods
=
[
"post"
])
def
machine_query
():
token
=
request
.
headers
.
get
(
'Authorization'
)
json_date
=
request
.
get_json
()
page
=
json_date
[
"page"
]
page_size
=
json_date
[
"page_size"
]
if
"machine_no"
in
json_date
:
machine_no
=
json_date
[
"machine_no"
]
machine_result
=
Machine
.
query
.
filter
(
Machine
.
machine_no
.
like
(
"
%
"
+
machine_no
+
"
%
"
))
.
offset
((
page
-
1
)
*
page_size
)
.
limit
(
page_size
)
elif
"machine_mac"
in
json_date
:
machine_mac
=
json_date
[
"machine_mac"
]
machine_result
=
Machine
.
query
.
filter
(
Machine
.
mac
.
like
(
"
%
"
+
machine_mac
+
"
%
"
))
.
offset
((
page
-
1
)
*
page_size
)
.
limit
(
page_size
)
if
token
:
SECRET_KEY
=
os
.
getenv
(
'SECRET_KEY'
)
payload
=
verify_jwt
(
token
,
SECRET_KEY
)
# return str(payload.get("user_id"))
# 这边是拿到了user_id,接下来链表查询即可
if
not
payload
:
return
TOKEN_NOT_VALID_ERROR
else
:
user_id
=
payload
.
get
(
"user_id"
)
if
not
user_id
:
return
TOKEN_NOT_VALID_ERROR
user_info
=
Management
.
query
.
filter_by
()
.
first
()
if
not
user_info
:
return
TOKEN_NOT_VALID_ERROR
if
"machine_no"
in
json_date
:
machine_no
=
json_date
[
"machine_no"
]
query1
=
"select a.* ,b.management_id FROM machine as a JOIN management_machine as b ON "
\
"a.machine_no = b.machine_no WHERE management_id='{}' and a.machine_no like '{}' limit {},{}"
.
\
format
(
user_id
,
"
%
"
+
machine_no
+
"
%
"
,
(
page
-
1
)
*
page_size
,
page
*
page_size
)
elif
"machine_mac"
in
json_date
:
machine_mac
=
json_date
[
"machine_mac"
]
# machine_result = Machine.query.filter(Machine.mac.like("%"+machine_mac+"%")).offset((page-1)*page_size).limit(page_size)
query1
=
"select a.* ,b.management_id FROM machine as a JOIN management_machine as b ON "
\
"a.machine_no = b.machine_no WHERE management_id='{}' and mac like '{}' limit {},{}"
.
\
format
(
user_id
,
"
%
"
+
machine_mac
+
"
%
"
,
(
page
-
1
)
*
page_size
,
page
*
page_size
)
else
:
query1
=
"select a.* ,b.management_id FROM machine as a JOIN management_machine as b ON "
\
"a.machine_no = b.machine_no WHERE management_id={} limit {},{}"
.
\
format
(
user_id
,
(
page
-
1
)
*
page_size
,
page
*
page_size
)
machine_result
=
db
.
session
.
execute
(
query1
)
.
fetchall
()
result_date
=
[]
# # 将数据遍历和筛选
for
i
in
machine_result
:
date
=
{
"machine_no"
:
i
.
machine_no
,
"machine_mac"
:
i
.
mac
,
"status"
:
i
.
status
,
"short_address"
:
i
.
short_address
,
"address"
:
i
.
address
,
"address_id"
:
i
.
place_id
}
result_date
.
append
(
date
)
return
BaseResponse
(
date
=
result_date
)
else
:
machine_result
=
Machine
.
query
.
filter_by
()
.
offset
((
page
-
1
)
*
page_size
)
.
limit
(
page_size
)
result_date
=
[]
# 将数据遍历和筛选
for
i
in
machine_result
:
date
=
{
"machine_no"
:
i
.
machine_no
,
"machine_mac"
:
i
.
mac
,
"status"
:
i
.
status
,
"short_address"
:
i
.
short_address
,
"address"
:
i
.
address
,
"address_id"
:
i
.
place_id
}
result_date
.
append
(
date
)
return
BaseResponse
(
date
=
result_date
)
return
"no_token"
# 编辑机柜edit_machine
@machine_query_route.route
(
"edit_machine"
,
methods
=
[
"post"
])
def
update_machine
():
json_data
=
request
.
get_json
()
machine_no
=
json_data
[
"machine_no"
]
machine_mac
=
json_data
[
"machine_mac"
]
short_address
=
json_data
[
"short_address"
]
if
"short_address"
in
json_data
else
None
...
...
myapps/management/api/tallyman_portal.py
View file @
7b2fe02d
...
...
@@ -2,7 +2,7 @@
import
datetime
import
logging
import
time
import
os
from
flask
import
Blueprint
,
jsonify
,
request
,
g
from
sqlalchemy
import
func
...
...
@@ -11,7 +11,7 @@ from config.commen_config import LOGIN_TYPE
from
models.base_model
import
db
from
models.models
import
TallymanAccount
,
TallymanMachine
,
TallymanLoginRecord
,
Machine
,
Hatch
,
TallyRecord
,
\
TallymanPlace
TallymanPlace
,
Management
from
service.tallyman_service
import
TallymanService
from
utils.error_code
import
TALLYMAN_ACCOUNT_EXIST
,
PHONE_NOT_VALID_ERROR
,
TOKEN_NOT_VALID_ERROR
,
PASSWORD_ERROR
,
\
TALLYMAN_ACCOUNT_NOT_EXIST
,
MACHINE_NOT_EXIST_ERROR
,
HATCH_NOT_EXIST_ERROR
,
MACHINE_ACTIVATED_ERROR
,
\
...
...
@@ -66,21 +66,35 @@ def del_man():
db
.
session
.
commit
()
return
BaseResponse
(
date
=
{
"success"
:
True
})
# 补货员list
#
查询
补货员list
@tallyman_route.route
(
"/query_man"
,
methods
=
[
'POST'
])
def
tallyman
():
token
=
request
.
headers
.
get
(
'Authorization'
)
json_date
=
request
.
get_json
()
tallyman
=
json_date
[
'tallyman'
]
tallyman
=
json_date
[
'tallyman'
]
if
"tallyman"
in
json_date
else
""
place_name
=
json_date
[
"place_name"
]
if
"place_name"
in
json_date
else
""
page
=
json_date
[
"page"
]
page_size
=
json_date
[
"page_size"
]
tallyman_result
=
TallymanAccount
.
query
.
filter
(
TallymanAccount
.
user_name
.
like
(
"
%
"
+
tallyman
+
"
%
"
),
TallymanAccount
.
status
==
1
)
.
offset
\
((
page
-
1
)
*
page_size
)
.
limit
(
page_size
)
if
not
token
:
return
TOKEN_NOT_VALID_ERROR
SECRET_KEY
=
os
.
getenv
(
'SECRET_KEY'
)
payload
=
verify_jwt
(
token
,
SECRET_KEY
)
if
not
payload
:
return
TOKEN_NOT_VALID_ERROR
user_id
=
payload
.
get
(
"user_id"
)
user_res
=
Management
.
query
.
filter_by
(
id
=
user_id
)
if
not
user_res
:
return
TOKEN_NOT_VALID_ERROR
# 多表查询
query1
=
"SELECT a.*,b.management_id,c.place_id , d.place_name FROM ((tallyman_account as a JOIN "
\
"management_tallyman as b on a.id = b.tallyman_id) JOIN tallyman_place as c on c.user_id = a.id) "
\
"JOIN place as d ON d.id = c.place_id WHERE b.management_id = {} and a.user_name like '{}' and"
\
" d.place_name like '{}' limit {},{}"
\
.
format
(
user_id
,
"
%
"
+
tallyman
+
"
%
"
,
"
%
"
+
place_name
+
"
%
"
,
(
page
-
1
)
*
page_size
,
page
*
page_size
)
tallyman_result
=
db
.
session
.
execute
(
query1
)
.
fetchall
()
result_date
=
[]
for
i
in
tallyman_result
:
query1
=
"SELECT b.place_name,a.user_id,b.id as 'place_id' FROM tallyman_place as a JOIN place as b ON"
\
" a.place_id = b.id where user_id= {} "
.
format
(
i
.
id
)
man_place_res
=
db
.
session
.
execute
(
query1
)
.
fetchone
()
date
=
{
date
=
{
"tallyman_id"
:
i
.
id
,
"user_no"
:
i
.
user_no
,
"user_name"
:
i
.
user_name
,
...
...
@@ -88,9 +102,8 @@ def tallyman():
"phone"
:
i
.
phone
,
"status"
:
i
.
status
,
"last_login"
:
i
.
last_login
,
"address_id"
:
man_place_res
[
2
],
"address_name"
:
man_place_res
[
0
]
"address_name"
:
i
.
place_name
,
"address_id"
:
i
.
place_id
}
result_date
.
append
(
date
)
return
BaseResponse
(
date
=
result_date
)
...
...
@@ -103,7 +116,6 @@ def edit_man():
phone
=
json_date
[
"phone"
]
t_name
=
json_date
[
"t_name"
]
level
=
json_date
[
"level"
]
machine_place_id
=
json_date
[
"machine_place_id"
]
man_result
=
TallymanAccount
.
query
.
filter_by
(
id
=
tallyman_id
)
.
first
()
if
not
man_result
:
return
TALLYMAN_ACCOUNT_NOT_EXIST
...
...
@@ -114,12 +126,6 @@ def edit_man():
man_result
.
user_name
=
t_name
man_result
.
level
=
level
db
.
session
.
add
(
man_result
)
machine_place_res
=
TallymanPlace
.
query
.
filter_by
(
user_id
=
tallyman_id
)
.
first
()
if
not
machine_place_res
:
return
TALLYMAN_ACCOUNT_NOT_EXIST
machine_place_res
.
place_id
=
machine_place_id
db
.
session
.
add
(
machine_place_res
)
db
.
session
.
commit
()
return
BaseResponse
(
date
=
{
"success"
:
True
})
# 为补货员添加机器
\ No newline at end of file
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