package com.izouma.nineth.repo;

import com.izouma.nineth.dto.openapi.TransferCollectionDTO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * 查询上架的藏品 图片 价格 id
 * @author ZouYuHong
 */
public interface TransferCollectionRepo extends JpaRepository<TransferCollectionDTO, Long>, JpaSpecificationExecutor<TransferCollectionDTO> {
    @Query(value = "select\n" +
            " min(ci.price) as price,\n" +
            " ANY_VALUE(ci.name) as name,\n" +
            " ANY_VALUE(ci.pic) as pic,\n" +
            " a.collection_id as id\n" +
            "from\n" +
            " collection_info ci,\n" +
            " asset a\n" +
            "where\n" +
            " ci.source = 'TRANSFER'\n" +
            " and ci.asset_id = a.id \n" +
            " and ci.on_shelf = 1 \n" +
            " and ci.salable = 1 \n" +
            " and ci.del = 0 \n" +
            " and ci.project_id = ?1 \n" +
            "and a.collection_id is not null\n" +
            " and ci.price >0\n" +
            "group by\n" +
            " a.collection_id\n" +
            "order by\n" +
            " a.collection_id desc\n" +
            "limit 500", nativeQuery = true)
    List<TransferCollectionDTO> transferCollections(Long projectId);

}