|
|
@ -10,28 +10,52 @@ async function findPatrolRecord (ctx, next) { |
|
|
|
if (patrolPlanId == 'all') { |
|
|
|
/* 如果有startTime && endTime,查询所有符合条件的数据 */ |
|
|
|
if (startTime && endTime) { |
|
|
|
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,查询每个点位最新一条符合条件的数据 */ |
|
|
|
let a = [] |
|
|
|
if (pointId) { |
|
|
|
a = await models.PatrolRecord.findAll({ |
|
|
|
where: { alarm, pointId: { $in: pointId.split(',') } }, |
|
|
|
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) { |
|
|
|
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,查询每个点位最新一条符合条件的数据 */ |
|
|
|
if (pointId) { |
|
|
|
a = await models.PatrolRecord.findAll({ |
|
|
|
where: { patrolPlanId: { $in: patrolPlanId.split(',') }, alarm, pointId: { $in: pointId.split(',') } }, |
|
|
|
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 |
|
|
|
}) |
|
|
|