Browse Source

抽查导出修改

dev
wenlele 1 year ago
parent
commit
c9f65660c2
  1. 2
      api/app/lib/controllers/data/road.js
  2. 2
      api/app/lib/controllers/data/task.js
  3. 81
      api/app/lib/controllers/report/index.js
  4. 1
      api/utils/xlsxDownload.js

2
api/app/lib/controllers/data/road.js

@ -94,7 +94,7 @@ async function getRoadSection (ctx) {
const models = ctx.fs.dc.models;
const { level, road, sectionStart, sectionEnd } = ctx.query;
let findOption = {
where: {},
where: { del: false },
order: [['id', 'DESC']],
attributes: ['id', 'routeName', 'startingPlaceName', 'stopPlaceName', 'routeCode', 'sectionNo', 'level']
}

2
api/app/lib/controllers/data/task.js

@ -18,7 +18,7 @@ async function getTask (ctx) {
{
attributes: ['id', 'routeName', 'routeCode'],
model: models.Road,
where: query.id == undefined ? {} : whereRoadOpt
where: query.id == undefined ? {del: false} : whereRoadOpt
},
{

81
api/app/lib/controllers/report/index.js

@ -1194,58 +1194,75 @@ async function exportSpotRode (ctx) {
}]
})
let town = await models.Town.findAll({}) || []
let village = await models.Village.findAll({ attributes: ['id', 'name'] }) || []
const header = [{
key: 'level',
title: '道路类型',
key: 'townshipCode',
title: '所属乡镇',
}, {
key: 'villageId',
title: '所属行政村',
}, {
key: 'routeName',
title: '路线名称',
title: '路名称',
}, {
key: 'routeCode',
title: '路线代码',
title: '道路代码',
}, {
key: 'startStation',
title: '起点桩号',
}, {
key: 'stopStation',
title: '止点桩号',
}, {
key: 'technicalLevel',
title: '技术等级',
}, {
key: 'sectionNo',
title: '路段序号',
key: 'pavementType',
title: '路面类型',
}, {
key: 'startingPlaceName',
title: '起点名称',
key: 'pavementWidth',
title: '路面宽度',
}, {
key: 'stopPlaceName',
title: '止点名称',
key: 'subgradeWidth',
title: '路基宽度',
}, {
key: 'chainageMileage',
title: '里程',
title: '桩号里程',
}, {
key: 'maintenanceCount',
title: '养护次数(次)',
},]
function judgeLevel (routeCode) {
if (routeCode) {
if (routeCode.startsWith('X')) {
return '县道'
} else if (routeCode.startsWith('Y')) {
return '乡道'
} else if (routeCode.startsWith('C')) {
return '村道'
}
return ''
} else {
return ''
}
}
// function judgeLevel (routeCode) {
// if (routeCode) {
// if (routeCode.startsWith('X')) {
// return '县道'
// } else if (routeCode.startsWith('Y')) {
// return '乡道'
// } else if (routeCode.startsWith('C')) {
// return '村道'
// }
// return ''
// } else {
// return ''
// }
// }
let exportData = listRes.map(({ dataValues: item }) => {
let road = item.road && item.road.dataValues || {}
return {
level:
judgeLevel(road.routeCode)
,
townshipCode: (town.find(d => d.code == road.townshipCode) || {}).name || '--',
villageId: (village.find(d => road.villageId == d.id) || {}).name || '--',
routeName: road.routeName,
routeCode: road.routeCode,
sectionNo: road.sectionNo,
startingPlaceName: road.startingPlaceName,
stopPlaceName: road.stopPlaceName,
startStation: road.startStation,
stopStation: road.stopStation,
technicalLevel: road.technicalLevel,
pavementType: road.pavementType,
pavementWidth: road.pavementWidth,
subgradeWidth: road.subgradeWidth,
chainageMileage: road.chainageMileage,
maintenanceCount: item.maintenanceCount,
}
@ -1253,8 +1270,8 @@ async function exportSpotRode (ctx) {
const fileName = `${moment(previewRes.date).format('YYYY年MM月DD日HH时mm分')}道路抽查记录` + '.csv'
const filePath = await xlsxDownload.simpleExcelDown({
data: exportData, header, fileName: fileName
// data: exportData, header, fileName: fileName, gather: { data: previewRes.gather || [] }
data: exportData, header, fileName: fileName,
})
const fileData = fs.readFileSync(filePath);

1
api/utils/xlsxDownload.js

@ -108,6 +108,7 @@ async function gatherSheet ({ sheet_2, data = [] }) {
style.border.bottom = 'thin';
style.border.bottomColor = '#000000';
for (let i = 0; i < data.length; i++) {
const row = sheet_2.addRow();
for (let h of header) {

Loading…
Cancel
Save