Files
java-template/test_daily_data.py
T
BrunoGaoandClaude 3248bb0a2a feat: 完成消息系统V2优化 - 基于user_id的高性能索引重构
## 主要更改

### 1. 数据库表结构增强
- **t_device_message_v2**: 新增7个关键字段
  - priority_level: 优先级数值(1-5)
  - channels: 分发渠道JSON
  - require_ack: 是否需要确认
  - metadata: 扩展元数据JSON
  - target_count: 目标用户总数
  - version: 乐观锁版本号

- **t_device_message_detail_v2**: 新增8个关键字段
  - distribution_id: 分发唯一ID
  - device_sn: 设备序列号
  - user_id: 用户ID(核心查询字段)
  - response_duration: 响应耗时
  - delivery_details: 分发详情JSON
  - client_info: 客户端信息JSON
  - location_info: 位置信息JSON
  - last_retry_time: 最后重试时间

### 2. 索引优化重构 (基于user_id)
- 删除原有device_sn相关索引
- 新建5个user_id高性能复合索引:
  - idx_customer_user_time: 客户+用户+时间
  - idx_customer_user_status: 客户+用户+状态
  - idx_customer_user_type: 客户+用户+类型
  - idx_user_org_priority: 用户+组织+优先级
  - idx_user_status_time: 用户+状态+时间

- detail表新建4个user_id相关索引:
  - uk_message_user_target: 唯一约束
  - idx_customer_user_status: 客户+用户+状态
  - idx_user_channel_time: 用户+渠道+时间
  - idx_user_delivery_status: 用户+分发状态

### 3. 数据迁移和初始化
- 自动生成distribution_id
- 根据urgency设置priority_level
- 初始化默认channels配置
- 保持现有数据完整性

### 4. 性能提升预期
- 用户消息查询: 预计10-20倍性能提升
- 确认状态查询: 支持快速人员清单检索
- 存储空间: JSON字段替代冗余VARCHAR
- 查询覆盖: 所有user_id查询都能命中索引

### 5. 文档和脚本
- 完整的V2优化SQL脚本
- 消息机制设计文档
- 数据库备份(22MB)
- 性能验证查询

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
2025-09-15 07:56:03 +08:00

58 lines
2.0 KiB
Python

#!/usr/bin/env python3
"""
Test script to check if daily data exists for the test user
"""
import requests
import json
# Test the API with the same parameters
api_url = "http://192.168.1.83:3333/proxy-default/t_user_health_data/page"
params = {
"page": 1,
"pageSize": 20,
"customerId": 0,
"orgId": "1939964806110937090",
"userId": "1940034533382479873",
"startDate": 1751299200000,
"endDate": 1757865599999
}
try:
response = requests.get(api_url, params=params)
response.raise_for_status()
data = response.json()
print("API Response Status:", data.get("code"))
print("API Response Message:", data.get("message"))
if "data" in data:
print("Total Records:", data["data"].get("total", 0))
print("Columns Count:", len(data["data"].get("columns", [])))
records = data["data"].get("records", [])
if records:
first_record = records[0]
print("\nFirst Record Fields:")
for key in sorted(first_record.keys()):
print(f" {key}: {first_record[key]}")
# Check specifically for slow fields
slow_fields = ["sleep", "sleepData", "work_out", "workoutData", "exercise_daily", "exercise_week"]
found_slow_fields = [field for field in slow_fields if field in first_record]
print(f"\nFound slow fields: {found_slow_fields}")
# Print columns info
columns = data["data"].get("columns", [])
if columns:
print(f"\nColumns ({len(columns)} total):")
for i, col in enumerate(columns[:10]): # Show first 10 columns
title = col.get("title", "No title")
dataIndex = col.get("dataIndex", "No dataIndex")
print(f" {i+1}. {title} ({dataIndex})")
if len(columns) > 10:
print(f" ... and {len(columns) - 10} more columns")
except Exception as e:
print(f"Error testing API: {e}")