package com.tzld.piaoquan.recommend.server.repository;

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
public interface DouHotVideoPortraitDataRepository extends JpaRepository<DouHotVideoPortraitData, Long> {

    List<DouHotVideoPortraitData> findAllByVidInAndType(List<String> videoIds, Integer type);

    @Query(value = "SELECT NEW com.tzld.piaoquan.recommend.server.repository.DouHotVideoProvince(" +
            "d.vid, d.name, d.option, " +
            "SUM(CASE WHEN d.type = 1 THEN d.value ELSE 0 END), " +
            "SUM(CASE WHEN d.type = 2 THEN d.value ELSE 0 END)" +
            ") FROM DouHotVideoPortraitData d " +
            "WHERE d.option = 4 AND d.vid IN (:videos) " +
            "GROUP BY d.vid, d.name, d.option "
            // + "HAVING SUM(CASE WHEN d.type = 2 THEN d.value ELSE 0 END) >= 100"
    )
    List<DouHotVideoProvince> findRecordTGIGe100AndRateDesc(@Param("videos") List<String> videos);
}