package com.qqchen.deploy.backend.workflow.repository;

import com.qqchen.deploy.backend.framework.repository.IBaseRepository;
import com.qqchen.deploy.backend.workflow.entity.WorkflowInstance;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface IWorkflowInstanceRepository extends IBaseRepository<WorkflowInstance, Long> {
    
    /**
     * 根据Flowable流程实例ID查询工作流实例
     */
    Optional<WorkflowInstance> findByProcessInstanceId(String processInstanceId);
    
    /**
     * 根据业务标识查询工作流实例列表
     */
    List<WorkflowInstance> findByBusinessKey(String businessKey);

    List<WorkflowInstance> findTop1ByWorkflowDefinitionIdOrderByCreateTimeDesc(Long workflowDefinitionId);

    Page<WorkflowInstance> findByWorkflowDefinitionIdOrderByCreateTimeDesc(Long workflowDefinitionId, Pageable pageable);

}
