def dtu_user_export(dtu_user_ids, filename): """ 将DTU用户导出到文件中 :param dtu_user_ids: :param filename: :return: """ prop_list = ['name', 'phone', 'email', 'state', 'remark', 'create_time'] name_list = ['姓名', '联系电话', '邮箱', '状态', '备注', '创建时间'] excel_fields = [] for index in range(0, len(prop_list)): excel_fields.append( ExcelField.require_field(prop_list[index], name_list[index])) dtu_users = find_dtu_users_by_ids(dtu_user_ids) __user_export(dtu_users, '用户列表', filename, excel_fields)
def admin_export(admin_ids, filename): """ 将管理员导出到文件中 :param admin_ids: :param filename: :return: """ prop_list = ['name', 'phone', 'email', 'state', 'remark', 'create_time'] name_list = ['用户名', '联系电话', '邮箱', '状态', '备注', '创建时间'] excel_fields = [] for index in range(0, len(prop_list)): excel_fields.append( ExcelField.require_field(prop_list[index], name_list[index])) admin_dicts = find_admins_by_ids(admin_ids) __user_export(admin_dicts, '管理员列表', filename, excel_fields)
def dtu_user_import(filename): """ 从EXCEL中导入DTU用户 :param filename: :return: """ prop_list = ['name', 'phone', 'email', 'state', 'remark', 'create_time'] name_list = ['姓名', '联系电话', '邮箱', '状态', '备注', '创建时间'] require_list = [True, True, True, True, True, False, True] excel_fields = [] for index in range(0, len(prop_list)): if require_list[index]: excel_fields.append( ExcelField.require_field(prop_list[index], name_list[index])) dtu_users = __user_import(filename, excel_fields) for dtu_user in dtu_users: create_dtu_user(dtu_user)
def manufacturer_export(man_ids, filename): """ 将厂商列表导出到文件中 :param man_ids: :param filename: :return: """ prop_list = [ 'name', 'phone', 'email', 'state', 'dtu_used_num', 'dtu_total_num', 'remark', 'create_time' ] name_list = ['供气商名称', '联系电话', '邮箱', '状态', 'DTU数量', 'DTU最大数量', '备注', '创建时间'] excel_fields = [] for index in range(0, len(prop_list)): excel_fields.append( ExcelField.require_field(prop_list[index], name_list[index])) manufacturers = find_manufacturers_by_ids(man_ids) __user_export(manufacturers, '供气商列表', filename, excel_fields)
def admin_import(filename): """ 从EXCEL中导入管理员 :param filename: :return: """ prop_list = ['name', 'phone', 'email', 'state', 'remark', 'create_time'] name_list = ['用户名', '联系电话', '邮箱', '状态', '备注', '创建时间'] require_list = [True, True, True, True, True, False, True] excel_fields = [] for index in range(0, len(prop_list)): if require_list[index]: excel_fields.append( ExcelField.require_field(prop_list[index], name_list[index])) admins = __user_import(filename, excel_fields) for admin in admins: try: create_admin(admin) except NotUniqueException: pass
def systemlog_export(systemlog_ids, filename): """ 将系统日志导出到文件中 :param systemlog_ids: :param filename: :return: """ prop_list = ['opr_user_name', 'action_type', 'state', 'opr_time'] name_list = ['操作人员名称', '行为', '状态', '操作日期'] excel_fields = [] for index in range(0, len(prop_list)): excel_fields.append( ExcelField.require_field(prop_list[index], name_list[index])) logs = conf_log_api.find_system_log(Q(id__in=systemlog_ids)) log_dicts = transfer_obj_to_dict( logs, ['id', 'opr_user.name', 'opr_time', 'action_type', 'state'], __transfer_system_log_database_to_display) __log_export(log_dicts, '系统日志列表', filename, excel_fields)
def oprlog_export(oprlog_ids, filename): """ 将系统日志导出到文件中 :param oprlog_ids: :param filename: :return: """ prop_list = [ 'opr_user_name', 'meter_dtu_dtu_no', 'meter_address', 'opr_type', 'val', 'state', 'opr_time' ] name_list = ['操作人员名称', 'DTU编号', '仪表物理地址', '操作类型', '值', '状态', '操作日期'] excel_fields = [] for index in range(0, len(prop_list)): excel_fields.append( ExcelField.require_field(prop_list[index], name_list[index])) logs = conf_log_api.find_opr_log(Q(id__in=oprlog_ids)) log_dicts = transfer_obj_to_dict(logs, [ 'id', 'opr_user.name', 'opr_time', 'val', 'state', 'opr_type', 'meter.dtu.dtu_no', 'meter.address' ], transfer_opr_log_database_to_display) __log_export(log_dicts, '操作日志列表', filename, excel_fields)
def alarmlog_export(alarmlog_ids, filename): """ 将警报日志导出到文件中 :param alarmlog_ids: :param filename: :return: """ prop_list = [ 'meter_dtu_user_name', 'meter_dtu_region_manufacturer_name', 'meter_dtu_dtu_no', 'meter_address', 'alarm_type', 'opr_time' ] name_list = ['仪表厂商名称', '仪表用户名称', '仪表DTU编号', '仪表物理地址', '警报类型', '警报时间'] excel_fields = [] for index in range(0, len(prop_list)): excel_fields.append( ExcelField.require_field(prop_list[index], name_list[index])) logs = conf_log_api.find_alarm_log(Q(id__in=alarmlog_ids)) log_dicts = transfer_obj_to_dict(logs, [ 'id', 'meter.dtu.user.name', 'meter.dtu.region.manufacturer.name', 'alarm_type', 'meter.address', 'meter.dtu.dtu_no', 'opr_time' ], __transfer_alarm_log_database_to_display) __log_export(log_dicts, '警报日志列表', filename, excel_fields)