添加token认证

duizhaopin
apan 2 years ago
parent f5ad1e62e9
commit 3d88fbddb1

@ -6,12 +6,14 @@
from flask import Blueprint, jsonify, request from flask import Blueprint, jsonify, request
from Common.Utils import Utils from Common.Utils import Utils
from db_logic.client import BllClient from db_logic.client import BllClient
from Common.auth import token_auth
client_router = Blueprint("client", __name__) client_router = Blueprint("client", __name__)
# 查看client列表 # 查看client列表
@client_router.route("/client_list", methods=["POST"]) @client_router.route("/client_list", methods=["POST"])
@token_auth.login_required
def get_client_list(): def get_client_list():
data = BllClient().get_all_client_list() data = BllClient().get_all_client_list()
data_list = Utils.msyql_table_model(data) data_list = Utils.msyql_table_model(data)

@ -4,7 +4,7 @@
@Date:2022/07/26 11:19:30 @Date:2022/07/26 11:19:30
''' '''
import datetime import datetime
from flask import jsonify, request from flask import jsonify, request, g
from flask import Blueprint from flask import Blueprint
from db_logic.client import BllClient from db_logic.client import BllClient
@ -15,6 +15,8 @@ from db_logic.user import BllUser
from models.user_models import EntityUser from models.user_models import EntityUser
from models.client_models import EntityClient from models.client_models import EntityClient
from Common.Utils import DrugStatus, PageParam, Utils from Common.Utils import DrugStatus, PageParam, Utils
from Common.auth import token_auth
drug_router = Blueprint("drug", __name__) drug_router = Blueprint("drug", __name__)
@ -22,12 +24,13 @@ drug_router = Blueprint("drug", __name__)
# 试剂扫码领用 # 试剂扫码领用
@drug_router.route("/use", methods=["GET", "POST"]) @drug_router.route("/use", methods=["GET", "POST"])
@token_auth.login_required
def drug_collect(): def drug_collect():
# 获取参数 # 获取参数
bar_code = request.values.get("bar_code") bar_code = request.values.get("bar_code")
# user_id=request.values.get("user_id") # user_id=request.values.get("user_id")
# 默认用户id后续从token 中获取 # 默认用户id后续从token 中获取
user_id = '4cea74ee-0d8b-11ed-943e-f47b094925e1' # user_id = '4cea74ee-0d8b-11ed-943e-f47b094925e1'
# 强制使用默认0不强制1强制 # 强制使用默认0不强制1强制
force_use = request.values.get("force_use") force_use = request.values.get("force_use")
force_use = force_use if force_use != '' else '0' force_use = force_use if force_use != '' else '0'
@ -57,7 +60,8 @@ def drug_collect():
data = Utils.false_return(status=2, msg=f'"{drug_entity.name}({drug_entity.bar_code})"此类药有更接近保质期的实例"{drug_obj.bar_code}", 存在于"{drug_obj.client_code}"号终端') data = Utils.false_return(status=2, msg=f'"{drug_entity.name}({drug_entity.bar_code})"此类药有更接近保质期的实例"{drug_obj.bar_code}", 存在于"{drug_obj.client_code}"号终端')
else: else:
# 领取试剂 # 领取试剂
user_info = BllUser().findEntity(EntityUser.user_id==user_id) # user_info = BllUser().findEntity(EntityUser.user_id==user_id)
user_info = g.current_user
drug_entity.by_user_date = Utils.get_str_datetime() drug_entity.by_user_date = Utils.get_str_datetime()
drug_entity.by_user_id=user_info.user_id drug_entity.by_user_id=user_info.user_id
drug_entity.by_user_name=user_info.real_name drug_entity.by_user_name=user_info.real_name
@ -77,13 +81,14 @@ def drug_collect():
# 试剂归还 # 试剂归还
@drug_router.route("/drug_return", methods=["GET", "POST"]) @drug_router.route("/drug_return", methods=["GET", "POST"])
@token_auth.login_required
def drug_return(): def drug_return():
# 获取参数 # 获取参数
bar_code = request.values.get("bar_code") bar_code = request.values.get("bar_code")
place = request.values.get("place") place = request.values.get("place")
# user_id = request.values.get("user_id") # user_id = request.values.get("user_id")
# 默认用户id后续从token 中获取 # 默认用户id后续从token 中获取
user_id = '4cea74ee-0d8b-11ed-943e-f47b094925e1' # user_id = '4cea74ee-0d8b-11ed-943e-f47b094925e1'
# 根据条码查询试剂信息 # 根据条码查询试剂信息
@ -97,7 +102,8 @@ def drug_return():
drug_info.status = DrugStatus.Normal drug_info.status = DrugStatus.Normal
if place: if place:
drug_info.place = place drug_info.place = place
user_info = BllUser().findEntity(EntityUser.user_id == user_id) # user_info = BllUser().findEntity(EntityUser.user_id == user_id)
user_info = g.current_user
BllMedicament().drugReturn(drug_info, BllClient().findEntity(drug_info.client_id), user_info) BllMedicament().drugReturn(drug_info, BllClient().findEntity(drug_info.client_id), user_info)
data = Utils.true_return(msg="药剂归还成功", data=Utils.to_dict(drug_info)) data = Utils.true_return(msg="药剂归还成功", data=Utils.to_dict(drug_info))
return jsonify(data) return jsonify(data)
@ -105,6 +111,7 @@ def drug_return():
# 试剂领用/归还,列表展示 # 试剂领用/归还,列表展示
@drug_router.route("/use_or_return_list", methods=["GET", "POST"]) @drug_router.route("/use_or_return_list", methods=["GET", "POST"])
@token_auth.login_required
def drug_use_retur_list(): def drug_use_retur_list():
status = request.values.get("status") status = request.values.get("status")
page = int(request.values.get("page", 1)) page = int(request.values.get("page", 1))
@ -116,6 +123,7 @@ def drug_use_retur_list():
# 试剂称重展示试剂详细信息 # 试剂称重展示试剂详细信息
@drug_router.route("/get_drug_info", methods=["GET", "POST"]) @drug_router.route("/get_drug_info", methods=["GET", "POST"])
@token_auth.login_required
def get_drug_info(): def get_drug_info():
bar_code = request.values.get("bar_code") bar_code = request.values.get("bar_code")
data_list = BllMedicament().get_bar_code_drug_info(bar_code=bar_code) data_list = BllMedicament().get_bar_code_drug_info(bar_code=bar_code)
@ -126,6 +134,7 @@ def get_drug_info():
# 试剂管理 # 试剂管理
@drug_router.route("/drug_manage", methods=["GET", "POST"]) @drug_router.route("/drug_manage", methods=["GET", "POST"])
@token_auth.login_required
def get_drug_manage(): def get_drug_manage():
seach_word = request.values.get("seach_word") seach_word = request.values.get("seach_word")
client_id = request.values.get("client_id") client_id = request.values.get("client_id")

