角色权限相关

duizhaopin
apan 2 years ago
parent f2772a4053
commit 34c9ccf59f

@ -4,8 +4,6 @@
@Date:2022/08/01 17:04:40
'''
import sys
from models.power_models import EntityModuleRelation
sys.path.append('.')
from sqlalchemy import or_
@ -15,20 +13,71 @@ from Common.auth import token_auth
from flask import Blueprint, jsonify, request, g
from db_logic.module_relation import BllModuleRelation
from models.user_models import EntityRole
from Common.Utils import Utils
from db_logic.user import BllUser
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.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"])
@token_auth.login_required
def get_user_power_list():
def get_login_user_power_list():
user_info = g.current_user
# user_id = '4cea74ee-0d8b-11ed-943e-f47b094925e1'
# 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)
return jsonify(Utils.true_return(data=module_list))
@ -40,9 +89,21 @@ def get_power_list():
# 思路角色表角色id->模块权限表object_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)))
# 获取模块列表
@power_router.route("/get_module_list", methods=["GET", "POST"])
# @token_auth.login_required

@ -324,11 +324,11 @@ class BllMedicament(Repository):
def drug_show_type_info(self, record_type, start_time, end_time, put_in_user_name, name, statue_type, page_param):
sql_all = """
SELECT
b.`name`, b.english_name, b.bar_code, b.purity, b.cas_number, a.use_quantity, b.`status`, a.create_date, a.create_user_name, b.client_id
b.`name`, b.english_name, b.bar_code, b.purity, b.cas_number, b.speci, a.use_quantity, b.`status`, a.create_date, a.create_user_name, b.client_id
FROM (
SELECT medicament_id, use_quantity, create_user_name, create_date FROM rms_medicament_record %s
) a LEFT JOIN (
SELECT medicament_id, `name`, english_name, bar_code, purity, cas_number, net_weight, remain, `status`, by_user_date, by_user_name, client_id
SELECT medicament_id, `name`, english_name, bar_code, purity, speci, cas_number, net_weight, remain, `status`, by_user_date, by_user_name, client_id
FROM rms_medicament %s
) b on b.medicament_id = a.medicament_id
"""

@ -25,10 +25,10 @@ class BllModule(Repository):
}
sql_data = Utils.msyql_table_model(self.execute(sql_all).fetchall())
for i in sql_data:
if i['module_type'] == "2":
data["sys_list"].append(i)
if i["module_type"] == "1":
data["client_list"].append(i)
else:
data["sys_list"].append(i)
data["sys_list"].sort(key=lambda x: x['sort_index'])
data["client_list"].sort(key=lambda x: x['sort_index'])
return data

@ -16,24 +16,62 @@ class BllModuleRelation(Repository):
return super().__init__(entityType)
def get_user_module_list(self, user_id, role_id):
def get_login_user_module_list(self, user_id, role_id):
sql_all = f"""
select c.module_id, c.module_code, c.sort_index, c.module_name from(
SELECT a.module_id, b.module_code, b.sort_index, b.module_name
from rms_module_relation as a
LEFT JOIN rms_module as b on a.module_id=b.module_id
WHERE object_id='{user_id}' AND object_type=2 AND b.module_type=2
WHERE object_id='{user_id}' AND object_type=2 AND b.module_type!=1
UNION
SELECT a.module_id, b.module_code, b.sort_index, b.module_name
from rms_module_relation as a
LEFT JOIN rms_module as b on a.module_id=b.module_id
WHERE object_id='{role_id}' AND object_type=1 AND b.module_type=2
WHERE object_id='{role_id}' AND object_type=1 AND b.module_type!=1
) c ORDER BY c.sort_index asc
"""
return self.execute(sql_all).fetchall()
def get_role_module(self):
def get_user_module_list(self, user_info):
sql_all = f"""
select a.module_id, a.module_name, a.module_type, a.module_code, a.sort_index,
CASE WHEN b.object_id is NULL THEN 0 ELSE 1 END have, IFNULL(b.object_type,0) object_type
from (
select * from rms_module) a LEFT JOIN (
select * from rms_module_relation where object_id='{user_info.user_id}' or object_id='{user_info.role_id}'
) b on a.module_id = b.module_id
"""
sql_data = self.execute(sql_all).fetchall()
data = Utils.msyql_table_model(sql_data)
data_dict = {
"drug_manage":[],
"standard_manage":[],
"consumables_manage": [],
"instrument_manage":[]
}
for i in data:
if i["module_type"] == "2":
data_dict["drug_manage"].append(i)
elif i["module_type"] == "3":
data_dict["standard_manage"].append(i)
elif i["module_type"] == "4":
data_dict["consumables_manage"].append(i)
elif i["module_type"] == "5":
data_dict["instrument_manage"].append(i)
return data_dict
def get_role_module_list(self, role_id):
sql_all = f"""
SELECT a.module_id, b.module_code, b.sort_index, b.module_name
from rms_module_relation as a
LEFT JOIN rms_module as b on a.module_id=b.module_id
WHERE object_id='{role_id}' AND object_type=1
"""
return self.execute(sql_all).fetchall()
def get_role_module(self, page_param):
sql_all = """
select
a.role_name,
@ -46,7 +84,13 @@ class BllModuleRelation(Repository):
LEFT JOIN rms_module as c
on c.module_id=b.module_id
"""
return self.execute(sql_all).fetchall()
try:
count_number = len(self.execute(sql_all).fetchall())
except Exception:
count_number = 0
page_param.totalRecords=count_number
page_sql_data = Utils.sql_paging_assemble(sql_all, page_param)
return page_sql_data
def add_inster_user_moduele(self):
role_id = "a699ff99-117b-11ed-a086-f47b094925e5"

@ -19,6 +19,7 @@ class EntityModule(Base):
)
module_id = Column(String(50), primary_key=True, comment="模块ID", default=get_uuid)
# 模块类型分析1柜体2试剂管理3 标准品管理4耗材管理5仪器管理
module_type = Column(String(50), comment="模块类型(1柜体,2后台)")
module_code = Column(String(50), comment="")
module_name = Column(String(50), comment="模块名称")
@ -49,6 +50,7 @@ class EntityModuleRelation(Base):
customer_id = Column(String(50), comment="客户id")
object_type = Column(String(50), comment="类型")
object_id = Column(String(50), comment="类型id")
# 模块类型分析1柜体2试剂管理3 标准品管理4耗材管理5仪器管理
module_type = Column(String(50), comment="模块类型(1柜体,2后台)")
module_id = Column(String(50), comment="模块id")
create_date = Column(String(50), comment="创建时间")

Loading…
Cancel
Save