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

1004 lines
30 KiB
JavaScript

/**
* 智能预警模块 Swagger 文档
* @file swagger-smart-alerts.js
* @description 定义智能预警相关的API文档
*/
/**
* @swagger
* tags:
* - name: 智能预警
* description: 智能预警系统管理
* - name: 智能耳标预警
* description: 智能耳标预警管理
* - name: 智能项圈预警
* description: 智能项圈预警管理
*/
/**
* @swagger
* components:
* schemas:
* AlertStats:
* type: object
* properties:
* totalAlerts:
* type: integer
* description: 总预警数量
* example: 25
* eartagAlerts:
* type: integer
* description: 耳标预警数量
* example: 15
* collarAlerts:
* type: integer
* description: 项圈预警数量
* example: 10
* eartagDevices:
* type: integer
* description: 耳标设备总数
* example: 100
* collarDevices:
* type: integer
* description: 项圈设备总数
* example: 80
* alertsByType:
* type: object
* properties:
* battery:
* type: integer
* description: 电量预警数量
* example: 5
* offline:
* type: integer
* description: 离线预警数量
* example: 8
* temperature:
* type: integer
* description: 温度预警数量
* example: 3
* movement:
* type: integer
* description: 运动预警数量
* example: 6
* wear:
* type: integer
* description: 佩戴预警数量
* example: 3
* alertsByLevel:
* type: object
* properties:
* high:
* type: integer
* description: 高级预警数量
* example: 8
* medium:
* type: integer
* description: 中级预警数量
* example: 12
* low:
* type: integer
* description: 低级预警数量
* example: 5
*
* EartagAlert:
* type: object
* properties:
* id:
* type: string
* description: 预警ID
* example: "alert_001"
* deviceId:
* type: string
* description: 设备ID
* example: "eartag_001"
* deviceName:
* type: string
* description: 设备名称
* example: "耳标设备001"
* animalId:
* type: string
* description: 动物ID
* example: "animal_001"
* animalName:
* type: string
* description: 动物名称
* example: "牛001"
* farmId:
* type: string
* description: 养殖场ID
* example: "farm_001"
* farmName:
* type: string
* description: 养殖场名称
* example: "示例养殖场"
* alertType:
* type: string
* enum: [battery, offline, temperature, movement, wear]
* description: 预警类型
* example: "battery"
* alertLevel:
* type: string
* enum: [high, medium, low]
* description: 预警级别
* example: "high"
* alertMessage:
* type: string
* description: 预警消息
* example: "设备电量低于10%"
* alertValue:
* type: number
* description: 预警值
* example: 8.5
* threshold:
* type: number
* description: 阈值
* example: 10
* status:
* type: string
* enum: [pending, processing, resolved, ignored]
* description: 处理状态
* example: "pending"
* isHandled:
* type: boolean
* description: 是否已处理
* example: false
* handledBy:
* type: string
* description: 处理人
* example: "admin"
* handledAt:
* type: string
* format: date-time
* description: 处理时间
* example: "2024-01-15T10:30:00Z"
* handledNote:
* type: string
* description: 处理备注
* example: "已更换电池"
* createdAt:
* type: string
* format: date-time
* description: 创建时间
* example: "2024-01-15T08:30:00Z"
* updatedAt:
* type: string
* format: date-time
* description: 更新时间
* example: "2024-01-15T10:30:00Z"
*
* CollarAlert:
* type: object
* properties:
* id:
* type: string
* description: 预警ID
* example: "alert_002"
* deviceId:
* type: string
* description: 设备ID
* example: "collar_001"
* deviceName:
* type: string
* description: 设备名称
* example: "项圈设备001"
* animalId:
* type: string
* description: 动物ID
* example: "animal_002"
* animalName:
* type: string
* description: 动物名称
* example: "牛002"
* farmId:
* type: string
* description: 养殖场ID
* example: "farm_001"
* farmName:
* type: string
* description: 养殖场名称
* example: "示例养殖场"
* alertType:
* type: string
* enum: [battery, offline, temperature, movement, wear, location]
* description: 预警类型
* example: "offline"
* alertLevel:
* type: string
* enum: [high, medium, low]
* description: 预警级别
* example: "medium"
* alertMessage:
* type: string
* description: 预警消息
* example: "设备离线超过2小时"
* alertValue:
* type: number
* description: 预警值
* example: 120
* threshold:
* type: number
* description: 阈值
* example: 60
* status:
* type: string
* enum: [pending, processing, resolved, ignored]
* description: 处理状态
* example: "pending"
* isHandled:
* type: boolean
* description: 是否已处理
* example: false
* handledBy:
* type: string
* description: 处理人
* example: "admin"
* handledAt:
* type: string
* format: date-time
* description: 处理时间
* example: "2024-01-15T12:30:00Z"
* handledNote:
* type: string
* description: 处理备注
* example: "设备已重新上线"
* createdAt:
* type: string
* format: date-time
* description: 创建时间
* example: "2024-01-15T10:30:00Z"
* updatedAt:
* type: string
* format: date-time
* description: 更新时间
* example: "2024-01-15T12:30:00Z"
*
* AlertHandleRequest:
* type: object
* required:
* - action
* properties:
* action:
* type: string
* enum: [resolve, ignore, process]
* description: 处理动作
* example: "resolve"
* note:
* type: string
* description: 处理备注
* example: "问题已解决"
* handledBy:
* type: string
* description: 处理人
* example: "admin"
*
* BatchHandleRequest:
* type: object
* required:
* - alertIds
* - action
* properties:
* alertIds:
* type: array
* items:
* type: string
* description: 预警ID列表
* example: ["alert_001", "alert_002", "alert_003"]
* action:
* type: string
* enum: [resolve, ignore, process]
* description: 处理动作
* example: "resolve"
* note:
* type: string
* description: 处理备注
* example: "批量处理预警"
* handledBy:
* type: string
* description: 处理人
* example: "admin"
*/
/**
* @swagger
* /smart-alerts/public/stats:
* get:
* tags:
* - 智能预警
* summary: 获取智能预警统计
* description: 获取智能预警的统计数据,包括各类预警的数量和设备总数
* responses:
* 200:
* description: 获取统计成功
* content:
* application/json:
* schema:
* allOf:
* - $ref: '#/components/schemas/ApiResponse'
* - type: object
* properties:
* data:
* $ref: '#/components/schemas/AlertStats'
* 500:
* description: 服务器内部错误
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/ErrorResponse'
*/
/**
* @swagger
* /smart-alerts/public/eartag/stats:
* get:
* tags:
* - 智能耳标预警
* summary: 获取智能耳标预警统计
* description: 获取智能耳标预警的统计数据,包括各类预警的数量和设备总数
* responses:
* 200:
* description: 获取统计成功
* content:
* application/json:
* schema:
* allOf:
* - $ref: '#/components/schemas/ApiResponse'
* - type: object
* properties:
* data:
* $ref: '#/components/schemas/AlertStats'
* 500:
* description: 服务器内部错误
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/ErrorResponse'
*/
/**
* @swagger
* /smart-alerts/public/eartag:
* get:
* tags:
* - 智能耳标预警
* summary: 获取智能耳标预警列表
* description: 获取智能耳标预警列表,支持分页、搜索和筛选
* parameters:
* - $ref: '#/components/parameters/PaginationQuery/properties/page'
* - $ref: '#/components/parameters/PaginationQuery/properties/limit'
* - in: query
* name: search
* schema:
* type: string
* description: 搜索关键词(设备名称、动物名称、养殖场名称)
* - in: query
* name: alertType
* schema:
* type: string
* enum: [battery, offline, temperature, movement, wear]
* description: 预警类型筛选
* - in: query
* name: alertLevel
* schema:
* type: string
* enum: [high, medium, low]
* description: 预警级别筛选
* - in: query
* name: status
* schema:
* type: string
* enum: [pending, processing, resolved, ignored]
* description: 处理状态筛选
* - in: query
* name: farmId
* schema:
* type: string
* description: 养殖场ID筛选
* - in: query
* name: isHandled
* schema:
* type: boolean
* description: 是否已处理筛选
* - in: query
* name: startDate
* schema:
* type: string
* format: date
* description: 开始日期
* - in: query
* name: endDate
* schema:
* type: string
* format: date
* description: 结束日期
* responses:
* 200:
* description: 获取列表成功
* content:
* application/json:
* schema:
* allOf:
* - $ref: '#/components/schemas/ApiResponse'
* - type: object
* properties:
* data:
* type: object
* properties:
* alerts:
* type: array
* items:
* $ref: '#/components/schemas/EartagAlert'
* pagination:
* type: object
* properties:
* total:
* type: integer
* example: 100
* page:
* type: integer
* example: 1
* limit:
* type: integer
* example: 10
* totalPages:
* type: integer
* example: 10
* 500:
* description: 服务器内部错误
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/ErrorResponse'
*/
/**
* @swagger
* /smart-alerts/public/eartag/{id}:
* get:
* tags:
* - 智能耳标预警
* summary: 获取单个智能耳标预警详情
* description: 获取指定ID的智能耳标预警详细信息
* parameters:
* - in: path
* name: id
* required: true
* schema:
* type: string
* description: 预警ID
* responses:
* 200:
* description: 获取详情成功
* content:
* application/json:
* schema:
* allOf:
* - $ref: '#/components/schemas/ApiResponse'
* - type: object
* properties:
* data:
* $ref: '#/components/schemas/EartagAlert'
* 400:
* description: 请求参数错误
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/ErrorResponse'
* 404:
* description: 预警不存在
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/ErrorResponse'
* 500:
* description: 服务器内部错误
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/ErrorResponse'
*/
/**
* @swagger
* /smart-alerts/public/eartag/{id}/handle:
* post:
* tags:
* - 智能耳标预警
* summary: 处理智能耳标预警
* description: 处理指定的智能耳标预警
* parameters:
* - in: path
* name: id
* required: true
* schema:
* type: string
* description: 预警ID
* requestBody:
* required: true
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/AlertHandleRequest'
* responses:
* 200:
* description: 处理成功
* content:
* application/json:
* schema:
* allOf:
* - $ref: '#/components/schemas/ApiResponse'
* - type: object
* properties:
* data:
* $ref: '#/components/schemas/EartagAlert'
* 400:
* description: 请求参数错误
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/ErrorResponse'
* 404:
* description: 预警不存在
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/ErrorResponse'
* 500:
* description: 服务器内部错误
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/ErrorResponse'
*/
/**
* @swagger
* /smart-alerts/public/eartag/batch-handle:
* post:
* tags:
* - 智能耳标预警
* summary: 批量处理智能耳标预警
* description: 批量处理多个智能耳标预警
* requestBody:
* required: true
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/BatchHandleRequest'
* responses:
* 200:
* description: 批量处理成功
* content:
* application/json:
* schema:
* allOf:
* - $ref: '#/components/schemas/ApiResponse'
* - type: object
* properties:
* data:
* type: object
* properties:
* successCount:
* type: integer
* description: 成功处理数量
* example: 5
* failedCount:
* type: integer
* description: 失败数量
* example: 0
* processedAlerts:
* type: array
* items:
* $ref: '#/components/schemas/EartagAlert'
* 400:
* description: 请求参数错误
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/ErrorResponse'
* 500:
* description: 服务器内部错误
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/ErrorResponse'
*/
/**
* @swagger
* /smart-alerts/public/eartag/export:
* get:
* tags:
* - 智能耳标预警
* summary: 导出智能耳标预警数据
* description: 导出智能耳标预警数据为Excel文件
* parameters:
* - in: query
* name: alertType
* schema:
* type: string
* enum: [battery, offline, temperature, movement, wear]
* description: 预警类型筛选
* - in: query
* name: alertLevel
* schema:
* type: string
* enum: [high, medium, low]
* description: 预警级别筛选
* - in: query
* name: status
* schema:
* type: string
* enum: [pending, processing, resolved, ignored]
* description: 处理状态筛选
* - in: query
* name: farmId
* schema:
* type: string
* description: 养殖场ID筛选
* - in: query
* name: startDate
* schema:
* type: string
* format: date
* description: 开始日期
* - in: query
* name: endDate
* schema:
* type: string
* format: date
* description: 结束日期
* responses:
* 200:
* description: 导出成功
* content:
* application/vnd.openxmlformats-officedocument.spreadsheetml.sheet:
* schema:
* type: string
* format: binary
* 500:
* description: 服务器内部错误
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/ErrorResponse'
*/
/**
* @swagger
* /smart-alerts/public/collar/stats:
* get:
* tags:
* - 智能项圈预警
* summary: 获取智能项圈预警统计
* description: 获取智能项圈预警的统计数据,包括各类预警的数量和设备总数
* responses:
* 200:
* description: 获取统计成功
* content:
* application/json:
* schema:
* allOf:
* - $ref: '#/components/schemas/ApiResponse'
* - type: object
* properties:
* data:
* $ref: '#/components/schemas/AlertStats'
* 500:
* description: 服务器内部错误
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/ErrorResponse'
*/
/**
* @swagger
* /smart-alerts/public/collar:
* get:
* tags:
* - 智能项圈预警
* summary: 获取智能项圈预警列表
* description: 获取智能项圈预警列表,支持分页、搜索和筛选
* parameters:
* - $ref: '#/components/parameters/PaginationQuery/properties/page'
* - $ref: '#/components/parameters/PaginationQuery/properties/limit'
* - in: query
* name: search
* schema:
* type: string
* description: 搜索关键词(设备名称、动物名称、养殖场名称)
* - in: query
* name: alertType
* schema:
* type: string
* enum: [battery, offline, temperature, movement, wear, location]
* description: 预警类型筛选
* - in: query
* name: alertLevel
* schema:
* type: string
* enum: [high, medium, low]
* description: 预警级别筛选
* - in: query
* name: status
* schema:
* type: string
* enum: [pending, processing, resolved, ignored]
* description: 处理状态筛选
* - in: query
* name: farmId
* schema:
* type: string
* description: 养殖场ID筛选
* - in: query
* name: isHandled
* schema:
* type: boolean
* description: 是否已处理筛选
* - in: query
* name: startDate
* schema:
* type: string
* format: date
* description: 开始日期
* - in: query
* name: endDate
* schema:
* type: string
* format: date
* description: 结束日期
* responses:
* 200:
* description: 获取列表成功
* content:
* application/json:
* schema:
* allOf:
* - $ref: '#/components/schemas/ApiResponse'
* - type: object
* properties:
* data:
* type: object
* properties:
* alerts:
* type: array
* items:
* $ref: '#/components/schemas/CollarAlert'
* pagination:
* type: object
* properties:
* total:
* type: integer
* example: 100
* page:
* type: integer
* example: 1
* limit:
* type: integer
* example: 10
* totalPages:
* type: integer
* example: 10
* 500:
* description: 服务器内部错误
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/ErrorResponse'
*/
/**
* @swagger
* /smart-alerts/public/collar/{id}:
* get:
* tags:
* - 智能项圈预警
* summary: 获取单个智能项圈预警详情
* description: 获取指定ID的智能项圈预警详细信息
* parameters:
* - in: path
* name: id
* required: true
* schema:
* type: string
* description: 预警ID
* responses:
* 200:
* description: 获取详情成功
* content:
* application/json:
* schema:
* allOf:
* - $ref: '#/components/schemas/ApiResponse'
* - type: object
* properties:
* data:
* $ref: '#/components/schemas/CollarAlert'
* 400:
* description: 请求参数错误
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/ErrorResponse'
* 404:
* description: 预警不存在
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/ErrorResponse'
* 500:
* description: 服务器内部错误
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/ErrorResponse'
*/
/**
* @swagger
* /smart-alerts/public/collar/{id}/handle:
* post:
* tags:
* - 智能项圈预警
* summary: 处理智能项圈预警
* description: 处理指定的智能项圈预警
* parameters:
* - in: path
* name: id
* required: true
* schema:
* type: string
* description: 预警ID
* requestBody:
* required: true
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/AlertHandleRequest'
* responses:
* 200:
* description: 处理成功
* content:
* application/json:
* schema:
* allOf:
* - $ref: '#/components/schemas/ApiResponse'
* - type: object
* properties:
* data:
* $ref: '#/components/schemas/CollarAlert'
* 400:
* description: 请求参数错误
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/ErrorResponse'
* 404:
* description: 预警不存在
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/ErrorResponse'
* 500:
* description: 服务器内部错误
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/ErrorResponse'
*/
/**
* @swagger
* /smart-alerts/public/collar/batch-handle:
* post:
* tags:
* - 智能项圈预警
* summary: 批量处理智能项圈预警
* description: 批量处理多个智能项圈预警
* requestBody:
* required: true
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/BatchHandleRequest'
* responses:
* 200:
* description: 批量处理成功
* content:
* application/json:
* schema:
* allOf:
* - $ref: '#/components/schemas/ApiResponse'
* - type: object
* properties:
* data:
* type: object
* properties:
* successCount:
* type: integer
* description: 成功处理数量
* example: 5
* failedCount:
* type: integer
* description: 失败数量
* example: 0
* processedAlerts:
* type: array
* items:
* $ref: '#/components/schemas/CollarAlert'
* 400:
* description: 请求参数错误
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/ErrorResponse'
* 500:
* description: 服务器内部错误
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/ErrorResponse'
*/
/**
* @swagger
* /smart-alerts/public/collar/export:
* get:
* tags:
* - 智能项圈预警
* summary: 导出智能项圈预警数据
* description: 导出智能项圈预警数据为Excel文件
* parameters:
* - in: query
* name: alertType
* schema:
* type: string
* enum: [battery, offline, temperature, movement, wear, location]
* description: 预警类型筛选
* - in: query
* name: alertLevel
* schema:
* type: string
* enum: [high, medium, low]
* description: 预警级别筛选
* - in: query
* name: status
* schema:
* type: string
* enum: [pending, processing, resolved, ignored]
* description: 处理状态筛选
* - in: query
* name: farmId
* schema:
* type: string
* description: 养殖场ID筛选
* - in: query
* name: startDate
* schema:
* type: string
* format: date
* description: 开始日期
* - in: query
* name: endDate
* schema:
* type: string
* format: date
* description: 结束日期
* responses:
* 200:
* description: 导出成功
* content:
* application/vnd.openxmlformats-officedocument.spreadsheetml.sheet:
* schema:
* type: string
* format: binary
* 500:
* description: 服务器内部错误
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/ErrorResponse'
*/
module.exports = {};