|
@ -1,6 +1,7 @@ |
|
|
const { Op } = require("sequelize"); |
|
|
const { Op } = require("sequelize"); |
|
|
const Chicken = require("../model/chicken.model.js"); |
|
|
const Chicken = require("../model/chicken.model.js"); |
|
|
const Coop = require("../model/coop.model"); |
|
|
const Coop = require("../model/coop.model"); |
|
|
|
|
|
const { findDiffArr } = require("../utils/common"); |
|
|
const { getHouseById } = require("./house.service"); |
|
|
const { getHouseById } = require("./house.service"); |
|
|
class CoopService { |
|
|
class CoopService { |
|
|
async getCoopListById(house_id) { |
|
|
async getCoopListById(house_id) { |
|
@ -95,6 +96,39 @@ class CoopService { |
|
|
}); |
|
|
}); |
|
|
return res; |
|
|
return res; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 查询空闲鸡舍
|
|
|
|
|
|
// 没有进鸡记录的
|
|
|
|
|
|
async getEmptyCoopList(house_id) { |
|
|
|
|
|
const res = await Coop.findAll({ |
|
|
|
|
|
where: { |
|
|
|
|
|
house_id, |
|
|
|
|
|
}, |
|
|
|
|
|
}); |
|
|
|
|
|
const arr = res.map((item) => item.dataValues); |
|
|
|
|
|
const coopidArr = res?.map((item) => item.dataValues.id); |
|
|
|
|
|
// 筛选arr
|
|
|
|
|
|
const chickenList = await Chicken.findAll({ |
|
|
|
|
|
where: { |
|
|
|
|
|
house_id, |
|
|
|
|
|
}, |
|
|
|
|
|
}); |
|
|
|
|
|
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; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
module.exports = new CoopService(); |
|
|
module.exports = new CoopService(); |