一、说明信息
在流程审批中,每次提交审批需要添加必要的审批信息,如备注、驳回原因等批语信息。
批注信息在进行具体操作时由用户填写,在审批过程中展示审批流程中的审批信息。
二、审批操作时添加批注信息
<a onclick="completeTask(${task.id});" href="#">批注通过</a>
function completeTask(taskId){
var comment = window.prompt("批语", "");
$.ajax({
url:"${pageContext.request.contextPath}/task/completeTaskWithComment.do",
type:"post",
dataType:"json",
data:{
taskId:taskId,
comment:comment
},
success:function(result){
},
error:function(){
}
});
}
在办理任务时添加审批信息:
// 设置审批人,一般从session中获得
Authentication.setAuthenticatedUserId(UserUtils.getUserContext().getUserId);
// 设置批语信息
Comment addComment = taskService.addComment(taskId, processInstanceId, comment);
三、获取审批信息
在审批过程中可以展示流程各节点的审批信息,有两种方式,其一是通过任务获取关联的批注信息,其二是通过流程实例获取所有任务的批注信息。
- 通过任务获取批注
// 先获取当前流程实例的所有任务
HistoricTaskInstanceQuery hisTaskQuery = historyService.createHistoricTaskInstanceQuery();
hisTaskQuery.processInstanceId(processInstanceId);
hisTaskQuery.orderByTaskCreateTime().desc();
List<HistoricTaskInstance> list = hisTaskQuery.list();
// 再通过任务获取批注信息
List<List<Comment>> commentList = new ArrayList<List<Comment>>();
for (HistoricTaskInstance hisTaskInst : list) {
String hisTaskId = hisTaskInst.getId();
List<Comment> taskComments = taskService.getTaskComments(hisTaskId);
commentList.add(taskComments);
}
- 通过流程实例获取批注
// 通过流程实例可以直接获取与当前流程关联的所有任务的批注信息
List<Comment> processInstanceComments = taskService.getProcessInstanceComments(procInstId);
for (Comment comment : processInstanceComments) {
System.out.print(comment.getId() + "\t");
System.out.print(comment.getProcessInstanceId() + "\t");
System.out.print(comment.getTaskId() + "\t");
System.out.print(comment.getType() + "\t");
System.out.print(comment.getUserId() + "\t");
System.out.print(comment.getFullMessage() + "\t");
System.out.println(comment.getTime());
}
四、批注信息展示
批注信息展示一般同当前审批流程关联,一个审批流程的多个审批任务都关联一个具体的批注信息。
<table border="1">
<!-- 表头 -->
<thead>
<tr align="center" valign="middle">
<td width="200px">审批意见ID</td>
<td width="200px">审批流程实例</td>
<td width="200px">审批任务</td>
<td width="200px">类型</td>
<td width="200px">审批人</td>
<td width="200px">批语</td>
<td width="200px">审批时间</td>
</tr>
</thead>
<!-- 显示数据列表 -->
<tbody id="TableData" class="dataContainer">
<c:forEach items="${taskCommentList}" var="comment">
<tr align="center" class="TableDetail1 template">
<td>${comment.id}</td>
<td>${comment.processInstanceId}</td>
<td>${comment.taskId}</td>
<td>${comment.type}</td>
<td>${comment.userId}</td>
<td>${comment.fullMessage}</td>
<td>${comment.time}</td>
</tr>
</c:forEach>
</tbody>
</table>