Skip to content

Commit e3789f1

Browse files
committed
feat(flow): 实现流程删除和更新功能
- 添加流程删除接口,支持逻辑删除- 实现流程更新功能,提供更新接口 - 查询流程列表时过滤已删除数据- 统计流程数量时排除已删除记录 - 完善流程相关接口的租户和调用者信息 - 增加更新流程的API文档和参数校验- 优化流程定义仓库的查询条件处理
1 parent 5e960e9 commit e3789f1

File tree

8 files changed

+105
-4
lines changed

8 files changed

+105
-4
lines changed

src/main/java/tech/wetech/flexmodel/application/FlowApplicationService.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public List<ElementInstance> getHistoryElementList(String flowInstanceId) {
5656
*/
5757
public PageDTO<FlowModuleResponse> findFlowModuleList(FlowModuleListRequest request) {
5858
log.info("获取流程模块列表,参数: {}", request);
59-
Predicate predicate = Expressions.TRUE;
59+
Predicate predicate = Expressions.field(FlowDefinition::getIsDeleted).eq(false);
6060
if (StringUtils.isNotBlank(request.getFlowModuleId())) {
6161
predicate = predicate.and(Expressions.field(FlowDefinition::getFlowModuleId).eq(request.getFlowModuleId()));
6262
}
@@ -130,6 +130,19 @@ public DeployFlowResult deployFlow(DeployFlowParam deployFlowParam) {
130130
return processService.deployFlow(deployFlowParam);
131131
}
132132

133+
/**
134+
* 更新流程
135+
*/
136+
public UpdateFlowResult updateFlow(UpdateFlowParam updateFlowParam) {
137+
log.info("更新流程,流程模块ID: {}", updateFlowParam.getFlowModuleId());
138+
return processService.updateFlow(updateFlowParam);
139+
}
140+
141+
public void deleteFlow(String flowModuleId) {
142+
log.info("删除流程,流程模块ID: {}", flowModuleId);
143+
processService.deleteFlow(flowModuleId);
144+
}
145+
133146
/**
134147
* 获取流程模块信息
135148
*/
@@ -187,5 +200,4 @@ public FlowInstance findFlowInstance(String flowInstanceId) {
187200
}
188201
return flowInstanceService.findById(flowInstanceId);
189202
}
190-
191203
}

