63 lines
1.7 KiB
Python
63 lines
1.7 KiB
Python
|
|
#!/usr/bin/env python3
|
||
|
|
# -*- coding: utf-8 -*-
|
||
|
|
"""
|
||
|
|
检查数据库表结构
|
||
|
|
"""
|
||
|
|
|
||
|
|
import sys
|
||
|
|
import os
|
||
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||
|
|
|
||
|
|
from lib.db import execute_query
|
||
|
|
|
||
|
|
def check_table_structure():
|
||
|
|
"""检查表结构"""
|
||
|
|
print("="*60)
|
||
|
|
print("检查 t_equipment_charge_order 表结构")
|
||
|
|
print("="*60)
|
||
|
|
|
||
|
|
try:
|
||
|
|
# 查询表结构
|
||
|
|
sql = "DESCRIBE t_equipment_charge_order"
|
||
|
|
columns = execute_query(sql)
|
||
|
|
|
||
|
|
print(f"\n表中共有 {len(columns)} 个字段:\n")
|
||
|
|
|
||
|
|
field_names = []
|
||
|
|
for col in columns:
|
||
|
|
field_name = col.get('Field')
|
||
|
|
field_type = col.get('Type')
|
||
|
|
field_names.append(field_name)
|
||
|
|
print(f" - {field_name}: {field_type}")
|
||
|
|
|
||
|
|
print("\n" + "="*60)
|
||
|
|
print("常用字段检查:")
|
||
|
|
print("="*60)
|
||
|
|
|
||
|
|
# 检查常用字段是否存在
|
||
|
|
common_fields = [
|
||
|
|
'order_no', 'report_time', 'total_money', 'charge_money',
|
||
|
|
'service_money', 'electricity_money', 'charge_energy',
|
||
|
|
'company_id', 'user_id', 'state', 'start_time', 'end_time'
|
||
|
|
]
|
||
|
|
|
||
|
|
print("\n常用字段存在情况:")
|
||
|
|
for field in common_fields:
|
||
|
|
exists = "✓" if field in field_names else "✗"
|
||
|
|
print(f" {exists} {field}")
|
||
|
|
|
||
|
|
print("\n" + "="*60)
|
||
|
|
print("建议:")
|
||
|
|
print("="*60)
|
||
|
|
print("\n请使用上面列出的实际字段名创建配置!")
|
||
|
|
|
||
|
|
except Exception as e:
|
||
|
|
print(f"\n❌ 查询失败: {e}")
|
||
|
|
import traceback
|
||
|
|
traceback.print_exc()
|
||
|
|
|
||
|
|
input("\n按回车键退出...")
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
check_table_structure()
|