Commit 4a058744 authored by 技术总监-万宁's avatar 技术总监-万宁

业务平台会员管理功能开发中0727

parent 37705fa5
package com.ssy.lingxi.workflow.service;
import com.ssy.common.response.Wrapper;
import com.ssy.lingxi.workflow.api.model.vo.MultiParamsTaskResultVO;
import com.ssy.lingxi.workflow.api.model.vo.ProcessStartWithMultiParamsVO;
/**
* 多参数任务执行接口
* @author 万宁
* @version 2.0.0
* @date 2020-07-27
*/
public interface IMultiParamsTaskExecuteService {
/**
* 启动流程任务
* @return
*/
Wrapper<MultiParamsTaskResultVO> startProcess(ProcessStartWithMultiParamsVO startVO);
}
......@@ -19,6 +19,7 @@ public interface ITaskExecuteService {
*/
Wrapper<TaskResultVO> startProcess(ProcessStartVO startVO);
/**
* 完成流程任务
* @param taskVO
......
package com.ssy.lingxi.workflow.serviceimpl;
import com.ssy.common.response.ResponseCode;
import com.ssy.common.response.Wrapper;
import com.ssy.lingxi.workflow.api.model.contant.ProcessEnum;
import com.ssy.lingxi.workflow.api.model.vo.MultiParamsTaskResultVO;
import com.ssy.lingxi.workflow.api.model.vo.ProcessStartWithMultiParamsVO;
import com.ssy.lingxi.workflow.entity.ProcessTaskDefinitionDO;
import com.ssy.lingxi.workflow.repository.ProcessTaskDefinitionRepository;
import com.ssy.lingxi.workflow.service.IMultiParamsTaskExecuteService;
import org.camunda.bpm.engine.RepositoryService;
import org.camunda.bpm.engine.RuntimeService;
import org.camunda.bpm.engine.TaskService;
import org.camunda.bpm.engine.runtime.ProcessInstance;
import org.camunda.bpm.engine.task.Task;
import org.camunda.bpm.engine.variable.VariableMap;
import org.camunda.bpm.engine.variable.Variables;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 多参数任务执行接口实现类
* @author 万宁
* @version 2.0.0
* @date 2020-07-27
*/
@Service
public class MultiParamsTaskExecuteServiceImpl implements IMultiParamsTaskExecuteService {
/**
* 流程的第一步
*/
private final Integer FIRST_STEP = 1;
/**
* 流程跳转时,参数的key
*/
private final String TASK_JUMP_VAR_KEY = "status";
@Autowired
private ProcessTaskDefinitionRepository definitionRepository;
@Autowired
private TaskService taskService;
@Autowired
private RuntimeService runtimeService;
@Autowired
private RepositoryService repositoryService;
@Override
public Wrapper<MultiParamsTaskResultVO> startProcess(ProcessStartWithMultiParamsVO startVO) {
//判断枚举是否已经定义、流程步骤是否已经定义
List<ProcessTaskDefinitionDO> definitionDOList = definitionRepository.findProcessTaskDefinitionDOSByProcessEnum(startVO.getProcessEnum());
if(CollectionUtils.isEmpty(definitionDOList) || !ProcessEnum.existProcessEnum(startVO.getProcessEnum())) {
return Wrapper.fail(ResponseCode.WF_PROCESS_DEFINITION_DOES_NOT_EXIST);
}
//判断工作流是否已经部署
String processKey = ProcessEnum.getProcessKeyByCode(startVO.getProcessEnum());
if(repositoryService.createProcessDefinitionQuery().processDefinitionKey(processKey).list().size() == 0) {
return Wrapper.fail(ResponseCode.WF_PROCESS_DEPLOYMENT_DOES_NOT_EXIST);
}
//设置流程参数
Map<String, Object> varMap = new HashMap<>();
for(Map.Entry<String, Long> m : startVO.getParamMap().entrySet()) {
varMap.put(m.getKey(),m.getValue());
}
VariableMap variable = Variables.fromMap(varMap);
//启动流程
ProcessInstance process = runtimeService.startProcessInstanceByKey(processKey, variable);
//获取任务Id
Task task = taskService.createTaskQuery().processInstanceId(process.getProcessInstanceId()).list().get(0);
//第一个步骤
Integer firstTaskStep = definitionDOList.stream().mapToInt(ProcessTaskDefinitionDO::getTaskStep).min().getAsInt();
MultiParamsTaskResultVO resultVO = new MultiParamsTaskResultVO();
resultVO.setParamMap(startVO.getParamMap());
resultVO.setTaskId(task.getId());
//状态为第最小步骤值 - 1
resultVO.setStatus(firstTaskStep - 1);
return Wrapper.success(resultVO);
}
}
......@@ -24,6 +24,7 @@ import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.*;
import java.util.stream.Collectors;
/**
* 任务执行服务接口实现类
......@@ -97,6 +98,8 @@ public class TaskExecuteServiceImpl implements ITaskExecuteService {
return Wrapper.success(resultVO);
}
/**
* 执行流程任务
*
......
......@@ -18,6 +18,8 @@ repositories {
}
dependencies {
compile group: 'jakarta.validation', name: 'jakarta.validation-api', version: '2.0.2'
compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-openfeign', version: '2.2.2.RELEASE'
implementation project(':common')
testCompile group: 'junit', name: 'junit', version: '4.12'
}
rootProject.name = 'workflow-service-api'
\ No newline at end of file
package com.ssy.lingxi.workflow.api.feign;
import com.ssy.common.response.Wrapper;
import com.ssy.lingxi.workflow.api.model.vo.*;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.validation.Valid;
import java.util.List;
/**
* 工作流服务内部接口 - 带一个参数的任务执行接口
* @author 万宁
* @version 2.0.0
* @date 2020-07-27
*/
@FeignClient(name = "merchant-member-service")
@RequestMapping("/workflow/task")
public interface TaskExecuteControllerFeign {
/**
* 启动任务流程,带一个Long类型的参数
* @return
*/
@RequestMapping("/start")
Wrapper<TaskResultVO> startProcess(@RequestBody @Valid ProcessStartVO startVO);
/**
* 执行流程任务,带一个Long类型的参数
* @param executeVO
* @return
*/
@RequestMapping("/exec")
Wrapper completeTask(@RequestBody @Valid CompleteTaskVO executeVO);
/**
* 查询流程中某步骤的参数列表
* @param queryVO
* @return
*/
@RequestMapping("/param/list")
Wrapper<List<TaskParamVO>> listTaskParam(@Valid TaskParamQueryVO queryVO);
}
package com.ssy.lingxi.workflow.api.model.vo;
import java.io.Serializable;
import java.util.Map;
/**
* 任务结果返回VO,带多个参数
* @author 万宁
* @version 2.0.0
* @date 2020-07-25
*/
public class MultiParamsTaskResultVO implements Serializable {
private static final long serialVersionUID = 6083240167115495993L;
/**
* 记录在调用方的状态
*/
private Integer status;
/**
* 任务参数
*/
private Map<String, Long> paramMap;
/**
* 工作流任务Id
*/
private String taskId;
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public Map<String, Long> getParamMap() {
return paramMap;
}
public void setParamMap(Map<String, Long> paramMap) {
this.paramMap = paramMap;
}
public String getTaskId() {
return taskId;
}
public void setTaskId(String taskId) {
this.taskId = taskId;
}
}
......@@ -7,7 +7,7 @@ import javax.validation.constraints.Positive;
import java.io.Serializable;
/**
* 工作流启动任务接口参数VO
* 工作流启动任务接口参数VO,只带一个参数
* @author 万宁
* @version 2.0.0
* @date 2020-07-25
......
package com.ssy.lingxi.workflow.api.model.vo;
import com.ssy.lingxi.workflow.api.handler.annotation.ProcessEnumAnno;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Positive;
import java.io.Serializable;
import java.util.Map;
/**
* 工作流启动任务接口参数VO,带多个参数
* @author 万宁
* @version 2.0.0
* @date 2020-07-25
*/
public class ProcessStartWithMultiParamsVO implements Serializable {
private static final long serialVersionUID = -2600783390945537829L;
/**
* 工作流类型枚举,定义在ProcessEnum中
*/
@NotNull(message = "工作流类型枚举不能为空")
@ProcessEnumAnno
private Integer processEnum;
/**
* 任务参数的Value,有接口调用方传递,paramKey非空时必须传递
* 例如审核的会员Id,批准或拒绝的申请单Id等
*/
@NotNull(message = "任务参数不能为空")
@Positive(message = "任务参数要大于0")
private Map<String, Long> paramMap;
public Integer getProcessEnum() {
return processEnum;
}
public void setProcessEnum(Integer processEnum) {
this.processEnum = processEnum;
}
public Map<String, Long> getParamMap() {
return paramMap;
}
public void setParamMap(Map<String, Long> paramMap) {
this.paramMap = paramMap;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment