Activiti获取某个流程实例已经审批的节点记录

已知businessid即eventid获得对应的审批记录

某个流程实例的节点信息都是存放在ACT_HI_ACTINST表中

business key存放在ACT_HI_PROCINST中,得到HistoricProcessInstance后获得对应的流程实例id。然后根据流程实例id获得ACT_HI_ACTINST对应的数据。即审批记录存放在ACT_HI_ACTINST中。结束时间不为空则说明已经审批完成

 /**
	 * 
	 * @CreateUser:xxxxx
	 * @ReturnType:List
	 * @param businessEventId
	 * @return
	 * @CreateDate:2014-6-10下午5:07:02
	 * @UseFor :获得某个流程实例各个节点的审批记录
	 */
	public List getApproveHistory(String businessEventId) {

		List<TaskBo> taskBoList = new ArrayList<TaskBo>();
		HistoricProcessInstance hisProcessInstance = (HistoricProcessInstance) historyService
				.createHistoricProcessInstanceQuery()
				.processInstanceBusinessKey(businessEventId).singleResult();
		// 该流程实例的所有节点审批记录
		List<HistoricActivityInstanceQuery> hisActInstList = getHisUserTaskActivityInstanceList(hisProcessInstance
				.getId());
		for (Iterator iterator = hisActInstList.iterator(); iterator.hasNext();) {
			// 需要转换成HistoricActivityInstance
			HistoricActivityInstance activityInstance = (HistoricActivityInstance) iterator
					.next();
			//如果还没结束则不放里面
			if ("".equals(taskBo.getEndTime()) || taskBo.getEndTime() == null) {
				continue;
			}
			TaskBo taskBo = new TaskBo();
			taskBo.setTaskName(activityInstance.getActivityName());
			// 获得审批人名称 Assignee存放的是审批用户id
			if (activityInstance.getAssignee() != null) {
				taskBo.setApproveUserName(getUserName(activityInstance
						.getAssignee()));
			} else {
				taskBo.setApproveUserName("");
			}
			// 获取流程节点开始时间
			taskBo.setStartTime(activityInstance.getStartTime() != null ? DateTimeUtil
					.getFormatDate(activityInstance.getStartTime(),
							WorkflowConstants.DATEFORMATSTRING) : "");
			// 获取流程节点结束时间
			if (activityInstance.getEndTime() == null) {
				taskBo.setEndTime("");
			} else {
				taskBo.setEndTime(DateTimeUtil.getFormatDate(
						activityInstance.getEndTime(),
						WorkflowConstants.DATEFORMATSTRING));
			}
			taskBoList.add(taskBo);
		}
		return taskBoList;
	}

	/**
	 * 
	 * @CreateUser:xxxx
	 * @ReturnType:List
	 * @param processInstanceId
	 * @return
	 * @CreateDate:2014-6-25下午5:03:13
	 * @UseFor :在 ACT_HI_ACTINST 表中找到对应流程实例的userTask节点 不包括startEvent
	 */
	private List<HistoricActivityInstanceQuery> getHisUserTaskActivityInstanceList(
			String processInstanceId) {
		List<HistoricActivityInstanceQuery> hisActivityInstanceList = ((HistoricActivityInstanceQuery) historyService
				.createHistoricActivityInstanceQuery()
				.processInstanceId(processInstanceId).activityType("userTask")
				.finished().orderByHistoricActivityInstanceEndTime().desc())
				.list();
		return hisActivityInstanceList;
	}

	/**
	 * 
	 * @CreateUser:xxxx
	 * @ReturnType:String
	 * @param userId
	 * @return
	 * @CreateDate:2014-6-10下午5:04:30
	 * @UseFor :获得审批人
	 */
	private String getUserName(String userId) {
		User user = (User) identityService.createUserQuery().userId(userId)
				.singleResult();
		return user.getFirstName();
	}

你可能感兴趣的:(Activiti)