agent_9art/fix_session_id.py
jiao 6160691aa9 build: 调整项目Java版本为1.8
feat(archive-service): 新增敏感词风控相关实体与Mapper
feat(archive-service): 新增会话统计相关VO类
refactor(archive-service): 移除ArchiveMessage的deleted逻辑字段
fix: 修正数据库连接字符集配置为UTF-8
style(frontend): 优化nginx缓存配置规则
refactor(conversation-service): 替换var为显式类型声明
2026-05-29 15:46:55 +08:00

28 lines
1.3 KiB
Python

import re
import subprocess
cmd = "mysql -h sh-cdb-6fzlwnms.sql.tencentcdb.com -P 63912 -u assistant_prod -p'U%$4Tu_C3+4' -e 'SET NAMES utf8mb4; SELECT id, session_id FROM ai_assistant.archive_messages WHERE session_id LIKE \"%[%\";' 2>&1 | grep -v Warning"
result = subprocess.run(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
lines = result.stdout.decode('utf-8').strip().split('\n')
print('Total lines:', len(lines))
fixed = 0
for line in lines:
if not line.strip() or line.startswith('id') or '\t' not in line:
continue
parts = line.split('\t')
if len(parts) < 2:
continue
id_str, session_id = parts[0], parts[1]
# Replace [\"xxx\"] -> xxx or [xxx] -> xxx
new_id = re.sub(r'\[\s*"([^"]+)"\s*\]', r'\1', session_id)
new_id = re.sub(r'\[\s*([^\]]+)\s*\]', r'\1', new_id)
if new_id != session_id:
sql = "UPDATE ai_assistant.archive_messages SET session_id='%s' WHERE id=%s;" % (new_id, id_str)
subprocess.run(['mysql', '-h', 'sh-cdb-6fzlwnms.sql.tencentcdb.com', '-P', '63912', '-u', 'assistant_prod', '-pU%$4Tu_C3+4', '-e', sql], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
fixed += 1
if fixed % 100 == 0:
print('Fixed %d...' % fixed)
print('Done. Fixed=%d' % fixed)