在每次提交任務的時候需要描述一些批注信息,例如:請假流程提交的時候要描述信息為什么請假,如果領導駁回可以批注駁回原因等
1、添加批注
// 由于流程用戶上下文對象是線程獨立的,所以要在需要的位置設置,要保證設置和獲取操作在同一個線程中 Authentication.setAuthenticatedUserId(UserContext.get().getName());//批注人的名稱 一定要寫,不然查看的時候不知道人物信息 // 添加批注信息 taskService.addComment(taskId, null, comment);//comment為批注內容 // 完成任務 taskService.complete(taskId,vars);//vars是一些變量
2、獲取批注內容
public List<Comment> getPRocessComments(String taskId) { List<Comment> historyCommnets = new ArrayList<>();// 1) 獲取流程實例的ID Task task = this.taskService.createTaskQuery().taskId(taskId).singleResult(); ProcessInstance pi =runtimeService.createProcessInstanceQuery().processInstanceId(task.getProcessInstanceId()).singleResult();// 2)通過流程實例查詢所有的(用戶任務類型)歷史活動 List<HistoricActivityInstance> hais = historyService.createHistoricActivityInstanceQuery().processInstanceId(pi.getId()).activityType("userTask").list();// 3)查詢每個歷史任務的批注 for (HistoricActivityInstance hai : hais) { String historytaskId = hai.getTaskId(); List<Comment> comments = taskService.getTaskComments(historytaskId); // 4)如果當前任務有批注信息,添加到集合中 if(comments!=null && comments.size()>0){ historyCommnets.addAll(comments); } }// 5)返回 return historyCommnets; }
3、在準備任務表單頁面時顯示批注(將上面的list放入值棧中,用struts2標簽遍歷)
<!-- 顯示所有批注信息 例如: 1999-01-01 張三 : 你好 1999-01-02 李四 : 你也好 --> <s:iterator value="#comments"> <s:date name="time" format="yyyy-MM-dd hh:mm"/><br/> <s:property value="userId"/> : <s:property value="fullMessage"/><br/><br/> </s:iterator>
新聞熱點
疑難解答