package com.izouma.nineth.repo;

import com.izouma.nineth.domain.ActivityPriorityDocument;
import org.springframework.data.jpa.repository.*;

import javax.transaction.Transactional;
import java.math.BigInteger;
import java.util.List;
import java.util.Map;
import java.util.Optional;

public interface ActivityPriorityDocumentRepo extends JpaRepository<ActivityPriorityDocument, Long>, JpaSpecificationExecutor<ActivityPriorityDocument> {
    @Query("update ActivityPriorityDocument t set t.del = true where t.id = ?1")
    @Modifying
    @Transactional
    void softDelete(Long id);

    /**
     * 查询指定藏品有没有优先购买权
     * @param collectionId
     * @return
     */
    @Query( nativeQuery = true ,value ="select * from activity_priority_document where collection_id = ?1 and del = false")
   List <ActivityPriorityDocument> findByCollectionId(Long collectionId);

    /**
     * 查询指定藏品有没有优先购买权
     * @return
     */
    @Query( nativeQuery = true ,value ="select collection_id,item_id from activity_priority_document where del = false")
    List <Map<String, Object>> findByCollectionIds();


    /**
     * 查询有设置重置的优先购配置
     * @return
     */
    @Query( nativeQuery = true ,value ="select * from activity_priority_document where reset = true and del = false")
    List <ActivityPriorityDocument> findReset();

}