|
@ -1,7 +1,11 @@ |
|
|
const Die = require("../model/die.model"); |
|
|
const Die = require("../model/die.model"); |
|
|
|
|
|
const Chicken = require("../model/chicken.model"); |
|
|
const { Op } = require("sequelize"); |
|
|
const { Op } = require("sequelize"); |
|
|
const { getChickenByCoopIdAndHouseId } = require("./chicken.service"); |
|
|
const { getChickenByCoopIdAndHouseId } = require("./chicken.service"); |
|
|
const { getCoopById } = require("./coop.service"); |
|
|
const { getCoopById } = require("./coop.service"); |
|
|
|
|
|
const { getFactoryById } = require("./factory.service"); |
|
|
|
|
|
const { getDayLife } = require("../utils/common"); |
|
|
|
|
|
const { getAccountInfo } = require("./account.service"); |
|
|
class DieService { |
|
|
class DieService { |
|
|
async addDieLog(house_id, coop_id, reason_id, die_number, put_time) { |
|
|
async addDieLog(house_id, coop_id, reason_id, die_number, put_time) { |
|
|
const res = await Die.create({ |
|
|
const res = await Die.create({ |
|
@ -95,6 +99,42 @@ class DieService { |
|
|
const arr = res?.map((item) => item.dataValues); |
|
|
const arr = res?.map((item) => item.dataValues); |
|
|
return arr; |
|
|
return arr; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async getDefaultDieInfoByCoopId(coop_id, house_id) { |
|
|
|
|
|
// 根据coop ID查询 新建死淘记录时的默认回显信息
|
|
|
|
|
|
const res = await Chicken.findOne({ |
|
|
|
|
|
where: { |
|
|
|
|
|
house_id, |
|
|
|
|
|
coop_id: { |
|
|
|
|
|
[Op.like]: `%${coop_id}%`, |
|
|
|
|
|
}, |
|
|
|
|
|
}, |
|
|
|
|
|
}); |
|
|
|
|
|
if (res) { |
|
|
|
|
|
// 死淘数量不大于进鸡数量-之前录入的该舍死淘数量
|
|
|
|
|
|
const dieInfos = await Die.findAll({ |
|
|
|
|
|
coop_id, |
|
|
|
|
|
house_id, |
|
|
|
|
|
}); |
|
|
|
|
|
const dieArr = dieInfos.map((item) => item.dataValues); |
|
|
|
|
|
let dieTotal = 0; |
|
|
|
|
|
dieArr.map((item) => { |
|
|
|
|
|
dieTotal += item.die_number; |
|
|
|
|
|
}); |
|
|
|
|
|
res.dataValues.max_die_number = res.dataValues.chicken_number - dieTotal; |
|
|
|
|
|
// 默认鸡苗日龄为录入时间-进鸡时间
|
|
|
|
|
|
res.dataValues.day_life = getDayLife(new Date(), res.dataValues.put_time); |
|
|
|
|
|
// 鸡苗厂家/记录人
|
|
|
|
|
|
const factoryInfo = await getFactoryById(res.dataValues.factory_id); |
|
|
|
|
|
res.dataValues.factoryInfo = factoryInfo; |
|
|
|
|
|
const accountInfo = await getAccountInfo({ |
|
|
|
|
|
id: res.dataValues.log_user_id, |
|
|
|
|
|
}); |
|
|
|
|
|
res.dataValues.log_user = accountInfo.name; |
|
|
|
|
|
return res.dataValues; |
|
|
|
|
|
} |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
module.exports = new DieService(); |
|
|
module.exports = new DieService(); |