package com.zcxk.process.service;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zcxk.process.dto.ProcessDefinitionDTO;
import com.zcxk.process.dto.TaskPorcessResult;
import com.zcxk.process.entity.ProcessDefinition;
import com.zcxk.process.utils.Action;
import org.activiti.engine.history.HistoricTaskInstance;
import org.activiti.engine.impl.persistence.entity.VariableInstance;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;

import java.io.InputStream;
import java.util.List;
import java.util.Map;
import java.util.Set;

public interface WorkFlowService {
    /**
     * <p>根据场景查询工作流流程定义</p>
     *
     * @param siteId    站点
     * @param channelId 场景
     * @return
     */
    public ProcessDefinition findProccessDefByChannel(Integer siteId, Integer channelId);


    public ProcessDefinition findProcessDefinition(String tenantId, Integer companyId, Integer taskType);


    IPage<ProcessDefinitionDTO> selectPage(ProcessDefinition processDefinition, IPage<ProcessDefinitionDTO> iPage);
    public void saveProcessDefinition(ProcessDefinition processDefinition);

    public void editProcessDefinition(ProcessDefinition processDefinition);

    public void deleteProcessDefinition(Integer processId);

    public String getProcessBPMNContent(Integer processId);

    public void saveBPMNContent(Integer processId, String content, String svg);

    /**
     * <p>部署工作流</p>
     *
     * @param definition
     * @return
     */
    public boolean deploy(ProcessDefinition definition);

    /**
     * <p>部署工作流</p>
     *
     * @param processId
     */
    public void deploy(Integer processId);

    /**
     * <p>删除流程定义</p>
     * <p>cascade = true 级联删除，会删除所有和当前部署的规则相关的信息，包括历史的信息</p>
     * <p>cascade = false 普通删除，如果当前部署的规则还存在正在制作的流程，则抛异常</p>
     *
     * @param definition
     * @param cascade
     * @return
     */
    public boolean deleteProcessDefinition(ProcessDefinition definition, boolean cascade);

    /**
     * <p>启动工作流,返回启动后实例ID</p>
     *
     * @param def
     * @param
     * @param vars
     * @return
     */
    public String startProcess(ProcessDefinition def, Map<String, Object> vars);

    /**
     * <p>处理任务</p>
     *  @param action
     * @param taskId
     * @param reqMap
 *@param comment 备注
     * @return
     */
    public List<TaskPorcessResult> handleTask(Action action, String taskId, Map<String, Object> reqMap, String comment);
    //public void handleTask(Action action, String taskId, String userId, Map<String, Object> vars, String comment);

    /**
     * <p>转发任务</p>
     *
     * @param taskId
     * @param userId
     * @param newUserId
     * @param comment
     */
    public void transferTask(String taskId, String userId, String newUserId, String comment);

    /**
     * <p>驳回任务</p>
     *
     * @param taskId
     * @param userId
     * @param comment
     */
    public void rejectTask(String taskId, String userId, String comment);

    // 流程图高亮展示
    public InputStream queryProHighLighted(String processInstanceId) throws Exception;

    // 查看流程历史任务
    public List<HistoricTaskInstance> findHistoricTaskInstance(String processInstanceId);

    // 查看用户任务数
    long getCountTaskByUserId(String userId);

    /**
     * 获取流程所有得变量
     *
     * @param processInstanceId
     * @return
     */
    public Map<String, VariableInstance> getInstanceVars(String processInstanceId);

    public Map<String, Object> getProcessVars(String processInstanceId, boolean isLocal);

    /**
     * <p>获取任务节点的表单标识</p>
     *
     * @param taskId
     * @return
     */
    public String getTaskFormkey(String taskId);


    public ProcessInstance getProcessInstanceByTask(String taskId);

    public Object executeExpression(String expression);

    public String getProcessDefKey(String taskid);

    public String getTaskName(String taskid);

    /**
     * 删除工作流流程实例
     *
     * @param processInstanceId
     * @param remark
     * @return
     */
    public boolean deleteProcessInstance(String processInstanceId, String remark);
    /**
     * 强制终止流程工作流流程实例
     *
     * @param processInstanceId
     * @param
     * @return
     */
    public void stopProcessInstance(String processInstanceId);

    /**
     * 获取流程实例当前待处理任务
     *
     * @param processInstanceId
     * @return
     */
    public List<Task> getProcessRuntimeTask(String processInstanceId);

    /**
     * <p>获取任务的参与者</p>
     *
     * @param taskId
     * @return
     */
    public Set<String> getTaskParticipator(String taskId, boolean onlyAssignee,Map<String,Object>params);

    public Task getTaskById(String taskId);

    /**
     * <p>获取流程定义中所有用户任务节点</p>
     *
     * @param processDefinitionId
     * @return
     */
    public List<String> getProcessUserTaskList(String processDefinitionId);

    public Set<String> getUserTaskList(Integer siteId, Integer channelId, String processkey);

}
