优化项目bug
This commit is contained in:
@@ -5,6 +5,7 @@ const express = require('express');
|
||||
const router = express.Router();
|
||||
const { Op } = require('sequelize');
|
||||
const Animal = require('../models/Animal');
|
||||
const CattleType = require('../models/CattleType');
|
||||
const { verifyToken, requirePermission } = require('../middleware/auth');
|
||||
|
||||
// 公开路由,不需要认证
|
||||
@@ -112,17 +113,66 @@ router.get('/binding-info/:collarNumber', async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
// 类别映射函数(与前端保持一致)
|
||||
const getCategoryName = (cate) => {
|
||||
const categoryMap = {
|
||||
1: '犊牛',
|
||||
2: '育成母牛',
|
||||
3: '架子牛',
|
||||
4: '青年牛',
|
||||
5: '基础母牛',
|
||||
6: '育肥牛'
|
||||
};
|
||||
return categoryMap[cate] || '未知';
|
||||
};
|
||||
|
||||
// 性别映射函数
|
||||
const getSexName = (sex) => {
|
||||
const sexMap = {
|
||||
1: '公牛',
|
||||
2: '母牛'
|
||||
};
|
||||
return sexMap[sex] || '未知';
|
||||
};
|
||||
|
||||
// 来源类型映射函数
|
||||
const getSourceTypeName = (source) => {
|
||||
const sourceMap = {
|
||||
1: '合作社',
|
||||
2: '农户',
|
||||
3: '养殖场',
|
||||
4: '进口',
|
||||
5: '自繁'
|
||||
};
|
||||
return sourceMap[source] || '未知';
|
||||
};
|
||||
|
||||
// 动态查询品种名称
|
||||
const getBreedName = async (varieties) => {
|
||||
if (!varieties) return '未知品种';
|
||||
|
||||
try {
|
||||
const breed = await CattleType.findByPk(varieties, {
|
||||
attributes: ['id', 'name']
|
||||
});
|
||||
return breed ? breed.name : '未知品种';
|
||||
} catch (error) {
|
||||
console.error('查询品种信息失败:', error);
|
||||
return '未知品种';
|
||||
}
|
||||
};
|
||||
|
||||
// 格式化数据以匹配前端UI需求
|
||||
const bindingInfo = {
|
||||
// 基础信息
|
||||
basicInfo: {
|
||||
collarNumber: jbqDevice.cid,
|
||||
category: cattleInfo.cate || '奶牛',
|
||||
category: getCategoryName(cattleInfo.cate),
|
||||
calvingCount: cattleInfo.parity || 0,
|
||||
earTag: cattleInfo.earNumber,
|
||||
animalType: cattleInfo.sex === 1 ? '公牛' : cattleInfo.sex === 2 ? '母牛' : '未知',
|
||||
breed: cattleInfo.varieties || '荷斯坦',
|
||||
sourceType: cattleInfo.source || '自繁'
|
||||
animalType: getSexName(cattleInfo.sex),
|
||||
breed: await getBreedName(cattleInfo.varieties), // 使用动态查询品种名称
|
||||
sourceType: getSourceTypeName(cattleInfo.source)
|
||||
},
|
||||
// 出生信息
|
||||
birthInfo: {
|
||||
|
||||
@@ -25,8 +25,9 @@ publicRoutes.get('/eartags/export', async (req, res) => {
|
||||
// 搜索条件
|
||||
if (search) {
|
||||
whereConditions[Op.or] = [
|
||||
{ sn: { [Op.like]: `%${search}%` } },
|
||||
{ deviceId: { [Op.like]: `%${search}%` } }
|
||||
{ aaid: { [Op.like]: `%${search}%` } },
|
||||
{ cid: { [Op.like]: `%${search}%` } },
|
||||
{ sid: { [Op.like]: `%${search}%` } }
|
||||
];
|
||||
}
|
||||
|
||||
@@ -128,8 +129,9 @@ publicRoutes.get('/eartags', async (req, res) => {
|
||||
// 搜索条件
|
||||
if (search) {
|
||||
whereConditions[Op.or] = [
|
||||
{ sn: { [Op.like]: `%${search}%` } },
|
||||
{ deviceId: { [Op.like]: `%${search}%` } }
|
||||
{ aaid: { [Op.like]: `%${search}%` } },
|
||||
{ cid: { [Op.like]: `%${search}%` } },
|
||||
{ sid: { [Op.like]: `%${search}%` } }
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user