maochaoying 2 years ago
parent
commit
a2fd940de0
  1. 17
      src/controller/die.controller.js
  2. 11
      src/controller/reason.controller.js
  3. 2
      src/router/die.route.js
  4. 10
      src/router/reason.route.js
  5. 1
      src/service/chicken.service.js
  6. 32
      src/service/die.service.js
  7. 19
      src/service/reason.service.js

17
src/controller/die.controller.js

@ -9,13 +9,24 @@ class DieController {
async add(ctx, next) {
const { house_id, coop_id, reason_id, die_number, put_time } =
ctx.request.body;
ctx.body = Response(0, "新增死淘记录成功", null);
const res = await addDieLog(
house_id,
coop_id,
reason_id,
die_number,
put_time
);
ctx.body = Response(0, "新增死淘记录成功", res);
}
async info(ctx, next) {
ctx.body = Response(0, "查询单条死淘记录成功", null);
const { house_id, coop_id } = ctx.request.body;
const res = await getDieInfoById(house_id, coop_id);
ctx.body = Response(0, "查询单条死淘记录成功", res);
}
async all(ctx, next) {
ctx.body = Response(0, "查询死淘记录成功", null);
const { house_id } = ctx.request.body;
const res = await getAllDieInfo(house_id);
ctx.body = Response(0, "查询死淘记录成功", res);
}
}

11
src/controller/reason.controller.js

@ -0,0 +1,11 @@
const { getAllReason } = require("../service/reason.service");
const Response = require("../utils/response");
class ReasonController {
async list(ctx, next) {
const res = await getAllReason();
ctx.body = Response(0, "获取死亡原因成功", res);
}
}
module.exports = new ReasonController();

2
src/router/die.route.js

@ -8,7 +8,7 @@ const { add, info, all } = require("../controller/die.controller");
router.post("/add", auth, add);
// 根据id获取新进鸡苗记录详情。
router.get("/info", auth, info);
router.post("/info", auth, info);
// 根据条件查询新进记录
router.post("/all", auth, all);

10
src/router/reason.route.js

@ -0,0 +1,10 @@
const Router = require("koa-router");
const router = new Router({ prefix: "/reason" });
const { auth } = require("../middleware/auth.middleware");
const { list } = require("../controller/reason.controller");
router.get("/list", auth, list);
module.exports = router;

1
src/service/chicken.service.js

@ -31,7 +31,6 @@ class ChickenService {
log_user_id,
batch_number,
});
console.log(res);
return res ? res.dataValues : null;
}

32
src/service/die.service.js

@ -1,9 +1,35 @@
const Die = require("../model/die.model");
const { Op } = require("sequelize");
class DieService {
async addDieLog() {}
async getDieInfoById() {}
async getAllDieInfo() {}
async addDieLog(house_id, coop_id, reason_id, die_number, put_time) {
const res = await Die.create({
house_id,
coop_id,
reason_id,
die_number,
put_time,
});
return res ? res.dataValues : null;
}
async getDieInfoById(house_id, coop_id) {
const res = await Die.findAll({
where: {
house_id,
coop_id,
},
});
const arr = res?.map((item) => item.dataValues);
return arr;
}
async getAllDieInfo(house_id) {
const res = await Die.findAll({
where: {
house_id,
},
});
const arr = res?.map((item) => item.dataValues);
return arr;
}
}
module.exports = new DieService();

19
src/service/reason.service.js

@ -0,0 +1,19 @@
const Reason = require("../model/reason.model");
class ReasonService {
async getAllReason() {
const res = await Reason.findAll();
const arr = res.map((item) => item.dataValues);
return arr;
}
async getReasonById(id) {
const whereOpt = {};
id && Object.assign(whereOpt, { id });
const res = await Reason.findOne({
where: whereOpt,
});
return res ? res.dataValues : null;
}
}
module.exports = new ReasonService();
Loading…
Cancel
Save