Commit 129b3e6a by Aeolus

Merge remote-tracking branch 'origin/yanglei'

parents e4bbefdb 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'))
......@@ -384,3 +383,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"))
......@@ -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")
......@@ -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,28 +25,35 @@ 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_id": phone_result.id}, time.time() + 6000, SECRET_KEY)
date={
"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:
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_id": user_result.id}, time.time() + 6000, SECRET_KEY)
date = {
"token": token,
"success": True
}
return BaseResponse(data=date)
else:
return BaseResponse(**PASSWORD_ERROR)
......
#!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
from utils.error_code import MACHINE_NOT_EXIST_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__)
# 模糊查询到机器信息
@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,94 @@ 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():
token = request.headers.get('Authorization')
json_date = request.get_json()
page = json_date["page"]
page_size = json_date["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:
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
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})
......@@ -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)
# -*- coding: utf-8 -*-
import datetime
import logging
import time
import os
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, 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,\
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():
token = request.headers.get('Authorization')
json_date = request.get_json()
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"]
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:
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_name": i.place_name,
"address_id": i.place_id
}
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"]
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)
return BaseResponse(date={"success": True})
# 为补货员添加机器
\ No newline at end of file
# -*- 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__)
# 查询数据
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment