|
|
@ -4,8 +4,6 @@
|
|
|
|
@Date:2022/08/01 17:04:40
|
|
|
|
@Date:2022/08/01 17:04:40
|
|
|
|
'''
|
|
|
|
'''
|
|
|
|
import sys
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
|
|
from models.power_models import EntityModuleRelation
|
|
|
|
|
|
|
|
sys.path.append('.')
|
|
|
|
sys.path.append('.')
|
|
|
|
|
|
|
|
|
|
|
|
from sqlalchemy import or_
|
|
|
|
from sqlalchemy import or_
|
|
|
@ -15,20 +13,71 @@ 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
|
|
|
|
|
|
|
|
|
|
|
|
from models.user_models import EntityRole
|
|
|
|
from db_logic.user import BllUser
|
|
|
|
from Common.Utils import Utils
|
|
|
|
|
|
|
|
|
|
|
|
from models.power_models import EntityModuleRelation
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from models.user_models import EntityRole, EntityUser
|
|
|
|
|
|
|
|
from Common.Utils import PageParam, Utils
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
power_router = Blueprint('power', __name__)
|
|
|
|
power_router = Blueprint('power', __name__)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 获取用户权限
|
|
|
|
|
|
|
|
@power_router.route("/get_user_power_list", methods=["GET", "POST"])
|
|
|
|
|
|
|
|
@token_auth.login_required
|
|
|
|
|
|
|
|
def get_user_power_list():
|
|
|
|
|
|
|
|
user_id = request.values.get("user_id")
|
|
|
|
|
|
|
|
if user_id:
|
|
|
|
|
|
|
|
user_info = BllUser().findEntity(EntityUser.user_id == user_id)
|
|
|
|
|
|
|
|
data_list = BllModuleRelation().get_user_module_list(user_info)
|
|
|
|
|
|
|
|
return jsonify(Utils.true_return(data=data_list))
|
|
|
|
|
|
|
|
return jsonify(Utils.false_return(msg="用户id不能为空"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 分配用户权限
|
|
|
|
|
|
|
|
@power_router.route("/add_user_power", methods=["GET", "POST"])
|
|
|
|
|
|
|
|
@token_auth.login_required
|
|
|
|
|
|
|
|
def add_user_power_list():
|
|
|
|
|
|
|
|
user_id = request.values.get("user_id")
|
|
|
|
|
|
|
|
drug_module = request.values.getlist("drug_module_id")
|
|
|
|
|
|
|
|
standard_module = request.values.getlist("standard_module_id")
|
|
|
|
|
|
|
|
consumables_module = request.values.getlist("consumables_module_id")
|
|
|
|
|
|
|
|
instrument_modulet = request.values.getlist("instrument_module_id")
|
|
|
|
|
|
|
|
inster_dic = {
|
|
|
|
|
|
|
|
"2": drug_module if drug_module else [],
|
|
|
|
|
|
|
|
"3": standard_module if standard_module else [],
|
|
|
|
|
|
|
|
"4": consumables_module if consumables_module else [],
|
|
|
|
|
|
|
|
"5": instrument_modulet if instrument_modulet else [],
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
# 删除除去柜子权限外的所有权限
|
|
|
|
|
|
|
|
BllModuleRelation().delete(EntityModuleRelation.object_id == user_id, EntityModuleRelation.module_type != "1")
|
|
|
|
|
|
|
|
inster_module_list = []
|
|
|
|
|
|
|
|
for k,v in inster_dic.items():
|
|
|
|
|
|
|
|
for i in v:
|
|
|
|
|
|
|
|
inster_module_list.append(
|
|
|
|
|
|
|
|
EntityModuleRelation(
|
|
|
|
|
|
|
|
object_type=2,
|
|
|
|
|
|
|
|
object_id=user_id,
|
|
|
|
|
|
|
|
module_id=i,
|
|
|
|
|
|
|
|
module_type=k,
|
|
|
|
|
|
|
|
create_date=Utils.get_str_datetime(),
|
|
|
|
|
|
|
|
create_user_id=g.current_user.user_id,
|
|
|
|
|
|
|
|
create_user_name=g.current_user.real_name
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
BllModuleRelation().insert_many(inster_module_list)
|
|
|
|
|
|
|
|
return jsonify(Utils.true_return())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@power_router.route("/user_power", methods=["GET", "POST"])
|
|
|
|
@power_router.route("/user_power", methods=["GET", "POST"])
|
|
|
|
@token_auth.login_required
|
|
|
|
@token_auth.login_required
|
|
|
|
def get_user_power_list():
|
|
|
|
def get_login_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_login_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))
|
|
|
|
|
|
|
|
|
|
|
@ -39,10 +88,22 @@ def get_power_list():
|
|
|
|
# 根据角色表进行关联查询,
|
|
|
|
# 根据角色表进行关联查询,
|
|
|
|
# 思路:角色表角色id->模块权限表(object_id)-> 终端权限表()
|
|
|
|
# 思路:角色表角色id->模块权限表(object_id)-> 终端权限表()
|
|
|
|
# | |
|
|
|
|
# | |
|
|
|
|
# role_id=object_id module_id=module_id
|
|
|
|
# role_id=object_id module_id=module_id
|
|
|
|
data_list = BllModuleRelation().get_role_module()
|
|
|
|
page = int(request.values.get("page"))
|
|
|
|
|
|
|
|
page_size = int(request.values.get("page_size"))
|
|
|
|
|
|
|
|
page_param = PageParam(page, page_size)
|
|
|
|
|
|
|
|
data_list = BllModuleRelation().get_role_module(page_param)
|
|
|
|
|
|
|
|
return jsonify(Utils.true_return(data=Utils.msyql_table_model(data_list)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 通过角色id查询角色列表
|
|
|
|
|
|
|
|
@power_router.route("/get_role_module", methods=["GET", "POST"])
|
|
|
|
|
|
|
|
@token_auth.login_required
|
|
|
|
|
|
|
|
def get_role_module_list():
|
|
|
|
|
|
|
|
role_id = request.values.get("role_id")
|
|
|
|
|
|
|
|
data_list = BllModuleRelation().get_role_module_list(role_id)
|
|
|
|
return jsonify(Utils.true_return(data=Utils.msyql_table_model(data_list)))
|
|
|
|
return jsonify(Utils.true_return(data=Utils.msyql_table_model(data_list)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 获取模块列表
|
|
|
|
# 获取模块列表
|
|
|
|
@power_router.route("/get_module_list", methods=["GET", "POST"])
|
|
|
|
@power_router.route("/get_module_list", methods=["GET", "POST"])
|
|
|
|
# @token_auth.login_required
|
|
|
|
# @token_auth.login_required
|
|
|
|