#!/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) def get_module_list(self): sql_all = """ select module_id, module_type, module_name, sort_index, description from rms_module where is_enabled=1 """ data = { "sys_list":[], "client_list":[] } 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) data["sys_list"].sort(key=lambda x: x['sort_index']) data["client_list"].sort(key=lambda x: x['sort_index']) return data # return self.findList().all() 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().get_module_list() # print([i for i in aaa]) aaa_list = Utils.to_dict(aaa, 1) for i in aaa_list: print(i) print(aaa)