|
@ -2,211 +2,211 @@ |
|
|
const roadKeyMap = require('./road.json') |
|
|
const roadKeyMap = require('./road.json') |
|
|
|
|
|
|
|
|
async function importIn (ctx) { |
|
|
async function importIn (ctx) { |
|
|
// 数据导入
|
|
|
// 数据导入
|
|
|
try { |
|
|
try { |
|
|
const models = ctx.fs.dc.models; |
|
|
const models = ctx.fs.dc.models; |
|
|
const { level, } = ctx.query; |
|
|
const { level, } = ctx.query; |
|
|
const data = ctx.request.body; |
|
|
const data = ctx.request.body; |
|
|
|
|
|
|
|
|
const roadRes = await models.Road.findAll({ |
|
|
const roadRes = await models.Road.findAll({ |
|
|
where: { |
|
|
where: { |
|
|
level, |
|
|
level, |
|
|
del: false |
|
|
del: false |
|
|
} |
|
|
} |
|
|
}) |
|
|
}) |
|
|
let preCreateArr = [] |
|
|
let preCreateArr = [] |
|
|
for (let d of data) { |
|
|
for (let d of data) { |
|
|
if (roadRes.some(r => r.routeCode + r.sectionNo == d['路线代码'] + d['路段序号'])) { |
|
|
if (roadRes.some(r => r.routeCode + r.sectionNo == d['路线代码'] + d['路段序号'])) { |
|
|
//repeat
|
|
|
//repeat
|
|
|
} else { |
|
|
} else { |
|
|
// await models.Road.create(d);
|
|
|
// await models.Road.create(d);
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
ctx.status = 204 |
|
|
ctx.status = 204 |
|
|
} catch (error) { |
|
|
} catch (error) { |
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|
|
ctx.status = 400; |
|
|
ctx.status = 400; |
|
|
ctx.body = { |
|
|
ctx.body = { |
|
|
message: typeof error == 'string' ? error : undefined |
|
|
message: typeof error == 'string' ? error : undefined |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
async function get (ctx) { |
|
|
async function get (ctx) { |
|
|
try { |
|
|
try { |
|
|
const models = ctx.fs.dc.models; |
|
|
const models = ctx.fs.dc.models; |
|
|
const { codePrefix, level, road, sectionStart, sectionEnd, alterId } = ctx.query; |
|
|
const { codePrefix, level, road, sectionStart, sectionEnd, alterId } = ctx.query; |
|
|
|
|
|
|
|
|
let findOption = { |
|
|
let findOption = { |
|
|
where: { |
|
|
where: { |
|
|
del: false |
|
|
del: false |
|
|
}, |
|
|
}, |
|
|
order: [['id', 'DESC']], |
|
|
order: [['id', 'DESC']], |
|
|
} |
|
|
} |
|
|
if (level == '村') { |
|
|
if (level == '村') { |
|
|
findOption.include = [{ model: models.Village, }] |
|
|
findOption.include = [{ model: models.Village, }] |
|
|
} |
|
|
} |
|
|
if (alterId) { |
|
|
if (alterId) { |
|
|
findOption.where.id = { $notIn: alterId } |
|
|
findOption.where.id = { $notIn: alterId } |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (codePrefix) { |
|
|
if (codePrefix) { |
|
|
findOption.where.routeCode = { $like: `${codePrefix}%` } |
|
|
findOption.where.routeCode = { $like: `${codePrefix}%` } |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (level) { |
|
|
if (level) { |
|
|
findOption.where.level = level |
|
|
findOption.where.level = level |
|
|
} |
|
|
} |
|
|
if (road || sectionStart || sectionEnd) { |
|
|
if (road || sectionStart || sectionEnd) { |
|
|
findOption.where['$or'] = {} |
|
|
findOption.where['$or'] = {} |
|
|
if (road) { |
|
|
if (road) { |
|
|
findOption.where['$or']. |
|
|
findOption.where['$or']. |
|
|
routeName = { $like: `%${road}%` } |
|
|
routeName = { $like: `%${road}%` } |
|
|
} |
|
|
} |
|
|
if (sectionStart) { |
|
|
if (sectionStart) { |
|
|
findOption.where['$or']. |
|
|
findOption.where['$or']. |
|
|
startingPlaceName = { $like: `%${sectionStart}%` } |
|
|
startingPlaceName = { $like: `%${sectionStart}%` } |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
if (sectionEnd) { |
|
|
if (sectionEnd) { |
|
|
findOption.where['$or']. |
|
|
findOption.where['$or']. |
|
|
stopPlaceName = { $like: `%${sectionEnd}%` } |
|
|
stopPlaceName = { $like: `%${sectionEnd}%` } |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const roadRes = await models.Road.findAll(findOption) |
|
|
const roadRes = await models.Road.findAll(findOption) |
|
|
|
|
|
|
|
|
ctx.status = 200; |
|
|
ctx.status = 200; |
|
|
ctx.body = roadRes |
|
|
ctx.body = roadRes |
|
|
} catch (error) { |
|
|
} catch (error) { |
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|
|
ctx.status = 400; |
|
|
ctx.status = 400; |
|
|
ctx.body = { |
|
|
ctx.body = { |
|
|
message: typeof error == 'string' ? error : undefined |
|
|
message: typeof error == 'string' ? error : undefined |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
async function getRoadSection (ctx) { |
|
|
async function getRoadSection (ctx) { |
|
|
try { |
|
|
try { |
|
|
const models = ctx.fs.dc.models; |
|
|
const models = ctx.fs.dc.models; |
|
|
const { level, road, sectionStart, sectionEnd } = ctx.query; |
|
|
const { level, road, sectionStart, sectionEnd } = ctx.query; |
|
|
let findOption = { |
|
|
let findOption = { |
|
|
where: {}, |
|
|
where: { del: false }, |
|
|
order: [['id', 'DESC']], |
|
|
order: [['id', 'DESC']], |
|
|
attributes: ['id', 'routeName', 'startingPlaceName', 'stopPlaceName', 'routeCode', 'sectionNo', 'level'] |
|
|
attributes: ['id', 'routeName', 'startingPlaceName', 'stopPlaceName', 'routeCode', 'sectionNo', 'level'] |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (level) { |
|
|
if (level) { |
|
|
findOption.where.level = level |
|
|
findOption.where.level = level |
|
|
} |
|
|
} |
|
|
if (road || sectionStart || sectionEnd) { |
|
|
if (road || sectionStart || sectionEnd) { |
|
|
findOption.where['$or'] = {} |
|
|
findOption.where['$or'] = {} |
|
|
if (road) { |
|
|
if (road) { |
|
|
findOption.where['$or']. |
|
|
findOption.where['$or']. |
|
|
routeName = { $like: `%${road}%` } |
|
|
routeName = { $like: `%${road}%` } |
|
|
} |
|
|
} |
|
|
if (sectionStart) { |
|
|
if (sectionStart) { |
|
|
findOption.where['$or']. |
|
|
findOption.where['$or']. |
|
|
startingPlaceName = { $like: `%${sectionStart}%` } |
|
|
startingPlaceName = { $like: `%${sectionStart}%` } |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
if (sectionEnd) { |
|
|
if (sectionEnd) { |
|
|
findOption.where['$or']. |
|
|
findOption.where['$or']. |
|
|
stopPlaceName = { $like: `%${sectionEnd}%` } |
|
|
stopPlaceName = { $like: `%${sectionEnd}%` } |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const roadRes = await models.Road.findAll(findOption) |
|
|
const roadRes = await models.Road.findAll(findOption) |
|
|
|
|
|
|
|
|
ctx.status = 200; |
|
|
ctx.status = 200; |
|
|
ctx.body = roadRes |
|
|
ctx.body = roadRes |
|
|
} catch (error) { |
|
|
} catch (error) { |
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|
|
ctx.status = 400; |
|
|
ctx.status = 400; |
|
|
ctx.body = { |
|
|
ctx.body = { |
|
|
message: typeof error == 'string' ? error : undefined |
|
|
message: typeof error == 'string' ? error : undefined |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
async function edit (ctx) { |
|
|
async function edit (ctx) { |
|
|
try { |
|
|
try { |
|
|
const models = ctx.fs.dc.models; |
|
|
const models = ctx.fs.dc.models; |
|
|
const data = ctx.request.body; |
|
|
const data = ctx.request.body; |
|
|
|
|
|
|
|
|
if (!data.roadId) { |
|
|
if (!data.roadId) { |
|
|
await models.Road.create(data) |
|
|
await models.Road.create(data) |
|
|
} else { |
|
|
} else { |
|
|
await models.Road.update( |
|
|
await models.Road.update( |
|
|
data, { |
|
|
data, { |
|
|
where: { |
|
|
where: { |
|
|
id: data.roadId |
|
|
id: data.roadId |
|
|
} |
|
|
} |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
ctx.status = 204 |
|
|
ctx.status = 204 |
|
|
} catch (error) { |
|
|
} catch (error) { |
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|
|
ctx.status = 400; |
|
|
ctx.status = 400; |
|
|
ctx.body = { |
|
|
ctx.body = { |
|
|
message: typeof error == 'string' ? error : undefined |
|
|
message: typeof error == 'string' ? error : undefined |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
async function del (ctx) { |
|
|
async function del (ctx) { |
|
|
try { |
|
|
try { |
|
|
const models = ctx.fs.dc.models; |
|
|
const models = ctx.fs.dc.models; |
|
|
const { roadId } = ctx.params; |
|
|
const { roadId } = ctx.params; |
|
|
|
|
|
|
|
|
// await models.Road.destroy({
|
|
|
// await models.Road.destroy({
|
|
|
// where: {
|
|
|
// where: {
|
|
|
// id: roadId
|
|
|
// id: roadId
|
|
|
// }
|
|
|
// }
|
|
|
// })
|
|
|
// })
|
|
|
await models.Road.update({ |
|
|
await models.Road.update({ |
|
|
del: true |
|
|
del: true |
|
|
}, { |
|
|
}, { |
|
|
where: { |
|
|
where: { |
|
|
id: roadId |
|
|
id: roadId |
|
|
} |
|
|
} |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
ctx.status = 204 |
|
|
ctx.status = 204 |
|
|
} catch (error) { |
|
|
} catch (error) { |
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|
|
ctx.status = 400; |
|
|
ctx.status = 400; |
|
|
ctx.body = { |
|
|
ctx.body = { |
|
|
message: typeof error == 'string' ? error : undefined |
|
|
message: typeof error == 'string' ? error : undefined |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
async function getVillageList (ctx) { |
|
|
async function getVillageList (ctx) { |
|
|
try { |
|
|
try { |
|
|
const models = ctx.fs.dc.models; |
|
|
const models = ctx.fs.dc.models; |
|
|
const { } = ctx.query; |
|
|
const { } = ctx.query; |
|
|
|
|
|
|
|
|
const res = await models.Village.findAll() |
|
|
const res = await models.Village.findAll() |
|
|
|
|
|
|
|
|
ctx.status = 200; |
|
|
ctx.status = 200; |
|
|
ctx.body = res |
|
|
ctx.body = res |
|
|
} catch (error) { |
|
|
} catch (error) { |
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|
|
ctx.status = 400; |
|
|
ctx.status = 400; |
|
|
ctx.body = { |
|
|
ctx.body = { |
|
|
message: typeof error == 'string' ? error : undefined |
|
|
message: typeof error == 'string' ? error : undefined |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
module.exports = { |
|
|
module.exports = { |
|
|
importIn, |
|
|
importIn, |
|
|
getRoadSection, |
|
|
getRoadSection, |
|
|
get, edit, del, |
|
|
get, edit, del, |
|
|
getVillageList, |
|
|
getVillageList, |
|
|
}; |
|
|
}; |