activiti_demo.md 5.13 KB
Newer Older
custom's avatar
custom committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# 工作流demo

整体流程
* 打开工作流模块,设计工作流流程
* 实现一个当前功能启动工作流的接口
* 在自己的业务层调用自己实现的工作流类
* 启动工作流

1 新建工作流并填写对应的信息
![](/assets/wfl_demo_1.png)
![](/assets/wfl_demo_2.png)

2 编辑对应的审批节点链,可参考已实现的工作流程
![](/assets/wfl_demo_3.png)

16 17 18
3 编写一个自己的实现类,实现IActivitiCommonService接口  


19 20 21
![](/assets/wfl_demo_4.png)  


22
实现类代码如下
custom's avatar
custom committed
23 24
```java

25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
package hls.core.wfl.service.impl;  

import  com.hand.hap.activiti.dto.ReProcdef; 

import com.hand.hap.activiti.service.IActivitiService;
import com.hand.hap.activiti.service.IReProcdefService;
import com.hand.hap.core.IRequest;
import hls.core.prj.dto.PrjProject;
import hls.core.prj.dto.PrjProjectMeeting;
import hls.core.prj.mapper.PrjProjectMeetingMapper;
import hls.core.prj.service.PrjProjectService;
import hls.core.wfl.service.IActivitiCommonService;
import net.sf.json.JSONObject;
import org.activiti.rest.service.api.engine.variable.RestVariable;
import org.activiti.rest.service.api.runtime.process.ProcessInstanceCreateRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;import java.util.List;
import java.util.Map;
@Service
@Transactional
public class PrjActivitStartServiceImpl implements IActivitiCommonService
48 49
 { 
private static final String workFlowType = "PRJ_PROJECT"; @Autowired 
50
private IActivitiService activitiService;
51
@Autowired 
52
private IReProcdefService reProcdefService;
53
@Autowired 
54
private PrjProjectService projectService;
55
@Autowired 
56 57 58 59 60
private PrjProjectMeetingMapper meetingMapper; 
@Override 
public String getWorkFlowType() { return workFlowType; } 
@Override 
public void process(IRequest iRequest, List list, Map params) 
61
{
62 63
 ProcessInstanceCreateRequest processInstanceCreateRequest = getProcessInstanceCreateRequest((PrjProject)list.get(0),iRequest);
 activitiService.startProcess(iRequest, processInstanceCreateRequest);
64 65
 }
 private ProcessInstanceCreateRequest getProcessInstanceCreateRequest(PrjProject prjProject, IRequest iRequest) 
66 67
{ 
ProcessInstanceCreateRequest createRequest = new ProcessInstanceCreateRequest();
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
 PrjProject project=projectService.selectByPrimaryKey(iRequest,prjProject); ReProcdef reProcdefs ;  
reProcdefs = reProcdefService.queryReProcdef("PRJ_PROJECT_APPROVE","PRJ_PROJECT");  
String id = reProcdefs.getId_();
 String name = reProcdefs.getName_(); createRequest.setProcessDefinitionId(id); createRequest.setBusinessKey(prjProject.getProjectId().toString()); 
List<RestVariable> variables = new ArrayList<RestVariable>(); List<RestVariable> transientVariables = new ArrayList<RestVariable>();
 RestVariable restVariable1 = new RestVariable(); RestVariable restVariable2 = new RestVariable(); 
RestVariable restVariable3 = new RestVariable(); 
RestVariable restVariable4 = new RestVariable();
 RestVariable restVariable5 = new RestVariable(); 
RestVariable restVariable6 = new RestVariable(); 

restVariable1.setName("processDefinitionId"); 
restVariable1.setValue(id); variables.add(restVariable1); 
restVariable2.setName("prjProject"); 
JSONObject jsonObject= new JSONObject().fromObject(prjProject); restVariable2.setValue(jsonObject.toString()); variables.add(restVariable2); 
restVariable3.setName("iRequest"); restVariable3.setValue(iRequest); 
variables.add(restVariable3); 
restVariable4.setName("projectNum"); restVariable4.setValue(project.getProjectNumber()); variables.add(restVariable4); restVariable5.setName("projectName"); restVariable5.setValue(project.getProjectName()); variables.add(restVariable5); restVariable6.setName("startUserName"); restVariable6.setValue(iRequest.getEmployeeCode()); variables.add(restVariable6);
 RestVariable restVariable7 = new RestVariable(); 
RestVariable restVariable8 = new RestVariable(); RestVariable restVariable9 = new RestVariable(); restVariable7.setName("documentCategory"); restVariable7.setValue(project.getDocumentCategory()); variables.add(restVariable7); restVariable8.setName("documentType"); restVariable8.setValue(project.getDocumentType()); 
variables.add(restVariable8); restVariable9.setName("documentId"); restVariable9.setValue(project.getProjectId()); 
variables.add(restVariable9);
 RestVariable restVariable10 = new RestVariable(); 
restVariable10.setName("doubleFlag");
 PrjProjectMeeting meeting = new PrjProjectMeeting(); 
meeting.setProjectId(prjProject.getProjectId()); 
List<PrjProjectMeeting> list = meetingMapper.select(meeting); if(list.size() >0) { restVariable10.setValue("Y"); }else{ restVariable10.setValue("N"); }
 variables.add(restVariable10);
 RestVariable restVariable11 = new RestVariable(); restVariable11.setName("pName"); 
restVariable11.setValue(name);
 variables.add(restVariable11); createRequest.setVariables(variables); createRequest.setTransientVariables(transientVariables);
 return createRequest; 
}}
custom's avatar
custom committed
101 102 103 104

```
4 启动工作流
 ```
105 106 107
Map<String,Object> params = new HashMap<String,Object>();
params.put("workFlowType","PRJ_PROJECT");
activitiStartService.start(iRequest,projects,params);
custom's avatar
custom committed
108 109

```