Complete architecture reference for the A3 insurance platform — file locations, data flow, conventions, microservice map, and fullstack patterns
日本語の概要は準備中です。原文の説明を表示しています。
API endpoint design and testing for vehicle insurance data platform. Use when designing new API endpoints, testing existing ones, validating response formats, or debugging API issues. Covers 11 core endpoints including 3 new pie chart distribution endpoints, parameter validation, error handling, and integration patterns.
インストールする前に、エージェントに与えられる指示の中身を確認できます。
REST API design specifications for vehicle insurance data analysis platform.
Key Files:
Related Docs:
| 端点 | 方法 | 功能 | 优先级 |
|---|---|---|---|
/api/health | GET | 健康检查 | P0 |
/api/latest-date | GET | 获取最新日期 | P0 |
/api/refresh | POST | 刷新数据 | P0 |
/api/filter-options | GET | 获取筛选选项 | P0 |
/api/kpi-windows | POST | KPI 三口径数据 | P0 |
/api/week-comparison | POST | 周对比图表数据 | P0 |
/api/insurance-type-distribution | POST | 险别组合占比 | P0 |
/api/premium-range-distribution | POST | 业务员保费区间占比 | P0 |
/api/renewal-type-distribution | POST | 新转续占比 | P0 |
/api/policy-mapping | GET | 保单映射信息 | P1 |
/api/staff-performance-distribution | POST | 业务员业绩分布 | P1 |
/api/health - 健康检查请求:
GET /api/health
响应:
{
"status": "healthy",
"message": "API服务运行正常"
}
测试示例:
curl http://localhost:5001/api/health
/api/latest-date - 获取最新日期响应:
{
"success": true,
"latest_date": "2025-11-08"
}
错误响应:
{
"success": false,
"message": "获取最新日期失败: 未找到数据文件"
}
测试示例:
curl http://localhost:5001/api/latest-date
/api/refresh - 刷新数据请求: POST /api/refresh
响应:
{
"success": true,
"message": "数据刷新成功",
"latest_date": "2025-11-08"
}
注意事项:
测试示例:
curl -X POST http://localhost:5001/api/refresh
/api/filter-options - 获取筛选选项响应:
{
"success": true,
"data": {
"三级机构": ["达州", "德阳", "绵阳", "南充"],
"团队": ["达州业务一部", "德阳业务三部"],
"是否续保": ["是", "否"],
"是否新能源": ["是", "否"],
"是否过户车": ["是", "否"],
"险种大类": ["商业险", "交强险"],
"吨位": ["<2吨", "2-5吨", "5-10吨", ">10吨"],
"是否电销": ["全部", "是", "否"],
"机构团队映射": {
"达州": ["业务一部", "业务二部"],
"德阳": ["业务三部"]
},
"保单号": ["P202511080001", "P202511080002", "..."]
}
}
测试示例:
curl http://localhost:5001/api/filter-options
/api/kpi-windows - KPI 三口径数据请求:
POST /api/kpi-windows
Content-Type: application/json
{
"filters": {
"三级机构": "达州",
"团队": "业务一部",
"是否续保": "是"
},
"date": "2025-11-08"
}
参数说明:
filters (object, 可选): 筛选条件date (string, 可选): 锚定日期 (YYYY-MM-DD), 默认为最新日期响应:
{
"success": true,
"data": {
"anchor_date": "2025-11-08",
"premium": {
"day": 125000.50,
"last7d": 875420.30,
"last30d": 3250800.75
},
"policy_count": {
"day": 234,
"last7d": 1680,
"last30d": 6420
},
"commission": {
"day": 5000.00,
"last7d": 35016.81,
"last30d": 130032.03
}
}
}
业务逻辑:
测试示例:
curl -X POST http://localhost:5001/api/kpi-windows \
-H "Content-Type: application/json" \
-d '{"filters": {"三级机构": "达州"}}'
/api/week-comparison - 周对比图表数据请求:
POST /api/week-comparison
Content-Type: application/json
{
"metric": "premium",
"filters": {"三级机构": "达州"},
"date": "2025-11-08"
}
参数说明:
metric (string, 必填): 指标类型 (premium 或 count)filters (object, 可选): 筛选条件date (string, 可选): 锚定日期响应:
{
"success": true,
"data": {
"x_axis": ["周三", "周四", "周五", "周六", "周日", "周一", "周二"],
"series": [
{
"name": "D-14 (10-25)",
"data": [120000, 135000, 98000, 110000, 125000, 95000, 98000]
},
{
"name": "D-7 (11-01)",
"data": [95000, 88000, 92000, 105000, 98000, 87000, 92000]
},
{
"name": "D (11-08)",
"data": [112000, 118000, 105000, 120000, 115000, 110000, 111000]
}
]
}
}
周期划分: 以锚定日期为结束日,往前推 7 天为一个周期
测试示例:
curl -X POST http://localhost:5001/api/week-comparison \
-H "Content-Type: application/json" \
-d '{"metric": "premium"}'
/api/policy-mapping - 保单映射信息响应:
{
"success": true,
"data": {
"policy_to_staff": {
"P202511080001": "张三",
"P202511080002": "李四"
},
"staff_to_info": {
"张三": {
"三级机构": "达州",
"团队简称": "业务一部"
}
},
"conflicts": ["王五"]
}
}
测试示例:
curl http://localhost:5001/api/policy-mapping
/api/staff-performance-distribution - 业务员业绩分布请求:
POST /api/staff-performance-distribution
Content-Type: application/json
{
"period": "day",
"filters": {"三级机构": "达州"}
}
参数说明:
period (string, 必填): day, last7d, last30dfilters (object, 可选): 筛选条件响应:
{
"success": true,
"data": {
"distribution": [
{"range": "<1万", "count": 15, "percentage": 37.5},
{"range": "1-2万", "count": 12, "percentage": 30.0},
{"range": "2-3万", "count": 8, "percentage": 20.0},
{"range": "3-5万", "count": 3, "percentage": 7.5},
{"range": ">=5万", "count": 2, "percentage": 5.0}
]
}
}
测试示例:
curl -X POST http://localhost:5001/api/staff-performance-distribution \
-H "Content-Type: application/json" \
-d '{"period": "day"}'
{
"success": true,
"data": {
// 业务数据
}
}
{
"success": false,
"message": "错误描述信息"
}
HTTP 状态码:
200: 请求成功400: 参数错误404: 资源不存在500: 服务器内部错误// ✅ 推荐: 始终包含 success 字段
{"success": true, "data": {...}}
// ✅ 推荐: 错误消息清晰具体
{"success": false, "message": "数据刷新失败: Permission denied"}
// ✅ 推荐: 保持字段命名一致(统一下划线)
{"latest_date": "2025-11-08", "total_staff": 40}
// ✅ 推荐: 避免返回 null
{"success": false, "message": "未找到数据"}
{
"三级机构": str, # "达州" / "德阳" / "全部"
"团队": str, # "业务一部" / "全部"
"是否续保": str, # "是" / "否" / "全部"
"是否新能源": str, # "是" / "否" / "全部"
"保单号": str # "P202511080001"
}
验证逻辑:
# ✅ 推荐: 忽略无效字段
valid_keys = {'三级机构', '团队', '是否续保', ...}
filters = {k: v for k, v in filters.items() if k in valid_keys}
格式: YYYY-MM-DD
默认值: 最新数据日期
date_str = data.get('date', None)
if date_str:
try:
date = pd.to_datetime(date_str)
except Exception:
return jsonify({
"success": False,
"message": "日期格式不正确,请使用 YYYY-MM-DD 格式"
}), 400
有效值: "premium" | "count"
metric = data.get('metric', 'premium')
if metric not in ['premium', 'count']:
return jsonify({
"success": False,
"message": "metric 参数必须为 'premium' 或 'count'"
}), 400
有效值: "day" | "last7d" | "last30d"
period = data.get('period', 'day')
if period not in ['day', 'last7d', 'last30d']:
return jsonify({
"success": False,
"message": "period 参数必须为 'day', 'last7d' 或 'last30d'"
}), 400
| 参数 | 默认值 | 说明 |
|---|---|---|
filters | {} | 空对象表示不筛选 |
date | 最新日期 | 自动获取 |
metric | "premium" | 默认查询保费 |
period | "day" | 默认当日 |
data = request.get_json() or {}
filters = data.get('filters', {})
date = data.get('date', None)
# ✅ 宽进严出: 接受多种输入格式
if filters.get('三级机构') in ['全部', 'all', None, '']:
# 不筛选
# ✅ 提前验证,快速失败
if metric not in ['premium', 'count']:
return jsonify({"success": False, "message": "..."}), 400
# ✅ 友好的错误提示
return jsonify({
"success": False,
"message": "日期格式不正确,请使用 YYYY-MM-DD 格式: 2025-11-08"
}), 400
# ✅ 处理空值
data = request.get_json() or {}
filters = data.get('filters', {})
| 状态码 | 含义 | 使用场景 |
|---|---|---|
200 | OK | 请求成功 |
400 | Bad Request | 参数错误 |
404 | Not Found | 资源不存在 |
500 | Internal Server Error | 服务器内部错误 |
{
"success": false,
"message": "业务员映射缺失",
"code": "STAFF_MAPPING_MISSING",
"details": {
"unmatched_staff": ["张三", "李四"]
}
}
# ✅ 区分客户端错误和服务器错误
if metric not in ['premium', 'count']:
return jsonify({"success": False, "message": "..."}), 400 # 400
try:
result = processor.get_kpi_windows(...)
except Exception as e:
return jsonify({"success": False, "message": f"...{str(e)}"}), 500 # 500
# ✅ 记录详细错误日志
try:
result = processor.get_kpi_windows(...)
except Exception as e:
logging.error(f"获取KPI数据失败: {e}", exc_info=True)
return jsonify({"success": False, "message": "获取KPI数据失败"}), 500
# ✅ 避免泄露敏感信息
# ❌ 不推荐(泄露文件路径)
return jsonify({"success": False, "message": f"文件不存在: {file_path}"}), 404
# ✅ 推荐
return jsonify({"success": False, "message": "数据文件不存在"}), 404
# 健康检查
curl http://localhost:5001/api/health
# 最新日期
curl http://localhost:5001/api/latest-date
# 刷新数据
curl -X POST http://localhost:5001/api/refresh
# KPI 三口径
curl -X POST http://localhost:5001/api/kpi-windows \
-H "Content-Type: application/json" \
-d '{"filters": {"三级机构": "达州"}}'
# 周对比
curl -X POST http://localhost:5001/api/week-comparison \
-H "Content-Type: application/json" \
-d '{"metric": "premium"}'
# 业绩分布
curl -X POST http://localhost:5001/api/staff-performance-distribution \
-H "Content-Type: application/json" \
-d '{"period": "day"}'
测试工具: pytest + Flask Test Client
完整测试模板: TESTING_TEMPLATE.md
快速示例:
import pytest
from backend.api_server import app
@pytest.fixture
def client():
app.config['TESTING'] = True
with app.test_client() as client:
yield client
def test_health_check(client):
response = client.get('/api/health')
assert response.status_code == 200
✅ 推荐:
GET /api/filter-options
POST /api/kpi-windows
GET /api/policy-mapping
❌ 避免:
GET /api/getFilterOptions # 动词命名
POST /api/doRefresh # 动词命名
| 方法 | 语义 | 示例 |
|---|---|---|
| GET | 获取资源 | /api/health |
| POST | 创建/复杂查询 | /api/kpi-windows |
为什么查询用 POST?
✅ 扁平化设计(推荐):
/api/kpi-windows
/api/week-comparison
❌ 过度嵌套(避免):
/api/data/kpi/windows # 层级太深
/api/data/week/comparison
Axios 配置: frontend/src/services/api.js
关键特性:
使用示例:
import { apiClient } from '@/services/api'
// GET 请求
const response = await apiClient.get('/api/health')
// POST 请求
const response = await apiClient.post('/api/kpi-windows', {
filters: { 三级机构: '达州' },
date: '2025-11-08'
})
// 统一错误处理由拦截器完成
{ success: true/false, data/message }| 端点 | 方法 | 功能 | 必填参数 |
|---|---|---|---|
/api/health | GET | 健康检查 | - |
/api/latest-date | GET | 最新日期 | - |
/api/refresh | POST | 刷新数据 | - |
/api/filter-options | GET | 筛选选项 | - |
/api/kpi-windows | POST | KPI 三口径 | - |
/api/week-comparison | POST | 周对比 | metric |
/api/policy-mapping | GET | 保单映射 | - |
/api/staff-performance-distribution | POST | 业绩分布 | period |
✅ 适用:
❌ 不适用:
backend-data-processoranalyzing-auto-insurance-datavue-component-devbackend/api_server.py - Flask API 服务器
frontend/src/services/api.js - API 客户端
文档维护者: Claude Code AI Assistant 版本: v2.0 (重构版) 最后更新: 2025-11-08 下次审查: 2025-11-22
まだレビューはありません。使ってみた感想をお寄せください。
概要と使いどころ
Complete architecture reference for the A3 insurance platform — file locations, data flow, conventions, microservice map, and fullstack patterns
日本語の概要は準備中です。原文の説明を表示しています。
Drafts U.S. commercial real estate access and indemnity (right-of-entry) agreements for pre-closing due diligence. Covers license grants, non-invasive vs invasive testing gates, insurance/endorsement requirements, indemnity with discovery carve-outs, restoration and lien remedies, confidentiality, and anti-indemnity guardrails. Trigger: access agreement, right of entry, due diligence access, Phase I/II, invasive testing, pre-PSA site inspection.
日本語の概要は準備中です。原文の説明を表示しています。
当用户需要对意外险投保问卷进行专业、结构化的核保审查,提取职业类别、工作环境、作业内容、危险活动参与情况、交通出行习惯、特殊工作暴露及其他可能影响意外险承保判断的高风险信息,并生成适合意外险核保、补问流转和风险分层处理的结构化分析结果时使用本 skill。
日本語の概要は準備中です。原文の説明を表示しています。
Inspect, schema, and fill true AcroForm PDFs using sciClaw's pdf_form_inspect, pdf_form_schema, and pdf_form_fill tools. Use when: (1) checking whether a PDF is a real fillable AcroForm, (2) listing form field names, types, and choices, (3) filling a supported form from structured values, (4) preparing reviewable insurance, legal, administrative, or clinical form drafts, (5) reporting skipped fields or unused input keys after a fill. Do not use for scanned PDFs, OCR tasks, or XFA-only forms.
日本語の概要は準備中です。原文の説明を表示しています。
Guide actuarial analysis for insurance pricing. TRIGGERS - Use when user needs help with actuarial-analysis related tasks.
日本語の概要は準備中です。原文の説明を表示しています。
Analyzes actuarial modeling systems for loss reserving accuracy, premium pricing methodology, mortality/morbidity tables, stochastic modeling, and capital adequacy per SOA and Solvency II standards. USE THIS SKILL WHEN: - You need to review or audit actuarial models (reserving, pricing, capital) - Someone asks about loss triangle analysis or reserve adequacy - You are evaluating IBNR calculations, chain ladder methods, or Bornhuetter-Ferguson - A project involves insurance pricing, GLM rating models, or ratemaking - You need to assess Solvency II SCR calculations or RBC compliance - Someone mentions actuarial opinions, ASOP compliance, or SOA standards - You are reviewing stochastic models, ESG configurations, or DFA frameworks - A codebase uses actuarial libraries (chainladder, lifetables, ChainLadder R package) TRIGGER PHRASES: "actuarial", "loss reserving", "IBNR", "chain ladder", "premium pricing", "mortality table", "Solvency II", "capital adequacy", "ratemaking", "GLM pricing", "risk-based capital", "reserve analysis", "actuarial opinion"
日本語の概要は準備中です。原文の説明を表示しています。