peng.peng
1 year ago
4 changed files with 178 additions and 1 deletions
@ -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 |
|||
} |
@ -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; |
|||
}; |
@ -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…
Reference in new issue