SpringBoot整合Activiti(⼆)——流程审批完整⽰例
前两天做了⼀个SpringBoot整合Activiti的完整⽰例,功能包括:退回/通过(节点条件)、指定办理⼈、⽣成流程图、⾼亮显⽰已办节点、查询任务列表(办理⼈)等,下⾯先简单记录(含完整代码),⼗六上班后再详细补充。
1、画流程图:
⾼亮⽣成的流程图(流程已⾄办理):
这个流程图⽐较简单,这⾥不介绍如何画的了(记得让⽂件名称与id相同),下⾯有最终的流程图源码。
2、设置业户提交、资料不全、已签发的事件触发代码:
点击选择事件节点,下⽅properties⾥选择如下图:
找不到properties的话 要选择Activiti模式就可以:
#{activityDemoServiceImpl.updateBizStatus(execution,"tj")} 表⽰将使⽤activityDemoServiceImpl服务的updateBizStatus⽅法,⾥⾯有两个参数,execution是当前流程节点对象,可获取流程信息及业务key等,"tj"字符串参数。(这⾥设置的服务名是⼩写开头,实际服务名是⼤写开头,否则找不到——不知道是不是因为我⽤的5.22)
3、指定受理/审批 办理⼈员:
也是选中,然后如下图操作:
${activityDemoServiceImpl.findUrsForSL(execution)}跟上⾯⼀样,不过注意,事件监听是以#开头,这⾥是以$符号。
4、增加2、3设置的服务⽅法(ActivityDemoServiceImpl)
朝鲜有核武器SpringBoot的好处是默认会配置和注⼊很多服务,所以我们使⽤起来⾮常⽅便,流程图不需要单独部署,直接到服务根据流程名称或id就可以直接获取到想要的内容。
直接上代码了:
ample.rvice.impl;
import java.awt.image.BufferedImage;
import java.io.File;
党员个人述职报告
import java.io.FileOutputStream;低血压怎样调理
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import javax.imageio.ImageIO;
import org.del.BpmnModel;
import ine.HistoryService;
import ine.IdentityService;
import ine.RepositoryService;
import ine.RuntimeService;
import ine.TaskService;
import ine.delegate.DelegateExecution;
import ine.history.HistoricActivityInstance;
import ine.history.HistoricProcessInstance;
import ine.impl.cfg.ProcessEngineConfigurationImpl;
import ine.ity.ProcessDefinitionEntity;
import ine.impl.pvm.PvmTransition;
import ine.impl.pvm.process.ActivityImpl;
import pository.Deployment;
import pository.ProcessDefinition;
import ine.runtime.ProcessInstance;
import ine.runtime.ProcessInstance;
import ine.task.Task;
import org.activiti.image.ProcessDiagramGenerator;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class ActivityDemoServiceImpl {
@Autowired
private RuntimeService runtimeService;
@Autowired
private TaskService taskService;
@Autowired
private HistoryService historyService;
@Autowired
private RepositoryService repositoryService;
@Autowired
private ProcessEngineConfigurationImpl processEngineConfiguration;
/**
侵犯的意思* 启动流程
* @param bizId 业务id
*/
public void startProcess(String bizId) {
ProcessInstance pi = runtimeService.startProcessInstanceByKey("demo5", bizId);//流程图id,业务表id
System.out.println("流程启动成功,流程id:"+pi.getId());
}
/**
*
* <p>描述: 根据⽤户id查询待办任务列表</p>
* @author 范相如
* @date 2018年2⽉25⽇
*/
public List<Task> findTasksByUrId(String urId) {
List<Task> resultTask = ateTaskQuery().processDefinitionKey("demo5").taskCandidateOrAssigned(urId).list(); return resultTask;
}
/**
*
* <p>描述:任务审批(通过/拒接) </p>
* @author 范相如
* @date 2018年2⽉25⽇
* @param taskId 任务id
* @param urId ⽤户id
* @param result fal OR true
*/
public void completeTask(String taskId,String urId,String result) {
//获取流程实例
taskService.claim(taskId, urId);
Map<String,Object> vars = new HashMap<String,Object>();
vars.put("sign", "true");
}
/**
* 更改业务流程状态#{ActivityDemoServiceImpl.updateBizStatus(execution,"tj")}
* @param execution
* @param status
*/
public void updateBizStatus(DelegateExecution execution,String status) {
String bizId = ProcessBusinessKey();
String bizId = ProcessBusinessKey();
//根据业务id⾃⾏处理业务表
System.out.println("业务表["+bizId+"]状态更改成功,状态更改为:"+status);
}
//流程节点权限⽤户列表${ActivityDemoServiceImpl.findUrs(execution,sign)}
public List<String> findUrsForSL(DelegateExecution execution){
return Arrays.asList("sly1","sly2");
}
//流程节点权限⽤户列表${ActivityDemoServiceImpl.findUrs(execution,sign)}
public List<String> findUrsForSP(DelegateExecution execution){
return Arrays.asList("spy1","uspy2");
}
/**
*
* <p>描述: ⽣成流程图
* ⾸先启动流程,获取processInstanceId,替换即可⽣成</p>
* @author 范相如
* @date 2018年2⽉25⽇
* @param processInstanceId
* @throws Exception
鲤鱼的做法大全*/
public void queryProImg(String processInstanceId) throws Exception {
//获取历史流程实例
HistoricProcessInstance processInstance = ateHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
//根据流程定义获取输⼊流
InputStream is = ProcessDefinitionId());
BufferedImage bi = ad(is);
File file = new File("demo2.png");
if(!ists()) ateNewFile();
FileOutputStream fos = new FileOutputStream(file);
ImageIO.write(bi, "png", fos);
fos.clo();
is.clo();
System.out.println("图⽚⽣成成功");
List<Task> tasks = ateTaskQuery().taskCandidateUr("urId").list();
for(Task t : tasks) {
System.out.Name());
}
}
/**
* 流程图⾼亮显⽰
* ⾸先启动流程,获取processInstanceId,替换即可⽣成
* @throws Exception
*/
public void queryProHighLighted(String processInstanceId) throws Exception {
//获取历史流程实例
HistoricProcessInstance processInstance = ateHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult(); //获取流程图
BpmnModel bpmnModel = ProcessDefinitionId());
ProcessDiagramGenerator diagramGenerator = ProcessDiagramGenerator();
ProcessDefinitionEntity definitionEntity = (ProcessDefinitionId());
List<HistoricActivityInstance> highLightedActivitList = ateHistoricActivityInstanceQuery().processInstanceId(processInstanceId).list(); //⾼亮环节id集合
List<String> highLightedActivitis = new ArrayList<String>();
//⾼亮线路id集合
//⾼亮线路id集合
List<String> highLightedFlows = getHighLightedFlows(definitionEntity,highLightedActivitList);
葡萄怎么写for(HistoricActivityInstance tempActivity : highLightedActivitList){
String activityId = ActivityId();
highLightedActivitis.add(activityId);
}
//配置字体
InputStream imageStream = ateDiagram(bpmnModel, "png", highLightedActivitis, highLightedFlows,"宋体","微软雅⿊","⿊体",null,2.0 BufferedImage bi = ad(imageStream);
File file = new File("demo2.png");
if(!ists()) ateNewFile();
FileOutputStream fos = new FileOutputStream(file);
ImageIO.write(bi, "png", fos);
fos.clo();
imageStream.clo();
System.out.println("图⽚⽣成成功");
}
/**
* 获取需要⾼亮的线
* @param processDefinitionEntity
* @param historicActivityInstances
* @return
*/
private List<String> getHighLightedFlows(
ProcessDefinitionEntity processDefinitionEntity,
List<HistoricActivityInstance> historicActivityInstances) {
List<String> highFlows = new ArrayList<String>();// ⽤以保存⾼亮的线flowId
for (int i = 0; i < historicActivityInstances.size() - 1; i++) {// 对历史流程节点进⾏遍历
ActivityImpl activityImpl = processDefinitionEntity
.(i)
.getActivityId());// 得到节点定义的详细信息
List<ActivityImpl> sameStartTimeNodes = new ArrayList<ActivityImpl>();// ⽤以保存后需开始时间相同的节点
ActivityImpl sameActivityImpl1 = processDefinitionEntity
.(i + 1)
.getActivityId());
// 将后⾯第⼀个节点放在时间相同节点的集合⾥
sameStartTimeNodes.add(sameActivityImpl1);
for (int j = i + 1; j < historicActivityInstances.size() - 1; j++) {
HistoricActivityInstance activityImpl1 = historicActivityInstances
.get(j);// 后续第⼀个节点
人参泡水喝有什么功效
HistoricActivityInstance activityImpl2 = historicActivityInstances
.get(j + 1);// 后续第⼆个节点
if (StartTime().equals(
// 如果第⼀个节点和第⼆个节点开始时间相同保存
ActivityImpl sameActivityImpl2 = processDefinitionEntity
.ActivityId());
sameStartTimeNodes.add(sameActivityImpl2);
} el {
/
排骨米饭的做法/ 有不相同跳出循环
break;
}
}
List<PvmTransition> pvmTransitions = activityImpl
.getOutgoingTransitions();// 取出节点的所有出去的线
for (PvmTransition pvmTransition : pvmTransitions) {
// 对所有的线进⾏遍历
ActivityImpl pvmActivityImpl = (ActivityImpl) pvmTransition
.getDestination();
// 如果取出的线的⽬标节点存在时间相同的节点⾥,保存该线的id,进⾏⾼亮显⽰
if (ains(pvmActivityImpl)) {
highFlows.Id());
}
}