Files
nxxmdata/backend/swagger-stats.js
2025-09-23 18:13:11 +08:00

1151 lines
35 KiB
JavaScript

/**
* 统计数据模块 Swagger 文档
* @file swagger-stats.js
* @description 定义统计数据相关的API文档
*/
/**
* @swagger
* tags:
* - name: 统计数据
* description: 各类统计数据和监控信息
*/
/**
* @swagger
* components:
* schemas:
* DashboardStats:
* type: object
* properties:
* farmCount:
* type: integer
* description: 养殖场总数
* example: 12
* animalCount:
* type: integer
* description: 动物总数
* example: 5000
* deviceCount:
* type: integer
* description: 设备总数
* example: 150
* alertCount:
* type: integer
* description: 当前预警数量
* example: 25
* deviceOnlineRate:
* type: number
* format: float
* description: 设备在线率
* example: 0.95
* alertsByLevel:
* type: object
* properties:
* low:
* type: integer
* description: 低级预警数量
* example: 5
* medium:
* type: integer
* description: 中级预警数量
* example: 10
* high:
* type: integer
* description: 高级预警数量
* example: 8
* critical:
* type: integer
* description: 紧急预警数量
* example: 2
* recentActivities:
* type: array
* items:
* type: object
* properties:
* id:
* type: string
* description: 活动ID
* type:
* type: string
* description: 活动类型
* description:
* type: string
* description: 活动描述
* timestamp:
* type: string
* format: date-time
* description: 活动时间
* description: 最近活动记录
*
* FarmStats:
* type: object
* properties:
* totalFarms:
* type: integer
* description: 养殖场总数
* example: 12
* activeFarms:
* type: integer
* description: 活跃养殖场数量
* example: 10
* farmsByType:
* type: array
* items:
* type: object
* properties:
* type:
* type: string
* description: 养殖场类型
* example: "猪场"
* count:
* type: integer
* description: 数量
* example: 5
* percentage:
* type: number
* description: 占比
* example: 0.42
* description: 按类型分组的养殖场统计
* farmsByStatus:
* type: array
* items:
* type: object
* properties:
* status:
* type: string
* description: 养殖场状态
* example: "active"
* count:
* type: integer
* description: 数量
* example: 10
* percentage:
* type: number
* description: 占比
* example: 0.83
* description: 按状态分组的养殖场统计
* farmsByRegion:
* type: array
* items:
* type: object
* properties:
* region:
* type: string
* description: 地区
* example: "银川市"
* count:
* type: integer
* description: 数量
* example: 8
* description: 按地区分组的养殖场统计
* averageAnimalsPerFarm:
* type: number
* description: 平均每个养殖场的动物数量
* example: 416.67
* totalCapacity:
* type: integer
* description: 总养殖容量
* example: 8000
* utilizationRate:
* type: number
* description: 容量利用率
* example: 0.625
*
* AnimalStats:
* type: object
* properties:
* totalAnimals:
* type: integer
* description: 动物总数
* example: 5000
* animalsByType:
* type: array
* items:
* type: object
* properties:
* type:
* type: string
* description: 动物类型
* example: "猪"
* count:
* type: integer
* description: 数量
* example: 3000
* percentage:
* type: number
* description: 占比
* example: 0.6
* description: 按类型分组的动物统计
* animalsByHealth:
* type: array
* items:
* type: object
* properties:
* health_status:
* type: string
* description: 健康状态
* example: "healthy"
* count:
* type: integer
* description: 数量
* example: 4500
* percentage:
* type: number
* description: 占比
* example: 0.9
* description: 按健康状态分组的动物统计
* animalsByAge:
* type: array
* items:
* type: object
* properties:
* age_group:
* type: string
* description: 年龄组
* example: "幼崽"
* count:
* type: integer
* description: 数量
* example: 1000
* description: 按年龄分组的动物统计
* animalsByGender:
* type: array
* items:
* type: object
* properties:
* gender:
* type: string
* description: 性别
* example: "雌性"
* count:
* type: integer
* description: 数量
* example: 2800
* description: 按性别分组的动物统计
* birthRate:
* type: number
* description: 出生率(月度)
* example: 0.08
* mortalityRate:
* type: number
* description: 死亡率(月度)
* example: 0.02
* averageWeight:
* type: number
* description: 平均体重(公斤)
* example: 85.5
*
* DeviceStats:
* type: object
* properties:
* totalDevices:
* type: integer
* description: 设备总数
* example: 150
* onlineDevices:
* type: integer
* description: 在线设备数量
* example: 142
* offlineDevices:
* type: integer
* description: 离线设备数量
* example: 8
* onlineRate:
* type: number
* description: 在线率
* example: 0.947
* devicesByType:
* type: array
* items:
* type: object
* properties:
* type:
* type: string
* description: 设备类型
* example: "智能耳标"
* count:
* type: integer
* description: 数量
* example: 80
* online_count:
* type: integer
* description: 在线数量
* example: 75
* online_rate:
* type: number
* description: 在线率
* example: 0.9375
* description: 按类型分组的设备统计
* devicesByStatus:
* type: array
* items:
* type: object
* properties:
* status:
* type: string
* description: 设备状态
* example: "online"
* count:
* type: integer
* description: 数量
* example: 142
* description: 按状态分组的设备统计
* devicesByFarm:
* type: array
* items:
* type: object
* properties:
* farm_id:
* type: string
* description: 养殖场ID
* farm_name:
* type: string
* description: 养殖场名称
* device_count:
* type: integer
* description: 设备数量
* online_count:
* type: integer
* description: 在线设备数量
* description: 按养殖场分组的设备统计
* maintenanceScheduled:
* type: integer
* description: 计划维护的设备数量
* example: 5
* batteryLowDevices:
* type: integer
* description: 低电量设备数量
* example: 12
*
* AlertStats:
* type: object
* properties:
* totalAlerts:
* type: integer
* description: 预警总数
* example: 25
* activeAlerts:
* type: integer
* description: 活跃预警数量
* example: 18
* resolvedAlerts:
* type: integer
* description: 已解决预警数量
* example: 7
* alertsByLevel:
* type: array
* items:
* type: object
* properties:
* level:
* type: string
* description: 预警级别
* example: "high"
* count:
* type: integer
* description: 数量
* example: 8
* percentage:
* type: number
* description: 占比
* example: 0.32
* description: 按级别分组的预警统计
* alertsByType:
* type: array
* items:
* type: object
* properties:
* type:
* type: string
* description: 预警类型
* example: "health"
* count:
* type: integer
* description: 数量
* example: 10
* description: 按类型分组的预警统计
* alertsByFarm:
* type: array
* items:
* type: object
* properties:
* farm_id:
* type: string
* description: 养殖场ID
* farm_name:
* type: string
* description: 养殖场名称
* alert_count:
* type: integer
* description: 预警数量
* description: 按养殖场分组的预警统计
* averageResponseTime:
* type: number
* description: 平均响应时间(分钟)
* example: 15.5
* resolutionRate:
* type: number
* description: 解决率
* example: 0.72
*
* MonitorData:
* type: object
* properties:
* timestamp:
* type: string
* format: date-time
* description: 监控时间戳
* example: "2024-01-15T10:30:00Z"
* system_health:
* type: object
* properties:
* cpu_usage:
* type: number
* description: CPU使用率
* example: 0.25
* memory_usage:
* type: number
* description: 内存使用率
* example: 0.68
* disk_usage:
* type: number
* description: 磁盘使用率
* example: 0.45
* network_io:
* type: object
* properties:
* bytes_in:
* type: integer
* description: 入站字节数
* bytes_out:
* type: integer
* description: 出站字节数
* database_health:
* type: object
* properties:
* connection_count:
* type: integer
* description: 数据库连接数
* example: 15
* query_performance:
* type: object
* properties:
* avg_query_time:
* type: number
* description: 平均查询时间(毫秒)
* example: 25.5
* slow_queries:
* type: integer
* description: 慢查询数量
* example: 2
* api_performance:
* type: object
* properties:
* total_requests:
* type: integer
* description: 总请求数
* example: 1500
* avg_response_time:
* type: number
* description: 平均响应时间(毫秒)
* example: 120.5
* error_rate:
* type: number
* description: 错误率
* example: 0.02
* device_connectivity:
* type: object
* properties:
* total_devices:
* type: integer
* description: 设备总数
* example: 150
* connected_devices:
* type: integer
* description: 已连接设备数
* example: 142
* connection_rate:
* type: number
* description: 连接率
* example: 0.947
*
* MonthlyTrends:
* type: object
* properties:
* period:
* type: string
* description: 统计周期
* example: "2024-01"
* farm_trends:
* type: array
* items:
* type: object
* properties:
* month:
* type: string
* description: 月份
* example: "2024-01"
* farm_count:
* type: integer
* description: 养殖场数量
* example: 12
* new_farms:
* type: integer
* description: 新增养殖场
* example: 2
* description: 养殖场数量趋势
* animal_trends:
* type: array
* items:
* type: object
* properties:
* month:
* type: string
* description: 月份
* animal_count:
* type: integer
* description: 动物数量
* births:
* type: integer
* description: 出生数量
* deaths:
* type: integer
* description: 死亡数量
* description: 动物数量趋势
* device_trends:
* type: array
* items:
* type: object
* properties:
* month:
* type: string
* description: 月份
* device_count:
* type: integer
* description: 设备数量
* online_rate:
* type: number
* description: 在线率
* description: 设备数量和在线率趋势
* alert_trends:
* type: array
* items:
* type: object
* properties:
* month:
* type: string
* description: 月份
* alert_count:
* type: integer
* description: 预警数量
* resolution_rate:
* type: number
* description: 解决率
* description: 预警数量和解决率趋势
*/
/**
* @swagger
* /stats/dashboard:
* get:
* tags:
* - 统计数据
* summary: 获取仪表盘统计数据
* description: 获取系统仪表盘的核心统计数据
* security:
* - bearerAuth: []
* responses:
* 200:
* description: 获取仪表盘统计数据成功
* content:
* application/json:
* schema:
* allOf:
* - $ref: '#/components/schemas/ApiResponse'
* - type: object
* properties:
* data:
* $ref: '#/components/schemas/DashboardStats'
* 401:
* description: 未授权
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/ErrorResponse'
* 500:
* description: 服务器内部错误
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/ErrorResponse'
*/
/**
* @swagger
* /stats/farms:
* get:
* tags:
* - 统计数据
* summary: 获取养殖场统计数据
* description: 获取养殖场相关的详细统计数据
* security:
* - bearerAuth: []
* parameters:
* - in: query
* name: period
* schema:
* type: string
* enum: [day, week, month, year]
* default: month
* description: 统计周期
* - in: query
* name: region
* schema:
* type: string
* description: 地区筛选
* responses:
* 200:
* description: 获取养殖场统计数据成功
* content:
* application/json:
* schema:
* allOf:
* - $ref: '#/components/schemas/ApiResponse'
* - type: object
* properties:
* data:
* $ref: '#/components/schemas/FarmStats'
* 401:
* description: 未授权
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/ErrorResponse'
* 500:
* description: 服务器内部错误
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/ErrorResponse'
*/
/**
* @swagger
* /stats/animals:
* get:
* tags:
* - 统计数据
* summary: 获取动物统计数据
* description: 获取动物相关的详细统计数据
* security:
* - bearerAuth: []
* parameters:
* - in: query
* name: period
* schema:
* type: string
* enum: [day, week, month, year]
* default: month
* description: 统计周期
* - in: query
* name: farm_id
* schema:
* type: string
* description: 养殖场ID筛选
* - in: query
* name: animal_type
* schema:
* type: string
* description: 动物类型筛选
* responses:
* 200:
* description: 获取动物统计数据成功
* content:
* application/json:
* schema:
* allOf:
* - $ref: '#/components/schemas/ApiResponse'
* - type: object
* properties:
* data:
* $ref: '#/components/schemas/AnimalStats'
* 401:
* description: 未授权
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/ErrorResponse'
* 500:
* description: 服务器内部错误
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/ErrorResponse'
*/
/**
* @swagger
* /stats/devices:
* get:
* tags:
* - 统计数据
* summary: 获取设备统计数据
* description: 获取设备相关的详细统计数据
* security:
* - bearerAuth: []
* parameters:
* - in: query
* name: period
* schema:
* type: string
* enum: [day, week, month, year]
* default: month
* description: 统计周期
* - in: query
* name: farm_id
* schema:
* type: string
* description: 养殖场ID筛选
* - in: query
* name: device_type
* schema:
* type: string
* description: 设备类型筛选
* responses:
* 200:
* description: 获取设备统计数据成功
* content:
* application/json:
* schema:
* allOf:
* - $ref: '#/components/schemas/ApiResponse'
* - type: object
* properties:
* data:
* $ref: '#/components/schemas/DeviceStats'
* 401:
* description: 未授权
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/ErrorResponse'
* 500:
* description: 服务器内部错误
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/ErrorResponse'
*/
/**
* @swagger
* /stats/alerts:
* get:
* tags:
* - 统计数据
* summary: 获取预警统计数据
* description: 获取预警相关的详细统计数据
* security:
* - bearerAuth: []
* parameters:
* - in: query
* name: period
* schema:
* type: string
* enum: [day, week, month, year]
* default: month
* description: 统计周期
* - in: query
* name: farm_id
* schema:
* type: string
* description: 养殖场ID筛选
* - in: query
* name: alert_level
* schema:
* type: string
* enum: [low, medium, high, critical]
* description: 预警级别筛选
* - in: query
* name: alert_type
* schema:
* type: string
* description: 预警类型筛选
* responses:
* 200:
* description: 获取预警统计数据成功
* content:
* application/json:
* schema:
* allOf:
* - $ref: '#/components/schemas/ApiResponse'
* - type: object
* properties:
* data:
* $ref: '#/components/schemas/AlertStats'
* 401:
* description: 未授权
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/ErrorResponse'
* 500:
* description: 服务器内部错误
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/ErrorResponse'
*/
/**
* @swagger
* /stats/monitoring:
* get:
* tags:
* - 统计数据
* summary: 获取系统监控数据
* description: 获取系统实时监控数据
* security:
* - bearerAuth: []
* parameters:
* - in: query
* name: interval
* schema:
* type: string
* enum: [1m, 5m, 15m, 1h]
* default: 5m
* description: 监控数据间隔
* - in: query
* name: duration
* schema:
* type: string
* enum: [1h, 6h, 24h, 7d]
* default: 1h
* description: 监控数据时长
* responses:
* 200:
* description: 获取监控数据成功
* content:
* application/json:
* schema:
* allOf:
* - $ref: '#/components/schemas/ApiResponse'
* - type: object
* properties:
* data:
* type: array
* items:
* $ref: '#/components/schemas/MonitorData'
* 401:
* description: 未授权
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/ErrorResponse'
* 500:
* description: 服务器内部错误
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/ErrorResponse'
*/
/**
* @swagger
* /stats/monthly-trends:
* get:
* tags:
* - 统计数据
* summary: 获取月度数据趋势
* description: 获取各项指标的月度趋势数据
* security:
* - bearerAuth: []
* parameters:
* - in: query
* name: months
* schema:
* type: integer
* minimum: 1
* maximum: 24
* default: 12
* description: 获取最近几个月的数据
* - in: query
* name: metrics
* schema:
* type: array
* items:
* type: string
* enum: [farms, animals, devices, alerts]
* description: 要获取的指标类型
* style: form
* explode: false
* example: "farms,animals,devices"
* responses:
* 200:
* description: 获取月度趋势数据成功
* content:
* application/json:
* schema:
* allOf:
* - $ref: '#/components/schemas/ApiResponse'
* - type: object
* properties:
* data:
* $ref: '#/components/schemas/MonthlyTrends'
* 401:
* description: 未授权
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/ErrorResponse'
* 500:
* description: 服务器内部错误
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/ErrorResponse'
*/
/**
* @swagger
* /stats/public/dashboard:
* get:
* tags:
* - 统计数据
* summary: 获取公开仪表盘统计数据
* description: 获取公开的仪表盘统计数据(无需认证)
* responses:
* 200:
* description: 获取公开统计数据成功
* content:
* application/json:
* schema:
* allOf:
* - $ref: '#/components/schemas/ApiResponse'
* - type: object
* properties:
* data:
* type: object
* properties:
* farmCount:
* type: integer
* description: 养殖场总数
* example: 12
* animalCount:
* type: integer
* description: 动物总数
* example: 5000
* deviceCount:
* type: integer
* description: 设备总数
* example: 150
* lastUpdated:
* type: string
* format: date-time
* description: 最后更新时间
* example: "2024-01-15T10:30:00Z"
* 500:
* description: 服务器内部错误
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/ErrorResponse'
*/
/**
* @swagger
* /stats/public/monitoring:
* get:
* tags:
* - 统计数据
* summary: 获取公开监控数据
* description: 获取公开的系统监控数据(无需认证)
* responses:
* 200:
* description: 获取公开监控数据成功
* content:
* application/json:
* schema:
* allOf:
* - $ref: '#/components/schemas/ApiResponse'
* - type: object
* properties:
* data:
* type: object
* properties:
* system_status:
* type: string
* enum: [healthy, warning, critical]
* description: 系统状态
* example: "healthy"
* device_online_rate:
* type: number
* description: 设备在线率
* example: 0.95
* active_alerts:
* type: integer
* description: 活跃预警数量
* example: 5
* last_updated:
* type: string
* format: date-time
* description: 最后更新时间
* example: "2024-01-15T10:30:00Z"
* 500:
* description: 服务器内部错误
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/ErrorResponse'
*/
/**
* @swagger
* /stats/public/monthly-trends:
* get:
* tags:
* - 统计数据
* summary: 获取公开月度趋势数据
* description: 获取公开的月度趋势数据(无需认证)
* parameters:
* - in: query
* name: months
* schema:
* type: integer
* minimum: 1
* maximum: 12
* default: 6
* description: 获取最近几个月的数据
* responses:
* 200:
* description: 获取公开月度趋势数据成功
* content:
* application/json:
* schema:
* allOf:
* - $ref: '#/components/schemas/ApiResponse'
* - type: object
* properties:
* data:
* type: object
* properties:
* farm_trends:
* type: array
* items:
* type: object
* properties:
* month:
* type: string
* count:
* type: integer
* animal_trends:
* type: array
* items:
* type: object
* properties:
* month:
* type: string
* count:
* type: integer
* 500:
* description: 服务器内部错误
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/ErrorResponse'
*/
/**
* @swagger
* /stats/public/farm-count:
* get:
* tags:
* - 统计数据
* summary: 获取养殖场总数统计
* description: 获取实时的养殖场总数统计(无需认证)
* responses:
* 200:
* description: 获取养殖场总数成功
* content:
* application/json:
* schema:
* allOf:
* - $ref: '#/components/schemas/ApiResponse'
* - type: object
* properties:
* data:
* type: object
* properties:
* total:
* type: integer
* description: 养殖场总数
* example: 12
* active:
* type: integer
* description: 活跃养殖场数量
* example: 10
* last_updated:
* type: string
* format: date-time
* description: 最后更新时间
* example: "2024-01-15T10:30:00Z"
* 500:
* description: 服务器内部错误
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/ErrorResponse'
*/
/**
* @swagger
* /stats/public/animal-count:
* get:
* tags:
* - 统计数据
* summary: 获取动物总数统计
* description: 获取实时的动物总数统计(无需认证)
* responses:
* 200:
* description: 获取动物总数成功
* content:
* application/json:
* schema:
* allOf:
* - $ref: '#/components/schemas/ApiResponse'
* - type: object
* properties:
* data:
* type: object
* properties:
* total:
* type: integer
* description: 动物总数
* example: 5000
* by_type:
* type: array
* items:
* type: object
* properties:
* type:
* type: string
* description: 动物类型
* count:
* type: integer
* description: 数量
* description: 按类型分组的动物统计
* last_updated:
* type: string
* format: date-time
* description: 最后更新时间
* example: "2024-01-15T10:30:00Z"
* 500:
* description: 服务器内部错误
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/ErrorResponse'
*/
module.exports = {};