@ApiOperation(value = "获取流转历史列表")
@GetMapping(path = "/histoicFlow/{processInstanceId}")
public Response histoicFlow(
@PathVariable(name="processInstanceId") String processInstanceId){
List<Act> histoicFlowList = wfTaskService.histoicList(processInstanceId);
return Response.success().setData(histoicFlowList);
}
@Override
public List<Act> histoicList(String processInstanceId) {
List<Act> list = histoicMess(processInstanceId);
return list;
}
public List<Act> histoicMess(String processInstanceId) {
List<Act> actList = Lists.newArrayList();
List<HistoricTaskInstance> list = activitiEngine.getHistoryService().createHistoricTaskInstanceQuery()
.processInstanceId(processInstanceId).orderByHistoricTaskInstanceStartTime().asc().list();
for (int i = 0; i < list.size(); i++) {
HistoricTaskInstance histIns = list.get(i);
if (StringUtils.isNotBlank(histIns.getAssignee()) && histIns.getEndTime() != null) {
Act e = new Act();
String deleteReason = histIns.getDeleteReason();
if ("".equals(deleteReason) || deleteReason == null || deleteReason.equals("delete")) {
e.setDeleteReason(WorkFlowConstants.RETURN);// 退回
} else if (deleteReason.equals("completed")) {
e.setDeleteReason(WorkFlowConstants.ADOPT);// 审批通过
} else if (deleteReason.equals("1")) {
e.setDeleteReason(WorkFlowConstants.WITHDRAW);// 撤回
} else {
e.setDeleteReason(WorkFlowConstants.SUBMIT);// 提交
}
e.setTaskId(histIns.getId());
e.setStartTime(DateUtil.formatTime(histIns.getStartTime()));
if (histIns.getEndTime() != null) {
e.setEndTime(DateUtil.formatTime(histIns.getEndTime()));
}
e.setTenantId(histIns.getTenantId());
e.setActivityName(histIns.getName());
if (histIns.getDurationInMillis() != null) {
long durationInMillis = histIns.getDurationInMillis();
// 这个方法是将毫秒转化为几天几小时几分几秒
String dueTime = (durationInMillis / (24 * 60 * 60 * 1000)) + "天"
+ ((durationInMillis % (24 * 60 * 60 * 1000)) / (60 * 60 * 1000)) + "时"
+ +((durationInMillis % (24 * 60 * 60 * 1000) % (60 * 60 * 1000)) / (60 * 1000)) + "分"
+ +((durationInMillis % (24 * 60 * 60 * 1000) % (60 * 60 * 1000) % (60 * 1000)) / 1000)
+ "秒";
e.setDueTime(dueTime);
}
// 获取任务执行人名称
if (StringUtils.isNotEmpty(histIns.getAssignee())) {
PtyUser ptyUser = userService.selectByUsername(histIns.getAssignee());
e.setAssignee(ptyUser == null ? "" : ptyUser.getUserName());
}
// 获取意见评论内容
if (StringUtils.isNotBlank(histIns.getId())) {
List<Comment> commentList = activitiEngine.getTaskService().getTaskComments(histIns.getId());
if (commentList.size() > 0) {
e.setComment(commentList.get(0).getFullMessage());
}
}
actList.add(e);
}
if (histIns.getEndTime() == null) {
Act e = new Act();
e.setDeleteReason(WorkFlowConstants.TODOSUBMIT);// 待审核
e.setStartTime(DateUtil.formatTime(histIns.getStartTime()));
e.setActivityName(histIns.getName());
String identityId = null;
List<String> identityList = new ArrayList<String>();
if (StringUtils.isNotBlank(histIns.getAssignee())) {
PtyUser ptyUser = userService.selectByUsername(histIns.getAssignee());
identityId =(ptyUser==null ? "" : ptyUser.getUserName());
} else {
List<IdentityLink> identityLinkList = activitiEngine.getTaskService()
.getIdentityLinksForTask(histIns.getId());
for (IdentityLink identityLink : identityLinkList) {
String userId = identityLink.getUserId();
String groupid = identityLink.getGroupId();
if (StringUtils.isNotBlank(userId)) {
PtyUser ptyUser = userService.selectByUsername(userId);
identityList.add(ptyUser == null ? "" : ptyUser.getUserName());
}
if (StringUtils.isNotBlank(groupid)) {
PtyRole role = new PtyRole();
role.setRoleCode(groupid);
List<PtyRole> ptyRole = roleService.selectByRoleCode(role);
for (PtyRole roles : ptyRole) {
identityList.add(roles == null ? "" : roles.getRoleName());
}
}
identityList = identityList.stream().distinct().collect(Collectors.toList());
}
identityId = StringUtils.join(identityList.toArray(), ",");
}
e.setAssignee(identityId);
actList.add(e);
}
}
List<ProcessInstance> listProcess = activitiEngine.getRuntimeService().createProcessInstanceQuery()
.processInstanceId(processInstanceId).list();
if (listProcess.size() == 0 || listProcess == null) {
actList.get(actList.size() - 1).setDeleteReason("已终审");
}
return actList;
}