Browse Source

DEL 管廊巡检计划

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

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

@ -38,8 +38,8 @@ try {
// 测试环境
const pool = new Pool({
user: 'FashionAdmin',
host: '10.8.30.166',
database: 'inspection-bak',
host: '10.8.30.39',
database: 'inspection_231027_bak',
password: '123456',
port: 5432,
})
@ -66,6 +66,36 @@ try {
await client.query('BEGIN')
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
for (let r of resetBing) {
if (!r.projectId || !r.points || !r.points.length) {
@ -84,7 +114,7 @@ try {
}
const targetProject = (await client.query(`
SELECT * FROM project WHERE id=$1;
SELECT * FROM "project" WHERE id=$1;
`, [r.projectId]
)).rows[0]
if (!targetProject) {
@ -100,6 +130,8 @@ try {
// 变更点位
await client.query(updatePointSql)
//
index++
}

Loading…
Cancel
Save