camunda獲流程的審批記錄詳情示例


//所有的審批意見都會存到 ACT_HI_COMMENT 的表中,因此需要如下接口獲取
List<Comment> taskComments = taskService.getTaskComments(taskId);

//完整示例
@Test
public void taskGetComment(){
List<HistoricActivityInstance> list = historyService.createHistoricActivityInstanceQuery()
.processInstanceId("d66d9908-9a71-11ea-9906-40e230303674")
.orderByHistoricActivityInstanceStartTime()
.asc()
.list();
List<Map<String,Object>> result=new ArrayList<>(list.size());
System.out.println(list.size());
for (HistoricActivityInstance historicActivityInstance : list) {
Map<String,Object> map=new HashMap<>(5);
String taskId = historicActivityInstance.getTaskId();
List<Comment> taskComments = taskService.getTaskComments(taskId);
System.out.println(taskComments.size());
map.put("activityName",historicActivityInstance.getActivityName());
map.put("activityType",matching(historicActivityInstance.getActivityType()));
map.put("assignee",historicActivityInstance.getAssignee()==null?"":historicActivityInstance.getAssignee());
map.put("startTime",DateFormatUtils.format(historicActivityInstance.getStartTime(),"yyyy-MM-dd HH:mm:ss") );
map.put("endTime",DateFormatUtils.format(historicActivityInstance.getEndTime(),"yyyy-MM-dd HH:mm:ss"));
map.put("costTime",getDatePoor(historicActivityInstance.getEndTime(),historicActivityInstance.getStartTime()));

if (taskComments.size()>0){
map.put("message",taskComments.get(0).getFullMessage());
}else {
map.put("message","");
}
result.add(map);
}
System.out.println(JSON.toJSONString(result));
}

private String matching(String ActivityType){
String value="";
switch (ActivityType){
case "startEvent":
value="流程開始";
break;
case "userTask":
value="用戶處理";
break;
case "noneEndEvent":
value="流程結束";
break;
default:
value="未知節點";
break;
}
return value;
}

public String getDatePoor(Date endDate, Date nowDate) {

long nd = 1000 * 24 * 60 * 60;
long nh = 1000 * 60 * 60;
long nm = 1000 * 60;
long ns = 1000;
// 獲得兩個時間的毫秒時間差異
long diff = endDate.getTime() - nowDate.getTime();
// 計算差多少天
long day = diff / nd;
// 計算差多少小時
long hour = diff % nd / nh;
// 計算差多少分鍾
long min = diff % nd % nh / nm;
// 計算差多少秒//輸出結果
long sec = diff % nd % nh % nm / ns;
return day + "" + hour + "小時" + min + "分鍾"+ sec + "";
}
 //結果展示
[{
    "costTime": "0天0小時0分鍾0秒",
    "activityName": "開始",
    "startTime": "2020-05-20 16:13:50",
    "assignee": "無",
    "endTime": "2020-05-20 16:13:50",
    "activityType": "流程開始",
    "message": "無"
}, {
    "costTime": "0天0小時1分鍾2秒",
    "activityName": "數據處理",
    "startTime": "2020-05-20 16:13:50",
    "assignee": "ass001",
    "endTime": "2020-05-20 16:14:53",
    "activityType": "用戶處理",
    "message": "無"
}, {
    "costTime": "0天0小時1分鍾25秒",
    "activityName": "審批",
    "startTime": "2020-05-20 16:14:53",
    "assignee": "0000",
    "endTime": "2020-05-20 16:16:18",
    "activityType": "用戶處理",
    "message": "駁回原因:數據又遺漏"
}, {
    "costTime": "0天0小時0分鍾25秒",
    "activityName": "數據處理",
    "startTime": "2020-05-20 16:16:18",
    "assignee": "ass001",
    "endTime": "2020-05-20 16:16:44",
    "activityType": "用戶處理",
    "message": "無"
}, {
    "costTime": "0天0小時0分鍾19秒",
    "activityName": "審批",
    "startTime": "2020-05-20 16:16:44",
    "assignee": "0000",
    "endTime": "2020-05-20 16:17:03",
    "activityType": "用戶處理",
    "message": "駁回原因:數據有空值"
}, {
    "costTime": "0天0小時0分鍾5秒",
    "activityName": "數據處理",
    "startTime": "2020-05-20 16:17:03",
    "assignee": "ass001",
    "endTime": "2020-05-20 16:17:08",
    "activityType": "用戶處理",
    "message": "無"
}, {
    "costTime": "0天0小時0分鍾19秒",
    "activityName": "審批",
    "startTime": "2020-05-20 16:17:08",
    "assignee": "0000",
    "endTime": "2020-05-20 16:17:28",
    "activityType": "用戶處理",
    "message": "數據審批通過"
}, {
    "costTime": "0天0小時0分鍾0秒",
    "activityName": "結束",
    "startTime": "2020-05-20 16:17:28",
    "assignee": "無",
    "endTime": "2020-05-20 16:17:28",
    "activityType": "流程結束",
    "message": "無"
}]
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM