Skip to content

Commit

Permalink
feature: update workflow instance
Browse files Browse the repository at this point in the history
  • Loading branch information
kalencaya committed Sep 29, 2024
1 parent bf928cc commit e7fa60c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class DagInstanceServiceImpl extends ServiceImpl<DagInstanceMapper, DagInstance> implements DagInstanceService {
Expand Down Expand Up @@ -56,7 +57,7 @@ public boolean update(DagInstanceDTO instanceDTO) {
public boolean updateStatus(Long id, String fromStatus, String toStatus) {
LambdaUpdateWrapper<DagInstance> wrapper = Wrappers.lambdaUpdate(DagInstance.class)
.eq(DagInstance::getId, id)
.eq(DagInstance::getStatus, fromStatus)
.eq(StringUtils.hasText(fromStatus), DagInstance::getStatus, fromStatus)
.set(DagInstance::getStatus, toStatus);
return update(wrapper);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

Expand Down Expand Up @@ -66,7 +67,7 @@ public boolean update(DagStepDTO stepDTO) {
public boolean updateStatus(Long id, String fromStatus, String toStatus) {
LambdaUpdateWrapper<DagStep> wrapper = Wrappers.lambdaUpdate(DagStep.class)
.eq(DagStep::getId, id)
.eq(DagStep::getStatus, fromStatus)
.eq(StringUtils.hasText(fromStatus), DagStep::getStatus, fromStatus)
.set(DagStep::getStatus, toStatus);
return update(wrapper);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package cn.sliew.carp.module.workflow.api.controller;

import cn.sliew.carp.framework.common.security.annotations.AnonymousAccess;
import cn.sliew.carp.framework.web.response.ApiResponseWrapper;
import cn.sliew.carp.module.workflow.api.service.WorkflowInstanceService;
import cn.sliew.carp.module.workflow.api.service.param.WorkflowRunParam;
Expand All @@ -31,6 +32,7 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@AnonymousAccess
@RestController
@ApiResponseWrapper
@RequestMapping("/api/carp/workflow/instance")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@

package cn.sliew.carp.module.workflow.internal.service.impl;

import cn.sliew.carp.framework.common.dict.workflow.WorkflowInstanceState;
import cn.sliew.carp.framework.common.dict.workflow.WorkflowStepType;
import cn.sliew.carp.framework.common.dict.workflow.WorkflowTaskInstanceStage;
import cn.sliew.carp.framework.dag.service.DagInstanceComplexService;
import cn.sliew.carp.framework.dag.service.DagInstanceService;
import cn.sliew.carp.framework.dag.service.DagStepService;
import cn.sliew.carp.framework.dag.service.dto.DagInstanceComplexDTO;
import cn.sliew.carp.framework.dag.service.dto.DagInstanceDTO;
Expand All @@ -46,6 +49,8 @@ public class WorkflowInstanceServiceImpl implements WorkflowInstanceService {
@Autowired
private DagInstanceComplexService dagInstanceComplexService;
@Autowired
private DagInstanceService dagInstanceService;
@Autowired
private DagStepService dagStepService;

@Override
Expand Down Expand Up @@ -82,14 +87,22 @@ public WorkflowTaskInstance getTask(Long workflowTaskInstanceId) {
@Override
public Long simpleInitialize(Long workflowDefinitionId) {
Long workflowInstanceId = dagInstanceComplexService.initialize(workflowDefinitionId);
// todo 更新状态
dagInstanceService.updateStatus(workflowInstanceId, null, WorkflowInstanceState.PENDING.getValue());
List<DagStepDTO> dagStepDTOS = dagStepService.listSteps(workflowInstanceId);
for (DagStepDTO dagStepDTO : dagStepDTOS) {
dagStepService.updateStatus(dagStepDTO.getId(), null, WorkflowTaskInstanceStage.PENDING.getValue());
}
return workflowInstanceId;
}

@Override
public Long run(WorkflowRunParam param) {
Long workflowInstanceId = simpleInitialize(param.getId());
// todo 更新参数
// 更新参数
DagInstanceDTO instanceDTO = new DagInstanceDTO();
instanceDTO.setId(workflowInstanceId);
instanceDTO.setInputs(param.getGlobalVariable());
dagInstanceService.update(instanceDTO);
return workflowInstanceId;
}

Expand Down

0 comments on commit e7fa60c

Please sign in to comment.