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

125 lines
3.7 KiB

'use strict';
3 years ago
const fs = require('fs');
const xlsxDownload = require('../../../../utils/xlsxDownload.js');
const moment = require('moment');
async function dataExport (ctx) {
try {
3 years ago
const models = ctx.fs.dc.models;
const { userId } = ctx.fs.api
const { ids } = ctx.query;
const fileList = [
{
n: '道路',
tableName: 'road',
defaultKey: ['level'],
defaultValue: ['村'],
},
{
n: '道路',
tableName: 'road',
defaultKey: ['level'],
defaultValue: ['县'],
},
{
n: '道路',
tableName: 'road',
defaultKey: ['level'],
defaultValue: ['乡'],
},
{
n: '桥梁',
tableName: 'bridge'
},
{
n: '运政车辆',
tableName: 'municipal_vehicle',
defaultKey: ['type'],
defaultValue: ['出租车'],
},
{
n: '运政车辆',
tableName: 'municipal_vehicle',
defaultKey: ['type'],
defaultValue: ['危货'],
},
{
n: '运政业户',
tableName: 'municipal_business',
defaultKey: ['type'],
defaultValue: ['出租车'],
},
{
n: '运政业户',
tableName: 'municipal_business',
defaultKey: ['type'],
defaultValue: ['危货'],
},
{
n: '工程一览',
tableName: 'project',
defaultKey: ['done', 'type'],
defaultValue: [false, 'road'],
},
{
n: '工程一览',
tableName: 'project',
defaultKey: ['done', 'type'],
defaultValue: [false, 'bridge'],
},
{
n: '治超',
tableName: 'overspeed',
},
{
n: '公交线路',
tableName: 'bus_line',
},
{
n: '公交车辆',
tableName: 'bus_car',
},
]
3 years ago
let findOption = {
where: {}
}
if (ids) {
findOption.where.id = { $in: ids.split(',') }
}
3 years ago
const exportData = await models.BusCar.findAll(findOption)
const tableAttributes = models.BusCar.tableAttributes
let header = []
for (let k in tableAttributes) {
if (k != 'id') {
header.push({
title: tableAttributes[k].comment || '-',
key: k,
index: tableAttributes[k].index,
})
}
}
header.sort((a, b) => { return a.index - b.index })
3 years ago
const fileName = `摄像头信息列表_${moment().format('YYYYMMDDHHmmss')}` + '.csv'
const filePath = await xlsxDownload.simpleExcelDown({ data: exportData, header, fileName: fileName })
const fileData = fs.readFileSync(filePath);
3 years ago
ctx.status = 200;
ctx.set('Content-Type', 'application/x-xls');
ctx.set('Content-disposition', 'attachment; filename=' + encodeURI(fileName));
ctx.body = fileData;
} catch (error) {
3 years ago
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = {
message: typeof error == 'string' ? error : undefined
}
}
}
module.exports = {
dataExport
};