|
@ -21,9 +21,9 @@ class EnvironmentService { |
|
|
let humidityTotal = 0; |
|
|
let humidityTotal = 0; |
|
|
let co2Total = 0; |
|
|
let co2Total = 0; |
|
|
arr.map((i) => { |
|
|
arr.map((i) => { |
|
|
tempTotal += parseInt(i.temperature); |
|
|
|
|
|
humidityTotal += parseInt(i.humidity); |
|
|
|
|
|
co2Total += parseInt(i.co2); |
|
|
|
|
|
|
|
|
tempTotal += parseFloat(i.temperature); |
|
|
|
|
|
humidityTotal += parseFloat(i.humidity); |
|
|
|
|
|
co2Total += parseFloat(i.co2); |
|
|
}); |
|
|
}); |
|
|
return { |
|
|
return { |
|
|
...arr[0], |
|
|
...arr[0], |
|
@ -126,13 +126,13 @@ class EnvironmentService { |
|
|
let windSpeedTotal = 0; |
|
|
let windSpeedTotal = 0; |
|
|
let h2sTotal = 0; |
|
|
let h2sTotal = 0; |
|
|
item.map((i) => { |
|
|
item.map((i) => { |
|
|
tempTotal += parseInt(i.temperature); |
|
|
|
|
|
humidityTotal += parseInt(i.humidity); |
|
|
|
|
|
co2Total += parseInt(i.co2); |
|
|
|
|
|
nh3Total += parseInt(i.nh3); |
|
|
|
|
|
illuminationTotal += parseInt(i.illumination); |
|
|
|
|
|
windSpeedTotal += parseInt(i.wind_speed); |
|
|
|
|
|
h2sTotal += parseInt(i.h2s); |
|
|
|
|
|
|
|
|
tempTotal += parseFloat(i.temperature); |
|
|
|
|
|
humidityTotal += parseFloat(i.humidity); |
|
|
|
|
|
co2Total += parseFloat(i.co2); |
|
|
|
|
|
nh3Total += parseFloat(i.nh3); |
|
|
|
|
|
illuminationTotal += parseFloat(i.illumination); |
|
|
|
|
|
windSpeedTotal += parseFloat(i.wind_speed); |
|
|
|
|
|
h2sTotal += parseFloat(i.h2s); |
|
|
}); |
|
|
}); |
|
|
dataObj.push({ |
|
|
dataObj.push({ |
|
|
temperature: (tempTotal / len).toFixed(2), |
|
|
temperature: (tempTotal / len).toFixed(2), |
|
@ -177,13 +177,13 @@ class EnvironmentService { |
|
|
let windSpeedTotal = 0; |
|
|
let windSpeedTotal = 0; |
|
|
let h2sTotal = 0; |
|
|
let h2sTotal = 0; |
|
|
item.map((i) => { |
|
|
item.map((i) => { |
|
|
tempTotal += parseInt(i.temperature); |
|
|
|
|
|
humidityTotal += parseInt(i.humidity); |
|
|
|
|
|
co2Total += parseInt(i.co2); |
|
|
|
|
|
nh3Total += parseInt(i.nh3); |
|
|
|
|
|
illuminationTotal += parseInt(i.illumination); |
|
|
|
|
|
windSpeedTotal += parseInt(i.wind_speed); |
|
|
|
|
|
h2sTotal += parseInt(i.h2s); |
|
|
|
|
|
|
|
|
tempTotal += parseFloat(i.temperature); |
|
|
|
|
|
humidityTotal += parseFloat(i.humidity); |
|
|
|
|
|
co2Total += parseFloat(i.co2); |
|
|
|
|
|
nh3Total += parseFloat(i.nh3); |
|
|
|
|
|
illuminationTotal += parseFloat(i.illumination); |
|
|
|
|
|
windSpeedTotal += parseFloat(i.wind_speed); |
|
|
|
|
|
h2sTotal += parseFloat(i.h2s); |
|
|
}); |
|
|
}); |
|
|
dataObj.push({ |
|
|
dataObj.push({ |
|
|
temperature: (tempTotal / len).toFixed(2), |
|
|
temperature: (tempTotal / len).toFixed(2), |
|
@ -252,6 +252,7 @@ class EnvironmentService { |
|
|
|
|
|
|
|
|
// 因为目前设备并没有鸡场、鸡舍相关概念 默认为0,没有的数据默认为0
|
|
|
// 因为目前设备并没有鸡场、鸡舍相关概念 默认为0,没有的数据默认为0
|
|
|
async reportEnvironmentData(env, positionM, log_time, henhouseId, farmId) { |
|
|
async reportEnvironmentData(env, positionM, log_time, henhouseId, farmId) { |
|
|
|
|
|
try { |
|
|
// 根据uuid查询各自的id
|
|
|
// 根据uuid查询各自的id
|
|
|
const coopInfo = await getCoopIdByUUID(henhouseId); |
|
|
const coopInfo = await getCoopIdByUUID(henhouseId); |
|
|
const houseInfo = await getHouseIdByUUID(farmId); |
|
|
const houseInfo = await getHouseIdByUUID(farmId); |
|
@ -261,6 +262,7 @@ class EnvironmentService { |
|
|
} |
|
|
} |
|
|
const p = env.map(async (item) => { |
|
|
const p = env.map(async (item) => { |
|
|
// 查询传过来的coop_id和house_id
|
|
|
// 查询传过来的coop_id和house_id
|
|
|
|
|
|
if (item.layerIndex && item.lineIndex) { |
|
|
const res = await Environment.create({ |
|
|
const res = await Environment.create({ |
|
|
coop_id: coopInfo.id, |
|
|
coop_id: coopInfo.id, |
|
|
house_id: houseInfo.id, |
|
|
house_id: houseInfo.id, |
|
@ -272,15 +274,19 @@ class EnvironmentService { |
|
|
wind_speed: 0, |
|
|
wind_speed: 0, |
|
|
h2s: 0, |
|
|
h2s: 0, |
|
|
position_index: item.position_index, |
|
|
position_index: item.position_index, |
|
|
layer_index: item.layer_index, |
|
|
|
|
|
line_index: item.line_index, |
|
|
|
|
|
|
|
|
layer_index: item.layerIndex, |
|
|
|
|
|
line_index: item.lineIndex, |
|
|
positionM, |
|
|
positionM, |
|
|
log_time, |
|
|
log_time, |
|
|
}); |
|
|
}); |
|
|
return res; |
|
|
return res; |
|
|
|
|
|
} |
|
|
}); |
|
|
}); |
|
|
const real = await Promise.all(p); |
|
|
const real = await Promise.all(p); |
|
|
return real; |
|
|
return real; |
|
|
|
|
|
} catch (error) { |
|
|
|
|
|
console.log(error); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 获取环境实时监测数据
|
|
|
// 获取环境实时监测数据
|
|
|