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.
102 lines
3.0 KiB
102 lines
3.0 KiB
'use strict';
|
|
|
|
async function busCarLevelList (ctx) {
|
|
try {
|
|
const models = ctx.fs.dc.models;
|
|
const { userId } = ctx.fs.api;
|
|
|
|
let data = []
|
|
const busCarRes = await models.BusCar.findAll({
|
|
attributes: ['id', 'company', 'fleet', 'vehicleLicensePlateNumber', 'line'],
|
|
})
|
|
for (let c of busCarRes) {
|
|
const { company, fleet, line } = c
|
|
const corCompany = data.find(d => d.name === company)
|
|
if (!corCompany) {
|
|
data.push({
|
|
name: company,
|
|
child: [{
|
|
name: fleet,
|
|
child: [{ ...c.dataValues }]
|
|
}]
|
|
})
|
|
} else {
|
|
const corFleet = corCompany.child.find(d => d.name === fleet)
|
|
if (!corFleet) {
|
|
corCompany.child.push({
|
|
name: fleet,
|
|
child: [{ ...c.dataValues }]
|
|
})
|
|
} else {
|
|
corFleet.child.push({ ...c.dataValues })
|
|
}
|
|
}
|
|
}
|
|
|
|
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
|
|
}
|
|
}
|
|
}
|
|
|
|
async function vehicleStatistic (ctx) {
|
|
try {
|
|
const models = ctx.fs.dc.models;
|
|
const { userId } = ctx.fs.api;
|
|
|
|
const taxiBusiness = await models.MunicipalBusiness.findAll({
|
|
where: {
|
|
type: '出租车'
|
|
},
|
|
attributes: ['id', 'nameOfBusinessOwner']
|
|
})
|
|
const hazardousGoodsBusiness = await models.MunicipalBusiness.findAll({
|
|
where: {
|
|
type: '危货'
|
|
},
|
|
attributes: ['id', 'nameOfBusinessOwner']
|
|
})
|
|
const passengerTransport = await models.Statistic.findOne({
|
|
where: {
|
|
type: 'vehicle'
|
|
}
|
|
})
|
|
|
|
const vehicleState = {
|
|
passengerTransport: passengerTransport ? passengerTransport.count : 0,
|
|
taxi: await models.MunicipalVehicle.count({
|
|
where: {
|
|
type: '出租车'
|
|
},
|
|
}),
|
|
hazardousGoods: await models.MunicipalVehicle.count({
|
|
where: {
|
|
type: '危货'
|
|
}
|
|
}),
|
|
bus: await models.BusCar.count(),
|
|
taxiBusiness: taxiBusiness,
|
|
hazardousGoodsBusiness: hazardousGoodsBusiness,
|
|
}
|
|
|
|
ctx.status = 200
|
|
ctx.body = vehicleState
|
|
} catch (error) {
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
|
|
ctx.status = 400;
|
|
ctx.body = {
|
|
message: typeof error == 'string' ? error : undefined
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
module.exports = {
|
|
busCarLevelList,
|
|
vehicleStatistic,
|
|
};
|