package com.mosquito.project.permission;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 审批记录Repository
 */
@Repository
public interface ApprovalRecordRepository extends JpaRepository<SysApprovalRecord, Long> {

    List<SysApprovalRecord> findByStatus(String status);

    List<SysApprovalRecord> findByApplicantId(Long applicantId);

    List<SysApprovalRecord> findByCurrentApproverId(Long approverId);

    @Query("SELECT r FROM SysApprovalRecord r WHERE r.bizType = :bizType AND r.bizId = :bizId")
    List<SysApprovalRecord> findByBizTypeAndBizId(@Param("bizType") String bizType, @Param("bizId") Long bizId);

    @Query("SELECT r FROM SysApprovalRecord r WHERE r.currentApproverId = :userId AND r.status = 'PENDING'")
    List<SysApprovalRecord> findPendingByApproverId(@Param("userId") Long userId);

    @Query("SELECT r FROM SysApprovalRecord r WHERE r.applicantId = :userId AND r.status != 'PENDING'")
    List<SysApprovalRecord> findProcessedByApplicantId(@Param("userId") Long userId);
}
