maochaoying 2 years ago
parent
commit
dcdb22c7de
  1. 12
      src/controller/environment.controller.js
  2. 52
      src/model/environment.model.js
  3. 27
      src/model/feeding.model.js
  4. 10
      src/router/environment.route.js
  5. 8
      src/service/environment.service.js

12
src/controller/environment.controller.js

@ -0,0 +1,12 @@
const { getEnvironmentByCoopId } = require("../service/environment.service");
const Response = require("../utils/response");
class EnvironmentController {
async detail(ctx, next) {
const { coop_id } = ctx.request.query;
const res = await getEnvironmentByCoopId(coop_id);
ctx.body = Response(0, "获取当前鸡舍的环境检测结果成功", res);
}
}
module.exports = new EnvironmentController();

52
src/model/environment.model.js

@ -0,0 +1,52 @@
const { DataTypes } = require("sequelize");
const seq = require("../db/seq");
const Environment = seq.define("chicken_environment", {
// id 会被sequelize自动创建, 管理
coop_id: {
type: DataTypes.INTEGER,
allowNull: false,
comment: "鸡舍id",
},
temperature: {
type: DataTypes.STRING,
allowNull: false,
comment: "温度",
},
humidity: {
type: DataTypes.STRING,
allowNull: false,
comment: "湿度",
},
co2: {
type: DataTypes.STRING,
allowNull: false,
comment: "co2",
},
nh3: {
type: DataTypes.STRING,
allowNull: false,
comment: "nh3",
},
illumination: {
type: DataTypes.STRING,
allowNull: false,
comment: "光照强度",
},
wind_speed: {
type: DataTypes.STRING,
allowNull: false,
comment: "风速",
},
h2s: {
type: DataTypes.STRING,
allowNull: false,
comment: "h2s",
},
});
// 强制同步数据库(创建数据表)
// Environment.sync({ force: true });
module.exports = Environment;

27
src/model/feeding.model.js

@ -0,0 +1,27 @@
const { DataTypes } = require("sequelize");
const seq = require("../db/seq");
const Feeding = seq.define("chicken_feeding", {
// id 会被sequelize自动创建, 管理
coop_id: {
type: DataTypes.INTEGER,
allowNull: false,
comment: "鸡舍id",
},
feeding: {
type: DataTypes.STRING,
allowNull: false,
comment: "饲喂量",
},
water_intake: {
type: DataTypes.STRING,
allowNull: false,
comment: "饮水量",
},
});
// 强制同步数据库(创建数据表)
// Feeding.sync({ force: true });
module.exports = Feeding;

10
src/router/environment.route.js

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

8
src/service/environment.service.js

@ -0,0 +1,8 @@
const Environment = require("../model/environment.model");
class EnvironmentService {
async getEnvironmentByCoopId(coop_id) {
return null;
}
}
module.exports = new EnvironmentService();
Loading…
Cancel
Save