Browse Source

(+)消防接口提交

master
peng.peng 1 year ago
parent
commit
35937670c5
  1. 60
      api/app/lib/controllers/superScreen/fire.js
  2. 3
      api/app/lib/middlewares/authenticator.js
  3. 98
      api/app/lib/models/fire_alarm.js
  4. 18
      api/app/lib/routes/superScreen/fire.js

60
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
}

3
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);
}

98
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;
};

18
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));
};
Loading…
Cancel
Save