|
|
@ -1,4 +1,6 @@ |
|
|
|
const Environment = require("../model/environment.model"); |
|
|
|
const { getCoopIdByUUID } = require("./coop.service"); |
|
|
|
const { getHouseIdByUUID } = require("./house.service"); |
|
|
|
const { isIntTime } = require("../utils/common"); |
|
|
|
const moment = require("moment"); |
|
|
|
const { Op } = require("sequelize"); |
|
|
@ -249,15 +251,19 @@ class EnvironmentService { |
|
|
|
} |
|
|
|
|
|
|
|
// 因为目前设备并没有鸡场、鸡舍相关概念 默认为0,没有的数据默认为0
|
|
|
|
async reportEnvironmentData(env, positionM, log_time, coop_id, house_id) { |
|
|
|
async reportEnvironmentData(env, positionM, log_time, henhouseId, farmId) { |
|
|
|
// 根据uuid查询各自的id
|
|
|
|
const coopInfo = await getCoopIdByUUID(henhouseId); |
|
|
|
const houseInfo = await getHouseIdByUUID(farmId); |
|
|
|
// position_index, positionM, log_time;
|
|
|
|
if (!env) { |
|
|
|
if (!env || !coopInfo || !houseInfo) { |
|
|
|
return; |
|
|
|
} |
|
|
|
const p = env.map(async (item) => { |
|
|
|
// 查询传过来的coop_id和house_id
|
|
|
|
const res = await Environment.create({ |
|
|
|
coop_id: parseInt(coop_id), |
|
|
|
house_id: parseInt(house_id), |
|
|
|
coop_id: coopInfo.id, |
|
|
|
house_id: houseInfo.id, |
|
|
|
temperature: item.temperature, |
|
|
|
humidity: item.humidity, |
|
|
|
co2: item.co2, |
|
|
@ -266,6 +272,8 @@ class EnvironmentService { |
|
|
|
wind_speed: 0, |
|
|
|
h2s: 0, |
|
|
|
position_index: item.position_index, |
|
|
|
layer_index: item.layer_index, |
|
|
|
line_index: item.line_index, |
|
|
|
positionM, |
|
|
|
log_time, |
|
|
|
}); |
|
|
@ -290,7 +298,8 @@ class EnvironmentService { |
|
|
|
arr.map((item) => { |
|
|
|
let temp = filterArr.filter( |
|
|
|
(it) => |
|
|
|
it.position_index == item.position_index && |
|
|
|
it.line_index == item.line_index && |
|
|
|
it.layer_index == item.layer_index && |
|
|
|
it.positionM == item.positionM |
|
|
|
); |
|
|
|
if (temp && temp.length > 0) { |
|
|
@ -298,60 +307,58 @@ class EnvironmentService { |
|
|
|
filterArr.push(item); |
|
|
|
} |
|
|
|
}); |
|
|
|
console.log(filterArr); |
|
|
|
let lastArr = []; |
|
|
|
filterArr.map((item) => { |
|
|
|
const position_index = item.position_index; |
|
|
|
const pliesFlag = position_index.split("")[1]; |
|
|
|
const layer_index = item.layer_index; |
|
|
|
if (plies_number == "1") { |
|
|
|
if (["1", "4"].includes(pliesFlag)) { |
|
|
|
if (layer_index == 1) { |
|
|
|
// 第一层
|
|
|
|
const temp = lastArr.filter((i) => i.index == item.position_index); |
|
|
|
const temp = lastArr.filter((i) => i.index == item.line_index); |
|
|
|
if (temp && temp.length > 0) { |
|
|
|
lastArr.map((itl) => { |
|
|
|
if (itl.index == item.position_index) { |
|
|
|
if (itl.index == item.line_index) { |
|
|
|
itl.data?.push(item); |
|
|
|
} |
|
|
|
}); |
|
|
|
} else { |
|
|
|
lastArr.push({ |
|
|
|
index: item.position_index, |
|
|
|
index: item.line_index, |
|
|
|
data: [item], |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (plies_number == "2") { |
|
|
|
if (["2", "5"].includes(pliesFlag)) { |
|
|
|
if (layer_index == 2) { |
|
|
|
// 第二层
|
|
|
|
const temp = lastArr.filter((i) => i.index == item.position_index); |
|
|
|
const temp = lastArr.filter((i) => i.index == item.line_index); |
|
|
|
if (temp && temp.length > 0) { |
|
|
|
lastArr.map((itl) => { |
|
|
|
if (itl.index == item.position_index) { |
|
|
|
if (itl.index == item.line_index) { |
|
|
|
itl.data?.push(item); |
|
|
|
} |
|
|
|
}); |
|
|
|
} else { |
|
|
|
lastArr.push({ |
|
|
|
index: item.position_index, |
|
|
|
index: item.line_index, |
|
|
|
data: [item], |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (plies_number == "3") { |
|
|
|
if (["3", "6"].includes(pliesFlag)) { |
|
|
|
if (layer_index == 3) { |
|
|
|
// 第三层
|
|
|
|
const temp = lastArr.filter((i) => i.index == item.position_index); |
|
|
|
const temp = lastArr.filter((i) => i.index == item.line_index); |
|
|
|
if (temp && temp.length > 0) { |
|
|
|
lastArr.map((itl) => { |
|
|
|
if (itl.index == item.position_index) { |
|
|
|
if (itl.index == item.line_index) { |
|
|
|
itl.data?.push(item); |
|
|
|
} |
|
|
|
}); |
|
|
|
} else { |
|
|
|
lastArr.push({ |
|
|
|
index: item.position_index, |
|
|
|
index: item.line_index, |
|
|
|
data: [item], |
|
|
|
}); |
|
|
|
} |
|
|
|