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

import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.activiti.engine.history.HistoricTaskInstance;
import org.activiti.engine.impl.persistence.entity.ExecutionEntity;
import org.activiti.engine.impl.persistence.entity.TaskEntity;
import org.activiti.engine.runtime.ProcessInstance;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

/**
 * 环节实例对象
 * @author lw
 *
 */
public class ActivityInstanceModel  implements Serializable {
	
	static final long serialVersionUID = 1L;
	/**
	 * 流程定义ID
	 */
	String procDefId;
	/**
	 * 流程定义名称
	 */
	String procDefName;
	/**
	 * 父流程实例ID
	 */
	String parentProcInstId;
	/**
	 * 流程实例ID
	 */
	String procInstId;
	/**
	 * 流程名称
	 */
	String procTitle;
	/**
	 * 执行ID
	 */
	String executionId;
	/**
	 * 环节定义ID
	 */
	String actDefName;
	
	/**
	 * 环节定义名称
	 */
	String actDefId;
	/**
	 * 环节实例ID-任务节点对应任务ID
	 */
	String actInstId;
	/**
	 * 父环节实例ID
	 */
	String parentActInstId;
	/**
	 * 上一步环节实例ID
	 */
	String prevActInstId;
	/**
	 * 上一步环节定义ID
	 */
	String prevActDefId;
	/**
	 * 上一步环节定义名称
	 */
	String prevActDefName;
	/**
	 * 当前环节发送人帐号
	 */
	String sender;
	/**
	 * 发送人ID
	 */
	String sendUserId;
	/**
	 * 当前环节发送人姓名
	 */
	String sendUserName;
	
	/**
	 * 当前环节发送人组织机构ID
	 */
	String senderOrgId;
	
	/**
	 * 当前环节发送人组织机构名称
	 */
	String senderOrgName;
	/**
	 * 当前环节的接收人，待办任务可能没有数据
	 */
	String receiver;
	/**
	 * 环节所有者
	 */
	String owner;
	/**
	 * 状态
	 */
	String actState;
	/**
	 * 创建时间
	 */
	Date createTime;
	/**
	 * 完成时间
	 */
	Date finishTime;
	/**
	 * 持续时间-耗时
	 */
	Date dueDate;
	/**
	 * 环节实例变量--待定
	 */
	Map localVariables = new HashMap();
	/**
	 * 租户ID--待定
	 */
	String tenantId;
	
	/**
	 * 接收人信息，receiver为接收人帐号
	 */
	String receiverUserId;
	String receiverUserName;
	String receiverOrgId;
	String receiverOrgName;
	
	
	private ActivityDefinitionModel activityDefinition;
	
