package com.blueland.bpm.engine.core.service;

import java.util.List;
import java.util.Map;

import org.activiti.engine.task.IdentityLink;
import org.activiti.engine.task.Task;

import com.blueland.bpm.engine.core.model.ActivityInstanceModel;
import com.blueland.bpm.engine.core.model.BusinessDataObject;
import com.blueland.bpm.engine.core.model.ProcessInstanceModel;
import com.blueland.bpm.engine.core.model.ProcessLogModel;
import com.blueland.bpm.engine.util.ProcessModelUtils;
import com.blueland.bpm.engine.util.WorkFlowException;
/**
 * 流程实例Service
 * @version:  1.0
 * @author lw 
 */
public interface ProcessInstanceService  extends ActivitiService{
	/**
	 * 获取任务实例
	 * @param taskId
	 * @return
	 * @throws WorkFlowException
	 */
	public ActivityInstanceModel getTask(String taskId)throws WorkFlowException;
	
	public ActivityInstanceModel getHistoryTask(String taskId)throws WorkFlowException;
	/**
	 * 获取流程变量
	 * @param taskId
	 * @return
	 * @throws WorkFlowException
	 */
	public Map<String,Object> getProcessInstanceVariables(String processInstanceId)throws WorkFlowException;
	
	/**
	 * 获取流程实例信息
	 * @param procInstId
	 * @return
	 * @throws WorkFlowException
	 */
	public ProcessInstanceModel  getProcessInstanceById(String procInstId) throws WorkFlowException;
	
	/**
	 * 获取流程实例信息
	 * @param bizKey
	 * @return
	 * @throws WorkFlowException
	 */
	public ProcessInstanceModel getProcessInstanceByBizKey(String bizKey) throws WorkFlowException;
	
	/**
	 * 获取流程实例列表信息
	 * @param bizKey
	 * @return
	 * @throws WorkFlowException
	 */
	public List<ProcessInstanceModel> getProcessInstancesByBizKey(String bizKey) throws WorkFlowException;
	
	/**
	 * 获取任务变量
	 * @param taskId
	 * @return
	 * @throws WorkFlowException
	 */
	public Map<String,Object> getTaskVariables(String taskId)throws WorkFlowException;
	
	/**
	 * 获取任务变量
	 * @param taskId
	 * @return
	 * @throws WorkFlowException
	 */
	public Map<String,Object> getHistoryTaskVariables(String taskId)throws WorkFlowException;
	
	/**
	 * 获取任务的Fields变量
	 * @param taskId
	 * @return
	 * @throws WorkFlowException
	 */
	public Map<String,Object> getTaskFieldVariables(String taskId)throws WorkFlowException;
	/**
	 * 获取任务的Fields变量
	 * @param taskId
	 * @return
	 * @throws WorkFlowException
	 */
	public String getTaskFieldVariable(String taskId)throws WorkFlowException;
	
	/**
	 * 获取流程的Fields变量
	 * @param taskId
	 * @return
	 * @throws WorkFlowException
	 */
	public String getProcessFieldVariable(String procInstId)throws WorkFlowException;
	/**
	 * 获取流程的Fields变量
	 * @param taskId
	 * @return
	 * @throws WorkFlowException
	 */
	public String getProcessFieldVariableByFinished(String procInstId)throws WorkFlowException;

	/**
	 * 获取流程业务变量
	 * @param procInstId 流程实例Id
	 * @return
	 * @throws WorkFlowException
	 */
	
	public BusinessDataObject getBusinessDataObject(String procInstId)throws WorkFlowException;
	
	/**
	 * 获取任务绑定的资源
	 * @param taskId
	 * @return
	 * @throws WorkFlowException
	 */
	public List<IdentityLink> getIdentityLinkByTaskId(String taskId)throws WorkFlowException;
	/**
	 * 获取办结流程的任务实例
	 * @param procInstId
	 * @param endTaskId
	 * @return
	 * @throws WorkFlowException
	 */
	public ActivityInstanceModel getTaskByProcessFinished(String procInstId,String endTaskId)throws WorkFlowException;
	/**
	 * 获取流程所有的已办环节
	 * @param procInstId
	 * @return
	 */
	public List<ActivityInstanceModel> getAllHistTaskByProcess(String procInstId);
	/**
	 * 获取流程用户任务列表
	 * @param procInstId
	 * @return
	 * @throws WorkFlowException
	 */
	public List<ActivityInstanceModel> getProcessAllTasks(String procInstId)throws WorkFlowException;
	
