diff --git a/src/controller/control.controller.js b/src/controller/control.controller.js new file mode 100644 index 0000000..38701d6 --- /dev/null +++ b/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(); diff --git a/src/model/control.model.js b/src/model/control.model.js index 75cd031..1c15cbc 100644 --- a/src/model/control.model.js +++ b/src/model/control.model.js @@ -2,7 +2,6 @@ const { DataTypes } = require("sequelize"); const seq = require("../db/seq"); -// 鸡苗出栏 const Control = seq.define("chicken_control", { // id 会被sequelize自动创建, 管理 temperature_start: { @@ -20,11 +19,13 @@ const Control = seq.define("chicken_control", { temperature_default_start: { type: DataTypes.STRING, allowNull: false, + defaultValue: 0, comment: "默认起始温度", }, temperature_default_end: { type: DataTypes.STRING, allowNull: false, + defaultValue: 0, comment: "默认结束温度", }, humidity_start: { @@ -42,41 +43,49 @@ const Control = seq.define("chicken_control", { humidity_default_start: { type: DataTypes.STRING, allowNull: false, + defaultValue: 0, comment: "默认起始湿度", }, humidity_default_end: { type: DataTypes.STRING, allowNull: false, + defaultValue: 0, comment: "默认结束湿度", }, current_co2: { type: DataTypes.STRING, allowNull: false, + defaultValue: 0, comment: "当前co2含量", }, default_co2: { type: DataTypes.STRING, allowNull: false, + defaultValue: 0, comment: "默认的co2值", }, current_nh3: { type: DataTypes.STRING, allowNull: false, + defaultValue: 0, comment: "当前nh3含量", }, default_nh3: { type: DataTypes.STRING, allowNull: false, + defaultValue: 0, comment: "默认的nh3值", }, current_h2s: { type: DataTypes.STRING, allowNull: false, + defaultValue: 0, comment: "当前h2s含量", }, default_h2s: { type: DataTypes.STRING, allowNull: false, + defaultValue: 0, comment: "默认的h2s值", }, coop_id: { diff --git a/src/model/report.model.js b/src/model/report.model.js new file mode 100644 index 0000000..61989c8 --- /dev/null +++ b/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; diff --git a/src/router/control.route.js b/src/router/control.route.js new file mode 100644 index 0000000..c40ab68 --- /dev/null +++ b/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; diff --git a/src/service/control.service.js b/src/service/control.service.js new file mode 100644 index 0000000..a81b592 --- /dev/null +++ b/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();