|
|
@ -6,11 +6,11 @@ class EnvironmentService { |
|
|
|
async getEnvironmentByCoopId(house_id, coop_id) { |
|
|
|
// 目前没有栋舍概念 暂且注释,取平均值
|
|
|
|
const res = await Environment.findAll({ |
|
|
|
// where: {
|
|
|
|
// coop_id,
|
|
|
|
// house_id,
|
|
|
|
// },
|
|
|
|
// order: [["log_time", "DESC"]],
|
|
|
|
where: { |
|
|
|
coop_id, |
|
|
|
house_id, |
|
|
|
}, |
|
|
|
order: [["log_time", "DESC"]], |
|
|
|
}); |
|
|
|
const arr = res.map((item) => item.dataValues); |
|
|
|
if (arr && arr.length > 0) { |
|
|
@ -66,8 +66,8 @@ class EnvironmentService { |
|
|
|
|
|
|
|
async getEnvironmentHistoryList(house_id, coop_id, time_id, indicator_id) { |
|
|
|
let whereObj = { |
|
|
|
// house_id,
|
|
|
|
// coop_id,
|
|
|
|
house_id, |
|
|
|
coop_id, |
|
|
|
}; |
|
|
|
// 需要根据id进行筛选 7天、全部、24小时
|
|
|
|
if (time_id == "1") { |
|
|
@ -249,15 +249,15 @@ class EnvironmentService { |
|
|
|
} |
|
|
|
|
|
|
|
// 因为目前设备并没有鸡场、鸡舍相关概念 默认为0,没有的数据默认为0
|
|
|
|
async reportEnvironmentData(env, positionM, log_time) { |
|
|
|
async reportEnvironmentData(env, positionM, log_time, coop_id, house_id) { |
|
|
|
// position_index, positionM, log_time;
|
|
|
|
if (!env) { |
|
|
|
return; |
|
|
|
} |
|
|
|
const p = env.map(async (item) => { |
|
|
|
const res = await Environment.create({ |
|
|
|
house_id: 0, |
|
|
|
coop_id: 0, |
|
|
|
coop_id: parseInt(coop_id), |
|
|
|
house_id: parseInt(house_id), |
|
|
|
temperature: item.temperature, |
|
|
|
humidity: item.humidity, |
|
|
|
co2: item.co2, |
|
|
@ -274,6 +274,13 @@ class EnvironmentService { |
|
|
|
const real = await Promise.all(p); |
|
|
|
return real; |
|
|
|
} |
|
|
|
|
|
|
|
// 获取环境实时监测数据
|
|
|
|
async getRealTimeData(plies_number) { |
|
|
|
const res = await Environment.findAll(); |
|
|
|
const arr = res?.map((item) => item.dataValues); |
|
|
|
return arr; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
module.exports = new EnvironmentService(); |