Browse Source

update

master
maochaoying 2 years ago
parent
commit
4a1890ba40
  1. 23
      src/service/die.service.js

23
src/service/die.service.js

@ -26,13 +26,18 @@ class DieService {
// 需要根据鸡舍编号和批次号进行模糊查询 // 需要根据鸡舍编号和批次号进行模糊查询
async getAllDieInfo(house_id, coop_ids = [], batch_number = "") { async getAllDieInfo(house_id, coop_ids = [], batch_number = "") {
const res = await Die.findAll({
where: {
house_id,
let whereObj = {
house_id,
};
coop_ids &&
coop_ids.length > 0 &&
Object.assign(whereObj, {
coop_id: { coop_id: {
[Op.in]: coop_ids, [Op.in]: coop_ids,
}, },
},
});
const res = await Die.findAll({
where: whereObj,
}); });
const arr = res?.map((item) => item.dataValues); const arr = res?.map((item) => item.dataValues);
// 对arr中的数据进行处理 // 对arr中的数据进行处理
@ -60,8 +65,8 @@ class DieService {
item.house_id item.house_id
); );
const coopInfo = await getCoopById(item.coop_id); const coopInfo = await getCoopById(item.coop_id);
item.batch_number = chickenInfo.batch_number;
item.coop_name = coopInfo.coop_name;
item.batch_number = chickenInfo?.batch_number;
item.coop_name = coopInfo?.coop_name;
return item; return item;
}); });
const hasBatch = await Promise.all(p); const hasBatch = await Promise.all(p);
@ -70,7 +75,11 @@ class DieService {
if (batch_number == "") { if (batch_number == "") {
return true; return true;
} else { } else {
return item.batch_number.indexOf(batch_number) != -1;
if (item.batch_number) {
return item.batch_number?.indexOf(batch_number) != -1;
} else {
return false;
}
} }
}); });
return result; return result;

Loading…
Cancel
Save