/** * 动物管理模块 Swagger 文档 * @file swagger-animals.js */ const animalsPaths = { // 获取所有动物列表 '/animals': { 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: 'farmId', in: 'query', schema: { type: 'integer' }, description: '养殖场ID筛选' }, { name: 'status', in: 'query', schema: { type: 'string', enum: ['healthy', 'sick', 'quarantine', 'sold'] }, description: '动物状态筛选' }, { name: 'category', in: 'query', schema: { type: 'integer', enum: [1, 2, 3, 4, 5, 6] }, description: '动物类别筛选:1-犊牛,2-育成母牛,3-架子牛,4-青年牛,5-基础母牛,6-育肥牛' }, { name: 'sex', in: 'query', schema: { type: 'integer', enum: [1, 2] }, description: '性别筛选:1-公牛,2-母牛' } ], responses: { '200': { description: '获取成功', content: { 'application/json': { schema: { type: 'object', properties: { success: { type: 'boolean', example: true }, data: { type: 'array', items: { $ref: '#/components/schemas/Animal' } }, pagination: { type: 'object', properties: { page: { type: 'integer' }, limit: { type: 'integer' }, total: { type: 'integer' }, totalPages: { type: 'integer' } } } } } } } } } }, post: { tags: ['动物管理'], summary: '创建新动物档案', description: '创建新的动物档案记录', requestBody: { required: true, content: { 'application/json': { schema: { type: 'object', required: ['earNumber', 'sex', 'varieties', 'cate', 'farmId'], properties: { earNumber: { type: 'string', description: '耳标号' }, sex: { type: 'integer', enum: [1, 2], description: '性别:1-公牛,2-母牛' }, strain: { type: 'string', description: '品系' }, varieties: { type: 'integer', description: '品种ID' }, cate: { type: 'integer', enum: [1, 2, 3, 4, 5, 6], description: '类别:1-犊牛,2-育成母牛,3-架子牛,4-青年牛,5-基础母牛,6-育肥牛' }, birthWeight: { type: 'number', description: '出生重量(kg)' }, birthday: { type: 'integer', description: '出生日期(时间戳)' }, farmId: { type: 'integer', description: '养殖场ID' }, penId: { type: 'integer', description: '栏舍ID' }, batchId: { type: 'integer', description: '批次ID' }, intoTime: { type: 'integer', description: '入场时间(时间戳)' }, parity: { type: 'integer', description: '胎次' }, source: { type: 'integer', enum: [1, 2, 3, 4, 5], description: '来源:1-合作社,2-农户,3-养殖场,4-进口,5-自繁' }, sourceDay: { type: 'integer', description: '来源日龄' }, sourceWeight: { type: 'number', description: '来源重量(kg)' }, weight: { type: 'number', description: '当前重量(kg)' }, algebra: { type: 'string', description: '代数' }, colour: { type: 'string', description: '毛色' }, descent: { type: 'string', description: '血统' }, imgs: { type: 'string', description: '图片URL(多个用逗号分隔)' } } } } } }, responses: { '201': { description: '创建成功', content: { 'application/json': { schema: { type: 'object', properties: { success: { type: 'boolean', example: true }, message: { type: 'string', example: '动物档案创建成功' }, data: { $ref: '#/components/schemas/Animal' } } } } } }, '400': { description: '请求参数错误', content: { 'application/json': { schema: { $ref: '#/components/schemas/ErrorResponse' } } } } } } }, // 公共动物数据 '/animals/public': { get: { tags: ['动物管理'], summary: '获取公共动物数据', description: '获取可公开访问的动物基本信息', security: [], // 公共接口不需要认证 responses: { '200': { description: '获取成功', content: { 'application/json': { schema: { type: 'object', properties: { success: { type: 'boolean', example: true }, data: { type: 'array', items: { type: 'object', properties: { id: { type: 'integer' }, earNumber: { type: 'string' }, sex: { type: 'integer' }, varieties: { type: 'integer' }, cate: { type: 'integer' }, weight: { type: 'number' }, isOut: { type: 'integer' } } } }, message: { type: 'string' } } } } } } } } }, // 获取动物绑定信息 '/animals/binding-info/{collarNumber}': { get: { tags: ['动物管理'], summary: '获取动物绑定信息', description: '根据项圈编号获取动物的详细绑定信息', parameters: [ { name: 'collarNumber', in: 'path', required: true, schema: { type: 'string' }, description: '项圈编号' } ], responses: { '200': { description: '获取成功', content: { 'application/json': { schema: { type: 'object', properties: { success: { type: 'boolean', example: true }, message: { type: 'string' }, data: { type: 'object', properties: { basicInfo: { type: 'object', properties: { collarNumber: { type: 'string', description: '项圈编号' }, category: { type: 'string', description: '动物类别' }, calvingCount: { type: 'integer', description: '产犊次数' }, earTag: { type: 'string', description: '耳标号' }, animalType: { type: 'string', description: '动物类型' }, breed: { type: 'string', description: '品种' }, sourceType: { type: 'string', description: '来源类型' } } }, birthInfo: { type: 'object', properties: { birthDate: { type: 'string', description: '出生日期' }, birthWeight: { type: 'string', description: '出生重量' }, weaningWeight: { type: 'string', description: '断奶重量' }, entryDate: { type: 'string', description: '入场日期' }, weaningAge: { type: 'integer', description: '断奶日龄' } } }, pedigreeInfo: { type: 'object', properties: { fatherId: { type: 'string', description: '父亲ID' }, motherId: { type: 'string', description: '母亲ID' }, grandfatherId: { type: 'string', description: '祖父ID' }, grandmotherId: { type: 'string', description: '祖母ID' }, bloodline: { type: 'string', description: '血统' }, generation: { type: 'string', description: '世代' } } }, insuranceInfo: { type: 'object', properties: { policyNumber: { type: 'string', description: '保单号' }, insuranceCompany: { type: 'string', description: '保险公司' }, coverageAmount: { type: 'string', description: '保额' }, premium: { type: 'string', description: '保费' }, startDate: { type: 'string', description: '开始日期' }, endDate: { type: 'string', description: '结束日期' }, status: { type: 'string', description: '保险状态' } } }, loanInfo: { type: 'object', properties: { loanNumber: { type: 'string', description: '贷款编号' }, bankName: { type: 'string', description: '银行名称' }, loanAmount: { type: 'string', description: '贷款金额' }, interestRate: { type: 'string', description: '利率' }, loanDate: { type: 'string', description: '放款日期' }, maturityDate: { type: 'string', description: '到期日期' }, status: { type: 'string', description: '贷款状态' } } }, deviceInfo: { type: 'object', properties: { deviceId: { type: 'integer', description: '设备ID' }, batteryLevel: { type: 'number', description: '电池电量' }, temperature: { type: 'number', description: '温度' }, status: { type: 'string', description: '设备状态' }, lastUpdate: { type: 'string', description: '最后更新时间' }, location: { type: 'string', description: '位置信息' } } }, farmInfo: { type: 'object', properties: { farmName: { type: 'string', description: '农场名称' }, farmAddress: { type: 'string', description: '农场地址' }, penName: { type: 'string', description: '栏舍名称' }, batchName: { type: 'string', description: '批次名称' } } } } } } } } } }, '404': { description: '未找到指定的动物或设备', content: { 'application/json': { schema: { $ref: '#/components/schemas/ErrorResponse' } } } } } } }, // 获取指定动物详情 '/animals/{id}': { get: { tags: ['动物管理'], summary: '获取动物详情', description: '根据动物ID获取详细信息', parameters: [ { name: 'id', in: 'path', required: true, schema: { type: 'integer' }, description: '动物ID' } ], responses: { '200': { description: '获取成功', content: { 'application/json': { schema: { type: 'object', properties: { success: { type: 'boolean', example: true }, data: { $ref: '#/components/schemas/Animal' } } } } } }, '404': { description: '动物不存在', content: { 'application/json': { schema: { $ref: '#/components/schemas/ErrorResponse' } } } } } }, put: { tags: ['动物管理'], summary: '更新动物信息', description: '更新指定动物的档案信息', parameters: [ { name: 'id', in: 'path', required: true, schema: { type: 'integer' }, description: '动物ID' } ], requestBody: { required: true, content: { 'application/json': { schema: { type: 'object', properties: { earNumber: { type: 'string', description: '耳标号' }, sex: { type: 'integer', enum: [1, 2], description: '性别' }, strain: { type: 'string', description: '品系' }, varieties: { type: 'integer', description: '品种ID' }, cate: { type: 'integer', enum: [1, 2, 3, 4, 5, 6], description: '类别' }, weight: { type: 'number', description: '当前重量(kg)' }, penId: { type: 'integer', description: '栏舍ID' }, batchId: { type: 'integer', description: '批次ID' }, event: { type: 'string', description: '事件记录' }, eventTime: { type: 'integer', description: '事件时间(时间戳)' }, isVaccin: { type: 'integer', enum: [0, 1], description: '是否疫苗' }, isInsemination: { type: 'integer', enum: [0, 1], description: '是否配种' }, isInsure: { type: 'integer', enum: [0, 1], description: '是否保险' }, isMortgage: { type: 'integer', enum: [0, 1], description: '是否抵押' } } } } } }, responses: { '200': { description: '更新成功', content: { 'application/json': { schema: { type: 'object', properties: { success: { type: 'boolean', example: true }, message: { type: 'string', example: '动物信息更新成功' }, data: { $ref: '#/components/schemas/Animal' } } } } } }, '400': { description: '请求参数错误', content: { 'application/json': { schema: { $ref: '#/components/schemas/ErrorResponse' } } } }, '404': { description: '动物不存在', content: { 'application/json': { schema: { $ref: '#/components/schemas/ErrorResponse' } } } } } }, delete: { tags: ['动物管理'], summary: '删除动物档案', description: '删除指定动物档案(软删除)', parameters: [ { name: 'id', in: 'path', required: true, schema: { type: 'integer' }, description: '动物ID' } ], responses: { '200': { description: '删除成功', content: { 'application/json': { schema: { type: 'object', properties: { success: { type: 'boolean', example: true }, message: { type: 'string', example: '动物档案删除成功' } } } } } }, '404': { description: '动物不存在', content: { 'application/json': { schema: { $ref: '#/components/schemas/ErrorResponse' } } } } } } }, // 动物健康记录 '/animals/{id}/health': { get: { tags: ['动物管理'], summary: '获取动物健康记录', description: '获取指定动物的健康记录', parameters: [ { name: 'id', in: 'path', required: true, schema: { type: 'integer' }, description: '动物ID' } ], responses: { '200': { description: '获取成功', content: { 'application/json': { schema: { type: 'object', properties: { success: { type: 'boolean', example: true }, data: { type: 'array', items: { type: 'object', properties: { id: { type: 'integer' }, animalId: { type: 'integer' }, checkDate: { type: 'string', format: 'date' }, temperature: { type: 'number' }, weight: { type: 'number' }, healthStatus: { type: 'string' }, symptoms: { type: 'string' }, treatment: { type: 'string' }, veterinarian: { type: 'string' }, notes: { type: 'string' } } } } } } } } } } }, post: { tags: ['动物管理'], summary: '添加动物健康记录', description: '为指定动物添加健康检查记录', parameters: [ { name: 'id', in: 'path', required: true, schema: { type: 'integer' }, description: '动物ID' } ], requestBody: { required: true, content: { 'application/json': { schema: { type: 'object', required: ['checkDate', 'healthStatus'], properties: { checkDate: { type: 'string', format: 'date', description: '检查日期' }, temperature: { type: 'number', description: '体温' }, weight: { type: 'number', description: '体重' }, healthStatus: { type: 'string', enum: ['healthy', 'sick', 'recovering', 'quarantine'], description: '健康状态' }, symptoms: { type: 'string', description: '症状描述' }, treatment: { type: 'string', description: '治疗方案' }, veterinarian: { type: 'string', description: '兽医姓名' }, notes: { type: 'string', description: '备注' } } } } } }, responses: { '201': { description: '添加成功', content: { 'application/json': { schema: { type: 'object', properties: { success: { type: 'boolean', example: true }, message: { type: 'string', example: '健康记录添加成功' } } } } } } } } }, // 动物繁殖记录 '/animals/{id}/breeding': { get: { tags: ['动物管理'], summary: '获取动物繁殖记录', description: '获取指定动物的繁殖记录', parameters: [ { name: 'id', in: 'path', required: true, schema: { type: 'integer' }, description: '动物ID' } ], responses: { '200': { description: '获取成功', content: { 'application/json': { schema: { type: 'object', properties: { success: { type: 'boolean', example: true }, data: { type: 'array', items: { type: 'object', properties: { id: { type: 'integer' }, animalId: { type: 'integer' }, breedingDate: { type: 'string', format: 'date' }, matingType: { type: 'string', enum: ['natural', 'artificial'] }, sireId: { type: 'integer' }, expectedCalvingDate: { type: 'string', format: 'date' }, actualCalvingDate: { type: 'string', format: 'date' }, calvingResult: { type: 'string' }, offspringCount: { type: 'integer' }, notes: { type: 'string' } } } } } } } } } } } } }; // 动物数据模型 const animalSchemas = { Animal: { type: 'object', properties: { id: { type: 'integer', description: '动物ID' }, orgId: { type: 'integer', description: '组织ID' }, earNumber: { type: 'string', description: '耳标号' }, sex: { type: 'integer', enum: [1, 2], description: '性别:1-公牛,2-母牛' }, strain: { type: 'string', description: '品系' }, varieties: { type: 'integer', description: '品种ID' }, cate: { type: 'integer', enum: [1, 2, 3, 4, 5, 6], description: '类别:1-犊牛,2-育成母牛,3-架子牛,4-青年牛,5-基础母牛,6-育肥牛' }, birthWeight: { type: 'number', description: '出生重量(kg)' }, birthday: { type: 'integer', description: '出生日期(时间戳)' }, penId: { type: 'integer', description: '栏舍ID' }, intoTime: { type: 'integer', description: '入场时间(时间戳)' }, parity: { type: 'integer', description: '胎次' }, source: { type: 'integer', enum: [1, 2, 3, 4, 5], description: '来源:1-合作社,2-农户,3-养殖场,4-进口,5-自繁' }, sourceDay: { type: 'integer', description: '来源日龄' }, sourceWeight: { type: 'number', description: '来源重量(kg)' }, weight: { type: 'number', description: '当前重量(kg)' }, event: { type: 'string', description: '事件记录' }, eventTime: { type: 'integer', description: '事件时间(时间戳)' }, lactationDay: { type: 'integer', description: '泌乳天数' }, semenNum: { type: 'string', description: '精液编号' }, isWear: { type: 'integer', enum: [0, 1], description: '是否佩戴设备' }, batchId: { type: 'integer', description: '批次ID' }, imgs: { type: 'string', description: '图片URL(多个用逗号分隔)' }, isEleAuth: { type: 'integer', enum: [0, 1], description: '是否电子认证' }, isQuaAuth: { type: 'integer', enum: [0, 1], description: '是否质量认证' }, isDelete: { type: 'integer', enum: [0, 1], description: '是否删除' }, isOut: { type: 'integer', enum: [0, 1], description: '是否出栏' }, createUid: { type: 'integer', description: '创建用户ID' }, createTime: { type: 'integer', description: '创建时间(时间戳)' }, algebra: { type: 'string', description: '代数' }, colour: { type: 'string', description: '毛色' }, infoWeight: { type: 'number', description: '信息重量' }, descent: { type: 'string', description: '血统' }, isVaccin: { type: 'integer', enum: [0, 1], description: '是否疫苗' }, isInsemination: { type: 'integer', enum: [0, 1], description: '是否配种' }, isInsure: { type: 'integer', enum: [0, 1], description: '是否保险' }, isMortgage: { type: 'integer', enum: [0, 1], description: '是否抵押' }, updateTime: { type: 'integer', description: '更新时间(时间戳)' }, breedBullTime: { type: 'integer', description: '配种时间(时间戳)' }, level: { type: 'string', description: '等级' }, sixWeight: { type: 'number', description: '6月龄重量' }, eighteenWeight: { type: 'number', description: '18月龄重量' }, twelveDayWeight: { type: 'number', description: '12日龄重量' }, eighteenDayWeight: { type: 'number', description: '18日龄重量' }, xxivDayWeight: { type: 'number', description: '24日龄重量' }, semenBreedImgs: { type: 'string', description: '配种图片' }, sellStatus: { type: 'integer', description: '销售状态' }, weightCalculateTime: { type: 'integer', description: '重量计算时间' }, dayOfBirthday: { type: 'integer', description: '出生天数' }, userId: { type: 'integer', description: '用户ID' } } } }; module.exports = { animalsPaths, animalSchemas };