#!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2025/3/18 14:48 # @Author : AngesZhu # @File : get_data_demo_service.py # @Desc : 获取渠道模版数据 from utils.data_file_utils import ExcelHandler from utils.logger_utils import logger from utils.path_utils import PathOperator def get_columns_from_channel(channel_name): # 路径获取并获取文件信息 logger.info(f"获取渠道{channel_name} 对应的字段配置信息") path_operator = PathOperator() base_path = path_operator.get_parent_path(path_operator.get_full_path()) field_rules_path = path_operator.join_path(base_path, "test_data", "data_demo") names = path_operator.get_all_files(field_rules_path) names = [item for item in names if not item.startswith(".")] # 获取目录下所有模版列表 matches = list(filter(lambda item: channel_name in item, names)) if len(matches) > 1: return False, "渠道模版不能存在两个以上" excel_obj = ExcelHandler(path_operator.join_path(field_rules_path, matches[0])) excel_data = excel_obj.read_excel(sheet_name=0, header=0, usecols=None) logger.info(f"读取的excel模版表头:{excel_data.columns.tolist()}") return True, { "path": field_rules_path, "name": matches[0], "columns": excel_data.columns.tolist(), "values": excel_data.values.tolist() }