|
|
@ -1,8 +1,10 @@ |
|
|
|
const Market = require("../model/market.model"); |
|
|
|
const Chicken = require("../model/chicken.model"); |
|
|
|
const { getChickenByBatchId } = require("./chicken.service"); |
|
|
|
const { getBatchCoopByIds } = require("./coop.service"); |
|
|
|
const { getVarietyById } = require("./variety.service"); |
|
|
|
const { getAccountInfo } = require("./account.service"); |
|
|
|
const { getDieTotal } = require("./die.service"); |
|
|
|
const { getDayLife } = require("../utils/common"); |
|
|
|
const { Op } = require("sequelize"); |
|
|
|
const { DATE_FILTER } = require("../constant/constant"); |
|
|
@ -40,7 +42,6 @@ class MarketService { |
|
|
|
const arr = res?.map((item) => item.dataValues); |
|
|
|
const p = arr.map(async (item) => { |
|
|
|
const childrenInfo = await getChickenByBatchId(item.batch_id); |
|
|
|
console.log(childrenInfo); |
|
|
|
const coop_ids = childrenInfo.coop_id.split(","); |
|
|
|
// // 根据coop_id批量查询
|
|
|
|
const coopInfo = await getBatchCoopByIds(coop_ids); |
|
|
@ -59,7 +60,6 @@ class MarketService { |
|
|
|
}); |
|
|
|
// 根据当前的batch_id查询基本信息
|
|
|
|
const chickenInfo = await getChickenByBatchId(batch_id); |
|
|
|
console.log(chickenInfo); |
|
|
|
const log_user_id = chickenInfo.log_user_id; |
|
|
|
const variety_id = chickenInfo.variety_id; |
|
|
|
const userInfo = await getAccountInfo({ id: log_user_id }); |
|
|
@ -79,6 +79,33 @@ class MarketService { |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
async getDefaultMarketInfo(house_id, batch_number) { |
|
|
|
const res = await Chicken.findOne({ |
|
|
|
where: { |
|
|
|
is_marketed: 0, |
|
|
|
house_id, |
|
|
|
batch_number, |
|
|
|
}, |
|
|
|
}); |
|
|
|
if (res) { |
|
|
|
const coop_ids = res.dataValues.coop_id.split(","); |
|
|
|
const coopInfos = await getBatchCoopByIds(coop_ids); |
|
|
|
res.dataValues.coopInfos = coopInfos; |
|
|
|
// 出栏数量默认等于“进鸡数量-死淘数量”
|
|
|
|
const dieTotal = await getDieTotal(coop_ids, house_id); |
|
|
|
res.dataValues.market_default_number = |
|
|
|
res.dataValues.chicken_number - dieTotal; |
|
|
|
// 出栏日龄=出栏时间-进鸡时间
|
|
|
|
res.dataValues.day_life = getDayLife(new Date(), res.put_time); |
|
|
|
const varietyInfo = await getVarietyById(res.dataValues.variety_id); |
|
|
|
res.dataValues.varietyInfo = varietyInfo; |
|
|
|
const userInfo = await getAccountInfo({ id: res.dataValues.log_user_id }); |
|
|
|
res.dataValues.log_user = userInfo.name; |
|
|
|
return res.dataValues; |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
module.exports = new MarketService(); |