155 lines
4.8 KiB
Python
155 lines
4.8 KiB
Python
#!/usr/bin/env python3
|
||
"""
|
||
测试Java和Python服务集成的脚本
|
||
"""
|
||
|
||
import requests
|
||
import json
|
||
import time
|
||
|
||
def test_python_service():
|
||
"""测试Python服务"""
|
||
print("🔍 测试Python AI审核服务...")
|
||
|
||
# 测试健康检查
|
||
try:
|
||
response = requests.get("http://localhost:8081/api/v1/health", timeout=5)
|
||
if response.status_code == 200:
|
||
print("✅ Python服务健康检查通过")
|
||
print(f" 响应: {response.json()}")
|
||
else:
|
||
print(f"❌ Python服务健康检查失败: {response.status_code}")
|
||
return False
|
||
except Exception as e:
|
||
print(f"❌ 无法连接Python服务: {e}")
|
||
print("💡 请确保Python服务已启动: python start_ai_service.py")
|
||
return False
|
||
|
||
# 测试审核接口
|
||
test_data = {
|
||
"order_id": "TEST001",
|
||
"order_status": "WAITEXAMINE",
|
||
"oem_id": 2,
|
||
"car_type": "0",
|
||
"card_name": "张三",
|
||
"card_number": "123456789012345678",
|
||
"car_frame": "WDDGF4HB9CA123456",
|
||
"buyer_name": "张三",
|
||
"id_card_score": 85,
|
||
"bill_score": 92
|
||
}
|
||
|
||
try:
|
||
start_time = time.time()
|
||
response = requests.post(
|
||
"http://localhost:8081/api/v1/audit",
|
||
json=test_data,
|
||
headers={"Content-Type": "application/json"},
|
||
timeout=10
|
||
)
|
||
elapsed_time = (time.time() - start_time) * 1000
|
||
|
||
if response.status_code == 200:
|
||
result = response.json()
|
||
print("✅ Python审核接口测试通过")
|
||
print(f" 审核结果: {result['result']}")
|
||
print(f" 置信度: {result['confidence']}")
|
||
print(f" 原因: {result['reason']}")
|
||
print(f" 响应时间: {elapsed_time:.0f}ms")
|
||
return True
|
||
else:
|
||
print(f"❌ Python审核接口测试失败: {response.status_code}")
|
||
print(f" 错误信息: {response.text}")
|
||
return False
|
||
except Exception as e:
|
||
print(f"❌ Python审核接口调用失败: {e}")
|
||
return False
|
||
|
||
def test_java_service():
|
||
"""测试Java服务 (如果有健康检查接口)"""
|
||
print("\n🔍 测试Java TYCM服务...")
|
||
|
||
# 尝试连接Java服务
|
||
try:
|
||
# 假设Java服务有健康检查接口 (根据实际情况调整)
|
||
response = requests.get("http://localhost:5610/actuator/health", timeout=5)
|
||
if response.status_code == 200:
|
||
print("✅ Java服务连接正常")
|
||
print(f" 响应: {response.json()}")
|
||
return True
|
||
else:
|
||
print(f"⚠️ Java服务状态码: {response.status_code}")
|
||
return False
|
||
except Exception as e:
|
||
print(f"⚠️ 无法连接Java服务: {e}")
|
||
print("💡 请确保Java服务已启动在端口5610")
|
||
return False
|
||
|
||
def print_configuration_guide():
|
||
"""打印配置指南"""
|
||
print("\n" + "="*60)
|
||
print("🔧 配置指南")
|
||
print("="*60)
|
||
|
||
print("\n📝 1. 启用决策树服务,在Java项目中添加配置:")
|
||
print(" 文件位置: src/main/resources/application.yml")
|
||
print(" 添加配置:")
|
||
print("""
|
||
ai:
|
||
decision:
|
||
enabled: true
|
||
service:
|
||
url: http://localhost:8080
|
||
""")
|
||
|
||
print("\n📝 2. 或者包含AI决策配置文件:")
|
||
print(" 在 application.yml 中添加:")
|
||
print("""
|
||
spring:
|
||
profiles:
|
||
include: ai-decision
|
||
""")
|
||
|
||
print("\n📝 3. 测试切换:")
|
||
print(" - enabled: false -> 使用原有AI审核逻辑")
|
||
print(" - enabled: true -> 使用新的Python决策树服务")
|
||
|
||
print("\n📝 4. 监控日志:")
|
||
print(" Java日志关键词: 'Python决策树服务', 'AI决策树'")
|
||
print(" Python日志: 查看控制台输出")
|
||
|
||
def main():
|
||
print("🧪 TYCM AI审核服务集成测试")
|
||
print("="*60)
|
||
|
||
# 测试Python服务
|
||
python_ok = test_python_service()
|
||
|
||
# 测试Java服务
|
||
java_ok = test_java_service()
|
||
|
||
# 总结
|
||
print("\n" + "="*60)
|
||
print("📊 测试结果总结")
|
||
print("="*60)
|
||
print(f"Python AI服务: {'✅ 正常' if python_ok else '❌ 异常'}")
|
||
print(f"Java TYCM服务: {'✅ 正常' if java_ok else '⚠️ 未确认'}")
|
||
|
||
if python_ok:
|
||
print("\n🎉 Python AI审核服务运行正常!")
|
||
print("💡 现在可以在Java项目中启用决策树配置来使用此服务")
|
||
print_configuration_guide()
|
||
else:
|
||
print("\n❌ Python服务有问题,请检查:")
|
||
print(" 1. 是否已启动: python start_ai_service.py")
|
||
print(" 2. 端口8080是否被占用")
|
||
print(" 3. 依赖是否正确安装")
|
||
|
||
if not java_ok:
|
||
print("\n⚠️ Java服务连接失败,这是正常的如果:")
|
||
print(" 1. Java服务未启动")
|
||
print(" 2. 没有健康检查接口")
|
||
print(" 3. 端口不是5610")
|
||
|
||
if __name__ == "__main__":
|
||
main() |