Browse Source

fix bug

master
maochaoying 2 years ago
parent
commit
6cc71511bc
  1. 9
      src/controller/chicken.controller.js
  2. 10
      src/router/chicken.route.js
  3. 20
      src/service/chicken.service.js
  4. 2
      src/service/coop.service.js
  5. 21
      src/service/market.service.js

9
src/controller/chicken.controller.js

@ -3,6 +3,7 @@ const {
getChickenInfoById,
getAllChickenInfo,
getChickenInfoByHouseId,
getBatchNumbersByHouseId,
} = require("../service/chicken.service");
const Response = require("../utils/response");
@ -54,7 +55,13 @@ class ChickenController {
async batchs(ctx, next) {
const { house_id } = ctx.request.query;
const res = await getChickenInfoByHouseId(house_id);
ctx.body = Response(0, "查询批次号成功", res);
ctx.body = Response(0, "查询批次号详细成功", res);
}
async batchnum(ctx, next) {
const { house_id } = ctx.request.query;
const res = await getBatchNumbersByHouseId(house_id);
ctx.body = Response(0, "查询批次号简易信息成功", res);
}
}

10
src/router/chicken.route.js

@ -3,7 +3,13 @@ const Router = require("koa-router");
const router = new Router({ prefix: "/chicken" });
const { auth, hasAdminPermission } = require("../middleware/auth.middleware");
const { add, info, all, batchs } = require("../controller/chicken.controller");
const {
add,
info,
all,
batchs,
batchnum,
} = require("../controller/chicken.controller");
router.post("/add", auth, add);
@ -15,4 +21,6 @@ router.post("/all", auth, all);
router.get("/batchs", auth, batchs);
router.get("/batchnum", auth, batchnum);
module.exports = router;

20
src/service/chicken.service.js

@ -80,6 +80,15 @@ class ChickenService {
return res ? res.dataValues : null;
}
async getAllChickenByBatchId(batch_number) {
const res = await Chicken.findOne({
where: {
batch_number,
},
});
return res ? res.dataValues : null;
}
async getAllChickenInfo(
batch_number = "",
coop_ids = [],
@ -142,6 +151,17 @@ class ChickenService {
const real = await Promise.all(p);
return real;
}
async getBatchNumbersByHouseId(house_id) {
const res = await Chicken.findAll({
where: {
house_id,
is_marketed: 0,
},
});
const arr = res?.map((item) => item.dataValues);
return arr;
}
}
module.exports = new ChickenService();

2
src/service/coop.service.js

@ -82,6 +82,7 @@ class CoopService {
const chickenInfo = await Chicken.findAll({
where: {
coop_id: id,
is_marketed: 0,
},
});
console.log(chickenInfo);
@ -111,6 +112,7 @@ class CoopService {
const chickenList = await Chicken.findAll({
where: {
house_id,
is_marketed: 0,
},
});
const chickArr = chickenList.map((item) => item.dataValues.coop_id);

21
src/service/market.service.js

@ -1,6 +1,6 @@
const Market = require("../model/market.model");
const Chicken = require("../model/chicken.model");
const { getChickenByBatchId } = require("./chicken.service");
const { getAllChickenByBatchId } = require("./chicken.service");
const { getBatchCoopByIds } = require("./coop.service");
const { getVarietyById } = require("./variety.service");
const { getAccountInfo } = require("./account.service");
@ -23,6 +23,17 @@ class MarketService {
house_id,
out_time,
});
// 新增后 将chicken表中该batch_number对应的row中is_marketed改为1
const updateRes = await Chicken.update(
{
is_marketed: 1,
},
{
where: {
batch_number: batch_id,
},
}
);
return res ? res.dataValues : null;
}
@ -41,11 +52,13 @@ class MarketService {
});
const arr = res?.map((item) => item.dataValues);
const p = arr.map(async (item) => {
const childrenInfo = await getChickenByBatchId(item.batch_id);
const coop_ids = childrenInfo.coop_id.split(",");
const childrenInfo = await getAllChickenByBatchId(item.batch_id);
const coop_ids = childrenInfo?.coop_id?.split(",");
// // 根据coop_id批量查询
if (coop_ids) {
const coopInfo = await getBatchCoopByIds(coop_ids);
item.coopInfo = coopInfo;
}
return item;
});
const real = await Promise.all(p);
@ -59,7 +72,7 @@ class MarketService {
},
});
// 根据当前的batch_id查询基本信息
const chickenInfo = await getChickenByBatchId(batch_id);
const chickenInfo = await getAllChickenByBatchId(batch_id);
const log_user_id = chickenInfo.log_user_id;
const variety_id = chickenInfo.variety_id;
const userInfo = await getAccountInfo({ id: log_user_id });

Loading…
Cancel
Save