Skip to content

Commit a5b07fd

Browse files
committed
feat: 流程克隆功能 - 一键复制流程定义(含变量/参数)为新草稿(需求14)
1 parent 669a58a commit a5b07fd

2 files changed

Lines changed: 79 additions & 1 deletion

File tree

Juggle.Api/Controllers/Api/FlowDefinitionController.cs

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,76 @@ public async Task<ApiResult> Import([FromBody] System.Text.Json.JsonElement body
303303
}
304304
}
305305

306+
/// <summary>克隆/复制流程定义(含变量、参数)</summary>
307+
[HttpPost("clone/{id}")]
308+
public async Task<ApiResult> Clone(long id)
309+
{
310+
var source = await _db.FlowDefinitions.FindAsync(id);
311+
if (source == null || source.Deleted == 1) return ApiResult.Fail("流程不存在");
312+
313+
var newKey = $"flow_{Guid.NewGuid():N}";
314+
var cloned = new FlowDefinitionEntity
315+
{
316+
FlowKey = newKey,
317+
FlowName = $"{source.FlowName}_副本",
318+
FlowDesc = source.FlowDesc,
319+
FlowType = source.FlowType,
320+
GroupName = source.GroupName,
321+
FlowContent = source.FlowContent,
322+
Status = 0,
323+
CreatedAt = DateTime.Now.ToString("o")
324+
};
325+
_db.FlowDefinitions.Add(cloned);
326+
await _db.SaveChangesAsync();
327+
328+
// 复制变量
329+
var vars = await _db.VariableInfos
330+
.Where(v => v.FlowDefinitionId == id && v.Deleted == 0).ToListAsync();
331+
foreach (var v in vars)
332+
{
333+
_db.VariableInfos.Add(new VariableInfoEntity
334+
{
335+
FlowDefinitionId = cloned.Id,
336+
FlowKey = newKey,
337+
VariableCode = v.VariableCode,
338+
VariableName = v.VariableName,
339+
DataType = v.DataType,
340+
VariableType = v.VariableType,
341+
DefaultValue = v.DefaultValue,
342+
Description = v.Description,
343+
Deleted = 0,
344+
CreatedAt = DateTime.Now.ToString("o")
345+
});
346+
}
347+
348+
// 复制参数(入参/出参)
349+
var pars = await _db.Parameters
350+
.Where(p => p.OwnerId == id && (p.ParamType == 5 || p.ParamType == 6) && p.Deleted == 0)
351+
.ToListAsync();
352+
foreach (var p in pars)
353+
{
354+
_db.Parameters.Add(new ParameterEntity
355+
{
356+
OwnerId = cloned.Id,
357+
OwnerCode = newKey,
358+
ParamType = p.ParamType,
359+
ParamCode = p.ParamCode,
360+
ParamName = p.ParamName,
361+
DataType = p.DataType,
362+
ObjectCode = p.ObjectCode,
363+
Required = p.Required,
364+
DefaultValue = p.DefaultValue,
365+
Description = p.Description,
366+
SortNum = p.SortNum,
367+
Deleted = 0,
368+
CreatedAt = DateTime.Now.ToString("o")
369+
});
370+
}
371+
372+
await _db.SaveChangesAsync();
373+
return ApiResult.Success(new { id = cloned.Id, flowKey = newKey, flowName = cloned.FlowName });
374+
}
375+
306376
/// <summary>部署流程</summary>
307377
[HttpPost("deploy")]
308378
public async Task<ApiResult> Deploy([FromBody] FlowDeployRequest req)

JuggleNet6.Frontend/src/views/flow/FlowDefinitionList.vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,12 @@
5858
</template>
5959
</el-table-column>
6060
<el-table-column prop="createdAt" label="创建时间" width="180" show-overflow-tooltip />
61-
<el-table-column label="操作" width="260" fixed="right">
61+
<el-table-column label="操作" width="320" fixed="right">
6262
<template #default="{ row }">
6363
<el-button size="small" type="primary" link @click="goDesign(row)">设计</el-button>
6464
<el-button size="small" type="success" link @click="doDeploy(row)">部署</el-button>
6565
<el-button size="small" link @click="openEdit(row)">编辑</el-button>
66+
<el-button size="small" type="info" link @click="doClone(row)">克隆</el-button>
6667
<el-button size="small" type="warning" link @click="doExport(row)">导出</el-button>
6768
<el-button size="small" type="danger" link @click="doDelete(row)">删除</el-button>
6869
</template>
@@ -176,6 +177,13 @@ async function handleSubmit() {
176177
loadData()
177178
}
178179
180+
async function doClone(row: any) {
181+
await ElMessageBox.confirm(`确认克隆流程「${row.flowName}」为新草稿?`, '提示', { type: 'info' })
182+
const res: any = await request.post(`/flow/definition/clone/${row.id}`, {})
183+
ElMessage.success(`克隆成功:${res.data?.flowName || ''}`)
184+
loadData()
185+
}
186+
179187
async function doDelete(row: any) {
180188
await ElMessageBox.confirm(`确认删除流程「${row.flowName}」?`, '提示', { type: 'warning' })
181189
await request.delete(`/flow/definition/delete/${row.id}`)

0 commit comments

Comments
 (0)