	public static ActivityInstanceModel buildAndActDef(HistoricTaskInstance task,ActivityDefinitionModel activityDefinitionModel){
		ActivityInstanceModel activityInstance=new ActivityInstanceModel();
		if(task==null)
			return activityInstance;
		activityInstance.procDefId=task.getProcessDefinitionId();
		activityInstance.procDefName=task.getProcessDefinitionName();
		activityInstance.procTitle=task.getProcTitle();
		activityInstance.procInstId=task.getProcessInstanceId();
		activityInstance.actInstId=task.getId();
		activityInstance.owner=task.getOwner();
		activityInstance.receiver=task.getAssignee();
		activityInstance.receiverUserId=task.getAssigneeUserId();
		activityInstance.receiverOrgId=task.getAssigneeOrgId();
		activityInstance.receiverOrgName=task.getAssigneeOrgName();
		activityInstance.receiverUserName=task.getAssigneeUserName();
		activityInstance.sender=task.getSender();
		activityInstance.sendUserName=task.getSendUserName();
		activityInstance.sendUserId=task.getSendUserId();
		activityInstance.senderOrgId=task.getSenderOrgId();
		activityInstance.senderOrgName=task.getSenderOrgName();
		activityInstance.procDefName=task.getProcessDefinitionName();
		activityInstance.createTime=task.getStartTime();
		activityInstance.finishTime=task.getEndTime();
		activityInstance.executionId=task.getExecutionId();
		activityInstance.prevActInstId=task.getPreTaskId();
		activityInstance.prevActDefId=task.getPreTaskDefKey();
		activityInstance.prevActDefName=task.getPreTaskDefName();
		activityInstance.actState="1";
		activityInstance.dueDate=task.getDueDate();
		activityInstance.tenantId=task.getTenantId();
		activityInstance.localVariables=task.getTaskLocalVariables();
		activityInstance.actDefId=task.getTaskDefinitionKey();
		activityInstance.actDefName=task.getName();
		activityInstance.activityDefinition=activityDefinitionModel;
		return activityInstance;
	}
	/**
	 * 构建环节实例
	 * @param task
	 * @return
	 */
	public static ActivityInstanceModel buildAndActDef(TaskEntity task,ActivityDefinitionModel activityDefinitionModel){
		ActivityInstanceModel activityInstance=new ActivityInstanceModel();
		if(task==null)
			return activityInstance;
		activityInstance.procDefId=task.getProcessDefinitionId();
		activityInstance.procDefName=task.getProcessDefinitionName();
		activityInstance.procTitle=task.getProcTitle();
		activityInstance.procInstId=task.getProcessInstanceId();
		activityInstance.actInstId=task.getId();
		activityInstance.owner=task.getOwner();
		activityInstance.receiver=task.getAssignee();
		activityInstance.receiverUserId=task.getAssigneeUserId();
		activityInstance.receiverOrgId=task.getAssigneeOrgId();
		activityInstance.receiverOrgName=task.getAssigneeOrgName();
		activityInstance.receiverUserName=task.getAssigneeUserName();
		activityInstance.sender=task.getSender();
		activityInstance.sendUserId=task.getSendUserId();
		activityInstance.sendUserName=task.getSendUserName();
		activityInstance.senderOrgId=task.getSenderOrgId();
		activityInstance.senderOrgName=task.getSenderOrgName();
		activityInstance.procDefName=task.getProcessDefinitionName();
		activityInstance.createTime=task.getCreateTime();
		activityInstance.executionId=task.getExecutionId();
		activityInstance.prevActInstId=task.getPreTaskId();
		activityInstance.prevActDefId=task.getPreTaskDefKey();
		activityInstance.prevActDefName=task.getPreTaskDefName();
		activityInstance.actState="0";
		activityInstance.tenantId=task.getTenantId();
		activityInstance.localVariables=task.getTaskLocalVariables();
		activityInstance.dueDate=task.getDueDate();
		activityInstance.actDefId=task.getTaskDefinitionKey();
		activityInstance.actDefName=task.getName();
		activityInstance.activityDefinition=activityDefinitionModel;
		return activityInstance;
	}
	
	
	public String getProcInstId() {
		return procInstId;
	}
	public void setProcInstId(String procInstId) {
		this.procInstId = procInstId;
	}
	public String getProcTitle() {
		return procTitle;
	}
	public void setProcTitle(String procTitle) {
		this.procTitle = procTitle;
	}
	public String getExecutionId() {
		return executionId;
	}
	public void setExecutionId(String executionId) {
		this.executionId = executionId;
	}
	public String getActInstId() {
		return actInstId;
	}
	public void setActInstId(String actInstId) {
		this.actInstId = actInstId;
	}
	public String getParentActInstId() {
		return parentActInstId;
	}
	public void setParentActInstId(String parentActInstId) {
		this.parentActInstId = parentActInstId;
	}
	public String getPrevActInstId() {
		return prevActInstId;
	}
	public void setPrevActInstId(String prevActInstId) {
		this.prevActInstId = prevActInstId;
	}
	public String getPrevActDefId() {
		return prevActDefId;
	}
	public void setPrevActDefId(String prevActDefId) {
		this.prevActDefId = prevActDefId;
	}
	public String getPrevActDefName() {
		return prevActDefName;
	}
	public void setPrevActDefName(String prevActDefName) {
		this.prevActDefName = prevActDefName;
	}
	public String getSender() {
		return sender;
	}
	public void setSender(String sender) {
		this.sender = sender;
	}
	public String getSendUserName() {
		return sendUserName;
	}
	public void setSendUserName(String sendUserName) {
		this.sendUserName = sendUserName;
	}
	public String getReceiver() {
		return receiver;
	}
	public void setReceiver(String receiver) {
		this.receiver = receiver;
	}
	public String getOwner() {
		return owner;
	}
	public void setOwner(String owner) {
		this.owner = owner;
	}
	public String getActState() {
		return actState;
	}
	public void setActState(String actState) {
		this.actState = actState;
	}
	public Date getCreateTime() {
		return createTime;
	}
	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}
	public Date getFinishTime() {
		return finishTime;
	}
	public void setFinishTime(Date finishTime) {
		this.finishTime = finishTime;
	}
	public Date getDueDate() {
		return dueDate;
	}
	public void setDueDate(Date dueDate) {
		this.dueDate = dueDate;
	}
	public Map getLocalVariables() {
		return localVariables;
	}
	public void setLocalVariables(Map localVariables) {
		this.localVariables = localVariables;
	}
	public String getTenantId() {
		return tenantId;
	}
	public void setTenantId(String tenantId) {
		this.tenantId = tenantId;
	}
	public ActivityDefinitionModel getActivityDefinition() {
		return activityDefinition;
	}
	public void setActivityDefinition(ActivityDefinitionModel activityDefinition) {
		this.activityDefinition = activityDefinition;
	}
	public String getProcDefId() {
		return procDefId;
	}
	public void setProcDefId(String procDefId) {
		this.procDefId = procDefId;
	}
	public String getProcDefName() {
		return procDefName;
	}
	public void setProcDefName(String procDefName) {
		this.procDefName = procDefName;
	}
	public String getActDefName() {
		return actDefName;
	}
	public void setActDefName(String actDefName) {
		this.actDefName = actDefName;
	}
	public String getActDefId() {
		return actDefId;
	}
	public void setActDefId(String actDefId) {
		this.actDefId = actDefId;
	}
	public String getSenderOrgId() {
		return senderOrgId;
	}
	public void setSenderOrgId(String senderOrgId) {
		this.senderOrgId = senderOrgId;
	}
	public String getSenderOrgName() {
		return senderOrgName;
	}
	public void setSenderOrgName(String senderOrgName) {
		this.senderOrgName = senderOrgName;
	}
	
	public void setSendUserId(String sendUserId) {
		this.sendUserId = sendUserId;
	}
	public String getSendUserId() {
		return this.sendUserId;
	}
	public void setReceiverUserId(String receiverUserName) {
		this.receiverUserId = receiverUserName;
	}
	public String getReceiverUserId() {
		return this.receiverUserId;
	}
	public void setReceiverUserName(String receiverUserName) {
		this.receiverUserName = receiverUserName;
	}
	public String getReceiverUserName() {
		return this.receiverUserName;
	}
	public void setReceiverOrgId(String receiverUserName) {
		this.receiverOrgId = receiverUserName;
	}
	public String getReceiverOrgId() {
		return this.receiverOrgId;
	}
	public void setReceiverOrgName(String receiverOrgName) {
		this.receiverOrgName = receiverOrgName;
	}
	public String getReceiverOrgName() {
		return this.receiverOrgName;
	}
	public String getParentProcInstId() {
		return parentProcInstId;
	}
	public void setParentProcInstId(String parentProcInstId) {
		this.parentProcInstId = parentProcInstId;
	}
	public String toString() {
		return ToStringBuilder.reflectionToString(this,ToStringStyle.MULTI_LINE_STYLE);
	}

}
