{ "openapi": "3.0.0", "info": { "title": "药店销售预测系统API", "description": "用于药店销售预测的RESTful API", "version": "1.0.0", "contact": { "name": "API开发团队", "email": "support@example.com" } }, "tags": [ { "name": "数据管理", "description": "数据上传和查询相关接口" }, { "name": "模型训练", "description": "模型训练相关接口" }, { "name": "模型预测", "description": "预测销售数据相关接口" }, { "name": "模型管理", "description": "模型查询、导出和删除接口" } ], "paths": { "/api/products": { "get": { "tags": ["数据管理"], "summary": "获取所有产品列表", "description": "返回系统中所有产品的ID和名称", "responses": { "200": { "description": "成功获取产品列表", "content": { "application/json": { "schema": { "type": "object", "properties": { "status": {"type": "string", "example": "success"}, "data": { "type": "array", "items": { "type": "object", "properties": { "product_id": {"type": "string", "example": "P001"}, "product_name": {"type": "string", "example": "产品A"} } } } } } } } }, "500": {"description": "服务器内部错误"} } } }, "/api/products/{product_id}": { "get": { "tags": ["数据管理"], "summary": "获取单个产品详情", "description": "返回指定产品ID的详细信息", "parameters": [ { "name": "product_id", "in": "path", "required": true, "schema": {"type": "string"}, "description": "产品ID,例如P001" } ], "responses": { "200": { "description": "成功获取产品详情", "content": { "application/json": { "schema": { "type": "object", "properties": { "status": {"type": "string", "example": "success"}, "data": { "type": "object", "properties": { "product_id": {"type": "string", "example": "P001"}, "product_name": {"type": "string", "example": "产品A"}, "data_points": {"type": "integer", "example": 365}, "date_range": { "type": "object", "properties": { "start": {"type": "string", "example": "2023-01-01"}, "end": {"type": "string", "example": "2023-12-31"} } } } } } } } } }, "404": {"description": "产品不存在"}, "500": {"description": "服务器内部错误"} } } }, "/api/products/{product_id}/sales": { "get": { "tags": ["数据管理"], "summary": "获取产品销售数据", "description": "返回指定产品在特定日期范围内的销售数据", "parameters": [ { "name": "product_id", "in": "path", "required": true, "schema": {"type": "string"}, "description": "产品ID,例如P001" }, { "name": "start_date", "in": "query", "schema": {"type": "string"}, "description": "开始日期,格式为YYYY-MM-DD" }, { "name": "end_date", "in": "query", "schema": {"type": "string"}, "description": "结束日期,格式为YYYY-MM-DD" } ], "responses": { "200": { "description": "成功获取销售数据", "content": { "application/json": { "schema": { "type": "object", "properties": { "status": {"type": "string", "example": "success"}, "data": { "type": "array", "items": { "type": "object", "properties": { "date": {"type": "string", "example": "2023-12-01"}, "sales": {"type": "integer", "example": 150} } } } } } } } }, "404": {"description": "产品不存在"}, "500": {"description": "服务器内部错误"} } } }, "/api/data/upload": { "post": { "tags": ["数据管理"], "summary": "上传销售数据", "description": "上传新的销售数据文件(Excel格式)", "requestBody": { "content": { "multipart/form-data": { "schema": { "type": "object", "properties": { "file": { "type": "string", "format": "binary" } } } } } }, "responses": { "200": { "description": "数据上传成功", "content": { "application/json": { "schema": { "type": "object", "properties": { "status": {"type": "string", "example": "success"}, "message": {"type": "string", "example": "数据上传成功"}, "data": { "type": "object", "properties": { "products": {"type": "integer", "example": 10}, "rows": {"type": "integer", "example": 3650} } } } } } } }, "400": {"description": "请求错误"}, "500": {"description": "服务器内部错误"} } } }, "/api/training": { "get": { "tags": ["模型训练"], "summary": "获取所有训练任务列表", "description": "返回所有正在进行、已完成或失败的训练任务", "responses": { "200": { "description": "成功获取任务列表", "content": { "application/json": { "schema": { "type": "object", "properties": { "status": {"type": "string", "example": "success"}, "data": { "type": "array", "items": { "type": "object", "properties": { "task_id": {"type": "string", "example": "uuid-1234"}, "product_id": {"type": "string", "example": "P001"}, "model_type": {"type": "string", "example": "mlstm"}, "status": {"type": "string", "example": "completed"}, "start_time": {"type": "string", "example": "2023-12-25T10:00:00Z"}, "metrics": {"type": "object", "example": {"R2": 0.95, "RMSE": 5.5}}, "error": {"type": "string", "nullable": true}, "model_path": {"type": "string", "example": "/path/to/model.pth"} } } } } } } } } } }, "post": { "tags": ["模型训练"], "summary": "启动模型训练任务", "description": "为指定产品启动一个新的模型训练任务", "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object", "properties": { "product_id": {"type": "string", "example": "P001"}, "model_type": {"type": "string", "enum": ["mlstm", "transformer", "kan", "optimized_kan", "tcn", "xgboost"]}, "store_id": {"type": "string", "example": "S001"}, "epochs": {"type": "integer", "default": 50} }, "required": ["product_id", "model_type"] } } } }, "responses": { "200": { "description": "训练任务已启动", "content": { "application/json": { "schema": { "type": "object", "properties": { "message": {"type": "string", "example": "模型训练已开始"}, "task_id": {"type": "string", "example": "new-uuid-5678"} } } } } }, "400": {"description": "请求错误"} } } }, "/api/training/{task_id}": { "get": { "tags": ["模型训练"], "summary": "查询训练任务状态", "description": "获取特定训练任务的当前状态和详情", "parameters": [ { "name": "task_id", "in": "path", "required": true, "schema": {"type": "string"}, "description": "训练任务ID" } ], "responses": { "200": { "description": "成功获取任务状态", "content": { "application/json": { "schema": { "type": "object", "properties": { "status": {"type": "string", "example": "success"}, "data": { "type": "object", "properties": { "product_id": {"type": "string", "example": "P001"}, "model_type": {"type": "string", "example": "mlstm"}, "status": {"type": "string", "example": "running"}, "progress": {"type": "number", "example": 50.5}, "created_at": {"type": "string", "example": "2023-12-25T10:00:00Z"} } } } } } } }, "404": {"description": "任务不存在"}, "500": {"description": "服务器内部错误"} } } }, "/api/prediction": { "post": { "tags": ["模型预测"], "summary": "使用模型进行预测", "description": "使用指定模型预测未来销售数据", "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object", "properties": { "product_id": {"type": "string"}, "model_type": {"type": "string", "enum": ["mlstm", "transformer", "kan", "optimized_kan", "tcn"]}, "store_id": {"type": "string"}, "version": {"type": "string"}, "future_days": {"type": "integer"}, "include_visualization": {"type": "boolean"}, "start_date": {"type": "string"} }, "required": ["product_id", "model_type"] } } } }, "responses": { "200": { "description": "预测成功", "content": { "application/json": { "schema": { "type": "object", "properties": { "status": {"type": "string", "example": "success"}, "data": { "type": "object", "properties": { "product_id": {"type": "string", "example": "P001"}, "product_name": {"type": "string", "example": "产品A"}, "model_type": {"type": "string", "example": "mlstm"}, "predictions": { "type": "array", "items": { "type": "object", "properties": { "date": {"type": "string", "example": "2024-01-01"}, "predicted_sales": {"type": "integer", "example": 100} } } }, "visualization": {"type": "string", "example": "base64-encoded-image-string"} } } } } } } }, "400": {"description": "请求错误"}, "404": {"description": "产品或模型不存在"}, "500": {"description": "服务器内部错误"} } } }, "/api/prediction/compare": { "post": { "tags": ["模型预测"], "summary": "比较不同模型预测结果", "description": "比较不同模型对同一产品的预测结果", "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object", "properties": { "product_id": {"type": "string"}, "model_types": {"type": "array", "items": {"type": "string"}}, "versions": {"type": "array", "items": {"type": "string"}}, "include_visualization": {"type": "boolean"} }, "required": ["product_id", "model_types"] } } } }, "responses": { "200": { "description": "比较成功", "content": { "application/json": { "schema": { "type": "object", "properties": { "status": {"type": "string", "example": "success"}, "data": { "type": "object", "properties": { "product_id": {"type": "string", "example": "P001"}, "comparison": { "type": "array", "items": { "type": "object", "properties": { "date": {"type": "string", "example": "2024-01-01"}, "mlstm": {"type": "integer", "example": 100}, "transformer": {"type": "integer", "example": 102} } } }, "visualization": {"type": "string", "example": "base64-encoded-image-string"} } } } } } } }, "400": {"description": "请求错误"}, "404": {"description": "产品或模型不存在"}, "500": {"description": "服务器内部错误"} } } }, "/api/prediction/history": { "get": { "tags": ["模型预测"], "summary": "获取历史预测记录", "responses": { "200": { "description": "获取成功", "content": { "application/json": { "schema": { "type": "object", "properties": { "status": {"type": "string", "example": "success"}, "data": { "type": "array", "items": { "type": "object", "properties": { "prediction_id": {"type": "string", "example": "pred-uuid-1"}, "product_id": {"type": "string", "example": "P001"}, "model_type": {"type": "string", "example": "mlstm"}, "created_at": {"type": "string", "example": "2023-12-20T11:00:00Z"} } } } } } } } } } } }, "/api/prediction/history/{prediction_id}": { "get": { "tags": ["模型预测"], "summary": "获取特定预测记录的详情", "parameters": [ { "name": "prediction_id", "in": "path", "required": true, "schema": {"type": "string"} } ], "responses": { "200": { "description": "获取成功", "content": { "application/json": { "schema": { "type": "object", "properties": { "status": {"type": "string", "example": "success"}, "data": { "type": "object", "properties": { "prediction_id": {"type": "string", "example": "pred-uuid-1"}, "product_id": {"type": "string", "example": "P001"}, "model_type": {"type": "string", "example": "mlstm"}, "predictions": { "type": "array", "items": { "type": "object", "properties": { "date": {"type": "string", "example": "2023-12-21"}, "predicted_sales": {"type": "integer", "example": 110} } } }, "analysis": {"type": "object", "example": {"trend": "upward"}} } } } } } } }, "404": {"description": "记录不存在"} } }, "delete": { "tags": ["模型预测"], "summary": "删除预测记录", "parameters": [ { "name": "prediction_id", "in": "path", "required": true, "schema": {"type": "string"} } ], "responses": { "200": { "description": "删除成功", "content": { "application/json": { "schema": { "type": "object", "properties": { "status": {"type": "string", "example": "success"}, "message": {"type": "string", "example": "预测记录已删除"} } } } } }, "404": {"description": "记录不存在"} } } }, "/api/models": { "get": { "tags": ["模型管理"], "summary": "获取模型列表", "parameters": [ {"name": "product_id", "in": "query", "schema": {"type": "string"}}, {"name": "model_type", "in": "query", "schema": {"type": "string"}} ], "responses": { "200": { "description": "获取成功", "content": { "application/json": { "schema": { "type": "object", "properties": { "status": {"type": "string", "example": "success"}, "data": { "type": "array", "items": { "type": "object", "properties": { "model_id": {"type": "string", "example": "P001_mlstm_v1"}, "product_id": {"type": "string", "example": "P001"}, "model_type": {"type": "string", "example": "mlstm"}, "version": {"type": "string", "example": "v1"}, "created_at": {"type": "string", "example": "2023-12-15T09:00:00Z"} } } } } } } } } } } }, "/api/models/{model_id}": { "get": { "tags": ["模型管理"], "summary": "获取模型详情", "parameters": [ {"name": "model_id", "in": "path", "required": true, "schema": {"type": "string"}} ], "responses": { "200": { "description": "获取成功", "content": { "application/json": { "schema": { "type": "object", "properties": { "status": {"type": "string", "example": "success"}, "data": { "type": "object", "properties": { "model_id": {"type": "string", "example": "P001_mlstm_v1"}, "product_id": {"type": "string", "example": "P001"}, "model_type": {"type": "string", "example": "mlstm"}, "version": {"type": "string", "example": "v1"}, "metrics": {"type": "object", "example": {"R2": 0.95, "RMSE": 5.5}} } } } } } } }, "404": {"description": "模型不存在"} } }, "delete": { "tags": ["模型管理"], "summary": "删除模型", "parameters": [ {"name": "model_id", "in": "path", "required": true, "schema": {"type": "string"}} ], "responses": { "200": { "description": "删除成功", "content": { "application/json": { "schema": { "type": "object", "properties": { "status": {"type": "string", "example": "success"}, "message": {"type": "string", "example": "模型已删除"} } } } } }, "404": {"description": "模型不存在"} } } }, "/api/models/{model_id}/export": { "get": { "tags": ["模型管理"], "summary": "导出模型", "parameters": [ {"name": "model_id", "in": "path", "required": true, "schema": {"type": "string"}} ], "responses": { "200": {"description": "模型文件下载"}, "404": {"description": "模型不存在"} } } }, "/api/model_types": { "get": { "tags": ["模型管理"], "summary": "获取系统支持的所有模型类型", "responses": { "200": { "description": "获取成功", "content": { "application/json": { "schema": { "type": "object", "properties": { "status": {"type": "string", "example": "success"}, "data": { "type": "array", "items": { "type": "object", "properties": { "id": {"type": "string", "example": "mlstm"}, "name": {"type": "string", "example": "mLSTM"} } } } } } } } } } } }, "/api/models/{product_id}/{model_type}/versions": { "get": { "tags": ["模型管理"], "summary": "获取模型版本列表", "parameters": [ {"name": "product_id", "in": "path", "required": true, "schema": {"type": "string"}}, {"name": "model_type", "in": "path", "required": true, "schema": {"type": "string"}} ], "responses": { "200": { "description": "获取成功", "content": { "application/json": { "schema": { "type": "object", "properties": { "status": {"type": "string", "example": "success"}, "data": { "type": "object", "properties": { "product_id": {"type": "string", "example": "P001"}, "model_type": {"type": "string", "example": "mlstm"}, "versions": {"type": "array", "items": {"type": "string"}, "example": ["v1", "v2"]}, "latest_version": {"type": "string", "example": "v2"} } } } } } } } } } }, "/api/stores": { "get": { "tags": ["数据管理"], "summary": "获取所有店铺列表", "responses": { "200": { "description": "获取成功", "content": { "application/json": { "schema": { "type": "object", "properties": { "status": {"type": "string", "example": "success"}, "data": { "type": "array", "items": { "type": "object", "properties": { "store_id": {"type": "string", "example": "S001"}, "store_name": {"type": "string", "example": "第一分店"} } } }, "count": {"type": "integer", "example": 2} } } } } } } }, "post": { "tags": ["数据管理"], "summary": "创建新店铺", "responses": { "200": { "description": "创建成功", "content": { "application/json": { "schema": { "type": "object", "properties": { "status": {"type": "string", "example": "success"}, "message": {"type": "string", "example": "店铺创建成功"}, "data": { "type": "object", "properties": { "store_id": {"type": "string", "example": "S003"} } } } } } } } } } }, "/api/stores/{store_id}": { "get": { "tags": ["数据管理"], "summary": "获取单个店铺信息", "parameters": [ {"name": "store_id", "in": "path", "required": true, "schema": {"type": "string"}} ], "responses": { "200": { "description": "获取成功", "content": { "application/json": { "schema": { "type": "object", "properties": { "status": {"type": "string", "example": "success"}, "data": { "type": "object", "properties": { "store_id": {"type": "string", "example": "S001"}, "store_name": {"type": "string", "example": "第一分店"}, "location": {"type": "string", "example": "市中心"}, "size": {"type": "number", "example": 120.5}, "type": {"type": "string", "example": "旗舰店"}, "opening_date": {"type": "string", "example": "2022-01-01"}, "status": {"type": "string", "example": "active"} } } } } } } }, "404": {"description": "店铺不存在"} } }, "put": { "tags": ["数据管理"], "summary": "更新店铺信息", "parameters": [ {"name": "store_id", "in": "path", "required": true, "schema": {"type": "string"}} ], "responses": { "200": { "description": "更新成功", "content": { "application/json": { "schema": { "type": "object", "properties": { "status": {"type": "string", "example": "success"}, "message": {"type": "string", "example": "店铺更新成功"} } } } } }, "404": {"description": "店铺不存在"} } }, "delete": { "tags": ["数据管理"], "summary": "删除店铺", "parameters": [ {"name": "store_id", "in": "path", "required": true, "schema": {"type": "string"}} ], "responses": { "200": { "description": "删除成功", "content": { "application/json": { "schema": { "type": "object", "properties": { "status": {"type": "string", "example": "success"}, "message": {"type": "string", "example": "店铺删除成功"} } } } } }, "404": {"description": "店铺不存在"} } } }, "/api/stores/{store_id}/products": { "get": { "tags": ["数据管理"], "summary": "获取店铺的产品列表", "parameters": [ {"name": "store_id", "in": "path", "required": true, "schema": {"type": "string"}} ], "responses": { "200": { "description": "获取成功", "content": { "application/json": { "schema": { "type": "object", "properties": { "status": {"type": "string", "example": "success"}, "data": { "type": "array", "items": { "type": "object", "properties": { "product_id": {"type": "string", "example": "P001"}, "product_name": {"type": "string", "example": "产品A"} } } }, "count": {"type": "integer", "example": 1} } } } } } } } }, "/api/stores/{store_id}/statistics": { "get": { "tags": ["数据管理"], "summary": "获取店铺销售统计信息", "parameters": [ {"name": "store_id", "in": "path", "required": true, "schema": {"type": "string"}} ], "responses": { "200": { "description": "获取成功", "content": { "application/json": { "schema": { "type": "object", "properties": { "status": {"type": "string", "example": "success"}, "data": { "type": "object", "properties": { "total_sales": {"type": "number", "example": 150000.0}, "total_quantity": {"type": "integer", "example": 7500}, "products_count": {"type": "integer", "example": 50} } } } } } } } } } }, "/api/sales/data": { "get": { "tags": ["数据管理"], "summary": "获取销售数据列表", "responses": { "200": { "description": "获取成功", "content": { "application/json": { "schema": { "type": "object", "properties": { "status": {"type": "string", "example": "success"}, "data": { "type": "array", "items": { "type": "object", "properties": { "date": {"type": "string", "example": "2023-12-01"}, "store_id": {"type": "string", "example": "S001"}, "product_id": {"type": "string", "example": "P001"}, "sales": {"type": "integer", "example": 150}, "price": {"type": "number", "example": 25.5} } } }, "total": {"type": "integer", "example": 100}, "page": {"type": "integer", "example": 1}, "page_size": {"type": "integer", "example": 1} } } } } } } } } } }