maochaoying 2 years ago
parent
commit
9b40cdd3b7
  1. 39
      src/controller/control.controller.js
  2. 11
      src/model/control.model.js
  3. 48
      src/model/report.model.js
  4. 12
      src/router/control.route.js
  5. 19
      src/service/control.service.js

39
src/controller/control.controller.js

@ -0,0 +1,39 @@
const {
getSettingByCoopId,
changeSetting,
} = require("../service/control.service");
const Response = require("../utils/response");
class ControlController {
async detail(ctx, next) {
const { coop_id } = ctx.request.query;
const res = await getSettingByCoopId(coop_id);
ctx.body = Response(0, "获取环境控制设定成功", res);
}
async change(ctx, next) {
const {
coop_id,
temperature_start,
temperature_end,
humidity_start,
humidity_end,
current_co2,
current_nh3,
current_h2s,
} = ctx.request.body;
const res = await changeSetting(
coop_id,
temperature_start,
temperature_end,
humidity_start,
humidity_end,
current_co2,
current_nh3,
current_h2s
);
ctx.body = Response(0, "改变环境设定值成功", res);
}
}
module.exports = new ControlController();

11
src/model/control.model.js

@ -2,7 +2,6 @@ const { DataTypes } = require("sequelize");
const seq = require("../db/seq"); const seq = require("../db/seq");
// 鸡苗出栏
const Control = seq.define("chicken_control", { const Control = seq.define("chicken_control", {
// id 会被sequelize自动创建, 管理 // id 会被sequelize自动创建, 管理
temperature_start: { temperature_start: {
@ -20,11 +19,13 @@ const Control = seq.define("chicken_control", {
temperature_default_start: { temperature_default_start: {
type: DataTypes.STRING, type: DataTypes.STRING,
allowNull: false, allowNull: false,
defaultValue: 0,
comment: "默认起始温度", comment: "默认起始温度",
}, },
temperature_default_end: { temperature_default_end: {
type: DataTypes.STRING, type: DataTypes.STRING,
allowNull: false, allowNull: false,
defaultValue: 0,
comment: "默认结束温度", comment: "默认结束温度",
}, },
humidity_start: { humidity_start: {
@ -42,41 +43,49 @@ const Control = seq.define("chicken_control", {
humidity_default_start: { humidity_default_start: {
type: DataTypes.STRING, type: DataTypes.STRING,
allowNull: false, allowNull: false,
defaultValue: 0,
comment: "默认起始湿度", comment: "默认起始湿度",
}, },
humidity_default_end: { humidity_default_end: {
type: DataTypes.STRING, type: DataTypes.STRING,
allowNull: false, allowNull: false,
defaultValue: 0,
comment: "默认结束湿度", comment: "默认结束湿度",
}, },
current_co2: { current_co2: {
type: DataTypes.STRING, type: DataTypes.STRING,
allowNull: false, allowNull: false,
defaultValue: 0,
comment: "当前co2含量", comment: "当前co2含量",
}, },
default_co2: { default_co2: {
type: DataTypes.STRING, type: DataTypes.STRING,
allowNull: false, allowNull: false,
defaultValue: 0,
comment: "默认的co2值", comment: "默认的co2值",
}, },
current_nh3: { current_nh3: {
type: DataTypes.STRING, type: DataTypes.STRING,
allowNull: false, allowNull: false,
defaultValue: 0,
comment: "当前nh3含量", comment: "当前nh3含量",
}, },
default_nh3: { default_nh3: {
type: DataTypes.STRING, type: DataTypes.STRING,
allowNull: false, allowNull: false,
defaultValue: 0,
comment: "默认的nh3值", comment: "默认的nh3值",
}, },
current_h2s: { current_h2s: {
type: DataTypes.STRING, type: DataTypes.STRING,
allowNull: false, allowNull: false,
defaultValue: 0,
comment: "当前h2s含量", comment: "当前h2s含量",
}, },
default_h2s: { default_h2s: {
type: DataTypes.STRING, type: DataTypes.STRING,
allowNull: false, allowNull: false,
defaultValue: 0,
comment: "默认的h2s值", comment: "默认的h2s值",
}, },
coop_id: { coop_id: {

48
src/model/report.model.js

@ -0,0 +1,48 @@
const { DataTypes } = require("sequelize");
const seq = require("../db/seq");
const Report = seq.define("chicken_report", {
// id 会被sequelize自动创建, 管理
coop_id: {
type: DataTypes.INTEGER,
allowNull: false,
comment: "鸡舍id",
},
long_id: {
type: DataTypes.INTEGER,
allowNull: false,
comment: "鸡笼号",
},
type_id: {
type: DataTypes.INTEGER,
allowNull: false,
comment: "预警类型",
},
img: {
type: DataTypes.TEXT,
allowNull: true,
comment: "现场图片",
},
is_handled: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: 0,
comment: "是否已经解决",
},
remark: {
type: DataTypes.STRING,
allowNull: true,
comment: "备注",
},
user_id: {
type: DataTypes.INTEGER,
allowNull: false,
comment: "处理人",
},
});
// 强制同步数据库(创建数据表)
// Report.sync({ force: true });
module.exports = Report;

12
src/router/control.route.js

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

19
src/service/control.service.js

@ -0,0 +1,19 @@
const Control = require("../model/control.model");
class ControlService {
async getSettingByCoopId(coop_id) {
return null;
}
async changeSetting(
coop_id,
temperature_start,
temperature_end,
humidity_start,
humidity_end,
current_co2,
current_nh3,
current_h2s
) {}
}
module.exports = new ControlService();
Loading…
Cancel
Save