CODE
1 year ago
12 changed files with 1354 additions and 1190 deletions
@ -1,202 +1,212 @@ |
|||||
'use strict'; |
'use strict'; |
||||
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 |
||||
}) |
} |
||||
let preCreateArr = [] |
}) |
||||
for (let d of data) { |
let preCreateArr = [] |
||||
if (roadRes.some(r => r.routeCode + r.sectionNo == d['路线代码'] + d['路段序号'])) { |
for (let d of data) { |
||||
//repeat
|
if (roadRes.some(r => r.routeCode + r.sectionNo == d['路线代码'] + d['路段序号'])) { |
||||
} else { |
//repeat
|
||||
// await models.Road.create(d);
|
} else { |
||||
} |
// await models.Road.create(d);
|
||||
} |
} |
||||
|
} |
||||
ctx.status = 204 |
|
||||
} catch (error) { |
ctx.status = 204 |
||||
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
} catch (error) { |
||||
ctx.status = 400; |
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
||||
ctx.body = { |
ctx.status = 400; |
||||
message: typeof error == 'string' ? error : undefined |
ctx.body = { |
||||
} |
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: { |
||||
order: [['id', 'DESC']], |
del: false |
||||
} |
}, |
||||
if (level == '村') { |
order: [['id', 'DESC']], |
||||
findOption.include = [{ model: models.Village, }] |
} |
||||
} |
if (level == '村') { |
||||
if (alterId) { |
findOption.include = [{ model: models.Village, }] |
||||
findOption.where.id = { $notIn: alterId } |
} |
||||
} |
if (alterId) { |
||||
|
findOption.where.id = { $notIn: alterId } |
||||
if (codePrefix) { |
} |
||||
findOption.where.routeCode = { $like: `${codePrefix}%` } |
|
||||
} |
if (codePrefix) { |
||||
|
findOption.where.routeCode = { $like: `${codePrefix}%` } |
||||
if (level) { |
} |
||||
findOption.where.level = level |
|
||||
} |
if (level) { |
||||
if (road || sectionStart || sectionEnd) { |
findOption.where.level = level |
||||
findOption.where['$or'] = {} |
} |
||||
if (road) { |
if (road || sectionStart || sectionEnd) { |
||||
findOption.where['$or']. |
findOption.where['$or'] = {} |
||||
routeName = { $like: `%${road}%` } |
if (road) { |
||||
} |
findOption.where['$or']. |
||||
if (sectionStart) { |
routeName = { $like: `%${road}%` } |
||||
findOption.where['$or']. |
} |
||||
startingPlaceName = { $like: `%${sectionStart}%` } |
if (sectionStart) { |
||||
|
findOption.where['$or']. |
||||
} |
startingPlaceName = { $like: `%${sectionStart}%` } |
||||
if (sectionEnd) { |
|
||||
findOption.where['$or']. |
} |
||||
stopPlaceName = { $like: `%${sectionEnd}%` } |
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; |
const roadRes = await models.Road.findAll(findOption) |
||||
let findOption = { |
|
||||
where: {}, |
ctx.status = 200; |
||||
order: [['id', 'DESC']], |
ctx.body = roadRes |
||||
attributes: ['id', 'routeName', 'startingPlaceName', 'stopPlaceName', 'routeCode', 'sectionNo', 'level'] |
} catch (error) { |
||||
} |
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
||||
|
ctx.status = 400; |
||||
if (level) { |
ctx.body = { |
||||
findOption.where.level = level |
message: typeof error == 'string' ? error : undefined |
||||
} |
} |
||||
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) { |
async function getRoadSection (ctx) { |
||||
try { |
try { |
||||
const models = ctx.fs.dc.models; |
const models = ctx.fs.dc.models; |
||||
const data = ctx.request.body; |
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 (!data.roadId) { |
|
||||
await models.Road.create(data) |
|
||||
} else { |
|
||||
await models.Road.update( |
|
||||
data, { |
|
||||
where: { |
|
||||
id: data.roadId |
|
||||
} |
} |
||||
}) |
if (sectionEnd) { |
||||
} |
findOption.where['$or']. |
||||
|
stopPlaceName = { $like: `%${sectionEnd}%` } |
||||
ctx.status = 204 |
} |
||||
} catch (error) { |
} |
||||
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|
||||
ctx.status = 400; |
const roadRes = await models.Road.findAll(findOption) |
||||
ctx.body = { |
|
||||
message: typeof error == 'string' ? error : undefined |
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 del(ctx) { |
async function edit (ctx) { |
||||
try { |
try { |
||||
const models = ctx.fs.dc.models; |
const models = ctx.fs.dc.models; |
||||
const { roadId } = ctx.params; |
const data = ctx.request.body; |
||||
|
|
||||
await models.Road.destroy({ |
if (!data.roadId) { |
||||
where: { |
await models.Road.create(data) |
||||
id: roadId |
} else { |
||||
} |
await models.Road.update( |
||||
}) |
data, { |
||||
|
where: { |
||||
ctx.status = 204 |
id: data.roadId |
||||
} catch (error) { |
} |
||||
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
}) |
||||
ctx.status = 400; |
} |
||||
ctx.body = { |
|
||||
message: typeof error == 'string' ? error : undefined |
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 |
||||
|
} |
||||
|
} |
||||
} |
} |
||||
|
|
||||
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, |
||||
}; |
}; |
File diff suppressed because it is too large
@ -0,0 +1,17 @@ |
|||||
|
{ |
||||
|
// 使用 IntelliSense 了解相关属性。 |
||||
|
// 悬停以查看现有属性的描述。 |
||||
|
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 |
||||
|
"version": "0.2.0", |
||||
|
"configurations": [ |
||||
|
{ |
||||
|
"type": "node", |
||||
|
"request": "launch", |
||||
|
"name": "启动程序", |
||||
|
"skipFiles": [ |
||||
|
"<node_internals>/**" |
||||
|
], |
||||
|
"program": "${workspaceFolder}\\index.js" |
||||
|
} |
||||
|
] |
||||
|
} |
@ -0,0 +1,11 @@ |
|||||
|
FROM repository.anxinyun.cn/base-images/nodejs12:20.10.12.2 |
||||
|
|
||||
|
COPY . /var/app |
||||
|
|
||||
|
WORKDIR /var/app |
||||
|
|
||||
|
RUN npm cache clean -f |
||||
|
RUN rm -rf package-lock.json |
||||
|
RUN npm install --registry http://10.8.30.22:7000 |
||||
|
|
||||
|
CMD ["node", "index.js"] |
@ -0,0 +1,7 @@ |
|||||
|
FROM repository.anxinyun.cn/base-images/nodejs12:20.10.12.2 |
||||
|
COPY ./scripts/1.3.1/data/1_insert_report_data /var/app |
||||
|
WORKDIR /var/app |
||||
|
RUN npm cache clean -f |
||||
|
RUN rm -rf package-lock.json |
||||
|
RUN npm install --registry https://nexus.ngaiot.com/repository/fs-npm/ |
||||
|
CMD ["node", "index.js"] |
Binary file not shown.
@ -0,0 +1,58 @@ |
|||||
|
try { |
||||
|
const { Pool, Client } = require('pg') |
||||
|
const XLSX = require('xlsx') |
||||
|
const path = require('path') |
||||
|
const fs = require("fs"); |
||||
|
|
||||
|
// 测试环境
|
||||
|
const pool = new Pool({ |
||||
|
user: 'postgres', |
||||
|
host: '10.8.30.32', |
||||
|
database: 'highways4good', |
||||
|
password: '123', |
||||
|
port: 5432, |
||||
|
}) |
||||
|
|
||||
|
const fun = async () => { |
||||
|
// note: we don't try/catch this because if connecting throws an exception
|
||||
|
// we don't need to dispose of the client (it will be undefined)
|
||||
|
const client = await pool.connect() |
||||
|
try { |
||||
|
await client.query('BEGIN') |
||||
|
console.log(`开始`); |
||||
|
|
||||
|
// 读取数据文件
|
||||
|
let workbook = XLSX.readFile(path.join(__dirname, './data/乡道(新)(1).xlsx')); |
||||
|
let firstSheetName = workbook.SheetNames[0]; |
||||
|
let worksheet = workbook.Sheets[firstSheetName]; |
||||
|
let res = XLSX.utils.sheet_to_json(worksheet, { |
||||
|
defval: '' |
||||
|
}); |
||||
|
|
||||
|
for (let r of res) { |
||||
|
console.log(r); |
||||
|
fs.writeFileSync('AnswerOld.sql', `;\n`, 'utf-8'); |
||||
|
// let time = generateRandomTimeString()
|
||||
|
// console.log(time);
|
||||
|
// await client.query(
|
||||
|
// `INSERT INTO report (report_type, project_type, road, time,content,user_id) VALUES($1, $2, $3, $4, $5, $6) `,
|
||||
|
// ['conserve', 'road', r['养护道路'], time, r['养护内容'], userId])
|
||||
|
// // break
|
||||
|
} |
||||
|
|
||||
|
// await client.query('ROLLBACK')
|
||||
|
await client.query('COMMIT') |
||||
|
console.log('执行完毕~') |
||||
|
} catch (e) { |
||||
|
await client.query('ROLLBACK') |
||||
|
console.log('执行错误~') |
||||
|
throw e |
||||
|
} finally { |
||||
|
client.release(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
fun() |
||||
|
} catch (error) { |
||||
|
console.error(error) |
||||
|
} |
@ -0,0 +1,17 @@ |
|||||
|
{ |
||||
|
"name": "appkey-generator", |
||||
|
"version": "1.0.0", |
||||
|
"description": "tool", |
||||
|
"main": "index.js", |
||||
|
"scripts": { |
||||
|
"test": "mocha", |
||||
|
"start": "set NODE_ENV=development&&node index" |
||||
|
}, |
||||
|
"author": "liu", |
||||
|
"license": "ISC", |
||||
|
"dependencies": { |
||||
|
"crypto-js": "^4.1.1", |
||||
|
"pg": "^7.18.2", |
||||
|
"xlsx": "^0.17.1" |
||||
|
} |
||||
|
} |
@ -0,0 +1,9 @@ |
|||||
|
alter table road |
||||
|
add del bool default false; |
||||
|
|
||||
|
alter table road |
||||
|
add spot bool default true; |
||||
|
|
||||
|
comment on column road.del is '标志道路是否被删除'; |
||||
|
|
||||
|
comment on column road.spot is '是否应该在抽查中被抽取'; |
Loading…
Reference in new issue