优化项目bug
This commit is contained in:
@@ -24,15 +24,15 @@ const calculateAgeInMonths = (birthday) => {
|
||||
};
|
||||
|
||||
/**
|
||||
* 类别中文映射
|
||||
* 类别中文映射(与前端保持一致)
|
||||
*/
|
||||
const getCategoryName = (cate) => {
|
||||
const categoryMap = {
|
||||
1: '犊牛',
|
||||
2: '繁殖牛',
|
||||
3: '基础母牛',
|
||||
4: '隔离牛',
|
||||
5: '治疗牛',
|
||||
2: '育成母牛',
|
||||
3: '架子牛',
|
||||
4: '青年牛',
|
||||
5: '基础母牛',
|
||||
6: '育肥牛'
|
||||
};
|
||||
return categoryMap[cate] || '未知';
|
||||
@@ -128,10 +128,20 @@ class IotCattleController {
|
||||
|
||||
// 搜索条件
|
||||
if (search) {
|
||||
whereConditions[Op.or] = [
|
||||
{ earNumber: { [Op.like]: `%${search}%` } },
|
||||
{ strain: { [Op.like]: `%${search}%` } }
|
||||
];
|
||||
// 尝试将搜索词转换为数字,如果成功则按数字搜索,否则按字符串搜索
|
||||
const searchNumber = parseInt(search);
|
||||
if (!isNaN(searchNumber)) {
|
||||
// 数字搜索:精确匹配耳号
|
||||
whereConditions[Op.or] = [
|
||||
{ earNumber: searchNumber },
|
||||
{ strain: { [Op.like]: `%${search}%` } }
|
||||
];
|
||||
} else {
|
||||
// 字符串搜索:模糊匹配
|
||||
whereConditions[Op.or] = [
|
||||
{ strain: { [Op.like]: `%${search}%` } }
|
||||
];
|
||||
}
|
||||
console.log('=== 搜索条件构建 ===');
|
||||
console.log('搜索关键词:', search);
|
||||
console.log('搜索条件对象:', JSON.stringify(whereConditions, null, 2));
|
||||
@@ -159,16 +169,13 @@ class IotCattleController {
|
||||
console.log('完整查询条件:', JSON.stringify(whereConditions, null, 2));
|
||||
console.log('分页参数:', { offset, limit: pageSize });
|
||||
|
||||
// 先获取总数(严格查询未删除的记录)
|
||||
// 先获取总数
|
||||
console.log('=== 开始数据库查询 ===');
|
||||
console.log('查询时间:', new Date().toISOString());
|
||||
|
||||
const countStartTime = Date.now();
|
||||
const totalCount = await IotCattle.count({
|
||||
where: {
|
||||
...whereConditions,
|
||||
isDelete: 0 // 确保只统计未删除的记录
|
||||
}
|
||||
where: whereConditions
|
||||
});
|
||||
const countEndTime = Date.now();
|
||||
|
||||
@@ -176,13 +183,10 @@ class IotCattleController {
|
||||
console.log('查询耗时:', countEndTime - countStartTime, 'ms');
|
||||
console.log('总记录数:', totalCount);
|
||||
|
||||
// 获取分页数据(严格查询未删除的记录)
|
||||
// 获取分页数据
|
||||
const dataStartTime = Date.now();
|
||||
const rows = await IotCattle.findAll({
|
||||
where: {
|
||||
...whereConditions,
|
||||
isDelete: 0 // 确保只查询未删除的记录
|
||||
},
|
||||
where: whereConditions,
|
||||
attributes: [
|
||||
'id', 'earNumber', 'sex', 'strain', 'varieties', 'cate',
|
||||
'birthWeight', 'birthday', 'penId', 'batchId', 'orgId',
|
||||
|
||||
Reference in New Issue
Block a user