chore: 模版创建流水线

This commit is contained in:
xiaojunnuo
2025-06-25 18:18:57 +08:00
parent 9296ba7492
commit 29906ec057
11 changed files with 127 additions and 38 deletions
@@ -119,7 +119,7 @@ export class PipelineService extends BaseService<PipelineEntity> {
async page(pageReq: PageReq<PipelineEntity>) {
//模版流水线不要被查询出来
set(pageReq,"query.templateId",0)
set(pageReq,"query.isTemplate",false)
const result = await super.page(pageReq);
await this.fillLastVars(result.records);
@@ -45,10 +45,11 @@ export class TemplateService extends BaseService<TemplateEntity> {
let newPipeline = cloneDeep(pipelineEntity)
//创建pipeline模版
newPipeline.id = undefined;
newPipeline.title = template.title+"模版流水线"
newPipeline.title = template.title + "模版流水线"
newPipeline.templateId = template.id
newPipeline.isTemplate = true
const pipelineJson:Pipeline = JSON.parse(newPipeline.content)
const pipelineJson: Pipeline = JSON.parse(newPipeline.content)
delete pipelineJson.triggers
pipelineJson.id = template.id
pipelineJson.userId = template.userId
@@ -56,7 +57,7 @@ export class TemplateService extends BaseService<TemplateEntity> {
newPipeline.content = JSON.stringify(pipelineJson)
newPipeline = await tx.getRepository(PipelineEntity).save(newPipeline)
const update :any= {}
const update: any = {}
update.id = template.id
update.pipelineId = newPipeline.id
await tx.getRepository(TemplateEntity).save(update)
@@ -86,19 +87,40 @@ export class TemplateService extends BaseService<TemplateEntity> {
pipeline,
}
}
async batchDelete(ids: number[], userId: number) {
const where :any= {
const where: any = {
id: In(ids),
}
if (userId > 0) {
where.userId = userId
}
const list = await this.getRepository().find({where })
const list = await this.getRepository().find({where})
ids = list.map(item => item.id)
const pipelineIds = list.map(item => item.pipelineId)
await this.delete(ids);
await this.pipelineService.batchDelete(pipelineIds,userId)
await this.pipelineService.batchDelete(pipelineIds, userId)
}
async createPipelineByTemplate(body: PipelineEntity) {
const templateId = body.templateId;
const template = await this.info(templateId);
if (!template && template.userId !== body.userId) {
throw new Error('模板不存在');
}
const tempPipeline = await this.pipelineService.info(template.pipelineId)
const newPipeline = {
type: tempPipeline.type,
from : "template",
keepHistoryCount: tempPipeline.keepHistoryCount,
... body,
}
await this.pipelineService.save(newPipeline)
}
}