From c9f65660c238f9947eddf2f2508f9443f6475b1c Mon Sep 17 00:00:00 2001 From: wenlele Date: Fri, 22 Dec 2023 09:46:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=BD=E6=9F=A5=E5=AF=BC=E5=87=BA=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/lib/controllers/data/road.js | 378 ++++++++++++------------ api/app/lib/controllers/data/task.js | 2 +- api/app/lib/controllers/report/index.js | 81 +++-- api/utils/xlsxDownload.js | 1 + 4 files changed, 240 insertions(+), 222 deletions(-) diff --git a/api/app/lib/controllers/data/road.js b/api/app/lib/controllers/data/road.js index 38a41386..825d410b 100644 --- a/api/app/lib/controllers/data/road.js +++ b/api/app/lib/controllers/data/road.js @@ -2,211 +2,211 @@ const roadKeyMap = require('./road.json') async function importIn (ctx) { - // 数据导入 - try { - const models = ctx.fs.dc.models; - const { level, } = ctx.query; - const data = ctx.request.body; - - const roadRes = await models.Road.findAll({ - where: { - level, - del: false - } - }) - let preCreateArr = [] - for (let d of data) { - if (roadRes.some(r => r.routeCode + r.sectionNo == d['路线代码'] + d['路段序号'])) { - //repeat - } else { - // await models.Road.create(d); - } - } - - ctx.status = 204 - } catch (error) { - ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); - ctx.status = 400; - ctx.body = { - message: typeof error == 'string' ? error : undefined - } - } + // 数据导入 + try { + const models = ctx.fs.dc.models; + const { level, } = ctx.query; + const data = ctx.request.body; + + const roadRes = await models.Road.findAll({ + where: { + level, + del: false + } + }) + let preCreateArr = [] + for (let d of data) { + if (roadRes.some(r => r.routeCode + r.sectionNo == d['路线代码'] + d['路段序号'])) { + //repeat + } else { + // await models.Road.create(d); + } + } + + ctx.status = 204 + } catch (error) { + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); + ctx.status = 400; + ctx.body = { + message: typeof error == 'string' ? error : undefined + } + } } async function get (ctx) { - try { - const models = ctx.fs.dc.models; - const { codePrefix, level, road, sectionStart, sectionEnd, alterId } = ctx.query; - - let findOption = { - where: { - del: false - }, - order: [['id', 'DESC']], - } - if (level == '村') { - findOption.include = [{ model: models.Village, }] - } - if (alterId) { - findOption.where.id = { $notIn: alterId } - } - - if (codePrefix) { - findOption.where.routeCode = { $like: `${codePrefix}%` } - } - - if (level) { - findOption.where.level = level - } - if (road || sectionStart || sectionEnd) { - findOption.where['$or'] = {} - if (road) { - findOption.where['$or']. - routeName = { $like: `%${road}%` } - } - if (sectionStart) { - findOption.where['$or']. - startingPlaceName = { $like: `%${sectionStart}%` } - - } - if (sectionEnd) { - findOption.where['$or']. - stopPlaceName = { $like: `%${sectionEnd}%` } - - } - } - - const roadRes = await models.Road.findAll(findOption) - - ctx.status = 200; - ctx.body = roadRes - } catch (error) { - ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); - ctx.status = 400; - ctx.body = { - message: typeof error == 'string' ? error : undefined - } - } + try { + const models = ctx.fs.dc.models; + const { codePrefix, level, road, sectionStart, sectionEnd, alterId } = ctx.query; + + let findOption = { + where: { + del: false + }, + order: [['id', 'DESC']], + } + if (level == '村') { + findOption.include = [{ model: models.Village, }] + } + if (alterId) { + findOption.where.id = { $notIn: alterId } + } + + if (codePrefix) { + findOption.where.routeCode = { $like: `${codePrefix}%` } + } + + if (level) { + findOption.where.level = level + } + if (road || sectionStart || sectionEnd) { + findOption.where['$or'] = {} + if (road) { + findOption.where['$or']. + routeName = { $like: `%${road}%` } + } + if (sectionStart) { + findOption.where['$or']. + startingPlaceName = { $like: `%${sectionStart}%` } + + } + if (sectionEnd) { + findOption.where['$or']. + stopPlaceName = { $like: `%${sectionEnd}%` } + + } + } + + const roadRes = await models.Road.findAll(findOption) + + ctx.status = 200; + ctx.body = roadRes + } catch (error) { + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); + ctx.status = 400; + ctx.body = { + message: typeof error == 'string' ? error : undefined + } + } } async function getRoadSection (ctx) { - try { - const models = ctx.fs.dc.models; - const { level, road, sectionStart, sectionEnd } = ctx.query; - let findOption = { - where: {}, - order: [['id', 'DESC']], - attributes: ['id', 'routeName', 'startingPlaceName', 'stopPlaceName', 'routeCode', 'sectionNo', 'level'] - } - - if (level) { - findOption.where.level = level - } - if (road || sectionStart || sectionEnd) { - findOption.where['$or'] = {} - if (road) { - findOption.where['$or']. - routeName = { $like: `%${road}%` } - } - if (sectionStart) { - findOption.where['$or']. - startingPlaceName = { $like: `%${sectionStart}%` } - - } - if (sectionEnd) { - findOption.where['$or']. - stopPlaceName = { $like: `%${sectionEnd}%` } - } - } - - const roadRes = await models.Road.findAll(findOption) - - ctx.status = 200; - ctx.body = roadRes - } catch (error) { - ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); - ctx.status = 400; - ctx.body = { - message: typeof error == 'string' ? error : undefined - } - } + try { + const models = ctx.fs.dc.models; + const { level, road, sectionStart, sectionEnd } = ctx.query; + let findOption = { + where: { del: false }, + order: [['id', 'DESC']], + attributes: ['id', 'routeName', 'startingPlaceName', 'stopPlaceName', 'routeCode', 'sectionNo', 'level'] + } + + if (level) { + findOption.where.level = level + } + if (road || sectionStart || sectionEnd) { + findOption.where['$or'] = {} + if (road) { + findOption.where['$or']. + routeName = { $like: `%${road}%` } + } + if (sectionStart) { + findOption.where['$or']. + startingPlaceName = { $like: `%${sectionStart}%` } + + } + if (sectionEnd) { + findOption.where['$or']. + stopPlaceName = { $like: `%${sectionEnd}%` } + } + } + + const roadRes = await models.Road.findAll(findOption) + + ctx.status = 200; + ctx.body = roadRes + } catch (error) { + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); + ctx.status = 400; + ctx.body = { + message: typeof error == 'string' ? error : undefined + } + } } async function edit (ctx) { - try { - const models = ctx.fs.dc.models; - const data = ctx.request.body; - - if (!data.roadId) { - await models.Road.create(data) - } else { - await models.Road.update( - data, { - where: { - id: data.roadId - } - }) - } - - ctx.status = 204 - } catch (error) { - ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); - ctx.status = 400; - ctx.body = { - message: typeof error == 'string' ? error : undefined - } - } + try { + const models = ctx.fs.dc.models; + const data = ctx.request.body; + + if (!data.roadId) { + await models.Road.create(data) + } else { + await models.Road.update( + data, { + where: { + id: data.roadId + } + }) + } + + ctx.status = 204 + } catch (error) { + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); + ctx.status = 400; + ctx.body = { + message: typeof error == 'string' ? error : undefined + } + } } async function del (ctx) { - try { - const models = ctx.fs.dc.models; - const { roadId } = ctx.params; - - // await models.Road.destroy({ - // where: { - // id: roadId - // } - // }) - await models.Road.update({ - del: true - }, { - where: { - id: roadId - } - }) - - ctx.status = 204 - } catch (error) { - ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); - ctx.status = 400; - ctx.body = { - message: typeof error == 'string' ? error : undefined - } - } + try { + const models = ctx.fs.dc.models; + const { roadId } = ctx.params; + + // await models.Road.destroy({ + // where: { + // id: roadId + // } + // }) + await models.Road.update({ + del: true + }, { + where: { + id: roadId + } + }) + + ctx.status = 204 + } catch (error) { + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); + ctx.status = 400; + ctx.body = { + message: typeof error == 'string' ? error : undefined + } + } } async function getVillageList (ctx) { - try { - const models = ctx.fs.dc.models; - const { } = ctx.query; - - const res = await models.Village.findAll() - - ctx.status = 200; - ctx.body = res - } catch (error) { - ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); - ctx.status = 400; - ctx.body = { - message: typeof error == 'string' ? error : undefined - } - } + try { + const models = ctx.fs.dc.models; + const { } = ctx.query; + + const res = await models.Village.findAll() + + ctx.status = 200; + ctx.body = res + } catch (error) { + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); + ctx.status = 400; + ctx.body = { + message: typeof error == 'string' ? error : undefined + } + } } module.exports = { - importIn, - getRoadSection, - get, edit, del, - getVillageList, + importIn, + getRoadSection, + get, edit, del, + getVillageList, }; \ No newline at end of file diff --git a/api/app/lib/controllers/data/task.js b/api/app/lib/controllers/data/task.js index 6bdfa745..6e60259d 100644 --- a/api/app/lib/controllers/data/task.js +++ b/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 }, { diff --git a/api/app/lib/controllers/report/index.js b/api/app/lib/controllers/report/index.js index 3baa64df..9568424f 100644 --- a/api/app/lib/controllers/report/index.js +++ b/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); diff --git a/api/utils/xlsxDownload.js b/api/utils/xlsxDownload.js index 9e13f87f..af046879 100644 --- a/api/utils/xlsxDownload.js +++ b/api/utils/xlsxDownload.js @@ -107,6 +107,7 @@ async function gatherSheet ({ sheet_2, data = [] }) { style.border.rightColor = '#000000'; style.border.bottom = 'thin'; style.border.bottomColor = '#000000'; + for (let i = 0; i < data.length; i++) { const row = sheet_2.addRow();