|
|
@ -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, |
|
|
|
}; |