Browse Source

road 标志是否删除或是否可抽查

dev
CODE 1 year ago
parent
commit
2de9db1cc2
  1. 28
      api/app/lib/controllers/data/road.js
  2. 11
      api/app/lib/controllers/data/task.js
  3. 6
      api/app/lib/controllers/overview/building.js
  4. 24
      api/app/lib/controllers/report/index.js
  5. 20
      api/app/lib/models/road.js
  6. 17
      scripts/1.4.0/data/2_update_road_data_无需执行/.vscode/launch.json
  7. 11
      scripts/1.4.0/data/2_update_road_data_无需执行/Dockerfile
  8. 7
      scripts/1.4.0/data/2_update_road_data_无需执行/Dockerfilenew
  9. BIN
      scripts/1.4.0/data/2_update_road_data_无需执行/data/乡道(新)(1).xlsx
  10. 58
      scripts/1.4.0/data/2_update_road_data_无需执行/index.js
  11. 17
      scripts/1.4.0/data/2_update_road_data_无需执行/package.json
  12. 9
      scripts/1.4.0/schema/5.update_road.sql

28
api/app/lib/controllers/data/road.js

@ -1,7 +1,7 @@
'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;
@ -10,7 +10,8 @@ async function importIn(ctx) {
const roadRes = await models.Road.findAll({ const roadRes = await models.Road.findAll({
where: { where: {
level level,
del: false
} }
}) })
let preCreateArr = [] let preCreateArr = []
@ -32,13 +33,15 @@ async function importIn(ctx) {
} }
} }
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
},
order: [['id', 'DESC']], order: [['id', 'DESC']],
} }
if (level == '村') { if (level == '村') {
@ -86,7 +89,7 @@ async function get(ctx) {
} }
} }
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;
@ -129,7 +132,7 @@ async function getRoadSection(ctx) {
} }
} }
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;
@ -155,12 +158,19 @@ async function edit(ctx) {
} }
} }
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: {
// id: roadId
// }
// })
await models.Road.update({
del: true
}, {
where: { where: {
id: roadId id: roadId
} }
@ -176,7 +186,7 @@ async function del(ctx) {
} }
} }
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;

11
api/app/lib/controllers/data/task.js

