72 lines
2.5 KiB
Python
72 lines
2.5 KiB
Python
"""
|
|
检查同步问题
|
|
"""
|
|
import asyncio
|
|
import sys
|
|
sys.path.insert(0, ".")
|
|
|
|
from app.database import AsyncSessionLocal, init_db
|
|
from app.models import Company, Report, TaskLog
|
|
from sqlalchemy import select, desc
|
|
|
|
async def check_sync_issue():
|
|
print("=" * 60)
|
|
print("检查同步问题")
|
|
print("=" * 60)
|
|
|
|
await init_db()
|
|
|
|
async with AsyncSessionLocal() as db:
|
|
# 1. 检查公司状态
|
|
print("\n[1] 公司状态:")
|
|
stmt = select(Company)
|
|
result = await db.execute(stmt)
|
|
companies = result.scalars().all()
|
|
|
|
for c in companies:
|
|
print(f" - {c.stock_code} {c.short_name}: is_active={c.is_active}, org_id={c.org_id}")
|
|
|
|
# 2. 检查任务日志
|
|
print("\n[2] 最近任务日志:")
|
|
stmt = select(TaskLog).order_by(desc(TaskLog.started_at)).limit(10)
|
|
result = await db.execute(stmt)
|
|
logs = result.scalars().all()
|
|
|
|
for log in logs:
|
|
print(f" - [{log.started_at}] {log.task_name}: {log.status}")
|
|
if log.message:
|
|
print(f" 消息: {log.message}")
|
|
if log.error:
|
|
print(f" 错误: {log.error[:100]}...")
|
|
|
|
# 3. 检查报告
|
|
print("\n[3] 各公司报告数:")
|
|
for c in companies:
|
|
stmt = select(Report).where(Report.company_id == c.id)
|
|
result = await db.execute(stmt)
|
|
reports = result.scalars().all()
|
|
print(f" - {c.stock_code}: {len(reports)} 份")
|
|
|
|
# 写入文件
|
|
with open("check_sync_result.txt", "w", encoding="utf-8") as f:
|
|
f.write("公司状态:\n")
|
|
for c in companies:
|
|
f.write(f" - {c.stock_code} {c.short_name}: is_active={c.is_active}, org_id={c.org_id}\n")
|
|
f.write("\n任务日志:\n")
|
|
for log in logs:
|
|
f.write(f" - [{log.started_at}] {log.task_name}: {log.status}\n")
|
|
if log.message:
|
|
f.write(f" 消息: {log.message}\n")
|
|
if log.error:
|
|
f.write(f" 错误: {log.error}\n")
|
|
f.write("\n各公司报告数:\n")
|
|
for c in companies:
|
|
stmt = select(Report).where(Report.company_id == c.id)
|
|
result = await db.execute(stmt)
|
|
reports = result.scalars().all()
|
|
f.write(f" - {c.stock_code}: {len(reports)} 份\n")
|
|
print("\n结果已写入 check_sync_result.txt")
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(check_sync_issue())
|