import re
import json

input_file = '/app/project/python----/数据库/update_statements.sql'
output_file = '/app/project/python----/数据库/update_statements_converted.sql'

with open(input_file, 'r', encoding='utf-8') as f:
    content = f.read()

lines = content.split('\n')
new_lines = []

for line in lines:
    line = line.strip()
    if not line or line.startswith('--'):
        new_lines.append(line)
        continue

    # 提取 available 的值（JSON数组格式）
    match = re.search(r"available='(\[.*?\])'", line)
    if match:
        json_str = match.group(1)
        try:
            arr = json.loads(json_str)
            # 用逗号连接
            joined = ','.join(arr)
            # 替换原 available 值
            new_line = line.replace(f"available='{json_str}'", f"available='{joined}'")
            new_lines.append(new_line)
        except json.JSONDecodeError:
            new_lines.append(line)
    else:
        new_lines.append(line)

with open(output_file, 'w', encoding='utf-8') as f:
    f.write('\n'.join(new_lines))

print(f"转换完成，输出到: {output_file}")
