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
e64c0af3
Commit
e64c0af3
authored
Jan 07, 2022
by
yanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
05b51d64
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
246 additions
and
29 deletions
+246
-29
models/models.py
+9
-0
myapps/management/api/__init__.py
+6
-2
myapps/management/api/login.py
+20
-10
myapps/management/api/machine_portal.py
+71
-14
myapps/management/api/rent_portal.py
+3
-3
myapps/management/api/tallyman_portal.py
+126
-0
service/machine_service.py
+11
-0
utils/error_code.py
+0
-0
No files found.
models/models.py
View file @
e64c0af3
...
...
@@ -384,3 +384,12 @@ class Management(Base):
# 使用check_password,进行密码校验,返回True False。
def
check_password
(
self
,
pasword
):
return
check_password_hash
(
self
.
_password_hash_
,
pasword
)
class
TallymanPlace
(
Base
):
__tablename__
=
'tallyman_place'
id
=
Column
(
INTEGER
(
11
),
primary_key
=
True
,
unique
=
True
)
user_id
=
Column
(
String
(
25
,
'utf8mb4_unicode_ci'
))
place_id
=
Column
(
String
(
255
,
'utf8mb4_unicode_ci'
))
status
=
Column
(
TINYINT
(
3
),
nullable
=
False
,
comment
=
'状态1绑定 -1未绑定'
)
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"
))
myapps/management/api/__init__.py
View file @
e64c0af3
...
...
@@ -7,9 +7,10 @@ author:Aeolus
"""
from
flask
import
Flask
from
myapps.management.api.rent_
query
import
rent_query_route
from
myapps.management.api.machine_
management
import
machine_query_route
from
myapps.management.api.rent_
portal
import
rent_query_route
from
myapps.management.api.machine_
portal
import
machine_query_route
from
myapps.management.api.login
import
login_route
from
myapps.management.api.tallyman_portal
import
tallyman_route
...
...
@@ -18,3 +19,6 @@ def register_management_blueprint(app: Flask):
app
.
register_blueprint
(
rent_query_route
,
url_prefix
=
prefix
+
"/rent"
)
app
.
register_blueprint
(
machine_query_route
,
url_prefix
=
prefix
+
"/machine"
)
app
.
register_blueprint
(
login_route
,
url_prefix
=
prefix
+
"/login"
)
app
.
register_blueprint
(
tallyman_route
,
url_prefix
=
prefix
+
"/tallyman"
)
myapps/management/api/login.py
View file @
e64c0af3
...
...
@@ -3,9 +3,12 @@
import
json
import
logging
import
re
import
time
import
os
from
utils.jwt_util
import
generate_jwt
from
config.env_path_config
import
env_path
from
dotenv
import
load_dotenv
from
flask
import
Blueprint
,
request
,
jsonify
,
g
from
models.base_model
import
db
from
utils.my_response
import
BaseResponse
...
...
@@ -22,16 +25,19 @@ def login():
json_date
=
request
.
get_json
()
number
=
json_date
[
"number"
]
password
=
json_date
[
'password'
]
key
=
json_date
[
"key"
]
#手机号登录
phone_result
=
Management
.
query
.
filter_by
(
phone
=
number
,
status
=
1
)
.
first
()
if
phone_result
:
# 进行密码验证
if
phone_result
.
check_password
(
password
)
==
True
:
token_making
=
generate_token
(
key
,
360
)
# 从获取库里获取key
ky
=
phone_result
.
key
return
BaseResponse
(
data
=
certify_token
(
ky
,
token_making
))
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
)
date
=
{
"token"
:
token
,
"success"
:
True
}
return
BaseResponse
(
data
=
date
)
else
:
return
BaseResponse
(
**
PASSWORD_ERROR
)
...
...
@@ -40,10 +46,14 @@ def login():
if
user_result
:
# 进行密码验证
if
user_result
.
check_password
(
password
)
==
True
:
token_making
=
generate_token
(
key
,
360
)
# 从获取库里获取key
ky
=
user_result
.
key
return
BaseResponse
(
data
=
certify_token
(
ky
,
token_making
))
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
)
date
=
{
"token"
:
token
,
"success"
:
True
}
return
BaseResponse
(
data
=
date
)
else
:
return
BaseResponse
(
**
PASSWORD_ERROR
)
...
...
myapps/management/api/machine_
management
.py
→
myapps/management/api/machine_
portal
.py
View file @
e64c0af3
...
...
@@ -5,23 +5,14 @@ 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
from
utils.error_code
import
MACHINE_NOT_EXIST_ERROR
from
models.models
import
Machine
,
Hatch
,
Place
from
utils.error_code
import
MACHINE_NOT_EXIST_ERROR
,
NO_PLACE_ERROR
logger
=
logging
.
getLogger
(
__name__
)
# 创建蓝图
machine_query_route
=
Blueprint
(
'machine'
,
__name__
)
# 模糊查询到机器信息
@machine_query_route.route
(
"query_machine"
,
methods
=
[
"post"
])
def
query_machine
():
json_date
=
request
.
get_json
()
number
=
json_date
[
"number"
]
page
=
json_date
[
"page"
]
page_size
=
json_date
[
"page_size"
]
pass
# 修改机器信息
@machine_query_route.route
(
"query_edit"
,
methods
=
[
"post"
])
def
query_edit
():
...
...
@@ -37,7 +28,8 @@ def query_edit():
{
"address"
:
address
,
"short_address"
:
short_address
,
"status"
:
status
}
)
db
.
session
.
commit
()
return
BaseResponse
()
return
BaseResponse
(
data
=
True
)
# 显出机柜数量
@machine_query_route.route
(
"hatch_query"
,
methods
=
[
"post"
])
def
hatch_query
():
...
...
@@ -78,7 +70,7 @@ def query():
else
:
# 有返回add信息
add_result
=
Machine
.
query
.
filter
(
Machine
.
address
.
like
(
"
%
"
+
get_number
+
"
%
"
))
.
offset
((
page
-
1
)
*
page_size
)
.
limit
(
page_size
)
.
all
()
)
result_date
=
[]
for
add
in
add_result
:
date
=
{
...
...
@@ -92,7 +84,7 @@ def query():
return
BaseResponse
(
data
=
result_date
,
page
=
page
,
page_size
=
page_size
)
else
:
machine_result
=
Machine
.
query
.
filter
(
Machine
.
machine_no
.
like
(
"
%
"
+
get_number
+
"
%
"
))
.
offset
((
page
-
1
)
*
page_size
)
.
\
limit
(
page_size
)
.
all
()
limit
(
page_size
)
result_date
=
[]
for
machine
in
machine_result
:
date
=
{
...
...
@@ -104,3 +96,68 @@ def query():
}
result_date
.
append
(
date
)
return
BaseResponse
(
data
=
result_date
,
page
=
page
,
page_size
=
page_size
)
# 机器查询machine_query
@machine_query_route.route
(
"machine_query"
,
methods
=
[
"post"
])
def
machine_query
():
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
)
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
)
# 编辑机柜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
address_id
=
json_data
[
"address_id"
]
address_result
=
Place
.
query
.
filter_by
(
id
=
address_id
)
.
first
()
if
not
address_result
:
return
NO_PLACE_ERROR
machine_result
=
Machine
.
query
.
filter_by
(
mac
=
machine_mac
)
.
first
()
if
not
machine_result
:
return
MACHINE_NOT_EXIST_ERROR
machine_result
.
no
=
machine_no
machine_result
.
place_id
=
address_id
machine_result
.
short_address
=
address_result
.
place_name
machine_result
.
short_address
=
short_address
db
.
session
.
add
(
machine_result
)
db
.
session
.
commit
()
return
BaseResponse
(
date
=
{
"success"
:
True
})
# 更换机器状态change_machine_status
@machine_query_route.route
(
"change_machine_status"
,
methods
=
[
"post"
])
def
update_status
():
json_data
=
request
.
get_json
()
machine_mac
=
json_data
[
"machine_mac"
]
status
=
json_data
[
"status"
]
machine_result
=
Machine
.
query
.
filter_by
(
mac
=
machine_mac
)
.
first
()
if
not
machine_result
:
return
MACHINE_NOT_EXIST_ERROR
machine_result
.
status
=
status
db
.
session
.
add
(
machine_result
)
db
.
session
.
commit
()
return
BaseResponse
(
date
=
{
"success"
:
True
})
myapps/management/api/rent_
query
.py
→
myapps/management/api/rent_
portal
.py
View file @
e64c0af3
...
...
@@ -90,8 +90,8 @@ def details():
"back_money"
:
result
.
back_money
,
"is_pay"
:
result
.
is_pay
,
"rent_type"
:
result
.
rent_type
,
"add_time"
:
result
.
add_time
,
"pay_time"
:
result
.
pay_time
,
"add_time"
:
result
.
add_time
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
,
"pay_time"
:
result
.
pay_time
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
,
"over_time"
:
result
.
over_time
}
result_date
.
append
(
data
)
...
...
@@ -125,4 +125,4 @@ def edit_s():
db
.
session
.
add
(
rent_refund
)
db
.
session
.
commit
()
return
BaseResponse
()
return
BaseResponse
(
data
=
True
)
myapps/management/api/tallyman_portal.py
0 → 100644
View file @
e64c0af3
# -*- coding: utf-8 -*-
import
datetime
import
logging
import
time
from
flask
import
Blueprint
,
jsonify
,
request
,
g
from
sqlalchemy
import
func
from
config.base_config
import
MONGO_DATABASE_URI
from
config.commen_config
import
LOGIN_TYPE
from
models.base_model
import
db
from
models.models
import
TallymanAccount
,
TallymanMachine
,
TallymanLoginRecord
,
Machine
,
Hatch
,
TallyRecord
,
\
TallymanPlace
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
,
\
USER_ALREADY_REGISTER_ERROR
from
utils.jwt_util
import
verify_jwt
,
generate_jwt
from
utils.my_response
import
BaseResponse
logger
=
logging
.
getLogger
(
__name__
)
tallyman_route
=
Blueprint
(
'tallyman'
,
__name__
)
@tallyman_route.route
(
'/add_man'
,
methods
=
[
'GET'
,
'POST'
])
def
add_man
():
# 添加补货员账号
json_data
=
request
.
get_json
()
user_name
=
json_data
[
'name'
]
phone
=
json_data
[
'phone'
]
password
=
json_data
[
'password'
]
comment
=
json_data
[
'comment'
]
if
'comment'
in
json_data
else
None
# 是否存在手机号码
tallyman
=
TallymanAccount
.
query
.
filter_by
(
phone
=
phone
)
.
first
()
if
tallyman
:
if
tallyman
.
status
!=
-
1
:
return
jsonify
(
TALLYMAN_ACCOUNT_EXIST
)
else
:
tallyman
=
TallymanAccount
()
tallyman
.
user_no
=
"todo"
tallyman
.
level
=
1
tallyman
.
user_name
=
user_name
tallyman
.
phone
=
phone
tallyman
.
status
=
1
tallyman
.
comment
=
comment
tallyman
.
created_at
=
datetime
.
datetime
.
now
()
tallyman
.
updated_at
=
datetime
.
datetime
.
now
()
if
password
:
tallyman
.
password
=
password
db
.
session
.
add
(
tallyman
)
db
.
session
.
commit
()
tallyman
.
user_no
=
"SK"
+
str
(
tallyman
.
id
)
.
zfill
(
6
)
db
.
session
.
add
(
tallyman
)
db
.
session
.
commit
()
return
BaseResponse
(
date
=
{
"success"
:
True
})
# 删除补货员
@tallyman_route.route
(
'/del_man'
,
methods
=
[
'GET'
,
'POST'
])
def
del_man
():
json_date
=
request
.
get_json
()
tallyman_id
=
json_date
[
"tallyman_id"
]
tall_result
=
TallymanAccount
.
query
.
filter_by
(
id
=
tallyman_id
)
.
first
()
if
not
tall_result
:
return
TALLYMAN_ACCOUNT_NOT_EXIST
tall_result
.
status
=
-
1
db
.
session
.
add
(
tall_result
)
db
.
session
.
commit
()
return
BaseResponse
(
date
=
{
"success"
:
True
})
# 补货员list
@tallyman_route.route
(
"/query_man"
,
methods
=
[
'POST'
])
def
tallyman
():
json_date
=
request
.
get_json
()
tallyman
=
json_date
[
'tallyman'
]
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
)
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
=
{
"tallyman_id"
:
i
.
id
,
"user_no"
:
i
.
user_no
,
"user_name"
:
i
.
user_name
,
"level"
:
i
.
level
,
"phone"
:
i
.
phone
,
"status"
:
i
.
status
,
"last_login"
:
i
.
last_login
,
"address_id"
:
man_place_res
[
2
],
"address_name"
:
man_place_res
[
0
]
}
result_date
.
append
(
date
)
return
BaseResponse
(
date
=
result_date
)
# 编辑补货员信息
@tallyman_route.route
(
"/edit_man"
,
methods
=
[
"POST"
])
def
edit_man
():
json_date
=
request
.
get_json
()
tallyman_id
=
json_date
[
"tallyman_id"
]
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
phone_not
=
TallymanAccount
.
query
.
filter_by
(
phone
=
phone
,
status
=
1
)
.
first
()
if
phone_not
:
return
USER_ALREADY_REGISTER_ERROR
man_result
.
phone
=
phone
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
service/machine_service.py
0 → 100644
View file @
e64c0af3
# -*- coding: utf-8 -*-
import
logging
from
flask
import
Blueprint
,
request
,
jsonify
,
g
from
utils.my_response
import
BaseResponse
from
models.base_model
import
db
from
models.models
import
Machine
,
Production
,
Hatch
,
RentDetail
from
utils.error_code
import
MACHINE_NOT_EXIST_ERROR
,
HATCH_NOT_EXIST_ERROR
logger
=
logging
.
getLogger
(
__name__
)
# 查询数据
utils/error_code.py
View file @
e64c0af3
This diff is collapsed.
Click to expand it.
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