四好公路
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.
 
 
 
 

68 lines
2.0 KiB

'use strict';
async function overSpeedList (ctx) {
try {
const models = ctx.fs.dc.models;
const { userId } = ctx.fs.api;
const overSpeedRes = await models.Overspeed.findAll({
attributes: ['id', 'licensePlate', 'overrunRate', 'deductPoints', 'fine', 'processingTime'],
order: [['testTime', 'DESC']],
})
ctx.status = 200
ctx.body = {
processed: overSpeedRes.filter(s => s.processingTime).length,
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
};