You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
2.5 KiB
68 lines
2.5 KiB
#!/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
|
|
|