#!/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 = { # "client_list":[] "client_manage": [], "sys_manage": [], "standard_manage": [], "consumables_manage": [], "instrument_manage": [] } sql_data = Utils.msyql_table_model(self.execute(sql_all).fetchall()) for i in sql_data: if i["module_type"] == "1": data["client_manage"].append(i) elif i["module_type"] == "2": data["sys_manage"].append(i) elif i["module_type"] == "3": data["standard_manage"].append(i) elif i["module_type"] == "4": data["consumables_manage"].append(i) elif i["module_type"] == "5": data["instrument_manage"].append(i) return data 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)