zhaobing’ 1 year ago
parent
commit
3b09a4c7a6
  1. 2
      script/2.0.0/data/1_reset_project_bind_point/Dockerfile
  2. 153
      script/2.0.0/data/1_reset_project_bind_point/index.js

2
script/2.0.0/data/1_reset_project_bind_point/Dockerfile

@ -1,6 +1,6 @@
FROM repository.anxinyun.cn/base-images/nodejs12:20.10.12.2 FROM repository.anxinyun.cn/base-images/nodejs12:20.10.12.2
COPY . /var/app COPY ./script/2.0.0/data/1_reset_project_bind_point/ /var/app
WORKDIR /var/app WORKDIR /var/app

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

@ -9,7 +9,7 @@ try {
//! points 是要归属到这个结构物下的点位 id //! points 是要归属到这个结构物下的点位 id
const resetBing = [ const resetBing = [
{ {
projectId: 17, projectId: 20,
points: [192, 187, 196, points: [192, 187, 196,
188, 188,
189, 189,
@ -30,29 +30,118 @@ try {
] ]
}, },
{ {
projectId: 18, projectId: 21,
points: [138] points: [138]
},
{
projectId: 15,
points: [135]
},
{
projectId: 17,
points: [137]
},
{
projectId: 22,
points: [121,
122,
123,
124,
217,
125,
126,
127,
128,
130,
131,
132,
120,
119,
212,
213,
216,
208,
215
]
},
{
projectId: 19,
points: [159,
169,
165,
160,
161,
166,
162,
163,
164,
167,
168,
172,
170,
175,
171,
173,
174,
176,
177
]
},
{
projectId: 16,
points: [136]
},
{
projectId: 14,
points: [133]
},
{
projectId: 18,
points: [108,
106,
112,
142,
105,
145,
146,
148,
153,
149,
150,
151,
152,
156,
154,
155,
157,
158,
109
]
},
{
projectId: 13,
points: [139]
} }
] ]
// 测试环境 // 测试环境
const pool = new Pool({
user: 'FashionAdmin',
host: '10.8.30.166',
database: 'inspection-bak',
password: '123456',
port: 5432,
})
// 商用环境
// const pool = new Pool({ // const pool = new Pool({
// user: '', // user: 'FashionAdmin',
// host: '', // host: '10.8.30.39',
// database: '', // database: 'inspection_231027_bak',
// password: '', // password: '123456',
// port: 5432, // port: 5432,
// }) // })
// 商用环境
const pool = new Pool({
user: 'insAdmin',
host: '10.8.40.223',
database: 'inspection',
password: 'insAdmin123',
port: 5432,
})
const fun = async () => { const fun = async () => {
@ -66,6 +155,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 +203,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 +219,8 @@ try {
// 变更点位 // 变更点位
await client.query(updatePointSql) await client.query(updatePointSql)
//
index++ index++
} }

Loading…
Cancel
Save