1. Start the process
/*** 1 Start Process ** when the process reaches a node, one piece of data will be generated in the act_ru_execution table * if the current node is a user task node, in this case, the act_ru_task table will generate one piece of data (the task handler, the task creation time) */@ test public void startprocess () throws exception {/*** V1 myprocess: 2: 604 * V2 myprocess: 3: 704 * // runtimeservice. startprocessinstancebyid (processdefinitionid) // start the process with the key defined in the process. The process with the highest version processinstance Pi = runtimeservice is started. startprocessinstancebykey ("leaveflow"); system. out. println ("PID:" + pi. GETID () + ", activitiid:" + pi. getactivityid ());}
2. view the process status
Public void queryprocessstate () throws exception {string processinstanceid = "1401"; // query process instance processinstance Pi = runtimeservice by process instance id. createprocessinstancequery (). processinstanceid (processinstanceid ). singleresult (); If (Pi! = NULL) {system. Out. println ("the current process is in:" + pi. getactivityid ();} else {system. Out. println ("the process has ended !! ");}}
3. view public tasks
Public void querycommontask () throws exception {// create a task query object taskquery = taskservice. createtaskquery (); // configure the query object string candidateuser = "zhangsan"; taskquery // filter condition. taskcandidateuser (candidateuser) // paging condition //. listpage (firstresult, maxresults) // sorting condition. orderbytaskcreatetime (). DESC (); // execute the query list <task> tasks = taskquery. list (); system. out. println ("=================================public task list for [" + 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 ());}}
4. view private tasks
Public void querypersonaltask () throws exception {// create a task query object taskquery = taskservice. createtaskquery (); // configure the query object // string assignee = "user"; string assignee = ""; taskquery // filter condition. taskassignee (assignee) // paging condition //. listpage (firstresult, maxresults) // sorting condition. orderbytaskcreatetime (). DESC (); // execute the query 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 ());}}
5. claim a task
Public void taketask () throws exception {// claim string taskid = "1404"; string userid = ""; // Let the user of the specified userid claim the task taskservice of the specified taskid. claim (taskid, userid); system. out. println ("claim operation completed !! ");}
6. Handle tasks
Public void complete () throws exception {string taskid = "1602"; // complete task taskservice. Complete (taskid );}