|  | @ -3,72 +3,72 @@ | 
			
		
	
		
		
			
				
					|  |  | async function bindAnxin2pep (ctx) { |  |  | async function bindAnxin2pep (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 { clickHouse } = ctx.app.fs |  |  |       // const { clickHouse } = ctx.app.fs
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |       const { bindId, name, pepProjectId, anxinProjectId = [], app = [] } = ctx.request.body |  |  |       // const { bindId, name, pepProjectId, anxinProjectId = [], app = [] } = ctx.request.body
 | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |       let bindId_ = bindId |  |  |       // let bindId_ = bindId
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |       const existRes = await models.ProjectCorrelation.findOne({ |  |  |       // const existRes = await models.ProjectCorrelation.findOne({
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |          where: { |  |  |       //    where: {
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |             pepProjectId: pepProjectId |  |  |       //       pepProjectId: pepProjectId
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |          } |  |  |       //    }
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |       }) |  |  |       // })
 | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |       let storageData = { |  |  |       // let storageData = {
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |          name, pepProjectId, anxinProjectId, |  |  |       //    name, pepProjectId, anxinProjectId,
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |       } |  |  |       // }
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |       if (bindId_) { |  |  |       // if (bindId_) {
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |          if (!existRes) { |  |  |       //    if (!existRes) {
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |             throw '尚无已绑定的项企项目' |  |  |       //       throw '尚无已绑定的项企项目'
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |          } |  |  |       //    }
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |          // 修改
 |  |  |       //    // 修改
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |          await models.ProjectCorrelation.update(storageData, { |  |  |       //    await models.ProjectCorrelation.update(storageData, {
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |             where: { |  |  |       //       where: {
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |                pepProjectId: pepProjectId |  |  |       //          pepProjectId: pepProjectId
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |             }, |  |  |       //       },
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |             transaction |  |  |       //       transaction
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |          }) |  |  |       //    })
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |       } else { |  |  |       // } else {
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |          // 新增
 |  |  |       //    // 新增
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |          if (existRes) { |  |  |       //    if (existRes) {
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |             // 但是有之前的数据
 |  |  |       //       // 但是有之前的数据
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |             if (existRes.del) { |  |  |       //       if (existRes.del) {
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |                // 不过之前的删除了
 |  |  |       //          // 不过之前的删除了
 | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |             } else { |  |  |       //       } else {
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |                // 没有删除 重复添加
 |  |  |       //          // 没有删除 重复添加
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |                throw '当前项企项目已绑定' |  |  |       //          throw '当前项企项目已绑定'
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |             } |  |  |       //       }
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |          } else { |  |  |       //    } else {
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |             const createRes = await models.ProjectCorrelation.create(storageData, { |  |  |       //       const createRes = await models.ProjectCorrelation.create(storageData, {
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |                transaction |  |  |       //          transaction
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |             }) |  |  |       //       })
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |             bindId_ = createRes.id |  |  |       //       bindId_ = createRes.id
 | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |             await models.ProjectApp.bulkCreate(app.map((a, i, arr) => { |  |  |       //       await models.ProjectApp.bulkCreate(app.map((a, i, arr) => {
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |                if (!a.name || !a.url) { |  |  |       //          if (!a.name || !a.url) {
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |                   throw `${a.name} ${a.url} 缺少必要参数` |  |  |       //             throw `${a.name} ${a.url} 缺少必要参数`
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |                } |  |  |       //          }
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |                let curUrlArr = a.url.split('://') |  |  |       //          let curUrlArr = a.url.split('://')
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |                if(curUrlArr.length < 2){ |  |  |       //          if(curUrlArr.length < 2){
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |                   throw `${a.name} ${a.url} url 地址错误` |  |  |       //             throw `${a.name} ${a.url} url 地址错误`
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |                } |  |  |       //          }
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |                for (let ii = i; ii < arr.length; ii++) { |  |  |       //          for (let ii = i; ii < arr.length; ii++) {
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |                   let  |  |  |       //             let 
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |                } |  |  |       //          }
 | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |                return { |  |  |       //          return {
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |                   name: a.name, |  |  |       //             name: a.name,
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |                   url: a.url, |  |  |       //             url: a.url,
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |                   projectId: bindId_, |  |  |       //             projectId: bindId_,
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |                   lock: false, |  |  |       //             lock: false,
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |                } |  |  |       //          }
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |             })) |  |  |       //       }))
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |          } |  |  |       //    }
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |       } |  |  |       // }
 | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |       await transaction.commit(); |  |  |       // await transaction.commit();
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |       ctx.status = 204; |  |  |       // ctx.status = 204;
 | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					|  |  |    } catch (error) { |  |  |    } catch (error) { | 
			
		
	
		
		
			
				
					|  |  |       await transaction.rollback(); |  |  |       await transaction.rollback(); | 
			
		
	
		
		
			
				
					|  |  |       ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |  |  |       ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); | 
			
		
	
	
		
		
			
				
					|  | 
 |