From 35937670c5293c79cebc72caf2296091898329a2 Mon Sep 17 00:00:00 2001 From: "peng.peng" Date: Fri, 18 Aug 2023 10:17:33 +0800 Subject: [PATCH] =?UTF-8?q?=EF=BC=88+=EF=BC=89=E6=B6=88=E9=98=B2=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/lib/controllers/superScreen/fire.js | 60 ++++++++++++- api/app/lib/middlewares/authenticator.js | 3 + api/app/lib/models/fire_alarm.js | 98 +++++++++++++++++++++ api/app/lib/routes/superScreen/fire.js | 18 ++++ 4 files changed, 178 insertions(+), 1 deletion(-) create mode 100644 api/app/lib/models/fire_alarm.js create mode 100644 api/app/lib/routes/superScreen/fire.js diff --git a/api/app/lib/controllers/superScreen/fire.js b/api/app/lib/controllers/superScreen/fire.js index 61517bd..8bc189a 100644 --- a/api/app/lib/controllers/superScreen/fire.js +++ b/api/app/lib/controllers/superScreen/fire.js @@ -1,5 +1,63 @@ 'use strict'; +function getFireAlarmList(opts) { + return async function (ctx, next) { + const models = ctx.fs.dc.models; + let errMsg = { message: '获取消防告警失败' } + try { + const res = await models.FireAlarm.findAll(); + ctx.status = 200; + ctx.body = res; + } catch (error) { + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); + ctx.status = 400; + ctx.body = errMsg + } + } +} + +// 新增消防告警 +function addAlarm(opts) { + return async function (ctx, next) { + const models = ctx.fs.dc.models; + try { + const body = ctx.request.body + await models.FireAlarm.create(body) + + ctx.status = 204; + ctx.body = { message: '新建消防告警成功' } + } catch (error) { + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); + ctx.status = 400; + ctx.body = { message: '新建消防告警失败' } + } + } +} + +// 修改消防告警 +function updateAlarm(opts) { + return async function (ctx, next) { + try { + const models = ctx.fs.dc.models; + const { id } = ctx.params; + const body = ctx.request.body; + await models.FireAlarm.update( + body, + { where: { id: id, } } + ) + ctx.status = 204; + ctx.body = { message: '修改消防告警成功' } + + } catch (error) { + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); + ctx.status = 400; + ctx.body = { message: '修改消防告警失败' } + } + } +} + module.exports = { - + addAlarm, + updateAlarm, + getFireAlarmList } \ No newline at end of file diff --git a/api/app/lib/middlewares/authenticator.js b/api/app/lib/middlewares/authenticator.js index 614a5d4..07df3ec 100644 --- a/api/app/lib/middlewares/authenticator.js +++ b/api/app/lib/middlewares/authenticator.js @@ -61,6 +61,9 @@ let isPathExcluded = function (opts, path, method) { excludeOpts.push({ p: '/logout', o: 'PUT' }); excludeOpts.push({ p: '/water/realstate', o: 'GET' }); excludeOpts.push({ p: '/water/emergency', o: 'GET' }); + excludeOpts.push({ p: '/fire/alarm', o: 'GET' }); + excludeOpts.push({ p: '/fire/alarm', o: 'POST' }); + excludeOpts.push({ p: '/fire/alarm/:id', o: 'PUT' }); excludes = new ExcludesUrls(excludeOpts); } diff --git a/api/app/lib/models/fire_alarm.js b/api/app/lib/models/fire_alarm.js new file mode 100644 index 0000000..9bfdaad --- /dev/null +++ b/api/app/lib/models/fire_alarm.js @@ -0,0 +1,98 @@ +/* eslint-disable*/ + +'use strict'; + +module.exports = dc => { + const DataTypes = dc.ORM; + const sequelize = dc.orm; + const FireAlarm = sequelize.define("fireAlarm", { + id: { + type: DataTypes.INTEGER, + allowNull: false, + defaultValue: null, + comment: null, + primaryKey: true, + field: "id", + autoIncrement: true, + unique: "fire_alarm_id_uindex" + }, + createTime: { + type: DataTypes.DATE, + allowNull: true, + defaultValue: null, + comment: "创建时间", + primaryKey: false, + field: "createTime", + autoIncrement: false + }, + location: { + type: DataTypes.TEXT, + allowNull: true, + defaultValue: null, + comment: "地点", + primaryKey: false, + field: "location", + autoIncrement: false + }, + scene: { + type: DataTypes.STRING, + allowNull: true, + defaultValue: null, + comment: "场所", + primaryKey: false, + field: "scene", + autoIncrement: false + }, + fireMaterial: { + type: DataTypes.STRING, + allowNull: true, + defaultValue: null, + comment: "燃烧物质", + primaryKey: false, + field: "fire_material", + autoIncrement: false + }, + level: { + type: DataTypes.STRING, + allowNull: true, + defaultValue: null, + comment: "危险等级", + primaryKey: false, + field: "level", + autoIncrement: false + }, + state: { + type: DataTypes.INTEGER, + allowNull: true, + defaultValue: null, + comment: "事件状态:1 进行中 2已结束", + primaryKey: false, + field: "state", + autoIncrement: false + }, + longitude: { + type: DataTypes.STRING, + allowNull: true, + defaultValue: null, + comment: null, + primaryKey: false, + field: "longitude", + autoIncrement: false + }, + latitude: { + type: DataTypes.STRING, + allowNull: true, + defaultValue: null, + comment: null, + primaryKey: false, + field: "latitude", + autoIncrement: false + } + }, { + tableName: "fire_alarm", + comment: "", + indexes: [] + }); + dc.models.FireAlarm = FireAlarm; + return FireAlarm; +}; \ No newline at end of file diff --git a/api/app/lib/routes/superScreen/fire.js b/api/app/lib/routes/superScreen/fire.js new file mode 100644 index 0000000..786d5d1 --- /dev/null +++ b/api/app/lib/routes/superScreen/fire.js @@ -0,0 +1,18 @@ +'use strict'; + +const fire = require('../../controllers/superScreen/fire'); + +module.exports = function (app, router, opts, AuthCode) { + + //查询消防告警 + app.fs.api.logAttr['GET/fire/alarm'] = { content: '查询消防告警', visible: true }; + router.get('/fire/alarm', fire.addAlarm(opts)); + + //新增消防告警 + app.fs.api.logAttr['POST/fire/alarm'] = { content: '新增消防告警', visible: true }; + router.post('/fire/alarm', fire.addAlarm(opts)); + + //修改消防告警状态 + app.fs.api.logAttr['PUT/fire/alarm/:id'] = { content: '修改消防告警状态', visible: true }; + router.put('/fire/alarm/:id', fire.updateAlarm(opts)); +};