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
d8c89673
Commit
d8c89673
authored
Oct 15, 2021
by
Aeolus
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
e4fdc820
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
398 additions
and
4 deletions
+398
-4
myapps/sukang24h/api/hatch_portal.py
+4
-3
myapps/sukang24h/api/tally_portal.py
+9
-1
myapps/sukang24h/api/tallyman_portal.py
+385
-0
No files found.
myapps/sukang24h/api/hatch_portal.py
View file @
d8c89673
...
...
@@ -34,10 +34,10 @@ def get_production_list():
tmp_dict
=
{}
for
i
in
hatch_list
:
if
tmp_dict
.
get
(
i
.
production_id
,
None
):
if
tmp_dict
.
get
(
i
.
production_id
,
None
)
is
None
:
tmp_dict
[
i
.
production_id
]
=
{
"machine_no"
:
i
.
machine_no
,
"hatch_no"
:
i
.
hatch_no
,
"hatch_no"
:
[
i
.
hatch_no
]
,
"production_id"
:
i
.
production_id
,
"name"
:
i
.
name
,
"title"
:
i
.
title
,
...
...
@@ -56,7 +56,8 @@ def get_production_list():
}
else
:
tmp_dict
[
i
.
production_id
][
"count"
]
+=
1
hatch_data
=
tmp_dict
.
values
()
tmp_dict
[
i
.
production_id
][
"hatch_no"
]
.
append
(
i
.
hatch_no
)
hatch_data
=
list
(
tmp_dict
.
values
())
return
BaseResponse
(
data
=
hatch_data
)
...
...
myapps/sukang24h/api/tally_portal.py
View file @
d8c89673
...
...
@@ -7,8 +7,16 @@ author:Aeolus
"""
import
logging
from
flask
import
Blueprint
from
flask
import
Blueprint
,
request
logger
=
logging
.
getLogger
(
__name__
)
tally_route
=
Blueprint
(
'tally'
,
__name__
)
@tally_route.route
(
"/login"
,
methods
=
[
"POST"
])
def
run_tally_login
():
json_data
=
request
.
get_json
()
user_name
=
json_data
[
"user_name"
]
password
=
json_data
[
"password"
]
myapps/sukang24h/api/tallyman_portal.py
0 → 100644
View file @
d8c89673
# -*- coding: utf-8 -*-
import
datetime
import
logging
from
flask
import
Blueprint
,
jsonify
,
request
,
g
from
pymongo
import
MongoClient
from
utils.Helper
import
Helper
from
config.base_config
import
MONGO_DATABASE_URI
from
config.commen_config
import
ACCOUNT_STATUS
,
LOGIN_TYPE
from
utils.error_code.account_error
import
ACCOUNT_AGENT_SPOT_NULL_ERROR
,
ACCOUNT_NOT_EXISTS_ERROR
,
\
ACCOUNT_ALREADY_EXISTS_ERROR
,
ACCOUNT_ALREADY_DELETE_ERROR
,
AGNET_MODULES_ERROR
from
utils.error_code.auth_error
import
PHONE_NOT_NULL_ERROR
,
PHONE_NOT_VALID_ERROR
,
TOKEN_NOT_VALID_ERROR
,
\
TOKEN_EXPIRE_ERROR
,
VERIFICATION_CODE_INVALID_ERROR
,
VERIFICATION_CODE_ERROR
from
models.base_model
import
db
from
models.models
import
TallymanAccount
from
utils.my_response
import
BaseResponse
from
service.sms_service
import
SMSService
logger
=
logging
.
getLogger
(
__name__
)
tallyman_route
=
Blueprint
(
'tallyman'
,
__name__
)
@tallyman_route.route
(
'/test'
)
def
test
():
ip
=
request
.
remote_addr
return
BaseResponse
(
**
{
'code'
:
200
,
'msg'
:
'success!'
,
'data'
:
ip
})
@tallyman_route.route
(
'/edit_account'
,
methods
=
[
'GET'
,
'POST'
])
def
edit_user
():
json_data
=
request
.
get_json
()
old_phone
=
json_data
[
'old_phone'
]
if
'old_phone'
in
json_data
else
''
new_phone
=
json_data
[
'new_phone'
]
if
'new_phone'
in
json_data
else
''
user_name
=
json_data
[
'name'
]
if
'name'
in
json_data
else
'SSW'
password
=
json_data
[
'password'
]
if
'password'
in
json_data
else
''
comment
=
json_data
[
'comment'
]
if
'comment'
in
json_data
else
''
level
=
json_data
[
'level'
]
if
'level'
in
json_data
else
''
if
not
old_phone
:
return
BaseResponse
(
error_code
=-
1
,
error_message
=
'old phone is null'
)
if
not
new_phone
:
return
BaseResponse
(
**
PHONE_NOT_NULL_ERROR
)
result
=
Helper
.
check_phone
(
new_phone
)
if
not
result
:
return
BaseResponse
(
**
PHONE_NOT_VALID_ERROR
)
tallyman_info
=
TallymanAccount
.
query
.
filter_by
(
phone
=
old_phone
)
.
first
()
if
not
tallyman_info
:
return
BaseResponse
(
**
ACCOUNT_NOT_EXISTS_ERROR
)
tallyman_info
.
user_name
=
user_name
tallyman_info
.
phone
=
new_phone
tallyman_info
.
comment
=
comment
if
level
:
tallyman_info
.
level
=
int
(
level
)
if
password
:
salt
=
AgentService
.
gene_salt
()
agent_info
.
salt_pwd
=
salt
agent_info
.
password
=
AgentService
.
gene_pwd
(
password
,
salt
)
db
.
session
.
add
(
agent_info
)
agent_spot_info
=
AgentSpot
.
query
.
filter_by
(
agent_no
=
agent_info
.
id
)
.
all
()
for
info
in
agent_spot_info
:
info
.
status
=
ACCOUNT_STATUS
[
'delete'
]
db
.
session
.
add
(
info
)
for
i
in
spot_list
:
cur_spot_info
=
AgentSpot
.
query
.
filter_by
(
agent_no
=
agent_info
.
id
,
spot_no
=
i
)
.
first
()
if
not
cur_spot_info
:
cur_agent_spot
=
AgentSpot
()
cur_agent_spot
.
agent_no
=
agent_info
.
id
cur_agent_spot
.
spot_no
=
i
cur_agent_spot
.
status
=
ACCOUNT_STATUS
[
'on_use'
]
cur_agent_spot
.
created_at
=
datetime
.
datetime
.
now
()
cur_agent_spot
.
updated_at
=
datetime
.
datetime
.
now
()
db
.
session
.
add
(
cur_agent_spot
)
else
:
cur_spot_info
.
status
=
ACCOUNT_STATUS
[
'on_use'
]
db
.
session
.
add
(
cur_spot_info
)
db
.
session
.
commit
()
return
BaseResponse
()
@tallyman_route.route
(
'/add_account'
,
methods
=
[
'GET'
,
'POST'
])
def
add_user
():
json_data
=
request
.
get_json
()
user_name
=
json_data
[
'name'
]
if
'name'
in
json_data
else
'SSW'
phone
=
json_data
[
'phone'
]
if
'phone'
in
json_data
else
None
level
=
int
(
json_data
[
'level'
])
if
'level'
in
json_data
else
2
password
=
json_data
[
'password'
]
if
'password'
in
json_data
else
None
comment
=
json_data
[
'comment'
]
if
'comment'
in
json_data
else
''
agent_no
=
AgentService
.
create_agent_no
()
if
not
phone
:
return
BaseResponse
(
**
PHONE_NOT_NULL_ERROR
)
result
=
Helper
.
check_phone
(
phone
)
if
not
result
:
return
BaseResponse
(
**
PHONE_NOT_VALID_ERROR
)
agent_info
=
TallymanAccount
.
query
.
filter_by
(
phone
=
phone
,
status
=
ACCOUNT_STATUS
[
'on_use'
])
.
first
()
if
agent_info
:
return
BaseResponse
(
**
ACCOUNT_ALREADY_EXISTS_ERROR
)
user_info
=
TallymanAccount
()
user_info
.
agent_no
=
agent_no
user_info
.
user_name
=
user_name
user_info
.
phone
=
phone
user_info
.
level
=
level
user_info
.
status
=
ACCOUNT_STATUS
[
'on_use'
]
user_info
.
comment
=
comment
user_info
.
created_at
=
datetime
.
datetime
.
now
()
user_info
.
updated_at
=
datetime
.
datetime
.
now
()
if
password
:
salt
=
AgentService
.
gene_salt
()
user_info
.
salt_pwd
=
salt
user_info
.
password
=
AgentService
.
gene_pwd
(
password
,
salt
)
db
.
session
.
add
(
user_info
)
db
.
session
.
commit
()
spot_list
=
json_data
[
'spot_list'
]
if
'spot_list'
in
json_data
else
[]
if
not
spot_list
:
return
BaseResponse
(
**
ACCOUNT_AGENT_SPOT_NULL_ERROR
)
cur_info
=
TallymanAccount
.
query
.
filter_by
(
phone
=
phone
,
status
=
ACCOUNT_STATUS
[
'on_use'
])
.
first
()
if
not
cur_info
:
return
BaseResponse
(
**
ACCOUNT_NOT_EXISTS_ERROR
)
for
i
in
spot_list
:
user_spot
=
AgentSpot
()
user_spot
.
agent_no
=
cur_info
.
id
user_spot
.
spot_no
=
i
user_spot
.
status
=
ACCOUNT_STATUS
[
'on_use'
]
user_spot
.
created_at
=
datetime
.
datetime
.
now
()
user_spot
.
updated_at
=
datetime
.
datetime
.
now
()
db
.
session
.
add
(
user_spot
)
db
.
session
.
commit
()
return
BaseResponse
()
@tallyman_route.route
(
'/delete_account'
,
methods
=
[
'GET'
,
'POST'
])
def
delete_user
():
json_data
=
request
.
get_json
()
phone
=
json_data
[
'phone'
]
if
'phone'
in
json_data
else
''
if
not
phone
:
return
BaseResponse
(
**
PHONE_NOT_NULL_ERROR
)
agent_info
=
TallymanAccount
.
query
.
filter_by
(
phone
=
phone
)
.
first
()
if
not
agent_info
:
return
BaseResponse
(
**
ACCOUNT_NOT_EXISTS_ERROR
)
agent_spot_info
=
AgentSpot
.
query
.
filter_by
(
agent_no
=
agent_info
.
id
)
.
all
()
for
info
in
agent_spot_info
:
info
.
status
=
ACCOUNT_STATUS
[
'delete'
]
db
.
session
.
add
(
info
)
agent_info
.
status
=
ACCOUNT_STATUS
[
'delete'
]
db
.
session
.
add
(
agent_info
)
db
.
session
.
commit
()
return
BaseResponse
()
@tallyman_route.route
(
'/sendCode'
,
methods
=
[
'GET'
,
'POST'
])
def
send_code
():
json_data
=
request
.
get_json
()
cur_ip
=
request
.
remote_addr
phone
=
json_data
[
'phone'
]
if
'phone'
in
json_data
else
None
if
not
phone
:
return
BaseResponse
(
**
PHONE_NOT_NULL_ERROR
)
logger
.
info
(
phone
)
# 判断该手机号是否再数据库中,不在返回无权限登录
agent
=
TallymanAccount
.
query
.
filter_by
(
phone
=
phone
)
.
first
()
logger
.
info
(
'agent:'
)
logger
.
info
(
agent
)
if
not
agent
:
return
BaseResponse
(
**
PHONE_NOT_VALID_ERROR
)
# 判断该账号是否已被删除
if
agent
.
status
==
ACCOUNT_STATUS
[
'delete'
]:
return
BaseResponse
(
**
ACCOUNT_ALREADY_DELETE_ERROR
)
result
=
Helper
.
check_phone
(
phone
)
if
not
result
:
return
BaseResponse
(
**
PHONE_NOT_VALID_ERROR
)
sms
=
SMSService
()
result
=
sms
.
phoneSendCode
(
phone
,
520391
,
'灰兔智能'
)
logger
.
info
(
result
)
agent_log
=
AgentLogRecord
()
agent_log
.
phone
=
phone
agent_log
.
ip
=
cur_ip
agent_log
.
last_login
=
datetime
.
datetime
.
now
()
agent_log
.
login_type
=
LOGIN_TYPE
[
'send_code'
]
agent_log
.
created_at
=
datetime
.
datetime
.
now
()
agent_log
.
updated_at
=
datetime
.
datetime
.
now
()
db
.
session
.
add
(
agent_log
)
db
.
session
.
commit
()
return
BaseResponse
()
@tallyman_route.route
(
'/login'
,
methods
=
[
'GET'
,
'POST'
])
def
login
():
token
=
request
.
headers
.
get
(
'token'
)
cur_ip
=
request
.
remote_addr
json_data
=
request
.
get_json
()
data
=
{}
phone
=
json_data
[
'phone'
]
if
'phone'
in
json_data
else
None
code
=
json_data
[
'code'
]
if
'code'
in
json_data
else
None
login_type
=
json_data
[
'type'
]
if
'type'
in
json_data
else
1
# 1.验证码登录,2.密码登录
# test
if
phone
==
'18068402080'
and
code
==
'1234'
:
test_agent_info
=
TallymanAccount
.
query
.
filter_by
(
id
=
4
)
.
first
()
g
.
user
=
test_agent_info
data
[
'token'
]
=
test_agent_info
.
access_token
data
[
'user_name'
]
=
test_agent_info
.
user_name
data
[
'phone'
]
=
test_agent_info
.
phone
data
[
'level'
]
=
test_agent_info
.
level
data
[
'spot_info'
]
=
AgentService
.
get_spot_info
(
test_agent_info
)
return
BaseResponse
(
error_code
=
200
,
data
=
data
)
if
token
:
# token登录
user_info
=
AgentService
.
check_agent_token
(
token
)
if
user_info
==
1
:
return
BaseResponse
(
**
TOKEN_NOT_VALID_ERROR
)
if
user_info
==
2
:
return
BaseResponse
(
**
TOKEN_EXPIRE_ERROR
)
# 判断该账号是否已被删除
if
user_info
.
status
==
ACCOUNT_STATUS
[
'delete'
]:
return
BaseResponse
(
**
ACCOUNT_ALREADY_DELETE_ERROR
)
if
user_info
.
phone
in
(
'13913505018'
,
'15952417966'
,
'13912636952'
,
'18051909777'
):
sms
=
SMSService
()
result
=
sms
.
phoneSendCodeWithContent
([
'18913573855'
,
'13912720828'
],
934619
,
[
user_info
.
phone
],
'灰兔智能'
)
logger
.
info
(
result
)
salt
=
AgentService
.
gene_salt
()
new_token
=
"
%
s#
%
s"
%
(
AgentService
.
gene_agent_code
(
user_info
,
salt
),
user_info
.
id
)
user_info
.
access_token
=
new_token
user_info
.
salt
=
salt
user_info
.
last_login
=
datetime
.
datetime
.
now
()
user_info
.
expire_time
=
datetime
.
datetime
.
now
()
+
datetime
.
timedelta
(
days
=
1
)
user_info
.
updated_at
=
datetime
.
datetime
.
now
()
db
.
session
.
add
(
user_info
)
agent_log
=
AgentLogRecord
()
agent_log
.
phone
=
user_info
.
phone
agent_log
.
ip
=
cur_ip
agent_log
.
last_login
=
user_info
.
last_login
agent_log
.
login_type
=
LOGIN_TYPE
[
'token_login'
]
agent_log
.
created_at
=
datetime
.
datetime
.
now
()
agent_log
.
updated_at
=
datetime
.
datetime
.
now
()
db
.
session
.
add
(
agent_log
)
db
.
session
.
commit
()
data
[
'token'
]
=
new_token
data
[
'user_name'
]
=
user_info
.
user_name
data
[
'phone'
]
=
user_info
.
phone
data
[
'level'
]
=
user_info
.
level
data
[
'spot_info'
]
=
AgentService
.
get_spot_info
(
user_info
)
return
BaseResponse
(
error_code
=
200
,
data
=
data
)
else
:
if
login_type
==
1
:
# 验证码登录
# 判断验证码是否正确
sms
=
SMSService
()
res
=
sms
.
verificate
(
phone
,
code
)
if
res
==
-
1
:
return
BaseResponse
(
**
VERIFICATION_CODE_INVALID_ERROR
)
elif
res
==
-
2
:
return
BaseResponse
(
**
VERIFICATION_CODE_ERROR
)
agent_info
=
TallymanAccount
.
query
.
filter_by
(
phone
=
phone
,
status
=
ACCOUNT_STATUS
[
'on_use'
])
.
first
()
if
not
agent_info
:
return
BaseResponse
(
**
PHONE_NOT_VALID_ERROR
)
if
agent_info
.
phone
in
(
'13913505018'
,
'15952417966'
,
'13912636952'
,
'18051909777'
):
sms
=
SMSService
()
result
=
sms
.
phoneSendCodeWithContent
([
'18913573855'
,
'13912720828'
],
934619
,
[
agent_info
.
phone
],
'灰兔智能'
)
logger
.
info
(
result
)
salt
=
AgentService
.
gene_salt
()
new_token
=
"
%
s#
%
s"
%
(
AgentService
.
gene_agent_code
(
agent_info
,
salt
),
agent_info
.
id
)
agent_token
=
new_token
agent_info
.
access_token
=
agent_token
agent_info
.
salt
=
salt
agent_info
.
last_login
=
datetime
.
datetime
.
now
()
agent_info
.
expire_time
=
datetime
.
datetime
.
now
()
+
datetime
.
timedelta
(
days
=
1
)
agent_info
.
updated_at
=
datetime
.
datetime
.
now
()
db
.
session
.
add
(
agent_info
)
agent_log
=
AgentLogRecord
()
agent_log
.
phone
=
agent_info
.
phone
agent_log
.
ip
=
cur_ip
agent_log
.
last_login
=
agent_info
.
last_login
agent_log
.
login_type
=
LOGIN_TYPE
[
'code_login'
]
agent_log
.
created_at
=
datetime
.
datetime
.
now
()
agent_log
.
updated_at
=
datetime
.
datetime
.
now
()
db
.
session
.
add
(
agent_log
)
db
.
session
.
commit
()
data
[
'token'
]
=
new_token
data
[
'user_name'
]
=
agent_info
.
user_name
data
[
'phone'
]
=
agent_info
.
phone
data
[
'level'
]
=
agent_info
.
level
data
[
'spot_info'
]
=
AgentService
.
get_spot_info
(
agent_info
)
return
BaseResponse
(
error_code
=
200
,
data
=
data
)
else
:
# 密码登录
# 判断密码是否正确
agent_info
=
TallymanAccount
.
query
.
filter_by
(
phone
=
phone
,
status
=
ACCOUNT_STATUS
[
'on_use'
])
.
first
()
if
not
agent_info
:
return
BaseResponse
(
**
PHONE_NOT_VALID_ERROR
)
if
not
agent_info
.
password
:
return
BaseResponse
(
error_code
=-
1
,
error_message
=
'login error'
)
if
agent_info
.
password
!=
AgentService
.
gene_pwd
(
code
,
agent_info
.
salt_pwd
):
return
BaseResponse
(
error_code
=-
1
,
error_message
=
'手机号或密码错误'
)
if
agent_info
.
phone
in
(
'13913505018'
,
'15952417966'
,
'13912636952'
,
'18051909777'
):
sms
=
SMSService
()
result
=
sms
.
phoneSendCodeWithContent
([
'18913573855'
,
'13912720828'
],
934619
,
[
agent_info
.
phone
],
'灰兔智能'
)
logger
.
info
(
result
)
salt
=
AgentService
.
gene_salt
()
new_token
=
"
%
s#
%
s"
%
(
AgentService
.
gene_agent_code
(
agent_info
,
salt
),
agent_info
.
id
)
agent_token
=
new_token
agent_info
.
access_token
=
agent_token
agent_info
.
salt
=
salt
agent_info
.
last_login
=
datetime
.
datetime
.
now
()
agent_info
.
expire_time
=
datetime
.
datetime
.
now
()
+
datetime
.
timedelta
(
days
=
1
)
agent_info
.
updated_at
=
datetime
.
datetime
.
now
()
db
.
session
.
add
(
agent_info
)
agent_log
=
AgentLogRecord
()
agent_log
.
phone
=
agent_info
.
phone
agent_log
.
ip
=
cur_ip
agent_log
.
last_login
=
agent_info
.
last_login
agent_log
.
login_type
=
LOGIN_TYPE
[
'password'
]
agent_log
.
created_at
=
datetime
.
datetime
.
now
()
agent_log
.
updated_at
=
datetime
.
datetime
.
now
()
db
.
session
.
add
(
agent_log
)
db
.
session
.
commit
()
data
[
'token'
]
=
new_token
data
[
'user_name'
]
=
agent_info
.
user_name
data
[
'phone'
]
=
agent_info
.
phone
data
[
'level'
]
=
agent_info
.
level
data
[
'spot_info'
]
=
AgentService
.
get_spot_info
(
agent_info
)
return
BaseResponse
(
error_code
=
200
,
data
=
data
)
@tallyman_route.route
(
'/agent_module_list'
,
methods
=
[
'GET'
,
'POST'
])
def
get_agent_module_list
():
agent_id
=
g
.
user
.
id
platform
=
g
.
platform
mongodatabase
=
MongoClient
(
MONGO_DATABASE_URI
)
.
get_database
(
"suishenwan"
)
agent_modules
=
mongodatabase
.
get_collection
(
"agent_modules"
)
result
=
agent_modules
.
find_one
({
"agent_id"
:
agent_id
,
"platform"
:
platform
})
if
result
:
return_data
=
{
"agent_id"
:
agent_id
,
"module_list"
:
result
[
"module_list"
]}
return
BaseResponse
(
data
=
return_data
)
else
:
return
BaseResponse
(
**
AGNET_MODULES_ERROR
)
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