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.
		
		
		
		
		
			
		
			
				
					
					
						
							233 lines
						
					
					
						
							7.1 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							233 lines
						
					
					
						
							7.1 KiB
						
					
					
				
								'use strict';
							 | 
						|
								
							 | 
						|
								// const { simpleExcelDown } = require('../../../../utils/xlsxDownload');
							 | 
						|
								
							 | 
						|
								async function dataExport(ctx) {
							 | 
						|
								    try {
							 | 
						|
								        // 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',
							 | 
						|
								        //     },
							 | 
						|
								        // ]
							 | 
						|
								
							 | 
						|
								<<<<<<< HEAD
							 | 
						|
								        // const exportData = await models.BusCar.destroy({
							 | 
						|
								        //     where: {
							 | 
						|
								        //         id: { $in: ids.split(',') }
							 | 
						|
								        //     }
							 | 
						|
								        // })
							 | 
						|
								=======
							 | 
						|
								        const modalList = [
							 | 
						|
								            {
							 | 
						|
								                n: '道路',
							 | 
						|
								                k: 'road',
							 | 
						|
								                tableName: 'Road',
							 | 
						|
								            },
							 | 
						|
								            {
							 | 
						|
								                n: '桥梁',
							 | 
						|
								                k: 'bridge',
							 | 
						|
								                tableName: 'Bridge'
							 | 
						|
								            },
							 | 
						|
								            {
							 | 
						|
								                n: '运政车辆',
							 | 
						|
								                k: 'vehicle',
							 | 
						|
								                tableName: 'MunicipalVehicle',
							 | 
						|
								            },
							 | 
						|
								            {
							 | 
						|
								                n: '运政业户',
							 | 
						|
								                k: 'business',
							 | 
						|
								                tableName: 'MunicipalBusiness',
							 | 
						|
								            },
							 | 
						|
								            {
							 | 
						|
								                n: '工程一览',
							 | 
						|
								                k: 'project',
							 | 
						|
								                tableName: 'Project',
							 | 
						|
								            },
							 | 
						|
								            {
							 | 
						|
								                n: '治超',
							 | 
						|
								                k: 'overspeed',
							 | 
						|
								                tableName: 'Overspeed',
							 | 
						|
								            },
							 | 
						|
								            {
							 | 
						|
								                n: '公交线路',
							 | 
						|
								                k: 'busLine',
							 | 
						|
								                tableName: 'BusLine',
							 | 
						|
								            },
							 | 
						|
								            {
							 | 
						|
								                n: '公交车辆',
							 | 
						|
								                k: 'busCar',
							 | 
						|
								                tableName: 'BusCar',
							 | 
						|
								            },
							 | 
						|
								            {
							 | 
						|
								                n: '巡更记录',
							 | 
						|
								                k: 'patrol',
							 | 
						|
								                tableName: 'Report',
							 | 
						|
								            },
							 | 
						|
								            {
							 | 
						|
								                n: '养护记录',
							 | 
						|
								                k: 'maintenance',
							 | 
						|
								                tableName: 'Report',
							 | 
						|
								            },
							 | 
						|
								        ]
							 | 
						|
								>>>>>>> d8f96cea72338cf7a61dea293bd6d0cd5da48bb0
							 | 
						|
								
							 | 
						|
								        // const fileName = `摄像头信息列表_${moment().format('YYYYMMDDHHmmss')}` + '.csv'
							 | 
						|
								        // const filePath = await simpleExcelDown({ data: exportData, header, fileName: fileName })
							 | 
						|
								        // const fileData = fs.readFileSync(filePath);
							 | 
						|
								
							 | 
						|
								<<<<<<< HEAD
							 | 
						|
								        // ctx.status = 200;
							 | 
						|
								        // ctx.set('Content-Type', 'application/x-xls');
							 | 
						|
								        // ctx.set('Content-disposition', 'attachment; filename=' + encodeURI(fileName));
							 | 
						|
								        // ctx.body = fileData;
							 | 
						|
								    } catch (error) {
							 | 
						|
								        // ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
							 | 
						|
								        // ctx.status = 400;
							 | 
						|
								        // ctx.body = {
							 | 
						|
								        //     message: typeof error == 'string' ? error : undefined
							 | 
						|
								        // }
							 | 
						|
								    }
							 | 
						|
								=======
							 | 
						|
								        let findOption = {
							 | 
						|
								            where: {}
							 | 
						|
								        }
							 | 
						|
								        if (ids) {
							 | 
						|
								            findOption.where.id = { $in: ids.split(',') }
							 | 
						|
								        }
							 | 
						|
								        if (roadLevel) {
							 | 
						|
								            findOption.where.level = roadLevel
							 | 
						|
								        }
							 | 
						|
								        if (municipalType) {
							 | 
						|
								            findOption.where.type = municipalType
							 | 
						|
								        }
							 | 
						|
								
							 | 
						|
								        const exportData = await models[modalOption.tableName].findAll(findOption)
							 | 
						|
								        const tableAttributes = models[modalOption.tableName].tableAttributes
							 | 
						|
								        let header = []
							 | 
						|
								        for (let k in tableAttributes) {
							 | 
						|
								            const comment = tableAttributes[k].comment
							 | 
						|
								            if (k != 'id' && comment) {
							 | 
						|
								                if (comment == '品名' && municipalType == '出租车') {
							 | 
						|
								                    continue
							 | 
						|
								                }
							 | 
						|
								                header.push({
							 | 
						|
								                    title: comment || '-',
							 | 
						|
								                    key: k,
							 | 
						|
								                    index: tableAttributes[k].index,
							 | 
						|
								                })
							 | 
						|
								            }
							 | 
						|
								        }
							 | 
						|
								        header.sort((a, b) => { return a.index - b.index })
							 | 
						|
								
							 | 
						|
								        const fileName = `${modalOption.n}_${moment().format('YYYYMMDDHHmmss')}` + '.csv'
							 | 
						|
								        const filePath = await xlsxDownload.simpleExcelDown({ data: exportData, header, fileName: fileName, exp })
							 | 
						|
								        const fileData = fs.readFileSync(filePath);
							 | 
						|
								
							 | 
						|
								        ctx.status = 200;
							 | 
						|
								        ctx.set('Content-Type', 'application/x-xls');
							 | 
						|
								        ctx.set('Content-disposition', 'attachment; filename=' + encodeURI(fileName));
							 | 
						|
								        ctx.body = fileData;
							 | 
						|
								    } catch (error) {
							 | 
						|
								        ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
							 | 
						|
								        ctx.status = 400;
							 | 
						|
								        ctx.body = {
							 | 
						|
								            message: typeof error == 'string' ? error : undefined
							 | 
						|
								        }
							 | 
						|
								    }
							 | 
						|
								>>>>>>> d8f96cea72338cf7a61dea293bd6d0cd5da48bb0
							 | 
						|
								}
							 | 
						|
								
							 | 
						|
								async function godTrans(ctx) {
							 | 
						|
								    try {
							 | 
						|
								        const models = ctx.fs.dc.models;
							 | 
						|
								        const { userId } = ctx.fs.api
							 | 
						|
								
							 | 
						|
								        const res = await request.get('https://report.amap.com/ajax/districtRank.do?linksType=1&cityCode=360100')
							 | 
						|
								
							 | 
						|
								        const data = JSON.parse(res.text)
							 | 
						|
								        const nanchang = data.find(item => item.name == '南昌县') || {}
							 | 
						|
								        ctx.status = 200
							 | 
						|
								        ctx.body = nanchang
							 | 
						|
								    } catch (error) {
							 | 
						|
								        ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
							 | 
						|
								        ctx.status = 400;
							 | 
						|
								        ctx.body = {
							 | 
						|
								            message: typeof error == 'string' ? error : undefined
							 | 
						|
								        }
							 | 
						|
								    }
							 | 
						|
								}
							 | 
						|
								
							 | 
						|
								module.exports = {
							 | 
						|
								    dataExport
							 | 
						|
								};
							 |