|  | @ -15,31 +15,59 @@ async function bindAnxin2pep (ctx) { | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |       let bindId_ = bindId |  |  |       let bindId_ = bindId | 
			
		
	
		
		
			
				
					|  |  |       const now = moment() |  |  |       const now = moment() | 
			
		
	
		
		
			
				
					
					|  |  |       const existRes = await models.ProjectCorrelation.findOne({ |  |  |       // 仅限已有 pepProjectId 的项目
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |          where: { |  |  |       const existRes = pepProjectId ? await models.ProjectCorrelation.findOne({ | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					|  |  |  |  |  |          where: Object.assign( | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             {}, | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             pepProjectId ? { | 
			
		
	
		
		
			
				
					|  |  |                pepProjectId: pepProjectId |  |  |                pepProjectId: pepProjectId | 
			
		
	
		
		
			
				
					
					|  |  |          }, |  |  |             } : { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |          include: { |  |  |                name, | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |             model: models.ProjectApp |  |  |             } | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					|  |  |  |  |  |          ), | 
			
		
	
		
		
			
				
					|  |  |  |  |  |       }) : null | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |       if (name) { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |          const pepRepeatNameCount = await clickHouse.projectManage.query(`SELECT COUNT(*) AS count FROM t_pim_project WHERE project_name='${name}'`).toPromise() | 
			
		
	
		
		
			
				
					|  |  |  |  |  |          if (pepRepeatNameCount[0].count) { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             throw `已有相同名称【${name}】的项企项目` | 
			
		
	
		
		
			
				
					|  |  |  |  |  |          } | 
			
		
	
		
		
			
				
					|  |  |  |  |  |          const pomsRepeatNameRes = await models.ProjectCorrelation.findAll({ | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             where: { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                name | 
			
		
	
		
		
			
				
					|  |  |             } |  |  |             } | 
			
		
	
		
		
			
				
					|  |  |          }) |  |  |          }) | 
			
		
	
		
		
			
				
					|  |  |  |  |  |          if (pomsRepeatNameRes.some((pr) => { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             return ( | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                ( | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                   // 有修改id但是不等于当前修改id的
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                   bindId && pr.id != bindId && !pr.del | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                ) || ( | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                   !bindId && ( | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                      ( | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                         existRes && pr.id != existRes.id && !pr.del | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                      ) || ( | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                         !existRes && !pr.del | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                      ) | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                   ) | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                ) | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             ) | 
			
		
	
		
		
			
				
					|  |  |  |  |  |          })) { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             throw `已有相同名称【${name}】的自定义项目` | 
			
		
	
		
		
			
				
					|  |  |  |  |  |          } | 
			
		
	
		
		
			
				
					|  |  |  |  |  |       } | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |       let storageData = { |  |  |       let storageData = { | 
			
		
	
		
		
			
				
					|  |  |          name, pepProjectId, anxinProjectId, |  |  |          name, pepProjectId, anxinProjectId, | 
			
		
	
		
		
			
				
					|  |  |  |  |  |          updateTime: now, | 
			
		
	
		
		
			
				
					|  |  |          del: false, |  |  |          del: false, | 
			
		
	
		
		
			
				
					|  |  |       } |  |  |       } | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |       if (bindId) { |  |  |       if (bindId) { | 
			
		
	
		
		
			
				
					|  |  |          // 修改
 |  |  |          // 修改
 | 
			
		
	
		
		
			
				
					|  |  |          if (!existRes) { |  |  |  | 
			
		
	
		
		
			
				
					|  |  |             throw '尚无已绑定的项企项目' |  |  |  | 
			
		
	
		
		
			
				
					|  |  |          } |  |  |  | 
			
		
	
		
		
			
				
					|  |  |          if (name) { |  |  |  | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  |  | 
			
		
	
		
		
			
				
					|  |  |          } |  |  |  | 
			
		
	
		
		
			
				
					|  |  |          await models.ProjectCorrelation.update(storageData, { |  |  |          await models.ProjectCorrelation.update(storageData, { | 
			
		
	
		
		
			
				
					|  |  |             where: { |  |  |             where: { | 
			
		
	
		
		
			
				
					
					|  |  |                pepProjectId: pepProjectId |  |  |                id: bindId | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |             }, |  |  |             }, | 
			
		
	
		
		
			
				
					|  |  |             transaction |  |  |             transaction | 
			
		
	
		
		
			
				
					|  |  |          }) |  |  |          }) | 
			
		
	
	
		
		
			
				
					|  | @ -102,7 +130,7 @@ async function bindAnxin2pep (ctx) { | 
			
		
	
		
		
			
				
					|  |  | async function del (ctx) { |  |  | async function del (ctx) { | 
			
		
	
		
		
			
				
					|  |  |    try { |  |  |    try { | 
			
		
	
		
		
			
				
					|  |  |       const models = ctx.fs.dc.models; |  |  |       const models = ctx.fs.dc.models; | 
			
		
	
		
		
			
				
					
					|  |  |       const { bindId } = ctx.query |  |  |       const { bindId } = ctx.params | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |       await models.ProjectCorrelation.update({ |  |  |       await models.ProjectCorrelation.update({ | 
			
		
	
		
		
			
				
					|  |  |          del: true |  |  |          del: true | 
			
		
	
	
		
		
			
				
					|  | @ -112,7 +140,7 @@ async function del (ctx) { | 
			
		
	
		
		
			
				
					|  |  |          } |  |  |          } | 
			
		
	
		
		
			
				
					|  |  |       }) |  |  |       }) | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |       ctx.status = 20; |  |  |       ctx.status = 204; | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |    } catch (error) { |  |  |    } catch (error) { | 
			
		
	
		
		
			
				
					|  |  |       ctx.fs.logger.error(`path: ${ctx.path}, error: error`); |  |  |       ctx.fs.logger.error(`path: ${ctx.path}, error: error`); | 
			
		
	
		
		
			
				
					|  |  |       ctx.status = 400; |  |  |       ctx.status = 400; | 
			
		
	
	
		
		
			
				
					|  | 
 |