@ -20,7 +20,7 @@ from db_logic.medicament_template import BllMedicamentTemplate
from db_logic.meidcament_variety import BllMedicamentVariety from db_logic.meidcament_variety import BllMedicamentVariety
from models.client_models import EntityClient from models.client_models import EntityClient
from models.medicament_models import EntityMedicament, EntityMedicamentTemplate from models.medicament_models import EntityMedicament, EntityMedicamentTemplate
from Common.auth import token_auth
tmp_router = Blueprint("drug_tmplate", __name__) tmp_router = Blueprint("drug_tmplate", __name__)
@ -29,6 +29,7 @@ tmp_router = Blueprint("drug_tmplate", __name__)
# 试剂入库-模板展示 # 试剂入库-模板展示
@tmp_router.route("/show_tmp", methods=["GET", "POST"]) @tmp_router.route("/show_tmp", methods=["GET", "POST"])
@token_auth.login_required
def show_template(): def show_template():
client_id = request.values.get("client_id") client_id = request.values.get("client_id")
page = int(request.values.get("page", 1)) page = int(request.values.get("page", 1))
@ -57,6 +58,7 @@ def show_template():
# 选择药剂入库 # 选择药剂入库
@tmp_router.route("/select_drug", methods=["POST"]) @tmp_router.route("/select_drug", methods=["POST"])
@token_auth.login_required
def select_drug_info(): def select_drug_info():
seach_word =request.values.get("seach_word") seach_word =request.values.get("seach_word")
page = int(request.values.get("page", 1)) page = int(request.values.get("page", 1))
@ -69,11 +71,12 @@ def select_drug_info():
# 绑定入库 # 绑定入库
@tmp_router.route("/bind_tmp_enter_warehouse", methods=["GET", "POST"]) @tmp_router.route("/bind_tmp_enter_warehouse", methods=["GET", "POST"])
@token_auth.login_required
def bind_tmp_input_db(): def bind_tmp_input_db():
tmp_content = request.values.get("tmplate_content") tmp_content = request.values.get("tmplate_content")
customer_id = request.values.get("customer_id", '') customer_id = request.values.get("customer_id", '')
# client_id = request.values.get("client_id") client_id = request.values.get("client_id")
client_id = '1c39cb24-07f8-11ed-abd4-f47b094925e1' # client_id = '1c39cb24-07f8-11ed-abd4-f47b094925e1'
bar_code = request.values.get("bar_code") bar_code = request.values.get("bar_code")
# user_id = request.values.get("user_id") # user_id = request.values.get("user_id")
if not bar_code: if not bar_code:
@ -83,8 +86,8 @@ def bind_tmp_input_db():
return jsonify(Utils.false_return(msg="该药剂已被锁定")) return jsonify(Utils.false_return(msg="该药剂已被锁定"))
else: else:
drug_info = eval(tmp_content) drug_info = eval(tmp_content)
user_info = BllUser().findEntity('4cea74ee-0d8b-11ed-943e-f47b094925e1') # user_info = BllUser().findEntity('4cea74ee-0d8b-11ed-943e-f47b094925e1')
# user_info = g.current_user user_info = g.current_user
drug_variety = BllMedicamentVariety().createDrugVariety( drug_variety = BllMedicamentVariety().createDrugVariety(
customer_id=customer_id, customer_id=customer_id,
@ -137,13 +140,15 @@ def bind_tmp_input_db():
# 新增试剂模板 # 新增试剂模板
@tmp_router.route("/add_tmp", methods=["GET", "POST"]) @tmp_router.route("/add_tmp", methods=["GET", "POST"])
@token_auth.login_required
def add_tmp_info(): def add_tmp_info():
tmp_name = request.values.get("template_name") tmp_name = request.values.get("template_name")
# client_id = request.values.get("client_id") client_id = request.values.get("client_id")
client_id = '1c39cb24-07f8-11ed-abd4-f47b094925e1' # client_id = '1c39cb24-07f8-11ed-abd4-f47b094925e1'
tmp_content = request.values.get("template_content") tmp_content = request.values.get("template_content")
user_id = '4cea74ee-0d8b-11ed-943e-f47b094925e1' # user_id = '4cea74ee-0d8b-11ed-943e-f47b094925e1'
user = BllUser().findEntity(user_id) # user = BllUser().findEntity(user_id)
user = g.current_user
client = BllClient().findEntity(client_id) client = BllClient().findEntity(client_id)
sql_all = """ sql_all = """
select bar_code_count, start_bar_code from rms_medicament_template where start_bar_code=(select max(start_bar_code) max_start from rms_medicament_template) select bar_code_count, start_bar_code from rms_medicament_template where start_bar_code=(select max(start_bar_code) max_start from rms_medicament_template)
@ -199,6 +204,7 @@ def add_tmp_info():
# 导入入库模板 # 导入入库模板
@tmp_router.route("/put_in_tmp", methods=["GET", "POST"]) @tmp_router.route("/put_in_tmp", methods=["GET", "POST"])
@token_auth.login_required
def import_tmplate(): def import_tmplate():
try: try:
file_path = Utils.getUDiskPath() file_path = Utils.getUDiskPath()
@ -264,6 +270,7 @@ def import_tmplate():
# 删除模板 # 删除模板
@tmp_router.route("/del_tmp", methods=["GET", "POST"]) @tmp_router.route("/del_tmp", methods=["GET", "POST"])
@token_auth.login_required
def remove_tmp(): def remove_tmp():
tmp_id_list = request.values.get("template_id_list") tmp_id_list = request.values.get("template_id_list")
if tmp_id_list: if tmp_id_list:

@ -13,7 +13,7 @@ from models.warning_models import EntityWarning
from db_logic.medicament_record import BllMedicamentRecord from db_logic.medicament_record import BllMedicamentRecord
from db_logic.warning import BllWarning from db_logic.warning import BllWarning
from Common.Utils import PageParam, Utils from Common.Utils import PageParam, Utils
from Common.auth import token_auth
from flask import Blueprint from flask import Blueprint
@ -21,6 +21,7 @@ home_router = Blueprint('home', __name__, url_prefix="/home")
# 获取页面主概览数据 --- 查询条件缺少柜体id客户id # 获取页面主概览数据 --- 查询条件缺少柜体id客户id
@home_router.route('/home_number', methods=["GET", "POST"]) @home_router.route('/home_number', methods=["GET", "POST"])
@token_auth.login_required
def get_record_type_drug_record_json(): def get_record_type_drug_record_json():
customer_id = request.values.get('customer_id') customer_id = request.values.get('customer_id')
client_id = request.values.get('client_id') client_id = request.values.get('client_id')
@ -38,6 +39,7 @@ def get_record_type_drug_record_json():
# 主概览 当日入库-领用-归还,预警列表, 信息总览 # 主概览 当日入库-领用-归还,预警列表, 信息总览
@home_router.route("/home_info", methods=["GET", "POST"]) @home_router.route("/home_info", methods=["GET", "POST"])
@token_auth.login_required
def get_home_info(): def get_home_info():
resp_data = { resp_data = {
"new_day_record_number":{}, "new_day_record_number":{},
@ -61,6 +63,7 @@ def get_home_info():
# 试剂余量 # 试剂余量
@home_router.route("/home_drug_remaining", methods=["GET", "POST"]) @home_router.route("/home_drug_remaining", methods=["GET", "POST"])
@token_auth.login_required
def drug_remaining(): def drug_remaining():
client_id = request.values.get("client_id") client_id = request.values.get("client_id")
page = int(request.values.get("page", 1)) page = int(request.values.get("page", 1))
@ -78,6 +81,7 @@ def drug_remaining():
# 获取预警信息列表接口 # 获取预警信息列表接口
@home_router.route('/home_warning_list', methods=["GET", "POST"]) @home_router.route('/home_warning_list', methods=["GET", "POST"])
@token_auth.login_required
def get_warning_list(): def get_warning_list():
# customer_id = request.values.get('customer_id', '') # customer_id = request.values.get('customer_id', '')
seach_word = request.values.get("seach_word") seach_word = request.values.get("seach_word")
@ -106,6 +110,7 @@ def get_warning_list():
# 修改预警状态根据预警id进行 # 修改预警状态根据预警id进行
@home_router.route("/update_warning_tp", methods=["GET", "POST"]) @home_router.route("/update_warning_tp", methods=["GET", "POST"])
@token_auth.login_required
def update_warning_type(): def update_warning_type():
warning_id = request.values.get('warning_id') warning_id = request.values.get('warning_id')
@ -123,6 +128,7 @@ def update_warning_type():
# 获取环境控图 # 获取环境控图
@home_router.route("/get_monitoring_info", methods=["GET", "POST"]) @home_router.route("/get_monitoring_info", methods=["GET", "POST"])
@token_auth.login_required
def get_monitoring_info(): def get_monitoring_info():
client_id = request.values.get("client_id") client_id = request.values.get("client_id")
time_type = request.values.get("time_type") time_type = request.values.get("time_type")

@ -3,11 +3,14 @@
''' '''
@Date:2022/08/01 17:04:40 @Date:2022/08/01 17:04:40
''' '''
from operator import index
import sys import sys
sys.path.append('.')
from db_logic.user import BllUser from db_logic.user import BllUser
sys.path.append('.')
from Common.auth import token_auth
from flask import Blueprint, jsonify, request, g from flask import Blueprint, jsonify, request, g
from db_logic.module_relation import BllModuleRelation from db_logic.module_relation import BllModuleRelation
@ -16,10 +19,11 @@ power_router = Blueprint('power', __name__)
@power_router.route("/user_power", methods=["GET", "POST"]) @power_router.route("/user_power", methods=["GET", "POST"])
@token_auth.login_required
def get_user_power_list(): def get_user_power_list():
# user_info = g.current_user user_info = g.current_user
user_id = '4cea74ee-0d8b-11ed-943e-f47b094925e1' # user_id = '4cea74ee-0d8b-11ed-943e-f47b094925e1'
user_info = BllUser().findEntity(user_id) # user_info = BllUser().findEntity(user_id)
module_list = BllModuleRelation().get_user_module_list(user_id=user_info.user_id, role_id=user_info.role_id) module_list = BllModuleRelation().get_user_module_list(user_id=user_info.user_id, role_id=user_info.role_id)
module_list = Utils.msyql_table_model(module_list) module_list = Utils.msyql_table_model(module_list)
return jsonify(Utils.true_return(data=module_list)) return jsonify(Utils.true_return(data=module_list))

@ -3,13 +3,13 @@
''' '''
@Date:2022/07/19 17:12:23 @Date:2022/07/19 17:12:23
''' '''
from flask import jsonify, request from flask import jsonify, request, g
from Common.Utils import PageParam, Utils from Common.Utils import PageParam, Utils
from config.SystemConfig import SystemConfig from config.SystemConfig import SystemConfig
from db_logic.medicament_record import BllMedicamentRecord from db_logic.medicament_record import BllMedicamentRecord
from db_logic.medicament import BllMedicament from db_logic.medicament import BllMedicament
from Common.auth import token_auth
from flask import Blueprint from flask import Blueprint
report_router = Blueprint("report", __name__) report_router = Blueprint("report", __name__)
@ -42,6 +42,7 @@ report_router = Blueprint("report", __name__)
# 报表统计主页 # 报表统计主页
@report_router.route("/report_home", methods=["GET", "POST"]) @report_router.route("/report_home", methods=["GET", "POST"])
@token_auth.login_required
def report_home_show(): def report_home_show():
resp_data = { resp_data = {
"drug_use_type_data": "", "drug_use_type_data": "",
@ -79,6 +80,7 @@ def report_home_show():
# 库存信息总览 # 库存信息总览
@report_router.route("/stock_data_info", methods=["GET", "POST"]) @report_router.route("/stock_data_info", methods=["GET", "POST"])
@token_auth.login_required
def get_stock_data_info(): def get_stock_data_info():
name = request.values.get("name", None) name = request.values.get("name", None)
page = int(request.values.get('page', 1)) page = int(request.values.get('page', 1))
@ -96,6 +98,7 @@ def get_stock_data_info():
# 入库信息查询and 试剂信息查询 # 入库信息查询and 试剂信息查询
@report_router.route("/drug_details_info", methods=["GET", "POST"]) @report_router.route("/drug_details_info", methods=["GET", "POST"])
@token_auth.login_required
def drun_input_info(): def drun_input_info():
# 获取参数 # 获取参数
seach_word = request.values.get('seach_word') seach_word = request.values.get('seach_word')
@ -128,6 +131,7 @@ def drun_input_info():
# 库存消耗 # 库存消耗
# 试剂名称、纯度、cas码 查询rms_medicament 分组后获取 # 试剂名称、纯度、cas码 查询rms_medicament 分组后获取
@report_router.route("/stock_loss_info", methods=["GET", "POST"]) @report_router.route("/stock_loss_info", methods=["GET", "POST"])
@token_auth.login_required
def stock_loss_info(): def stock_loss_info():
# 获取参数 # 获取参数
seach_word = request.values.get('seach_word') seach_word = request.values.get('seach_word')
@ -148,6 +152,7 @@ def stock_loss_info():
# 试剂用量消耗 # 试剂用量消耗
@report_router.route("/drug_use_expend", methods=["GET", "POST"]) @report_router.route("/drug_use_expend", methods=["GET", "POST"])
@token_auth.login_required
def get_drug_use_expend(): def get_drug_use_expend():
# 参数获取 # 参数获取
seach_word = request.values.get('seach_word') seach_word = request.values.get('seach_word')
@ -167,6 +172,7 @@ def get_drug_use_expend():
# 人员用量消耗 # 人员用量消耗
@report_router.route("/drug_user_use_expend", methods=["GET", "POST"]) @report_router.route("/drug_user_use_expend", methods=["GET", "POST"])
@token_auth.login_required
def get_drug_user_use_expend(): def get_drug_user_use_expend():
# 参数获取 # 参数获取
seach_user = request.values.get('seach_user') seach_user = request.values.get('seach_user')
@ -186,6 +192,7 @@ def get_drug_user_use_expend():
# 使用频率 # 使用频率
@report_router.route("/use_frequency", methods=["GET", "POST"]) @report_router.route("/use_frequency", methods=["GET", "POST"])
@token_auth.login_required
def drug_use_frequency(): def drug_use_frequency():
seach_word = request.values.get('seach_word') seach_word = request.values.get('seach_word')
client_id = request.values.get("client_id") client_id = request.values.get("client_id")
@ -205,6 +212,7 @@ def drug_use_frequency():
# 入库、领用、归还记录 # 入库、领用、归还记录
@report_router.route("/drug_log_type_info", methods=["GET", "POST"]) @report_router.route("/drug_log_type_info", methods=["GET", "POST"])
@token_auth.login_required
def drug_log_type_info(): def drug_log_type_info():
page = int(request.values.get("page", 1)) page = int(request.values.get("page", 1))
page_size = int(request.values.get("page_size", 10)) page_size = int(request.values.get("page_size", 10))

@ -28,10 +28,11 @@ def user_login():
# 修改密码,根据token获取用户信息接受老密码进行校验新密码写入 # 修改密码,根据token获取用户信息接受老密码进行校验新密码写入
@user_router.route("/update_password", methods=["POST"]) @user_router.route("/update_password", methods=["POST"])
@token_auth.login_required
def user_update_password(): def user_update_password():
old_password = request.values.get("old_password") old_password = request.values.get("old_password")
new_password = request.values.get("new_password") new_password = request.values.get("new_password")
# user_id = g.current_user.user_id # user_id = g.current_user.use
msg_bool, msg_token = BllUser().update_password(g.current_user, old_password=old_password, new_password=new_password) msg_bool, msg_token = BllUser().update_password(g.current_user, old_password=old_password, new_password=new_password)
if msg_bool: if msg_bool:
return jsonify(Utils.true_return(data={"token": msg_token})) return jsonify(Utils.true_return(data={"token": msg_token}))

Loading…
Cancel
Save