烧录芯片查询API 接口测试

📚 完整功能演示手册


1️⃣ 健康检查接口

curl -X GET http://localhost:5000/health

响应示例:

{
  "status": "healthy",
  "database": "connected",
  "timestamp": "2026-04-26T01:51:49Z"
}

2️⃣ 数据上传功能

📤 批量上传数据

curl -X POST http://localhost:5000/api/upload-data \
  -H "Content-Type: application/json" \
  -d '{
    "data": [
      {
        "material_no": "B33010175-05",
        "chip_name": "GD32F303VET6",
        "column_group": "A",
        "last_update_user": 1
      },
      {
        "material_no": "Y33010344-00",
        "chip_name": "STM32F103RCT6",
        "column_group": "A",
        "last_update_user": 2
      },
      {
        "material_no": "C33010287-02",
        "chip_name": "W25Q128JVSIQ",
        "column_group": "B",
        "last_update_user": 1
      }
    ]
  }'

响应示例:

{
  "success": true,
  "summary": {
    "total_records": 3,
    "successful": 3,
    "failed": 0
  }
}

📊 CSV格式上传

curl -X POST http://localhost:5000/api/import-from-csv \
  -H "Content-Type: application/json" \
  -d '{
    "csv_content": "料号,芯片型号,列组,最后更新用户\nB33010175-05,GD32F303VET6,A,1\nY33010344-00,STM32F103RCT6,B,2"
  }'

3️⃣ 查询功能

🔍 根据料号查询芯片

curl -X POST http://localhost:5000/api/material-to-chip \
  -H "Content-Type: application/json" \
  -d '{"material_no": "B33010175-05"}'

响应示例:

{
  "success": true,
  "data": {
    "material_no": "B33010175-05",
    "chip_name": "GD32F303VET6",
    "column_group": "A",
    "last_update_user": 1
  }
}

🔄 根据芯片型号查询料号

curl -X POST http://localhost:5000/api/chip-to-materials \
  -H "Content-Type: application/json" \
  -d '{"chip_name": "GD32F303VET6"}'

响应示例:

{
  "success": true,
  "data": {
    "chip_name": "GD32F303VET6",
    "materials": [
      {
        "material_no": "B33010175-05",
        "column_group": "A",
        "last_update_user": 1
      }
    ],
    "count": 1
  }
}

📦 批量查询料号对应芯片

curl -X POST http://localhost:5000/api/batch-material-to-chip \
  -H "Content-Type: application/json" \
  -d '{
    "material_nos": ["B33010175-05", "Y33010344-00", "C33010287-02"]
  }'

响应示例:

{
  "success": true,
  "data": {
    "found": [
      {
        "material_no": "B33010175-05",
        "chip_name": "GD32F303VET6",
        "column_group": "A",
        "last_update_user": 1
      },
      {
        "material_no": "Y33010344-00",
        "chip_name": "STM32F103RCT6",
        "column_group": "A",
        "last_update_user": 2
      }
    ],
    "not_found": ["C33010287-02"],
    "total_requested": 3,
    "total_found": 2
  }
}

4️⃣ 删除功能

❌ 删除单条记录

curl -X DELETE http://localhost:5000/api/delete-record \
  -H "Content-Type: application/json" \
  -d '{"material_no": "B33010175-05"}'

响应示例:

{
  "success": true,
  "message": "成功删除料号 B33010175-05 的记录",
  "deleted_record": {
    "material_no": "B33010175-05",
    "chip_name": "GD32F303VET6"
  }
}

5️⃣ 错误处理示例

🚫 料号不存在

curl -X POST http://localhost:5000/api/material-to-chip \
  -H "Content-Type: application/json" \
  -d '{"material_no": "NONEXISTENT-00"}'

响应:

{
  "error": "未找到料号: NONEXISTENT-00",
  "code": 404
}

🚫 参数缺失

curl -X POST http://localhost:5000/api/material-to-chip \
  -H "Content-Type: application/json" \
  -d '{}'

响应:

{
  "error": "缺少参数: material_no",
  "code": 400
}

📝 工作流程总结

  1. 上传: 批量导入芯片数据
  2. 查询: 根据料号/芯片型号查找
  3. 管理: 批量操作和删除记录
  4. 监控: 健康检查确保服务正常

🚀 部署建议

  1. 生产环境配置:修改 .env 中的 FLASK_ENV=production
  2. 使用 Gunicorngunicorn -w 4 -b 0.0.0.0:5000 app:app
  3. 添加 Nginx 反向代理:提高性能和安全性
  4. 配置 SSL:使用 HTTPS 保护数据传输