|
|
@ -276,10 +276,89 @@ class EnvironmentService { |
|
|
|
} |
|
|
|
|
|
|
|
// 获取环境实时监测数据
|
|
|
|
async getRealTimeData(plies_number) { |
|
|
|
const res = await Environment.findAll(); |
|
|
|
async getRealTimeData(house_id, coop_id, plies_number) { |
|
|
|
const res = await Environment.findAll({ |
|
|
|
where: { |
|
|
|
house_id, |
|
|
|
coop_id, |
|
|
|
}, |
|
|
|
order: [["log_time", "DESC"]], |
|
|
|
}); |
|
|
|
const arr = res?.map((item) => item.dataValues); |
|
|
|
return arr; |
|
|
|
let filterArr = []; |
|
|
|
// 对arr进行筛选 将旧数据甩出
|
|
|
|
arr.map((item) => { |
|
|
|
let temp = filterArr.filter( |
|
|
|
(it) => |
|
|
|
it.position_index == item.position_index && |
|
|
|
it.positionM == item.positionM |
|
|
|
); |
|
|
|
if (temp && temp.length > 0) { |
|
|
|
} else { |
|
|
|
filterArr.push(item); |
|
|
|
} |
|
|
|
}); |
|
|
|
console.log(filterArr); |
|
|
|
let lastArr = []; |
|
|
|
filterArr.map((item) => { |
|
|
|
const position_index = item.position_index; |
|
|
|
const pliesFlag = position_index.split("")[1]; |
|
|
|
if (plies_number == "1") { |
|
|
|
if (["1", "4"].includes(pliesFlag)) { |
|
|
|
// 第一层
|
|
|
|
const temp = lastArr.filter((i) => i.index == item.position_index); |
|
|
|
if (temp && temp.length > 0) { |
|
|
|
lastArr.map((itl) => { |
|
|
|
if (itl.index == item.position_index) { |
|
|
|
itl.data?.push(item); |
|
|
|
} |
|
|
|
}); |
|
|
|
} else { |
|
|
|
lastArr.push({ |
|
|
|
index: item.position_index, |
|
|
|
data: [item], |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (plies_number == "2") { |
|
|
|
if (["2", "5"].includes(pliesFlag)) { |
|
|
|
// 第二层
|
|
|
|
const temp = lastArr.filter((i) => i.index == item.position_index); |
|
|
|
if (temp && temp.length > 0) { |
|
|
|
lastArr.map((itl) => { |
|
|
|
if (itl.index == item.position_index) { |
|
|
|
itl.data?.push(item); |
|
|
|
} |
|
|
|
}); |
|
|
|
} else { |
|
|
|
lastArr.push({ |
|
|
|
index: item.position_index, |
|
|
|
data: [item], |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (plies_number == "3") { |
|
|
|
if (["3", "6"].includes(pliesFlag)) { |
|
|
|
// 第三层
|
|
|
|
const temp = lastArr.filter((i) => i.index == item.position_index); |
|
|
|
if (temp && temp.length > 0) { |
|
|
|
lastArr.map((itl) => { |
|
|
|
if (itl.index == item.position_index) { |
|
|
|
itl.data?.push(item); |
|
|
|
} |
|
|
|
}); |
|
|
|
} else { |
|
|
|
lastArr.push({ |
|
|
|
index: item.position_index, |
|
|
|
data: [item], |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
return lastArr; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|