	/**
	 * 获取流程用户任务列表
	 * @param procInstId
	 * @return
	 * @throws WorkFlowException
	 */
	public List<ActivityInstanceModel> getTopProcessAllTasks(String topProcInstId)throws WorkFlowException;
	
	/**
	 * 获取未结束流程的最后一个用户任务
	 * @param procInstId
	 * @return
	 * @throws WorkFlowException
	 */
	public ActivityInstanceModel getLastTaskNotFinished(String procInstId,String endActivityId)throws WorkFlowException;
	
	/**
	 * 签收用户任务
	 * @param taskId
	 * @param userId
	 * @throws WorkFlowException
	 */
	public void claimTask(String taskId,String userId)throws WorkFlowException;
	/**
	 * 判断是否签收用户任务
	 * @param taskId
	 * @return
	 * @throws WorkFlowException
	 */
	public boolean isClaimTask(String taskId)throws WorkFlowException;
	/**
	 * 获取流程所有已运行用户任务
	 * @param processInstanceId
	 * @param sender
	 * @param prevTaskId
	 * @return
	 */
	public List<Task> getProcessTasks(String processInstanceId,String sender,String prevTaskId);
	/**
	 * 通过顶级流程实例ID-获取流程所有已运行用户任务
	 * @param processInstanceId
	 * @param sender
	 * @param prevTaskId
	 * @return
	 */
	public List<Task> getProcessTasksByTopId(String topPocessInstanceId,String sender,String preTaskId);
	/**
	 * 用户任务迁移
	 * @param taskIds
	 * @param assignee
	 * @param transferUserId
	 * @param transferDatatype
	 * @return
	 */
	public boolean taskTransfer(String[] taskIds,String assignee,String transferUserId,String transferDatatype);
	
	/**
	 * 获取所有流程意见列表
	 * @param procInstId
	 * @return
	 */
	public List<ProcessLogModel> getProcessComments(String procInstId);
	
	public List<ProcessLogModel> getActInstComments(String actInstId) ;

	/**
	 * 获取所有流程实例,一直递归至最顶级流程,不包含流程贯穿的流程
	 * @param procInstId
	 * @return
	 */
	public ProcessInstanceModel getTopProcessInstance(String procInstId);
	

	/**
	 * 获取所有流程实例,一直递归至最顶级流程,不包含流程贯穿的流程
	 * @param procInstId
	 * @return
	 */
	public List<ProcessInstanceModel> getAllProcessInstance(String procInstId);
	
	/**
	 * 获取当前流程实例的所有子流程实例ID
	 * @param procInstId
	 * @return
	 */
	public List<String> getSubProcessInstanceIds(String procInstId);
	
	/**
	 * 获取所有流程实例,一直递归至最顶级流程,不包含流程贯穿的流程
	 * @param procInstId
	 * @return
	 */
	public List<ProcessInstanceModel> getSubProcessInstance(String procInstId);
	
	
	/**
	 * 获取所有流程实例,一直递归至最顶级流程,包含流程贯穿的流程
	 * @param procInstId
	 * @return
	 */
	public List<ProcessInstanceModel> getAllProcessInstanceIncludeThrough(String procInstId);
	
	
	/**
	 * 获取流程贯穿的流程实例
	 * @param topProcInstId
	 * @return
	 */
	public List<ProcessInstanceModel> getThroughBizAppProcess(String topProcInstId);
	
	
	/**
	 * 获取某租户下所有流程贯穿的流程实例
	 * @param procInstId
	 * @return
	 */
	public List<ProcessInstanceModel> getAllThroughBizAppProcess(String tenantId);
	
	
	/**
	 * 获取当前任务能够驳回的环节实例对象
	 * @param taskId
	 * @return
	 */
	public List<ActivityInstanceModel> findBackAvtivity(String taskId);

	/**
	 * 终止正在运行的流程实例
	 * 
	 * @author:kaka
	 * @param dkey:流程定义key,businessKey:业务id
	 */
	public void endProcessInstance(String taskId, String procDefId) ;
}
