1ãå¯å¨æµç¨ããå¨å®æäºæµç¨å®ä¹é¨ç½²åï¼å°±è¦å¯å¨æµç¨å®ä¾äºã/***1å¯å¨æµç¨*å½æµç¨å°è¾¾ä¸ä¸ªèç¹æ¶ï¼ä¼å¨act_ru_execution表ä¸äº§ç1æ¡æ°æ®*å¦æå½åèç¹æ¯ç¨æ·ä»»å¡èç¹ï¼è¿æ¶ä¼å¨act_
1ãå¯å¨æµç¨ ããå¨å®æäºæµç¨å®ä¹é¨ç½²åï¼å°±è¦å¯å¨æµç¨å®ä¾äºã
/**
* 1 å¯å¨æµç¨
* å½æµç¨å°è¾¾ä¸ä¸ªèç¹æ¶ï¼ä¼å¨act_ru_execution表ä¸äº§ç1æ¡æ°æ®
* å¦æå½åèç¹æ¯ç¨æ·ä»»å¡èç¹ï¼è¿æ¶ä¼å¨act_ru_task表ä¸äº§ç1æ¡æ°æ®ï¼ä»»å¡çåç人ï¼ä»»å¡çå建æ¶é´ï¼
*/
@Test
public void startProcess() throws Exception {
/**
* v1 myProcess:2:604
* v2 myProcess:3:704
*/
// runtimeService.startProcessInstanceById(processDefinitionId)
// éè¿æµç¨å®ä¹çkeyå¯å¨æµç¨ï¼ä¼å¯å¨çæ¬æé«çæµç¨
ProcessInstance pi = runtimeService.startProcessInstanceByKey("LeaveFlow");
System.out.println("pid:" + pi.getId() +",activitiId:" + pi.getActivityId());
}
2ãæ¥çæµç¨ç¶æ
public void queryProcessState() throws Exception {
String processInstanceId="1401";
// éè¿æµç¨å®ä¾IDæ¥è¯¢æµç¨å®ä¾
ProcessInstance pi = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
if(pi!=null){
System.out.println("å½åæµç¨å¨ï¼" + pi.getActivityId());
}else{
System.out.println("æµç¨å·²ç»æ!!");
}
}
3ãæ¥çå
¬æä»»å¡
ãã对æå®ç¨æ·çå¯æ¥åçå
Œ
±ä»»å¡æ§è¡æ¥è¯¢ã
public void queryCommonTask() throws Exception {
// å建任å¡æ¥è¯¢å¯¹è±¡
TaskQuery taskQuery = taskService.createTaskQuery();
// é
ç½®æ¥è¯¢å¯¹è±¡
String candidateUser="å¼ ä¸";
taskQuery
// è¿æ»¤æ¡ä»¶
.taskCandidateUser(candidateUser)
// å页æ¡ä»¶
// .listPage(firstResult, maxResults)
// æåºæ¡ä»¶
.orderByTaskCreateTime().desc();
// æ§è¡æ¥è¯¢
List<Task> tasks = taskQuery.list();
System.out.println("======================ã"+candidateUser+"ãçå
Œ
±ä»»å¡å表=================");
for (Task task : tasks) {
System.out.print("id:"+task.getId()+",");
System.out.print("name:"+task.getName()+",");
System.out.print("createTime:"+task.getCreateTime()+",");
System.out.println("assignee:"+task.getAssignee());
}
}
说æï¼
ãã1.æ¥è¯¢ä»»å¡é¦å
使ç¨TaskServiceå建TaskQuery对象
ãã2.å¨æ¥è¯¢å¯¹è±¡ä¸ï¼æ·»å taskCandidateUserè¿æ»¤æ¡ä»¶ï¼ä»£è¡¨è¿æ»¤ä»»å¡å éè
为èªå·±çä»»å¡
ãã3.è°ç¨listæ¹æ³è¿åæå®ç¨æ·çå¯æ¥ä»»å¡å表
ãã4.ææå
Œ
±ä»»å¡çassigneeå±æ§ä¸ºç©º
4ãæ¥çç§æä»»å¡
ãã对æå®ç¨æ·çæªå®æç个人任å¡æ§è¡æ¥è¯¢ã
public void queryPersonalTask() throws Exception {
// å建任å¡æ¥è¯¢å¯¹è±¡
TaskQuery taskQuery = taskService.createTaskQuery();
// é
ç½®æ¥è¯¢å¯¹è±¡
// String assignee="user";
String assignee="æå";
taskQuery
// è¿æ»¤æ¡ä»¶
.taskAssignee(assignee)
// å页æ¡ä»¶
// .listPage(firstResult, maxResults)
// æåºæ¡ä»¶
.orderByTaskCreateTime().desc();
// æ§è¡æ¥è¯¢
List<Task> tasks = taskQuery.list();
System.out.println("======================ã"+assignee+"ãç代åä»»å¡å表=================");
for (Task task : tasks) {
System.out.print("id:"+task.getId()+",");
System.out.print("name:"+task.getName()+",");
System.out.print("createTime:"+task.getCreateTime()+",");
System.out.println("assignee:"+task.getAssignee());
}
}
说æï¼
ãã1) å 为æ¯ä»»å¡æ¥è¯¢ï¼æ以ä»processEngineä¸åºè¯¥å¾å°TaskService
ãã2) 使ç¨TaskServiceè·åå°ä»»å¡æ¥è¯¢å¯¹è±¡TaskQuery
ãã3) 为æ¥è¯¢å¯¹è±¡æ·»å æ¥è¯¢è¿æ»¤æ¡ä»¶ï¼ä½¿ç¨taskAssigneeæå®ä»»å¡çåéè
ï¼å³æ¥è¯¢æå®ç¨æ·ç代åä»»å¡ï¼ï¼æ·»å å页æåºçè¿æ»¤æ¡ä»¶
ãã4) è°ç¨listæ¹æ³æ§è¡æ¥è¯¢ï¼è¿ååçè
为æå®ç¨æ·çä»»å¡å表
ãã5) ä»»å¡IDãå称ãåç人ãå建æ¶é´å¯ä»¥ä»act_ru_task表ä¸æ¥å°ã
ãã6) Executionä¸ProcessInstanceè§5.6ç« èçä»ç»ãå¨è¿ç§æ
åµä¸ï¼ProcessInstanceç¸å½äºExecution
ãã7) å¦æassigneeå±æ§ä¸ºé¨é¨ç»çï¼ç»æ为空ãå 为ç°å¨æµç¨åªå°äºâå¡«å请åç³è¯·âé¶æ®µï¼åé¢çä»»å¡è¿æ²¡ææ§è¡ï¼å³å¨æ°æ®åºä¸æ²¡æé¨é¨ç»çå¯ä»¥åççä»»å¡ï¼æ以æ¥è¯¢ä¸ããå°ã
ãã8) ä¸ä¸ªTaskèç¹åExecutionèç¹æ¯1对1çæ
åµï¼å¨task对象ä¸ä½¿ç¨Execution_æ¥æ 示ä»ä»¬ä¹é´çå
³ç³»
ãã9) ä»»å¡IDå¨æ°æ®åºè¡¨act_ru_taskä¸å¯¹åºâID_âå
5ã认é¢ä»»å¡
ããé常ä¸ä¸ªä»»å¡ä¸ºå
Œ
±ä»»å¡ä»»å¡é½æä¸ä¸ªä»¥ä¸çåéè
ï¼ç¨æ·æ³è¦åçå®åºè¯¥å
è¿è¡è®¤é¢ä»»å¡æä½ï¼å³æèªå·±åæä»»å¡çæ¥æè
ã
public void takeTask() throws Exception {
// claim 认é¢
String taskId="1404";
String userId="æå";
// 让æå®userIdçç¨æ·è®¤é¢æå®taskIdçä»»å¡
taskService.claim(taskId, userId);
System.out.println("认é¢æä½å®æ¯ï¼ï¼");
}
说æï¼
ãã1.ä»»å¡ç¸å
³æä½ï¼é¦å
å¾å°taskService
ãã2.ç¡®å®è¢«è®¤é¢çä»»å¡IDå认é¢äººID
ãã3.è°ç¨taskServiceçclaimï¼è®¤é¢ï¼æ¹æ³ï¼æå
Œ
±ä»»å¡åææå®ç¨æ·ç ç§æä»»å¡
6ãåçä»»å¡
public void complete() throws Exception {
String taskId = "1602";
// å®æä»»å¡
taskService.complete(taskId );
}
说æï¼
ãã1) åçä»»å¡ï¼ä»ProcessEngineå¾å°çæ¯TaskServiceã
ãã2) å½æ§è¡å®è¿æ®µä»£ç ï¼å以åå·¥ç身份å»æ§è¡æ¥è¯¢çæ¶åï¼ä¼åç°è¿ä¸ªæ¶åå·²ç»æ²¡ææ°æ®äºã
ãã3) 对äºæ§è¡å®çä»»å¡ï¼activitiå°ä»act_ru_task表ä¸å é¤è¯¥ä»»å¡ï¼ä¸ä¸ä¸ªä»»å¡ä¼è¢«æå
¥è¿æ¥ã
ãã4) 以âé¨é¨ç»çâç身份è¿è¡æ¥è¯¢ï¼å¯ä»¥æ¥å°ç»æãå 为æµç¨æ§è¡å°é¨é¨ç»ç审æ¹è¿ä¸ªèç¹äºã
ãã5) åæ§è¡åçä»»å¡ä»£ç ï¼æ§è¡å®ä»¥å以âé¨é¨ç»çâ身份è¿è¡æ¥è¯¢ï¼æ²¡æç»æã
ãã6) éå¤ç¬¬3å4æ¥ç´å°æµç¨æ§è¡å®ã
7ãéªè¯æµç¨å·²ç»ç»æ
ããå¨æµç¨æ§è¡çè¿ç¨ä¸ï¼å建çæµç¨å®ä¾IDå¨æ´ä¸ªè¿ç¨ä¸é½ä¸ä¼åï¼å½æµç¨ç»æåï¼æµç¨å®ä¾å°ä¼è¢«å é¤
说æï¼
ãã1) å 为æ¯æ¥è¯¢æµç¨å®ä¾ï¼æ以å
è·åruntimeService
ãã2) å建æµç¨åå²æ¥è¯¢å¯¹è±¡ï¼è®¾ç½®å®ä¾IDè¿æ»¤åæ°
ãã3) ç±äºä¸ä¸ªæµç¨å®ä¾IDåªå¯¹åºä¸ä¸ªå®ä¾ï¼ä½¿ç¨singleResultæ§è¡æ¥è¯¢è¿åä¸ä¸ªå¯ä¸çç»æï¼å¦æç»ææ°é大äº1ï¼åæåºå¼å¸¸
ãã4) å¤ææå®IDçå®ä¾æ¯å¦åå¨ï¼å¦æç»æ为空ï¼å代表æµç¨ç»æï¼å®ä¾å·²è¢«å é¤
温馨提示:内容为网友见解,仅供参考