|
|
@ -116,36 +116,17 @@ class CoopService { |
|
|
|
|
|
|
|
// 查询空闲鸡舍
|
|
|
|
// 没有进鸡记录的
|
|
|
|
// 目前鸡舍新增字段is_empty进行判断即可。
|
|
|
|
async getEmptyCoopList(house_id) { |
|
|
|
const res = await Coop.findAll({ |
|
|
|
where: { |
|
|
|
house_id, |
|
|
|
is_empty: 1, |
|
|
|
}, |
|
|
|
}); |
|
|
|
const arr = res.map((item) => item.dataValues); |
|
|
|
const coopidArr = res?.map((item) => item.dataValues.id); |
|
|
|
// 筛选arr
|
|
|
|
const chickenList = await Chicken.findAll({ |
|
|
|
where: { |
|
|
|
house_id, |
|
|
|
is_marketed: 0, |
|
|
|
}, |
|
|
|
}); |
|
|
|
const chickArr = chickenList.map((item) => item.dataValues.coop_id); |
|
|
|
// 找到两个数组的非交集
|
|
|
|
const flat = chickArr |
|
|
|
.map((item) => item.split(",")) |
|
|
|
.flat() |
|
|
|
.map((item) => parseInt(item)); |
|
|
|
const resIds = findDiffArr(coopidArr, flat); |
|
|
|
let realRes = []; |
|
|
|
arr.map((item) => { |
|
|
|
if (resIds.includes(item.id)) { |
|
|
|
realRes.push(item); |
|
|
|
} |
|
|
|
}); |
|
|
|
// realRes 即为空闲 鸡舍
|
|
|
|
return realRes; |
|
|
|
return arr; |
|
|
|
} |
|
|
|
|
|
|
|
async getCoopNumbyHouseId(house_id) { |
|
|
@ -156,6 +137,23 @@ class CoopService { |
|
|
|
}); |
|
|
|
return res; |
|
|
|
} |
|
|
|
|
|
|
|
// 获得几个鸡舍的最大容纳量
|
|
|
|
async getMaxChickenNumByIds(coop_ids) { |
|
|
|
const res = await Coop.findAll({ |
|
|
|
where: { |
|
|
|
id: { |
|
|
|
[Op.in]: coop_ids, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}); |
|
|
|
const arr = res.map((item) => item.dataValues); |
|
|
|
let total = 0; |
|
|
|
arr.map((item) => { |
|
|
|
total += item.coop_cage_number * item.chicken_number; |
|
|
|
}); |
|
|
|
return total; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
module.exports = new CoopService(); |