parent
5362927ab9
commit
f41fc83dcb
@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- encoding: utf-8 -*-
|
||||
'''
|
||||
@Date:2022/08/01 17:04:40
|
||||
'''
|
||||
from operator import index
|
||||
import sys
|
||||
sys.path.append('.')
|
||||
|
||||
from flask import Blueprint, request, g
|
||||
from db_logic.module_relation import BllModuleRelation
|
||||
from Common.Utils import Utils
|
||||
power_router = Blueprint('power', __name__)
|
||||
|
||||
|
||||
@power_router.route("/user_power", methods=["GET", "POST"])
|
||||
def get_user_power_list():
|
||||
user_info = g.current_user
|
||||
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)
|
||||
if len(module_list) > 6:
|
||||
for module in module_list:
|
||||
if module["module_code"] == "DataReport":
|
||||
if module_list.index(module) in [1,2,4]:
|
||||
module_list.pop(module_list.index(module))
|
||||
module_list.insert(5, module)
|
||||
data = module_list
|
@ -0,0 +1,60 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- encoding: utf-8 -*-
|
||||
'''
|
||||
@Date:2022/08/01 15:36:46
|
||||
'''
|
||||
import sys
|
||||
sys.path.append('.')
|
||||
|
||||
from db_logic.db_base import Repository
|
||||
from models.power_models import EntityModule
|
||||
from Common.Utils import Utils
|
||||
|
||||
class BllModule(Repository):
|
||||
|
||||
def __init__(self, entityType=EntityModule):
|
||||
return super().__init__(entityType)
|
||||
"""
|
||||
module_id = Column(String(50), primary_key=True, comment="模块ID")
|
||||
module_type = Column(String(50), comment="模块类型")
|
||||
module_code = Column(String(50), comment="")
|
||||
module_name = Column(String(50), comment="模块名称")
|
||||
icon = Column(String(50), comment="图片")
|
||||
url_address = Column(String(50), comment="图片地址")
|
||||
sort_index = Column(Integer, comment="排序下标")
|
||||
module_weight = Column(Integer, comment="模块权重")
|
||||
parent_id = Column(String(50), comment="父id")
|
||||
is_enabled = Column(Integer, comment="是否启用")
|
||||
description = Column(String(50), comment="备注")
|
||||
create_date = Column(String(50), comment="创建时间")
|
||||
create_user_id = Column(String(50), comment="创建用户id")
|
||||
create_user_name = Column(String(50), comment="创建用户名")
|
||||
is_add = Column(Integer, comment="")
|
||||
"""
|
||||
def inster_info_list(self):
|
||||
obj_list = []
|
||||
from demo import data_list
|
||||
for i in data_list:
|
||||
obj = EntityModule(
|
||||
module_type=i.get("ModuleType"),
|
||||
module_name=i.get("ModuleName"),
|
||||
module_code=i.get("ModuleCode"),
|
||||
sort_index=i.get("SortIndex"),
|
||||
module_weight=i.get("SortIndex"),
|
||||
parent_id=0,
|
||||
is_enabled=1,
|
||||
create_date=Utils.get_str_datetime(),
|
||||
create_user_id='4cea74ee-0d8b-11ed-943e-f47b094925e1',
|
||||
create_user_name="admin",
|
||||
|
||||
|
||||
|
||||
)
|
||||
obj_list.append(obj)
|
||||
self.insert_many(obj_list)
|
||||
|
||||
if __name__ == '__main__':
|
||||
from Common.Utils import Utils
|
||||
aaa = BllModule().inster_info_list()
|
||||
# aaa_list = Utils.msyql_table_model(aaa)
|
||||
print(aaa)
|
@ -0,0 +1,67 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- encoding: utf-8 -*-
|
||||
'''
|
||||
@Date:2022/08/01 15:32:08
|
||||
'''
|
||||
import sys
|
||||
sys.path.append(".")
|
||||
from Common.Utils import Utils
|
||||
from db_logic.db_base import Repository
|
||||
from models.power_models import EntityModuleRelation
|
||||
|
||||
|
||||
class BllModuleRelation(Repository):
|
||||
|
||||
def __init__(self, entityType=EntityModuleRelation):
|
||||
return super().__init__(entityType)
|
||||
|
||||
|
||||
def get_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=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=1
|
||||
) c ORDER BY c.sort_index asc
|
||||
"""
|
||||
return self.execute(sql_all).fetchall()
|
||||
|
||||
def add_inster_user_moduele(self):
|
||||
role_id = "a699ff99-117b-11ed-a086-f47b094925e5"
|
||||
obj_list = []
|
||||
all_module_list = self.execute("select * from rms_module")
|
||||
all_module_list = Utils.msyql_table_model(all_module_list)
|
||||
for i in all_module_list:
|
||||
obj = EntityModuleRelation(
|
||||
object_type=1,
|
||||
object_id=role_id,
|
||||
module_type=i['module_type'],
|
||||
module_id=i['module_id'],
|
||||
create_date=Utils.get_str_datetime(),
|
||||
create_user_id='4cea74ee-0d8b-11ed-943e-f47b094925e1',
|
||||
create_user_name=''
|
||||
)
|
||||
obj_list.append(obj)
|
||||
self.insert_many(obj_list)
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
module_list = BllModuleRelation().get_user_module_list(
|
||||
user_id='4cea74ee-0d8b-11ed-943e-f47b094925e1', role_id='a699ff99-117b-11ed-a086-f47b094925e5')
|
||||
module_list = Utils.msyql_table_model(module_list)
|
||||
if len(module_list) > 6:
|
||||
for module in module_list:
|
||||
if module["module_code"] == "DataReport":
|
||||
if module_list.index(module) in [1,2,4]:
|
||||
module_list.pop(module_list.index(module))
|
||||
module_list.insert(5, module)
|
||||
data = module_list
|
||||
|
@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- encoding: utf-8 -*-
|
||||
'''
|
||||
@Date:2022/08/01 17:14:39
|
||||
'''
|
||||
from gc import isenabled
|
||||
import sys
|
||||
sys.path.append('.')
|
||||
|
||||
from db_logic.db_base import Repository
|
||||
from models.user_models import EntityRole
|
||||
|
||||
# 角色类
|
||||
class BllRole(Repository):
|
||||
|
||||
def __init__(self, entityType=EntityRole):
|
||||
return super().__init__(entityType)
|
||||
|
||||
def add_inster_role_user(self):
|
||||
obj_list = []
|
||||
name_list = [
|
||||
{"code": "admin", "name": "管理员", "index": 2},
|
||||
{"code": "maintain_user", "name": "维护人员", "index": 3},
|
||||
{"code": "simple_user", "name": "普通用户", "index": 1},
|
||||
|
||||
]
|
||||
for i in range(3):
|
||||
obj = EntityRole(
|
||||
role_code=name_list[i].get("code"),
|
||||
role_name=name_list[i].get("name"),
|
||||
role_level=name_list[i].get("index"),
|
||||
sort_index=name_list[i].get("index"),
|
||||
is_enabled=1
|
||||
|
||||
)
|
||||
obj_list.append(obj)
|
||||
self.insert_many(obj_list)
|
||||
|
||||
if __name__ == '__main__':
|
||||
BllRole().add_inster_role_user()
|
Loading…
Reference in new issue