四好公路
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
2.2 KiB

3 years ago
'use strict';
async function overSpeedList (ctx) {
try {
const models = ctx.fs.dc.models;
const { userId } = ctx.fs.api;
3 years ago
const { limit } = ctx.query;
3 years ago
const overSpeedRes = await models.Overspeed.findAll({
3 years ago
attributes: ['id', 'licensePlate', 'overrunRate', 'deductPoints', 'fine', 'processingTime', 'testTime'],
3 years ago
order: [['testTime', 'DESC']],
3 years ago
limit: limit || 120,
})
const overSpeedProcessedCount = await models.Overspeed.count({
where: {
processingTime: { $ne: null }
}
3 years ago
})
ctx.status = 200
ctx.body = {
3 years ago
processed: overSpeedProcessedCount,
3 years ago
overSpeedList: overSpeedRes,
}
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = {
message: typeof error == 'string' ? error : undefined
}
}
}
async function overSpeedProcessed (ctx) {
try {
const models = ctx.fs.dc.models;
const { userId } = ctx.fs.api;
const overSpeedCountRes = await models.Overspeed.count({
attributes: ['nameOfInspectionPoint'],
group: ['nameOfInspectionPoint'],
})
const overSpeedCountProcessedRes = await models.Overspeed.count({
attributes: ['nameOfInspectionPoint'],
where: { processingTime: { $ne: null } },
group: ['nameOfInspectionPoint'],
})
let data = []
for (let c of overSpeedCountRes) {
const corProcessed = overSpeedCountProcessedRes.find(d => d.nameOfInspectionPoint == c.nameOfInspectionPoint)
if (corProcessed) {
data.push({
name: c.nameOfInspectionPoint,
processed: corProcessed.count,
total: c.count,
})
}
}
ctx.status = 200
ctx.body = data
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = {
message: typeof error == 'string' ? error : undefined
}
}
}
module.exports = {
overSpeedList,
overSpeedProcessed
};