src/main/java/tech/wetech/flexmodel/application/MetricsApplicationService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import tech.wetech.flexmodel.application.dto.*;
77
import tech.wetech.flexmodel.codegen.entity.ApiDefinition;
88
import tech.wetech.flexmodel.codegen.entity.Datasource;
9+
import tech.wetech.flexmodel.codegen.entity.FlowDefinition;
910
import tech.wetech.flexmodel.codegen.entity.JobExecutionLog;
1011
import tech.wetech.flexmodel.domain.model.api.ApiDefinitionService;
1112
import tech.wetech.flexmodel.domain.model.api.ApiRequestLogService;
@@ -78,7 +79,7 @@ public FmMetricsResponse getFmMetrics() {
7879

7980
// 获取各种计数
8081
int reqLogCount = (int) apiLogService.count(TRUE);
81-
int flowDefCount = (int) flowDefService.count(TRUE);
82+
int flowDefCount = (int) flowDefService.count(Expressions.field(FlowDefinition::getIsDeleted).eq(false));
8283
int flowInsCount = (int) flowInstanceService.count(TRUE);
8384
int triggerCount = (int) triggerService.count(TRUE);
8485
int jobSuccessCount = (int) jobExecutionLogService.count(Expressions.field(JobExecutionLog::getExecutionStatus).eq("SUCCESS"));

src/main/java/tech/wetech/flexmodel/domain/model/flow/processor/DefinitionProcessor.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import tech.wetech.flexmodel.shared.utils.JsonUtils;
3131
import tech.wetech.flexmodel.shared.utils.StringUtils;
3232

33+
import java.time.LocalDateTime;
3334
import java.util.List;
3435

3536
@ApplicationScoped
@@ -106,6 +107,17 @@ public UpdateFlowResult update(UpdateFlowParam updateFlowParam) {
106107
return updateFlowResult;
107108
}
108109

110+
111+
public void delete(String flowModuleId) {
112+
if (StringUtils.isBlank(flowModuleId)) {
113+
throw new ParamException(ErrorEnum.PARAM_INVALID.getErrNo(), "flowModuleId is null");
114+
}
115+
FlowDefinition flowDefinition = flowDefinitionRepository.selectByModuleId(flowModuleId);
116+
flowDefinition.setIsDeleted(true);
117+
flowDefinition.setModifyTime(LocalDateTime.now());
118+
flowDefinitionRepository.updateByModuleId(flowDefinition);
119+
}
120+
109121
public DeployFlowResult deploy(DeployFlowParam deployFlowParam) {
110122
DeployFlowResult deployFlowResult = new DeployFlowResult();
111123
try {

src/main/java/tech/wetech/flexmodel/domain/model/flow/service/ProcessEngineImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ public FlowInstanceResult getFlowInstance(String flowInstanceId) {
110110
return runtimeProcessor.getFlowInstance(flowInstanceId);
111111
}
112112

113+
@Override
114+
public void deleteFlow(String flowModuleId) {
115+
definitionProcessor.delete(flowModuleId);
116+
}
117+
113118
@Override
114119
public InstanceDataListResult getInstanceData(String flowInstanceId, String instanceDataId) {
115120
return runtimeProcessor.getInstanceData(flowInstanceId, instanceDataId, true);

src/main/java/tech/wetech/flexmodel/domain/model/flow/service/ProcessService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,4 +238,6 @@ public interface ProcessService {
238238
* @param flowInstanceId
239239
*/
240240
FlowInstanceResult getFlowInstance(String flowInstanceId);
241+
242+
void deleteFlow(String flowModuleId);
241243
}

src/main/java/tech/wetech/flexmodel/infrastructure/persistence/FlowDefinitionFmRepository.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public FlowDefinition selectByModuleId(String flowModuleId) {
4343
public List<FlowDefinition> find(Predicate filter, Integer page, Integer size) {
4444
return session.dsl().selectFrom(FlowDefinition.class)
4545
.page(page, size)
46+
.where(filter)
4647
.orderByDesc("id")
4748
.execute();
4849
}

src/main/java/tech/wetech/flexmodel/interfaces/rest/FlowResource.java

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ public PageDTO<FlowInstance> findFlowInstanceList(
175175
)
176176
)})
177177
public CreateFlowResult createFlow(CreateFlowParam createFlowParam) {
178+
createFlowParam.setTenant("default");
179+
createFlowParam.setCaller("admin");
178180
return flowApplicationService.createFlow(createFlowParam);
179181
}
180182

@@ -205,9 +207,50 @@ public DeployFlowResult deployFlow(
205207
@PathParam("flowModuleId") String flowModuleId,
206208
DeployFlowParam deployFlowParam) {
207209
deployFlowParam.setFlowModuleId(flowModuleId);
210+
deployFlowParam.setTenant("default");
211+
deployFlowParam.setCaller("admin");
208212
return flowApplicationService.deployFlow(deployFlowParam);
209213
}
210214

215+
@Operation(summary = "更新流程")
216+
@PUT
217+
@Path("/{flowModuleId}")
218+
@RequestBody(
219+
name = "请求体",
220+
content = {@Content(
221+
mediaType = "application/json",
222+
schema = @Schema(
223+
implementation = UpdateFlowParamSchema.class
224+
)
225+
)}
226+
)
227+
@APIResponse(
228+
name = "200",
229+
responseCode = "200",
230+
description = "OK",
231+
content = {@Content(
232+
mediaType = "application/json",
233+
schema = @Schema(
234+
implementation = UpdateFlowResultSchema.class
235+
)
236+
)})
237+
public UpdateFlowResult updateFlow(
238+
@Parameter(name = "flowModuleId", description = "流程模块ID", in = ParameterIn.PATH)
239+
@PathParam("flowModuleId") String flowModuleId,
240+
UpdateFlowParam updateFlowParam) {
241+
updateFlowParam.setFlowModuleId(flowModuleId);
242+
updateFlowParam.setTenant("default");
243+
updateFlowParam.setCaller("admin");
244+
return flowApplicationService.updateFlow(updateFlowParam);
245+
}
246+
247+
@DELETE
248+
@Path("/{flowModuleId}")
249+
public void deleteFlow(@Parameter(name = "flowModuleId", description = "流程模块ID", in = ParameterIn.PATH)
250+
@PathParam("flowModuleId") String flowModuleId) {
251+
flowApplicationService.deleteFlow(flowModuleId);
252+
}
253+
211254
@Operation(summary = "获取流程模块信息")
212255
@APIResponse(
213256
name = "200",
@@ -398,6 +441,20 @@ public DeployFlowParamSchema() {
398441
}
399442
}
400443

444+
@Schema(
445+
properties = {
446+
@SchemaProperty(name = "flowModuleId", examples = {"flow_module_001"}, description = "流程模块ID"),
447+
@SchemaProperty(name = "tenant", examples = {"default"}, description = "租户"),
448+
@SchemaProperty(name = "caller", examples = {"admin"}, description = "调用者"),
449+
@SchemaProperty(name = "operator", examples = {"admin"}, description = "操作者")
450+
}
451+
)
452+
public static class UpdateFlowParamSchema extends DeployFlowParam {
453+
public UpdateFlowParamSchema() {
454+
super("default", "admin");
455+
}
456+
}
457+
401458
@Schema(
402459
properties = {
403460
@SchemaProperty(name = "errCode", examples = {"0"}, description = "错误码"),
@@ -409,6 +466,16 @@ public DeployFlowParamSchema() {
409466
public static class DeployFlowResultSchema extends DeployFlowResult {
410467
}
411468

469+
@Schema(
470+
properties = {
471+
@SchemaProperty(name = "errCode", examples = {"0"}, description = "错误码"),
472+
@SchemaProperty(name = "errMsg", examples = {"success"}, description = "错误信息"),
473+
}
474+
)
475+
public static class UpdateFlowResultSchema extends UpdateFlowResult {
476+
477+
}
478+
412479
@Schema(
413480
properties = {
414481
@SchemaProperty(name = "errCode", examples = {"0"}, description = "错误码"),

src/main/resources/import.idl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ model f_em_flow_definition {
138138
archive: Int @default(0) @comment("归档状态(0未删除,1删除)"),
139139
tenant: String @comment("租户"),
140140
caller?: String @comment("调用方"),
141+
is_deleted: Boolean @default(0) @comment("删除状态(0未删除,1已删除)"),
141142

142143
@index(name: "IDX_flow_define_module", fields: [flow_module_id])
143144
@comment("流程定义")
@@ -475,7 +476,7 @@ model f_job_execution_log {
475476
tenant_id? : String @length("50") @comment("租户ID"),
476477
created_at : DateTime @default(now()) @comment("创建时间"),
477478
updated_at : DateTime @default(now()) @comment("更新时间"),
478-
479+
479480
@index(name:"IDX_JOB_EXEC_TRIGGER_ID", unique: false, fields: [trigger_id]),
480481
@index(name:"IDX_JOB_EXEC_JOB_ID", unique: false, fields: [job_id]),
481482
@index(name:"IDX_JOB_EXEC_FLOW_INSTANCE", unique: false, fields: [flow_instance_id]),

0 commit comments

Comments
 (0)