package com.lesingle.modules.ugc.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lesingle.modules.ugc.entity.UgcWorkPage;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UgcWorkPageMapper extends BaseMapper<UgcWorkPage> {

    /**
     * 批量统计各作品的绘本页数（用于作品列表展示）
     */
    @Select("<script>"
            + "SELECT work_id AS workId, COUNT(1) AS pageCount FROM t_ugc_work_page WHERE work_id IN "
            + "<foreach collection=\"workIds\" item=\"id\" open=\"(\" separator=\",\" close=\")\">#{id}</foreach> "
            + "GROUP BY work_id"
            + "</script>")
    List<UgcWorkPageCountRow> countPagesGroupedByWorkIds(@Param("workIds") List<Long> workIds);
}
