|
@ -7,90 +7,75 @@ async function dataExport (ctx) { |
|
|
try { |
|
|
try { |
|
|
const models = ctx.fs.dc.models; |
|
|
const models = ctx.fs.dc.models; |
|
|
const { userId } = ctx.fs.api |
|
|
const { userId } = ctx.fs.api |
|
|
const { ids } = ctx.query; |
|
|
const { exp, ids, roadLevel, municipalType } = ctx.query; |
|
|
|
|
|
|
|
|
const fileList = [ |
|
|
if (!exp) { |
|
|
{ |
|
|
throw '参数错误'; |
|
|
n: '道路', |
|
|
} |
|
|
tableName: 'road', |
|
|
|
|
|
defaultKey: ['level'], |
|
|
const modalList = [ |
|
|
defaultValue: ['村'], |
|
|
|
|
|
}, |
|
|
|
|
|
{ |
|
|
|
|
|
n: '道路', |
|
|
|
|
|
tableName: 'road', |
|
|
|
|
|
defaultKey: ['level'], |
|
|
|
|
|
defaultValue: ['县'], |
|
|
|
|
|
}, |
|
|
|
|
|
{ |
|
|
{ |
|
|
n: '道路', |
|
|
n: '道路', |
|
|
tableName: 'road', |
|
|
k: 'road', |
|
|
defaultKey: ['level'], |
|
|
tableName: 'Road', |
|
|
defaultValue: ['乡'], |
|
|
|
|
|
}, |
|
|
}, |
|
|
{ |
|
|
{ |
|
|
n: '桥梁', |
|
|
n: '桥梁', |
|
|
tableName: 'bridge' |
|
|
k: 'bridge', |
|
|
}, |
|
|
tableName: 'Bridge' |
|
|
{ |
|
|
|
|
|
n: '运政车辆', |
|
|
|
|
|
tableName: 'municipal_vehicle', |
|
|
|
|
|
defaultKey: ['type'], |
|
|
|
|
|
defaultValue: ['出租车'], |
|
|
|
|
|
}, |
|
|
}, |
|
|
{ |
|
|
{ |
|
|
n: '运政车辆', |
|
|
n: '运政车辆', |
|
|
tableName: 'municipal_vehicle', |
|
|
k: 'vehicle', |
|
|
defaultKey: ['type'], |
|
|
tableName: 'MunicipalVehicle', |
|
|
defaultValue: ['危货'], |
|
|
|
|
|
}, |
|
|
}, |
|
|
{ |
|
|
{ |
|
|
n: '运政业户', |
|
|
n: '运政业户', |
|
|
tableName: 'municipal_business', |
|
|
k: 'business', |
|
|
defaultKey: ['type'], |
|
|
tableName: 'MunicipalBusiness', |
|
|
defaultValue: ['出租车'], |
|
|
|
|
|
}, |
|
|
|
|
|
{ |
|
|
|
|
|
n: '运政业户', |
|
|
|
|
|
tableName: 'municipal_business', |
|
|
|
|
|
defaultKey: ['type'], |
|
|
|
|
|
defaultValue: ['危货'], |
|
|
|
|
|
}, |
|
|
|
|
|
{ |
|
|
|
|
|
n: '工程一览', |
|
|
|
|
|
tableName: 'project', |
|
|
|
|
|
defaultKey: ['done', 'type'], |
|
|
|
|
|
defaultValue: [false, 'road'], |
|
|
|
|
|
}, |
|
|
}, |
|
|
{ |
|
|
{ |
|
|
n: '工程一览', |
|
|
n: '工程一览', |
|
|
tableName: 'project', |
|
|
k: 'project', |
|
|
defaultKey: ['done', 'type'], |
|
|
tableName: 'Project', |
|
|
defaultValue: [false, 'bridge'], |
|
|
|
|
|
}, |
|
|
}, |
|
|
{ |
|
|
{ |
|
|
n: '治超', |
|
|
n: '治超', |
|
|
tableName: 'overspeed', |
|
|
k: 'overspeed', |
|
|
|
|
|
tableName: 'Overspeed', |
|
|
}, |
|
|
}, |
|
|
{ |
|
|
{ |
|
|
n: '公交线路', |
|
|
n: '公交线路', |
|
|
tableName: 'bus_line', |
|
|
k: 'busLine', |
|
|
|
|
|
tableName: 'BusLine', |
|
|
}, |
|
|
}, |
|
|
{ |
|
|
{ |
|
|
n: '公交车辆', |
|
|
n: '公交车辆', |
|
|
tableName: 'bus_car', |
|
|
k: 'busCar', |
|
|
|
|
|
tableName: 'BusCar', |
|
|
}, |
|
|
}, |
|
|
] |
|
|
] |
|
|
|
|
|
|
|
|
|
|
|
const modalOption = modalList.find(item => item.k == exp); |
|
|
|
|
|
if (!modalOption) { |
|
|
|
|
|
throw '参数错误'; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
let findOption = { |
|
|
let findOption = { |
|
|
where: {} |
|
|
where: {} |
|
|
} |
|
|
} |
|
|
if (ids) { |
|
|
if (ids) { |
|
|
findOption.where.id = { $in: ids.split(',') } |
|
|
findOption.where.id = { $in: ids.split(',') } |
|
|
} |
|
|
} |
|
|
|
|
|
if (roadLevel) { |
|
|
|
|
|
findOption.where.level = roadLevel |
|
|
|
|
|
} |
|
|
|
|
|
if (municipalType) { |
|
|
|
|
|
findOption.where.type = municipalType |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
const exportData = await models.BusCar.findAll(findOption) |
|
|
const exportData = await models[modalOption.tableName].findAll(findOption) |
|
|
const tableAttributes = models.BusCar.tableAttributes |
|
|
const tableAttributes = models[modalOption.tableName].tableAttributes |
|
|
let header = [] |
|
|
let header = [] |
|
|
for (let k in tableAttributes) { |
|
|
for (let k in tableAttributes) { |
|
|
if (k != 'id') { |
|
|
if (k != 'id') { |
|
@ -103,7 +88,7 @@ async function dataExport (ctx) { |
|
|
} |
|
|
} |
|
|
header.sort((a, b) => { return a.index - b.index }) |
|
|
header.sort((a, b) => { return a.index - b.index }) |
|
|
|
|
|
|
|
|
const fileName = `摄像头信息列表_${moment().format('YYYYMMDDHHmmss')}` + '.csv' |
|
|
const fileName = `${modalOption.n}_${moment().format('YYYYMMDDHHmmss')}` + '.csv' |
|
|
const filePath = await xlsxDownload.simpleExcelDown({ data: exportData, header, fileName: fileName }) |
|
|
const filePath = await xlsxDownload.simpleExcelDown({ data: exportData, header, fileName: fileName }) |
|
|
const fileData = fs.readFileSync(filePath); |
|
|
const fileData = fs.readFileSync(filePath); |
|
|
|
|
|
|
|
|