Browse Source

巡检记录查询接口修改

master
xincheng 2 years ago
parent
commit
eba6554019
  1. 48
      api/app/lib/controllers/patrolRecord/patrolRecord.js
  2. 2
      api/app/lib/routes/patrolRecord/patrolRecord.js

48
api/app/lib/controllers/patrolRecord/patrolRecord.js

@ -10,28 +10,52 @@ async function findPatrolRecord (ctx, next) {
if (patrolPlanId == 'all') {
/* 如果有startTime && endTime,查询所有符合条件的数据 */
if (startTime && endTime) {
rslt = await models.PatrolRecord.findAll({
where: { alarm, inspectionTime: { $between: [startTime, endTime] }, pointId: { $in: pointId.split(',') } },
});
if (pointId) {
rslt = await models.PatrolRecord.findAll({
where: { alarm, inspectionTime: { $between: [startTime, endTime] }, pointId: { $in: pointId.split(',') } },
});
} else {
rslt = await models.PatrolRecord.findAll({
where: { alarm, inspectionTime: { $between: [startTime, endTime] } },
});
}
} else {
/* 如果没有startTime && endTime,查询每个点位最新一条符合条件的数据 */
a = await models.PatrolRecord.findAll({
where: { alarm, pointId: { $in: pointId.split(',') } },
});
let a = []
if (pointId) {
a = await models.PatrolRecord.findAll({
where: { pointId: { $in: pointId.split(',') } },
});
}
rslt = pointId.split(',').map(i => {
return a.filter(t => t.pointId === i).sort((a, b) => b.id - a.id)[0] || null
})
}
} else {
if (startTime && endTime) {
rslt = await models.PatrolRecord.findAll({
where: { patrolPlanId: { $in: patrolPlanId.split(',') }, alarm, inspectionTime: { $between: [startTime, endTime] }, pointId: { $in: pointId.split(',') } },
});
if (pointId) {
rslt = await models.PatrolRecord.findAll({
where: { patrolPlanId: { $in: patrolPlanId.split(',') }, alarm, inspectionTime: { $between: [startTime, endTime] }, pointId: { $in: pointId.split(',') } },
});
} else {
rslt = await models.PatrolRecord.findAll({
where: { patrolPlanId: { $in: patrolPlanId.split(',') }, alarm, inspectionTime: { $between: [startTime, endTime] } },
});
}
} else {
let a = []
/* 如果没有startTime && endTime,查询每个点位最新一条符合条件的数据 */
a = await models.PatrolRecord.findAll({
where: { patrolPlanId: { $in: patrolPlanId.split(',') }, alarm, pointId: { $in: pointId.split(',') } },
});
if (pointId) {
a = await models.PatrolRecord.findAll({
where: { patrolPlanId: { $in: patrolPlanId.split(',') }, pointId: { $in: pointId.split(',') } },
});
} else {
a = await models.PatrolRecord.findAll({
where: { patrolPlanId: { $in: patrolPlanId.split(',') } },
});
}
rslt = pointId.split(',').map(i => {
return a.filter(t => t.pointId === i).sort((a, b) => b.id - a.id)[0] || null
})

2
api/app/lib/routes/patrolRecord/patrolRecord.js

@ -3,6 +3,8 @@ const patrolRecord = require('../../controllers/patrolRecord/patrolRecord');
module.exports = function (app, router, opts) {
app.fs.api.logAttr['GET/patrolRecord/:patrolPlanId/:startTime/:endTime/:alarm/:pointId'] = { content: '获取巡检记录', visible: true };
// web端、小程序端查数据:patrolPlanId为all,不需要传pointId
// 小程序端查点位最新一条数据:startTime、endTime、alarm不传
router.get('/patrolRecord/:patrolPlanId/:startTime/:endTime/:alarm/:pointId', patrolRecord.findPatrolRecord);
app.fs.api.logAttr['POST/patrolRecord/add'] = { content: '新增巡检记录', visible: true }

Loading…
Cancel
Save