|
|
@ -1,10 +1,69 @@ |
|
|
|
const Control = require("../model/control.model"); |
|
|
|
const Chicken = require("../model/chicken.model"); |
|
|
|
const Device = require("../model/device.model"); |
|
|
|
const Coop = require("../model/coop.model"); |
|
|
|
const { Op, Sequelize } = require("sequelize"); |
|
|
|
const { getCoopListById } = require("./coop.service"); |
|
|
|
class ControlService { |
|
|
|
async getSettingByCoopId(coop_id) { |
|
|
|
return null; |
|
|
|
async getSettingByCoopId(house_id, coop_id) { |
|
|
|
const res = await Control.findOne({ |
|
|
|
where: { |
|
|
|
house_id, |
|
|
|
coop_id, |
|
|
|
}, |
|
|
|
}); |
|
|
|
return res ? res.dataValues : null; |
|
|
|
} |
|
|
|
|
|
|
|
async getControlInfoList(house_id, batch_number = "", coop_ids) { |
|
|
|
const res = await getCoopListById(house_id); |
|
|
|
// 查询该舍的环控信息
|
|
|
|
const p = res.map(async (item) => { |
|
|
|
const coop_id = item.id; |
|
|
|
const controlInfo = await Control.findOne({ |
|
|
|
where: { |
|
|
|
house_id, |
|
|
|
coop_id, |
|
|
|
}, |
|
|
|
}); |
|
|
|
item.controlInfo = controlInfo; |
|
|
|
// 设备信息
|
|
|
|
const deviceInfo = await Device.findOne({ |
|
|
|
where: { |
|
|
|
house_id, |
|
|
|
coop_id, |
|
|
|
}, |
|
|
|
}); |
|
|
|
item.deviceInfo = deviceInfo; |
|
|
|
// 查询批次号和日龄
|
|
|
|
const allChickenInfo = await Chicken.findAll({ |
|
|
|
where: { |
|
|
|
coop_id: { |
|
|
|
[Op.like]: `%${coop_id}%`, |
|
|
|
}, |
|
|
|
batch_number: { |
|
|
|
[Op.like]: `%${batch_number}%`, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}); |
|
|
|
const singleArr = allChickenInfo?.filter((item) => |
|
|
|
item.dataValues?.coop_id?.split(",").includes(coop_id + "") |
|
|
|
); |
|
|
|
if (singleArr && singleArr.length > 0) { |
|
|
|
item.chickenInfo = singleArr[0]; |
|
|
|
} |
|
|
|
return item; |
|
|
|
}); |
|
|
|
let real = await Promise.all(p); |
|
|
|
if (coop_ids) { |
|
|
|
const a = real.filter((item) => item.id == coop_ids); |
|
|
|
return a; |
|
|
|
} |
|
|
|
return real; |
|
|
|
} |
|
|
|
|
|
|
|
async changeSetting( |
|
|
|
house_id, |
|
|
|
coop_id, |
|
|
|
temperature_start, |
|
|
|
temperature_end, |
|
|
|