|
|
@ -232,6 +232,58 @@ class EnvironmentService { |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
// 因为目前设备并没有鸡场、鸡舍相关概念 默认为0,没有的数据默认为0
|
|
|
|
async reportEnvironmentData(env, positionM, log_time) { |
|
|
|
// position_index, positionM, log_time;
|
|
|
|
if (!env) { |
|
|
|
return; |
|
|
|
} |
|
|
|
const p = env.map(async (item) => { |
|
|
|
// 首先查询 position_index positionM 有没有数据 有则更新 无则创建
|
|
|
|
const envInfo = await Environment.findOne({ |
|
|
|
where: { |
|
|
|
position_index: item.position_index, |
|
|
|
positionM, |
|
|
|
}, |
|
|
|
}); |
|
|
|
if (envInfo) { |
|
|
|
const res = await Environment.update( |
|
|
|
{ |
|
|
|
temperature: item.temperature, |
|
|
|
humidity: item.humidity, |
|
|
|
co2: item.co2, |
|
|
|
log_time, |
|
|
|
}, |
|
|
|
{ |
|
|
|
where: { |
|
|
|
position_index: item.position_index, |
|
|
|
positionM, |
|
|
|
}, |
|
|
|
} |
|
|
|
); |
|
|
|
return res; |
|
|
|
} else { |
|
|
|
const res = await Environment.create({ |
|
|
|
house_id: 0, |
|
|
|
coop_id: 0, |
|
|
|
temperature: item.temperature, |
|
|
|
humidity: item.humidity, |
|
|
|
co2: item.co2, |
|
|
|
nh3: 0, |
|
|
|
illumination: 0, |
|
|
|
wind_speed: 0, |
|
|
|
h2s: 0, |
|
|
|
position_index: item.position_index, |
|
|
|
positionM, |
|
|
|
log_time, |
|
|
|
}); |
|
|
|
return res; |
|
|
|
} |
|
|
|
}); |
|
|
|
const real = await Promise.all(p); |
|
|
|
return real; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
module.exports = new EnvironmentService(); |