@ -1,6 +1,6 @@
'use strict'; 'use strict';
async function getTask(ctx) { async function getTask (ctx) {
try { try {
const models = ctx.fs.dc.models const models = ctx.fs.dc.models
const query = ctx.query const query = ctx.query
@ -8,7 +8,8 @@ async function getTask(ctx) {
isdanger: query.isdanger isdanger: query.isdanger
} }
const whereRoadOpt = { const whereRoadOpt = {
id: query.id id: query.id,
del: false
} }
const taskRes = await models.TaskManage.findAndCountAll({ const taskRes = await models.TaskManage.findAndCountAll({
order: [['id', 'DESC']], order: [['id', 'DESC']],
@ -40,7 +41,7 @@ async function getTask(ctx) {
} }
//删除任务 //删除任务
async function delTask(ctx) { async function delTask (ctx) {
try { try {
const models = ctx.fs.dc.models const models = ctx.fs.dc.models
const { id } = ctx.params const { id } = ctx.params
@ -56,12 +57,12 @@ async function delTask(ctx) {
} }
//编辑任务 //编辑任务
async function editTask(ctx) { async function editTask (ctx) {
//const transaction = await ctx.fs.dc.orm.transaction(); //const transaction = await ctx.fs.dc.orm.transaction();
try { try {
const models = ctx.fs.dc.models const models = ctx.fs.dc.models
const params = ctx.request.body const params = ctx.request.body
const road = await models.Road.findOne({ where: { id: params.routeId } }) const road = await models.Road.findOne({ where: { id: params.routeId, del: false } })
const user = await models.User.findOne({ where: { id: params.userId } }) const user = await models.User.findOne({ where: { id: params.userId } })
if (!params.id) { if (!params.id) {
await models.TaskManage.create({ await models.TaskManage.create({

6
api/app/lib/controllers/overview/building.js

@ -27,12 +27,14 @@ const areaCode = {
"360121572000": "良种繁殖场", "360121572000": "良种繁殖场",
} }
async function roadState(ctx) { async function roadState (ctx) {
try { try {
const models = ctx.fs.dc.models; const models = ctx.fs.dc.models;
const { userId } = ctx.fs.api; const { userId } = ctx.fs.api;
const roadRes = await models.Road.findAll({}) const roadRes = await models.Road.findAll({
del: false
})
const projectRoadRes = await models.Project.findAll({ const projectRoadRes = await models.Project.findAll({
type: 'road', type: 'road',
}) })

24
api/app/lib/controllers/report/index.js

@ -210,6 +210,9 @@ async function reportDetail (ctx) {
}, },
include: [{ include: [{
model: models.Road, model: models.Road,
where: {
del: false
},
as: 'road_', as: 'road_',
}], }],
}) })
@ -596,7 +599,9 @@ async function roadSpotPrepare (ctx) {
SELECT SELECT
SUM(COALESCE(CAST(chainage_mileage AS DOUBLE PRECISION), 0)) AS total_mileage SUM(COALESCE(CAST(chainage_mileage AS DOUBLE PRECISION), 0)) AS total_mileage
FROM road FROM road
WHERE ${keyMap[key]} ${otherWhere.length ? `AND ${otherWhere.join(' AND ')}` : ''} WHERE del = false
AND spot = true
AND ${keyMap[key]} ${otherWhere.length ? `AND ${otherWhere.join(' AND ')}` : ''}
`) `)
return res[0][0].total_mileage return res[0][0].total_mileage
} }
@ -607,7 +612,9 @@ async function roadSpotPrepare (ctx) {
} }
return await sequelize.query(` return await sequelize.query(`
SELECT id, chainage_mileage FROM road SELECT id, chainage_mileage FROM road
WHERE ${keyMap[key]} WHERE del = false
AND spot = true
AND ${keyMap[key]}
${lastRoadIds.length ? ${lastRoadIds.length ?
`AND id ${inOrNot ? 'IN' : 'NOT IN'} ( `AND id ${inOrNot ? 'IN' : 'NOT IN'} (
${lastRoadIds.map(item => `'${item}'`).join(',')},-1 ${lastRoadIds.map(item => `'${item}'`).join(',')},-1
@ -690,7 +697,9 @@ async function roadSpotPrepare (ctx) {
SELECT SELECT
DISTINCT township_code DISTINCT township_code
FROM road FROM road
WHERE township_code IS NOT NULL WHERE del = false
AND spot = true
AND township_code IS NOT NULL
`, { type: QueryTypes.SELECT }); `, { type: QueryTypes.SELECT });
let spotTownRoadIds = [] let spotTownRoadIds = []
@ -899,7 +908,8 @@ async function roadSpotDetail (ctx) {
include: [{ include: [{
model: models.Road, model: models.Road,
where: { where: {
...(keyword ? { routeName: { $ilike: `%${keyword}%` } } : {}) ...(keyword ? { routeName: { $ilike: `%${keyword}%` } } : {}),
del: false,
}, },
}, { }, {
model: models.RoadSpotCheckPreview, model: models.RoadSpotCheckPreview,
@ -975,7 +985,8 @@ async function roadSpotChange (ctx) {
const roadRes = await models.Road.findAll({ const roadRes = await models.Road.findAll({
where: { where: {
id: { $in: [originRoadId, changeRoadId] } id: { $in: [originRoadId, changeRoadId] },
del: false,
} }
}) })
@ -1100,6 +1111,9 @@ async function exportSpotRode (ctx) {
include: [{ include: [{
model: models.Road, model: models.Road,
// required: false, // required: false,
where: {
del: false,
}
}] }]
}) })

20
api/app/lib/models/road.js

@ -784,7 +784,25 @@ module.exports = dc => {
primaryKey: false, primaryKey: false,
field: "village_id", field: "village_id",
autoIncrement: false autoIncrement: false
} },
del: {
type: DataTypes.BOOLEAN,
allowNull: true,
defaultValue: false,
comment: null,
primaryKey: false,
field: "del",
autoIncrement: false
},
spot: {
type: DataTypes.BOOLEAN,
allowNull: true,
defaultValue: true,
comment: null,
primaryKey: false,
field: "spot",
autoIncrement: false
},
}, { }, {
tableName: "road", tableName: "road",
comment: "", comment: "",

17
scripts/1.4.0/data/2_update_road_data_无需执行/.vscode/launch.json

@ -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"
}
]
}

11
scripts/1.4.0/data/2_update_road_data_无需执行/Dockerfile

@ -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"]

7
scripts/1.4.0/data/2_update_road_data_无需执行/Dockerfilenew

@ -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"]

BIN
scripts/1.4.0/data/2_update_road_data_无需执行/data/乡道(新)(1).xlsx

Binary file not shown.

58
scripts/1.4.0/data/2_update_road_data_无需执行/index.js

@ -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)
}

17
scripts/1.4.0/data/2_update_road_data_无需执行/package.json

@ -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"
}
}

9
scripts/1.4.0/schema/5.update_road.sql

@ -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…
Cancel
Save