完善保险端前后端和养殖端小程序
This commit is contained in:
520
backend/swagger-simple.js
Normal file
520
backend/swagger-simple.js
Normal file
@@ -0,0 +1,520 @@
|
||||
/**
|
||||
* 简化版Swagger配置
|
||||
* @file swagger-simple.js
|
||||
* @description 简化的Swagger配置,确保API路径正确显示
|
||||
*/
|
||||
|
||||
const swaggerJSDoc = require('swagger-jsdoc');
|
||||
|
||||
const options = {
|
||||
definition: {
|
||||
openapi: '3.0.0',
|
||||
info: {
|
||||
title: '智能预警系统 API',
|
||||
version: '1.0.0',
|
||||
description: '智能耳标预警和智能项圈预警系统API文档',
|
||||
contact: {
|
||||
name: '开发团队',
|
||||
email: 'dev@example.com'
|
||||
}
|
||||
},
|
||||
servers: [
|
||||
{
|
||||
url: 'http://localhost:5350/api',
|
||||
description: '开发环境'
|
||||
}
|
||||
],
|
||||
tags: [
|
||||
{
|
||||
name: '智能耳标预警',
|
||||
description: '智能耳标预警相关接口'
|
||||
},
|
||||
{
|
||||
name: '智能项圈预警',
|
||||
description: '智能项圈预警相关接口'
|
||||
}
|
||||
]
|
||||
},
|
||||
apis: ['./routes/smart-alerts.js']
|
||||
};
|
||||
|
||||
const specs = swaggerJSDoc(options);
|
||||
|
||||
// 手动添加API路径,确保它们出现在文档中
|
||||
if (!specs.paths) {
|
||||
specs.paths = {};
|
||||
}
|
||||
|
||||
// 智能耳标预警API路径
|
||||
specs.paths['/smart-alerts/public/eartag/stats'] = {
|
||||
get: {
|
||||
tags: ['智能耳标预警'],
|
||||
summary: '获取智能耳标预警统计',
|
||||
description: '获取智能耳标预警的统计数据,包括各类预警的数量和设备总数',
|
||||
responses: {
|
||||
'200': {
|
||||
description: '获取统计成功',
|
||||
content: {
|
||||
'application/json': {
|
||||
schema: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
success: { type: 'boolean' },
|
||||
data: { type: 'object' },
|
||||
message: { type: 'string' }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
specs.paths['/smart-alerts/public/eartag'] = {
|
||||
get: {
|
||||
tags: ['智能耳标预警'],
|
||||
summary: '获取智能耳标预警列表',
|
||||
description: '获取智能耳标预警列表,支持分页、搜索和筛选',
|
||||
parameters: [
|
||||
{
|
||||
name: 'page',
|
||||
in: 'query',
|
||||
schema: { type: 'integer', default: 1 },
|
||||
description: '页码'
|
||||
},
|
||||
{
|
||||
name: 'limit',
|
||||
in: 'query',
|
||||
schema: { type: 'integer', default: 10 },
|
||||
description: '每页数量'
|
||||
},
|
||||
{
|
||||
name: 'search',
|
||||
in: 'query',
|
||||
schema: { type: 'string' },
|
||||
description: '搜索关键词'
|
||||
},
|
||||
{
|
||||
name: 'alertType',
|
||||
in: 'query',
|
||||
schema: { type: 'string', enum: ['battery', 'offline', 'temperature', 'movement'] },
|
||||
description: '预警类型筛选'
|
||||
}
|
||||
],
|
||||
responses: {
|
||||
'200': {
|
||||
description: '获取列表成功',
|
||||
content: {
|
||||
'application/json': {
|
||||
schema: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
success: { type: 'boolean' },
|
||||
data: { type: 'array', items: { type: 'object' } },
|
||||
total: { type: 'integer' },
|
||||
message: { type: 'string' }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
specs.paths['/smart-alerts/public/eartag/{id}'] = {
|
||||
get: {
|
||||
tags: ['智能耳标预警'],
|
||||
summary: '获取单个智能耳标预警详情',
|
||||
description: '获取指定ID的智能耳标预警详细信息',
|
||||
parameters: [
|
||||
{
|
||||
name: 'id',
|
||||
in: 'path',
|
||||
required: true,
|
||||
schema: { type: 'string' },
|
||||
description: '预警ID'
|
||||
}
|
||||
],
|
||||
responses: {
|
||||
'200': {
|
||||
description: '获取详情成功',
|
||||
content: {
|
||||
'application/json': {
|
||||
schema: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
success: { type: 'boolean' },
|
||||
data: { type: 'object' },
|
||||
message: { type: 'string' }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
specs.paths['/smart-alerts/public/eartag/{id}/handle'] = {
|
||||
post: {
|
||||
tags: ['智能耳标预警'],
|
||||
summary: '处理智能耳标预警',
|
||||
description: '处理指定的智能耳标预警',
|
||||
parameters: [
|
||||
{
|
||||
name: 'id',
|
||||
in: 'path',
|
||||
required: true,
|
||||
schema: { type: 'string' },
|
||||
description: '预警ID'
|
||||
}
|
||||
],
|
||||
requestBody: {
|
||||
required: true,
|
||||
content: {
|
||||
'application/json': {
|
||||
schema: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
action: { type: 'string', description: '处理动作' },
|
||||
notes: { type: 'string', description: '处理备注' },
|
||||
handler: { type: 'string', description: '处理人' }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
responses: {
|
||||
'200': {
|
||||
description: '处理成功',
|
||||
content: {
|
||||
'application/json': {
|
||||
schema: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
success: { type: 'boolean' },
|
||||
data: { type: 'object' },
|
||||
message: { type: 'string' }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
specs.paths['/smart-alerts/public/eartag/batch-handle'] = {
|
||||
post: {
|
||||
tags: ['智能耳标预警'],
|
||||
summary: '批量处理智能耳标预警',
|
||||
description: '批量处理多个智能耳标预警',
|
||||
requestBody: {
|
||||
required: true,
|
||||
content: {
|
||||
'application/json': {
|
||||
schema: {
|
||||
type: 'object',
|
||||
required: ['alertIds'],
|
||||
properties: {
|
||||
alertIds: { type: 'array', items: { type: 'string' }, description: '预警ID列表' },
|
||||
action: { type: 'string', description: '处理动作' },
|
||||
notes: { type: 'string', description: '处理备注' },
|
||||
handler: { type: 'string', description: '处理人' }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
responses: {
|
||||
'200': {
|
||||
description: '批量处理成功',
|
||||
content: {
|
||||
'application/json': {
|
||||
schema: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
success: { type: 'boolean' },
|
||||
data: { type: 'object' },
|
||||
message: { type: 'string' }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
specs.paths['/smart-alerts/public/eartag/export'] = {
|
||||
get: {
|
||||
tags: ['智能耳标预警'],
|
||||
summary: '导出智能耳标预警数据',
|
||||
description: '导出智能耳标预警数据,支持JSON和CSV格式',
|
||||
parameters: [
|
||||
{
|
||||
name: 'format',
|
||||
in: 'query',
|
||||
schema: { type: 'string', enum: ['json', 'csv'], default: 'json' },
|
||||
description: '导出格式'
|
||||
}
|
||||
],
|
||||
responses: {
|
||||
'200': {
|
||||
description: '导出成功',
|
||||
content: {
|
||||
'application/json': {
|
||||
schema: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
success: { type: 'boolean' },
|
||||
data: { type: 'array', items: { type: 'object' } },
|
||||
message: { type: 'string' }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 智能项圈预警API路径
|
||||
specs.paths['/smart-alerts/public/collar/stats'] = {
|
||||
get: {
|
||||
tags: ['智能项圈预警'],
|
||||
summary: '获取智能项圈预警统计',
|
||||
description: '获取智能项圈预警的统计数据,包括各类预警的数量和设备总数',
|
||||
responses: {
|
||||
'200': {
|
||||
description: '获取统计成功',
|
||||
content: {
|
||||
'application/json': {
|
||||
schema: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
success: { type: 'boolean' },
|
||||
data: { type: 'object' },
|
||||
message: { type: 'string' }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
specs.paths['/smart-alerts/public/collar'] = {
|
||||
get: {
|
||||
tags: ['智能项圈预警'],
|
||||
summary: '获取智能项圈预警列表',
|
||||
description: '获取智能项圈预警列表,支持分页、搜索和筛选',
|
||||
parameters: [
|
||||
{
|
||||
name: 'page',
|
||||
in: 'query',
|
||||
schema: { type: 'integer', default: 1 },
|
||||
description: '页码'
|
||||
},
|
||||
{
|
||||
name: 'limit',
|
||||
in: 'query',
|
||||
schema: { type: 'integer', default: 10 },
|
||||
description: '每页数量'
|
||||
},
|
||||
{
|
||||
name: 'search',
|
||||
in: 'query',
|
||||
schema: { type: 'string' },
|
||||
description: '搜索关键词'
|
||||
},
|
||||
{
|
||||
name: 'alertType',
|
||||
in: 'query',
|
||||
schema: { type: 'string', enum: ['battery', 'offline', 'temperature', 'movement', 'wear'] },
|
||||
description: '预警类型筛选'
|
||||
}
|
||||
],
|
||||
responses: {
|
||||
'200': {
|
||||
description: '获取列表成功',
|
||||
content: {
|
||||
'application/json': {
|
||||
schema: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
success: { type: 'boolean' },
|
||||
data: { type: 'array', items: { type: 'object' } },
|
||||
total: { type: 'integer' },
|
||||
message: { type: 'string' }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
specs.paths['/smart-alerts/public/collar/{id}'] = {
|
||||
get: {
|
||||
tags: ['智能项圈预警'],
|
||||
summary: '获取单个智能项圈预警详情',
|
||||
description: '获取指定ID的智能项圈预警详细信息',
|
||||
parameters: [
|
||||
{
|
||||
name: 'id',
|
||||
in: 'path',
|
||||
required: true,
|
||||
schema: { type: 'string' },
|
||||
description: '预警ID'
|
||||
}
|
||||
],
|
||||
responses: {
|
||||
'200': {
|
||||
description: '获取详情成功',
|
||||
content: {
|
||||
'application/json': {
|
||||
schema: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
success: { type: 'boolean' },
|
||||
data: { type: 'object' },
|
||||
message: { type: 'string' }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
specs.paths['/smart-alerts/public/collar/{id}/handle'] = {
|
||||
post: {
|
||||
tags: ['智能项圈预警'],
|
||||
summary: '处理智能项圈预警',
|
||||
description: '处理指定的智能项圈预警',
|
||||
parameters: [
|
||||
{
|
||||
name: 'id',
|
||||
in: 'path',
|
||||
required: true,
|
||||
schema: { type: 'string' },
|
||||
description: '预警ID'
|
||||
}
|
||||
],
|
||||
requestBody: {
|
||||
required: true,
|
||||
content: {
|
||||
'application/json': {
|
||||
schema: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
action: { type: 'string', description: '处理动作' },
|
||||
notes: { type: 'string', description: '处理备注' },
|
||||
handler: { type: 'string', description: '处理人' }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
responses: {
|
||||
'200': {
|
||||
description: '处理成功',
|
||||
content: {
|
||||
'application/json': {
|
||||
schema: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
success: { type: 'boolean' },
|
||||
data: { type: 'object' },
|
||||
message: { type: 'string' }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
specs.paths['/smart-alerts/public/collar/batch-handle'] = {
|
||||
post: {
|
||||
tags: ['智能项圈预警'],
|
||||
summary: '批量处理智能项圈预警',
|
||||
description: '批量处理多个智能项圈预警',
|
||||
requestBody: {
|
||||
required: true,
|
||||
content: {
|
||||
'application/json': {
|
||||
schema: {
|
||||
type: 'object',
|
||||
required: ['alertIds'],
|
||||
properties: {
|
||||
alertIds: { type: 'array', items: { type: 'string' }, description: '预警ID列表' },
|
||||
action: { type: 'string', description: '处理动作' },
|
||||
notes: { type: 'string', description: '处理备注' },
|
||||
handler: { type: 'string', description: '处理人' }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
responses: {
|
||||
'200': {
|
||||
description: '批量处理成功',
|
||||
content: {
|
||||
'application/json': {
|
||||
schema: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
success: { type: 'boolean' },
|
||||
data: { type: 'object' },
|
||||
message: { type: 'string' }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
specs.paths['/smart-alerts/public/collar/export'] = {
|
||||
get: {
|
||||
tags: ['智能项圈预警'],
|
||||
summary: '导出智能项圈预警数据',
|
||||
description: '导出智能项圈预警数据,支持JSON和CSV格式',
|
||||
parameters: [
|
||||
{
|
||||
name: 'format',
|
||||
in: 'query',
|
||||
schema: { type: 'string', enum: ['json', 'csv'], default: 'json' },
|
||||
description: '导出格式'
|
||||
}
|
||||
],
|
||||
responses: {
|
||||
'200': {
|
||||
description: '导出成功',
|
||||
content: {
|
||||
'application/json': {
|
||||
schema: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
success: { type: 'boolean' },
|
||||
data: { type: 'array', items: { type: 'object' } },
|
||||
message: { type: 'string' }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = specs;
|
||||
Reference in New Issue
Block a user