Compare commits
2 Commits
957d0803dd
...
0f121d718b
Author | SHA1 | Date |
---|---|---|
xincheng | 0f121d718b | 2 years ago |
刘欣程 | 2764e0137d | 2 years ago |
3 changed files with 112 additions and 0 deletions
@ -0,0 +1,52 @@ |
|||||
|
'use strict'; |
||||
|
|
||||
|
async function findPatrolRecord (ctx, next) { |
||||
|
let rslt = []; |
||||
|
let error = { name: 'FindError', message: '获取巡检记录失败' }; |
||||
|
try { |
||||
|
const models = ctx.fs.dc.models; |
||||
|
const { startTime, endTime, alarm, patrolPlanId } = ctx.params; |
||||
|
if (patrolPlanId.length == 0) { |
||||
|
error = { name: 'FindError', message: '获取巡检记录失败,无巡检计划id' }; |
||||
|
} else { |
||||
|
rslt = await models.PatrolRecord.findAll({ |
||||
|
where: { patrolPlanId: { $in: patrolPlanId.split(',') }, alarm, inspectionTime: { $between: [startTime, endTime] } }, |
||||
|
}); |
||||
|
} |
||||
|
ctx.status = 200; |
||||
|
ctx.body = rslt; |
||||
|
error = null |
||||
|
} catch (error) { |
||||
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
||||
|
ctx.status = 400; |
||||
|
ctx.body = { |
||||
|
"message": "获取巡检记录失败" |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
async function addPatrolRecord (ctx, next) { |
||||
|
let error = { name: 'addError', message: '新增巡检记录失败' }; |
||||
|
try { |
||||
|
const models = ctx.fs.dc.models; |
||||
|
const data = ctx.request.body; |
||||
|
let { patrolPlanId, lastInspectionTime, inspectionTime, points, alarm } = data |
||||
|
let record = { patrolPlanId, lastInspectionTime, inspectionTime, points, alarm } |
||||
|
|
||||
|
await models.PatrolRecord.create(record); |
||||
|
|
||||
|
ctx.status = 204; |
||||
|
error = null |
||||
|
} catch (error) { |
||||
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
||||
|
ctx.status = 400; |
||||
|
ctx.body = { |
||||
|
"message": '新增巡检计划失败' |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
module.exports = { |
||||
|
findPatrolRecord, |
||||
|
addPatrolRecord, |
||||
|
} |
@ -0,0 +1,50 @@ |
|||||
|
/* eslint-disable*/ |
||||
|
'use strict'; |
||||
|
|
||||
|
module.exports = dc => { |
||||
|
const DataTypes = dc.ORM; |
||||
|
const sequelize = dc.orm; |
||||
|
const PatrolRecord = sequelize.define("PatrolRecord", { |
||||
|
id: { |
||||
|
field: "id", |
||||
|
type: DataTypes.INTEGER, |
||||
|
allowNull: false, |
||||
|
primaryKey: true, |
||||
|
autoIncrement: true, |
||||
|
}, |
||||
|
patrolPlanId: { |
||||
|
field: "patrol_plan_id", |
||||
|
type: DataTypes.INTEGER, |
||||
|
allowNull: false, |
||||
|
primaryKey: false, |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
lastInspectionTime: { |
||||
|
field: "last_inspection_time", |
||||
|
type: DataTypes.DATE, |
||||
|
allowNull: true, |
||||
|
}, |
||||
|
inspectionTime: { |
||||
|
field: "inspection_time", |
||||
|
type: DataTypes.DATE, |
||||
|
allowNull: true, |
||||
|
}, |
||||
|
points: { |
||||
|
field: "points", |
||||
|
type: DataTypes.JSONB, |
||||
|
allowNull: true, |
||||
|
}, |
||||
|
alarm: { |
||||
|
field: "alarm", |
||||
|
type: DataTypes.BOOLEAN, |
||||
|
allowNull: false, |
||||
|
defaultValue: false, |
||||
|
}, |
||||
|
}, { |
||||
|
tableName: "patrol_record", |
||||
|
comment: "", |
||||
|
indexes: [] |
||||
|
}); |
||||
|
dc.models.PatrolRecord = PatrolRecord; |
||||
|
return PatrolRecord; |
||||
|
}; |
@ -0,0 +1,10 @@ |
|||||
|
'use strict'; |
||||
|
const patrolRecord = require('../../controllers/patrolRecord/patrolRecord'); |
||||
|
|
||||
|
module.exports = function (app, router, opts) { |
||||
|
app.fs.api.logAttr['GET/patrolRecord/:patrolPlanId/:startTime/:endTime/:alarm'] = { content: '获取巡检记录', visible: true }; |
||||
|
router.get('/patrolRecord/:patrolPlanId/:startTime/:endTime/:alarm', patrolRecord.findPatrolRecord); |
||||
|
|
||||
|
app.fs.api.logAttr['POST/patrolRecord/add'] = { content: '新增巡检记录', visible: true } |
||||
|
router.post('/patrolRecord/add', patrolRecord.addPatrolRecord); |
||||
|
}; |
Loading…
Reference in new issue