// 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)
constanxinClient=awaitanxinyunPool.connect()
constpomsClient=awaitpomsPool.connect()
anxinClient.on('error',err=>{
console.error(err);
})
pomsClient.on('error',()=>{
console.error(err);
})
try{
awaitanxinClient.query('BEGIN')
awaitpomsClient.query('BEGIN')
console.log(`开始`);
constprojects=(awaitanxinClient.query(`SELECT * FROM "t_project"`)).rows
// console.log(projects);
// 遍历项目
for(letprojectofprojects){
console.log(`遍历 ${project.id}${project.name}`);
// 查项目下结构物
conststrucCount=(awaitanxinClient.query(`SELECT count(*) FROM "t_project_structure" INNER JOIN "t_structure" ON "t_project_structure"."structure" = "t_structure"."id" WHERE "project" = ${project.id} AND "t_structure"."external_platform" IS NOT null`)).rows
// console.log(strucCount);
if(strucCount[0].count>0){
// 判断有没有创建这个项目
constprojectPoms=(awaitpomsClient.query(`SELECT * FROM project_correlation WHERE anxin_project_id @> ARRAY[${project.id}];`)).rows
if(projectPoms.length==0){
// 在运维平台新建项目
console.log(`创建运维项目`);
constprojectData=awaitpomsClient.query(`INSERT INTO project_correlation (anxin_project_id, create_time, create_user, name, del, update_time) VALUES ('{${project.id}}', NOW(),${create_user_id||1}, '${project.name}', false, NOW()) RETURNING id;`)