|
|
@ -5,14 +5,39 @@ async function findPatrolRecord (ctx, next) { |
|
|
|
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' }; |
|
|
|
const { startTime, endTime, alarm, patrolPlanId, pointId } = ctx.params; |
|
|
|
// patrolPlanId传all查所有
|
|
|
|
if (patrolPlanId == 'all') { |
|
|
|
/* 如果有startTime && endTime,查询所有符合条件的数据 */ |
|
|
|
if (startTime && endTime) { |
|
|
|
rslt = await models.PatrolRecord.findAll({ |
|
|
|
where: { alarm, inspectionTime: { $between: [startTime, endTime] }, pointId: { $in: pointId.split(',') } }, |
|
|
|
}); |
|
|
|
} else { |
|
|
|
/* 如果没有startTime && endTime,查询每个点位最新一条符合条件的数据 */ |
|
|
|
a = await models.PatrolRecord.findAll({ |
|
|
|
where: { alarm, 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 { |
|
|
|
rslt = await models.PatrolRecord.findAll({ |
|
|
|
where: { patrolPlanId: { $in: patrolPlanId.split(',') }, alarm, inspectionTime: { $between: [startTime, endTime] } }, |
|
|
|
}); |
|
|
|
if (startTime && endTime) { |
|
|
|
rslt = await models.PatrolRecord.findAll({ |
|
|
|
where: { patrolPlanId: { $in: patrolPlanId.split(',') }, alarm, inspectionTime: { $between: [startTime, endTime] }, pointId: { $in: pointId.split(',') } }, |
|
|
|
}); |
|
|
|
} else { |
|
|
|
/* 如果没有startTime && endTime,查询每个点位最新一条符合条件的数据 */ |
|
|
|
a = await models.PatrolRecord.findAll({ |
|
|
|
where: { patrolPlanId: { $in: patrolPlanId.split(',') }, alarm, 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 |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
ctx.status = 200; |
|
|
|
ctx.body = rslt; |
|
|
|
error = null |
|
|
|