import os

import yaml

topoCheckData = None


# 读取yaml
def read_yaml_file(filepath):
    with open(filepath, 'r') as file:
        data = yaml.load(file, Loader=yaml.FullLoader)
    return data

# 获取当前脚本所在的目录
current_dir = os.path.dirname(os.path.abspath(__file__))
topoCheckData = read_yaml_file(f"{current_dir}\\topoCheck.yaml")
# print(topoCheckData)
# print(topoCheckData["topoCheck"]["A03"])
# tempdata = topoCheckData["topoCheck"]
# print(f"标识码  名称  说明")
# for attr in tempdata:
#     print(
#         f"{attr}  {tempdata[attr]['note']}  {tempdata[attr]['UI']['description'].replace('说明: ', '').replace('说明:', '').replace('<br/>', '')}")


def getTopoCheckSQL(type, my_dict):
    # sqllist = []
    data = topoCheckData["topoCheck"][type]
    tempSql = data["ALG"]
    for key in my_dict:
        value = my_dict[key]
        k = f"@{key}@"
        tempSql = tempSql.replace(k, value)
    # print(tempSql)
    return tempSql


# 获取description
def getTopoCheckDescription(type):
    # sqllist = []
    data = topoCheckData["topoCheck"][type]
    description = data["UI"]["description"]
    return description


# 获取note
def getTopoCheckNote(type):
    # sqllist = []
    data = topoCheckData["topoCheck"][type]
    note = data["note"]
    return f"{type}:{note}"

# my_dict = {
#     "intable_s": "topology_table",
#     "outtable": "topology_table_temp"
# }
# sql = getTopoCheckSQL("A03", my_dict)
# print(sql)
# for s in sql.split(";"):
#     print(s)
