6 changed files with 120 additions and 4 deletions
-
9src/controller/market.controller.js
-
24src/model/config.model.js
-
26src/service/chicken.service.js
-
38src/service/config.service.js
-
18src/service/coop.service.js
-
9src/service/house.service.js
@ -0,0 +1,24 @@ |
|||
const { DataTypes } = require("sequelize"); |
|||
|
|||
const seq = require("../db/seq"); |
|||
|
|||
const Config = seq.define("chicken_config", { |
|||
// id 会被sequelize自动创建, 管理
|
|||
house_id: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: false, |
|||
unique: true, |
|||
comment: "所属鸡场id, 相当于外键", |
|||
}, |
|||
market_life_min: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: false, |
|||
defaultValue: 0, |
|||
comment: "出栏日龄,限制最小的出栏日龄,单位天", |
|||
}, |
|||
}); |
|||
|
|||
// 强制同步数据库(创建数据表)
|
|||
// Config.sync({ force: true });
|
|||
|
|||
module.exports = Config; |
@ -0,0 +1,38 @@ |
|||
const Config = require("../model/config.model"); |
|||
class ConfigService { |
|||
async initConfig(house_id, market_life_min = 0) { |
|||
const configInfo = await Config.findOne({ |
|||
where: { |
|||
house_id, |
|||
}, |
|||
}); |
|||
if (configInfo) { |
|||
await Config.update( |
|||
{ |
|||
market_life_min, |
|||
}, |
|||
{ |
|||
where: { |
|||
house_id, |
|||
}, |
|||
} |
|||
); |
|||
} else { |
|||
await Config.create({ |
|||
house_id, |
|||
market_life_min, |
|||
}); |
|||
} |
|||
} |
|||
|
|||
async getConfigByHouseId(house_id) { |
|||
const res = await Config.findOne({ |
|||
where: { |
|||
house_id, |
|||
}, |
|||
}); |
|||
return res ? res.dataValues : null; |
|||
} |
|||
} |
|||
|
|||
module.exports = new ConfigService(); |
Write
Preview
Loading…
Cancel
Save
Reference in new issue