From 4ae2855083c2ed4d57ec26ab26d184a78c247d67 Mon Sep 17 00:00:00 2001 From: "gao.zhiyuan" Date: Tue, 26 Jul 2022 11:48:49 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E8=B7=AF=E6=AE=B5=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/lib/controllers/data/road.js | 82 +++++++++++++++++++++++++--- api/app/lib/routes/data/index.js | 3 + api/log/development.log | 26 +++++++++ 3 files changed, 104 insertions(+), 7 deletions(-) diff --git a/api/app/lib/controllers/data/road.js b/api/app/lib/controllers/data/road.js index 5362d4d5..c3967c23 100644 --- a/api/app/lib/controllers/data/road.js +++ b/api/app/lib/controllers/data/road.js @@ -5,7 +5,7 @@ async function importIn (ctx) { // 数据导入 try { const models = ctx.fs.dc.models; - const { level } = ctx.query; + const { level, } = ctx.query; const data = ctx.request.body; const roadRes = await models.Road.findAll({ @@ -35,14 +35,81 @@ async function importIn (ctx) { async function get (ctx) { try { const models = ctx.fs.dc.models; - const { level } = ctx.query; + const { level, road, sectionStart, sectionEnd } = ctx.query; - const roadRes = await models.Road.findAll({ - where: { - level - }, + let findOption = { + where: {}, order: [['id', 'DESC']] - }) + } + + if (level) { + findOption.where.level = level + } + if (road || sectionStart || sectionEnd) { + findOption.where['$or'] = {} + if (road) { + findOption.where['$or'].push = { + 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'] + } + + if (level) { + findOption.where.level = level + } + if (road || sectionStart || sectionEnd) { + findOption.where['$or'] = {} + if (road) { + findOption.where['$or'].push = { + 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 @@ -104,5 +171,6 @@ async function del (ctx) { module.exports = { importIn, + getRoadSection, get, edit, del, }; \ No newline at end of file diff --git a/api/app/lib/routes/data/index.js b/api/app/lib/routes/data/index.js index c386eeba..9ecc0f52 100644 --- a/api/app/lib/routes/data/index.js +++ b/api/app/lib/routes/data/index.js @@ -73,6 +73,9 @@ module.exports = function (app, router, opts) { app.fs.api.logAttr['GET/road'] = { content: '获取道路数据', visible: true }; router.get('/road', road.get); + app.fs.api.logAttr['GET/road/section'] = { content: '获取道路路段数据', visible: true }; + router.get('/road/section', road.getRoadSection); + app.fs.api.logAttr['put/road'] = { content: '编辑道路数据', visible: true }; router.put('/road', road.edit); diff --git a/api/log/development.log b/api/log/development.log index 50a70f14..e257dbaa 100644 --- a/api/log/development.log +++ b/api/log/development.log @@ -8537,3 +8537,29 @@ 2022-07-26 09:52:19.623 - debug: [FS-LOGGER] Init. 2022-07-26 09:52:19.753 - info: [FS-ATTACHMENT] Inject attachment mw into router. 2022-07-26 09:52:19.753 - info: [FS-AUTH] Inject auth and api mv into router. +2022-07-26 11:33:33.533 - debug: [FS-LOGGER] Init. +2022-07-26 11:33:33.676 - info: [FS-ATTACHMENT] Inject attachment mw into router. +2022-07-26 11:33:33.677 - info: [FS-AUTH] Inject auth and api mv into router. +2022-07-26 11:35:35.369 - error: path: /road, error: ReferenceError: stopPlaceName is not defined +2022-07-26 11:35:38.298 - error: path: /road, error: ReferenceError: stopPlaceName is not defined +2022-07-26 11:35:41.257 - error: path: /road, error: ReferenceError: stopPlaceName is not defined +2022-07-26 11:35:46.213 - error: path: /road, error: ReferenceError: stopPlaceName is not defined +2022-07-26 11:35:48.608 - error: path: /road, error: ReferenceError: stopPlaceName is not defined +2022-07-26 11:35:56.490 - debug: [FS-LOGGER] Init. +2022-07-26 11:35:56.606 - info: [FS-ATTACHMENT] Inject attachment mw into router. +2022-07-26 11:35:56.606 - info: [FS-AUTH] Inject auth and api mv into router. +2022-07-26 11:36:00.269 - error: path: /road, error: ReferenceError: stopPlaceName is not defined +2022-07-26 11:36:31.053 - debug: [FS-LOGGER] Init. +2022-07-26 11:36:31.174 - info: [FS-ATTACHMENT] Inject attachment mw into router. +2022-07-26 11:36:31.174 - info: [FS-AUTH] Inject auth and api mv into router. +2022-07-26 11:36:37.420 - error: path: /road, error: ReferenceError: stopPlaceName is not defined +2022-07-26 11:36:48.130 - error: path: /road, error: ReferenceError: stopPlaceName is not defined +2022-07-26 11:36:58.215 - debug: [FS-LOGGER] Init. +2022-07-26 11:36:58.340 - info: [FS-ATTACHMENT] Inject attachment mw into router. +2022-07-26 11:36:58.340 - info: [FS-AUTH] Inject auth and api mv into router. +2022-07-26 11:38:05.804 - debug: [FS-LOGGER] Init. +2022-07-26 11:38:05.939 - info: [FS-ATTACHMENT] Inject attachment mw into router. +2022-07-26 11:38:05.939 - info: [FS-AUTH] Inject auth and api mv into router. +2022-07-26 11:43:16.204 - debug: [FS-LOGGER] Init. +2022-07-26 11:43:16.335 - info: [FS-ATTACHMENT] Inject attachment mw into router. +2022-07-26 11:43:16.335 - info: [FS-AUTH] Inject auth and api mv into router.