|
|
@ -1,6 +1,7 @@ |
|
|
|
const Chicken = require("../model/chicken.model"); |
|
|
|
const { getDayLife, haveSame } = require("../utils/common"); |
|
|
|
const { getDieTotal } = require("./die.service"); |
|
|
|
const { getEnvironmentByCoopId } = require("./environment.service"); |
|
|
|
const { |
|
|
|
getBatchCoopByIds, |
|
|
|
getEmptyCoopList, |
|
|
@ -87,6 +88,38 @@ class OverviewService { |
|
|
|
coopNum: hasCoopCount, |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
async getOverViewDetail(id) { |
|
|
|
const res = await Chicken.findOne({ |
|
|
|
where: { |
|
|
|
id, |
|
|
|
}, |
|
|
|
}); |
|
|
|
const info = res.dataValues; |
|
|
|
|
|
|
|
const ids = info.coop_id.split(","); |
|
|
|
const allCoops = await getBatchCoopByIds(ids); |
|
|
|
info.allCoops = allCoops |
|
|
|
.map((item) => { |
|
|
|
return item.coop_name; |
|
|
|
}) |
|
|
|
.join(","); |
|
|
|
// 获取该鸡舍的环境数据
|
|
|
|
const p = allCoops.map(async (item) => { |
|
|
|
const coop_id = item.id; |
|
|
|
const house_id = info.house_id; |
|
|
|
const environment = await getEnvironmentByCoopId(house_id, coop_id); |
|
|
|
item.environment = environment; |
|
|
|
return item; |
|
|
|
}); |
|
|
|
const real = await Promise.all(p); |
|
|
|
info.coopInfo = real; |
|
|
|
// 需要减去死淘
|
|
|
|
const dieNumber = await getDieTotal(ids, info.house_id); |
|
|
|
info.now_number = info.chicken_number - dieNumber; |
|
|
|
info.day_life = getDayLife(new Date(), info.real_life_init_time); |
|
|
|
return info; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
module.exports = new OverviewService(); |