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.
162 lines
5.2 KiB
162 lines
5.2 KiB
'use strict';
|
|
const zhidiaoSystem = require('../../../../utils/zhidiaoSystem.js');
|
|
|
|
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, vehicleLicensePlateNumber, line } = c
|
|
const corCompany = data.find(d => d.name === company)
|
|
if (!corCompany) {
|
|
data.push({
|
|
name: company || '--',
|
|
child: [{
|
|
name: fleet || '--',
|
|
child: [{
|
|
name: line || '--',
|
|
child: [{
|
|
id: c.id,
|
|
name: vehicleLicensePlateNumber,
|
|
}]
|
|
}]
|
|
}]
|
|
})
|
|
} else {
|
|
const corFleet = corCompany.child.find(d => d.name === fleet)
|
|
if (!corFleet) {
|
|
corCompany.child.push({
|
|
name: fleet || '--',
|
|
child: [{
|
|
name: line || '--',
|
|
child: [{
|
|
id: c.id,
|
|
name: vehicleLicensePlateNumber || '--',
|
|
}]
|
|
}]
|
|
})
|
|
} else {
|
|
const corLine = corFleet.child.find(d => d.name === line)
|
|
if (!corLine) {
|
|
corFleet.child.push({
|
|
name: line || '--',
|
|
child: [{
|
|
id: c.id,
|
|
name: vehicleLicensePlateNumber || '--',
|
|
}]
|
|
})
|
|
} else {
|
|
corLine.child.push({
|
|
id: c.id,
|
|
name: vehicleLicensePlateNumber || '--',
|
|
})
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
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 freightTransport = await models.Statistic.findOne({
|
|
where: {
|
|
type: 'freight'
|
|
}
|
|
})
|
|
|
|
const vehicleState = {
|
|
passengerTransport: passengerTransport ? passengerTransport.count : 0,
|
|
freightTransport: freightTransport ? freightTransport.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
|
|
}
|
|
}
|
|
}
|
|
|
|
async function busRunRealTime (ctx) {
|
|
try {
|
|
const { models } = ctx.fs.dc;
|
|
const { app } = ctx
|
|
|
|
const busCarRes = await models.BusCar.findAll({
|
|
attributes: ['id', 'vehicleLicensePlateNumber',],
|
|
})
|
|
|
|
const Authorization = zhidiaoSystem.createAuthorization()
|
|
const busRunRes = await app.fs.zhidiaoRequest.get(`getBusRunList`, {
|
|
header: {
|
|
Authorization: Authorization
|
|
}
|
|
})
|
|
|
|
ctx.status = 200;
|
|
ctx.body = (busRunRes || []).filter(b => busCarRes.some(bc => bc.vehicleLicensePlateNumber == b.busNoChar))
|
|
} 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,
|
|
busRunRealTime,
|
|
};
|