|
@ -0,0 +1,44 @@ |
|
|
|
|
|
const Chicken = require("../model/chicken.model"); |
|
|
|
|
|
const { getDayLife } = require("../utils/common"); |
|
|
|
|
|
const { getDieTotal } = require("./die.service"); |
|
|
|
|
|
const { |
|
|
|
|
|
getBatchCoopByIds, |
|
|
|
|
|
getEmptyCoopList, |
|
|
|
|
|
getCoopNumbyHouseId, |
|
|
|
|
|
} = require("./coop.service"); |
|
|
|
|
|
class OverviewService { |
|
|
|
|
|
async getAllOverViewList(house_id) { |
|
|
|
|
|
const res = await Chicken.findAll({ |
|
|
|
|
|
where: { |
|
|
|
|
|
house_id, |
|
|
|
|
|
is_marketed: 0, |
|
|
|
|
|
}, |
|
|
|
|
|
}); |
|
|
|
|
|
const arr = res?.map((item) => item.dataValues); |
|
|
|
|
|
const p = arr.map(async (item) => { |
|
|
|
|
|
const ids = item.coop_id.split(","); |
|
|
|
|
|
const allCoops = await getBatchCoopByIds(ids); |
|
|
|
|
|
item.allCoops = allCoops |
|
|
|
|
|
.map((item) => { |
|
|
|
|
|
return item.coop_name; |
|
|
|
|
|
}) |
|
|
|
|
|
.join(","); |
|
|
|
|
|
// 需要减去死淘
|
|
|
|
|
|
const dieNumber = await getDieTotal(ids, house_id); |
|
|
|
|
|
item.now_number = item.chicken_number - dieNumber; |
|
|
|
|
|
item.day_life = getDayLife(new Date(), item.real_life_init_time); |
|
|
|
|
|
return item; |
|
|
|
|
|
}); |
|
|
|
|
|
const result = await Promise.all(p); |
|
|
|
|
|
const emptyCoop = await getEmptyCoopList(house_id); |
|
|
|
|
|
const totalCount = await getCoopNumbyHouseId(house_id); |
|
|
|
|
|
const hasCoopCount = totalCount - (emptyCoop?.length || 0); |
|
|
|
|
|
const real = [...result, ...emptyCoop]; |
|
|
|
|
|
return { |
|
|
|
|
|
list: real, |
|
|
|
|
|
coopNum: hasCoopCount, |
|
|
|
|
|
}; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
module.exports = new OverviewService(); |