5 changed files with 128 additions and 1 deletions
-
39src/controller/control.controller.js
-
11src/model/control.model.js
-
48src/model/report.model.js
-
12src/router/control.route.js
-
19src/service/control.service.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(); |
@ -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; |
@ -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; |
@ -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(); |
Write
Preview
Loading…
Cancel
Save
Reference in new issue