Browse Source

DEL 管廊巡检计划

master
CODE 1 year ago
parent
commit
0e6da37a01
  1. 76
      script/2.0.0/data/1_reset_project_bind_point/index.js

76
script/2.0.0/data/1_reset_project_bind_point/index.js

@ -10,26 +10,26 @@ try {
const resetBing = [ const resetBing = [
{ {
projectId: 17, projectId: 17,
points: [192,187,196, points: [192, 187, 196,
188, 188,
189, 189,
186, 186,
190, 190,
191, 191,
193, 193,
194, 194,
195, 195,
197, 197,
182, 182,
178, 178,
179, 179,
180, 180,
181, 181,
183, 183,
184 184
] ]
}, },
{ {
projectId: 18, projectId: 18,
points: [138] points: [138]
} }
@ -38,8 +38,8 @@ try {
// 测试环境 // 测试环境
const pool = new Pool({ const pool = new Pool({
user: 'FashionAdmin', user: 'FashionAdmin',
host: '10.8.30.166', host: '10.8.30.39',
database: 'inspection-bak', database: 'inspection_231027_bak',
password: '123456', password: '123456',
port: 5432, port: 5432,
}) })
@ -66,6 +66,36 @@ try {
await client.query('BEGIN') await client.query('BEGIN')
console.log(`开始`); console.log(`开始`);
// 查所有管廊结构物
const projects = (await client.query(`SELECT * FROM "project" WHERE type='管廊'`)).rows
// console.log(projects);
// 查所有管廊结构物下的点位
const points = projects.length ? (await client.query(`SELECT * FROM point WHERE project_id IN (${projects.map(item => `'${item.id}'`).join(',')}, -1)`)).rows : []
// console.log(points);
// 查所有结构物相关的巡检计划
const plans = projects.length ? (await client.query(`SELECT * FROM patrol_plan WHERE structure_id IN (${projects.map(item => `'${item.id}'`).join(',')}, -1)`)).rows : []
if (plans.length)
// 删除计划相关人员
await client.query(`DELETE FROM patrol_plan_user WHERE patrol_plan_id IN (${plans.map(item => `'${item.id}'`).join(',')},-1)`)
// 查所有巡检记录
const records = plans.length ? (await client.query(`SELECT * FROM patrol_record WHERE patrol_plan_id IN (${plans.map(item => `'${item.id}'`).join(',')},-1)`)).rows : []
if (records.length) {
// 删除所有巡检问题
await client.query(`DELETE FROM patrol_record_issue_handle WHERE patrol_record_id IN (${records.map(item => `'${item.id}'`).join(',')},-1)`)
// 删除所有巡检记录
await client.query(`DELETE FROM patrol_record WHERE patrol_plan_id IN (${plans.map(item => `'${item.id}'`).join(',')},-1)`)
}
if (plans.length)
// 删除所有巡检计划
await client.query(`DELETE FROM patrol_plan WHERE structure_id IN (${projects.map(item => `'${item.id}'`).join(',')}, -1)`)
let index = 0 let index = 0
for (let r of resetBing) { for (let r of resetBing) {
if (!r.projectId || !r.points || !r.points.length) { if (!r.projectId || !r.points || !r.points.length) {
@ -84,7 +114,7 @@ try {
} }
const targetProject = (await client.query(` const targetProject = (await client.query(`
SELECT * FROM project WHERE id=$1; SELECT * FROM "project" WHERE id=$1;
`, [r.projectId] `, [r.projectId]
)).rows[0] )).rows[0]
if (!targetProject) { if (!targetProject) {
@ -100,6 +130,8 @@ try {
// 变更点位 // 变更点位
await client.query(updatePointSql) await client.query(updatePointSql)
//
index++ index++
} }

Loading…
Cancel
Save