diff --git a/src/controller/control.controller.js b/src/controller/control.controller.js index d19d2ea..c1fdc71 100644 --- a/src/controller/control.controller.js +++ b/src/controller/control.controller.js @@ -2,6 +2,7 @@ const { getSettingByCoopId, changeSetting, getControlInfoList, + getSettingInfoById, } = require("../service/control.service"); const Response = require("../utils/response"); @@ -12,6 +13,12 @@ class ControlController { ctx.body = Response(0, "获取环境控制设定成功", res); } + async info(ctx, next) { + const { house_id, coop_id } = ctx.request.query; + const res = await getSettingInfoById(house_id, coop_id); + ctx.body = Response(0, "获取环境控制信息成功", res); + } + async change(ctx, next) { const { house_id, diff --git a/src/model/config.model.js b/src/model/config.model.js index 9e70bb9..9b0f473 100644 --- a/src/model/config.model.js +++ b/src/model/config.model.js @@ -16,6 +16,48 @@ const Config = seq.define("chicken_config", { defaultValue: 36, comment: "出栏日龄,限制最小的出栏日龄,单位天", }, + temperature_default_start: { + type: DataTypes.STRING, + allowNull: false, + defaultValue: 25, + comment: "默认起始温度", + }, + temperature_default_end: { + type: DataTypes.STRING, + allowNull: false, + defaultValue: 27, + comment: "默认结束温度", + }, + humidity_default_start: { + type: DataTypes.STRING, + allowNull: false, + defaultValue: 60, + comment: "默认起始湿度", + }, + humidity_default_end: { + type: DataTypes.STRING, + allowNull: false, + defaultValue: 70, + comment: "默认结束湿度", + }, + default_co2: { + type: DataTypes.STRING, + allowNull: false, + defaultValue: 1000, + comment: "默认的co2值", + }, + default_nh3: { + type: DataTypes.STRING, + allowNull: false, + defaultValue: 1000, + comment: "默认的nh3值", + }, + default_h2s: { + type: DataTypes.STRING, + allowNull: false, + defaultValue: 1000, + comment: "默认的h2s值", + }, }); // 强制同步数据库(创建数据表) diff --git a/src/model/environment.model.js b/src/model/environment.model.js index e476f7e..34da469 100644 --- a/src/model/environment.model.js +++ b/src/model/environment.model.js @@ -7,7 +7,7 @@ const Environment = seq.define("chicken_environment", { house_id: { type: DataTypes.INTEGER, allowNull: false, - comment: "鸡舍id", + comment: "鸡场id", }, coop_id: { type: DataTypes.INTEGER, diff --git a/src/router/control.route.js b/src/router/control.route.js index eaa8ad3..3f13370 100644 --- a/src/router/control.route.js +++ b/src/router/control.route.js @@ -3,7 +3,12 @@ const Router = require("koa-router"); const router = new Router({ prefix: "/control" }); const { auth } = require("../middleware/auth.middleware"); -const { detail, change, list } = require("../controller/control.controller"); +const { + detail, + change, + list, + info, +} = require("../controller/control.controller"); router.get("/detail", auth, detail); @@ -11,4 +16,6 @@ router.post("/change", auth, change); router.post("/list", auth, list); +router.get("/info", auth, info); + module.exports = router; diff --git a/src/service/control.service.js b/src/service/control.service.js index 0818742..295589e 100644 --- a/src/service/control.service.js +++ b/src/service/control.service.js @@ -4,6 +4,7 @@ const Device = require("../model/device.model"); const { getDayLife } = require("../utils/common"); const Coop = require("../model/coop.model"); const { Op, Sequelize } = require("sequelize"); +const { getConfigByHouseId } = require("./config.service"); const { getCoopListById } = require("./coop.service"); class ControlService { async getSettingByCoopId(house_id, coop_id) { @@ -16,6 +17,25 @@ class ControlService { return res ? res.dataValues : null; } + async getSettingInfoById(house_id, coop_id) { + const res = await Control.findOne({ + where: { + house_id, + coop_id, + }, + }); + if (res) { + res.dataValues.hasData = true; + return res.dataValues; + } else { + // 如果没有配置过默认信息 + // 则需要在config表中查找该鸡场的默认信息返回 + const configInfo = await getConfigByHouseId(house_id); + configInfo.hasData = false; + return configInfo; + } + } + async getControlInfoList(house_id, batch_number = "", coop_ids) { const res = await getCoopListById(house_id); // 查询该舍的环控信息