package com.fs.store.mapper;

import java.util.List;
import com.fs.store.domain.FsArticleViews;
import com.fs.store.param.FsArticleViewListParam;
import com.fs.store.param.FsArticleViewListQueryParam;
import com.fs.store.vo.FsArticleViewListQueryVO;
import com.fs.store.vo.FsArticleViewListVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 文章阅读Mapper接口
 *
 * @author fs
 * @date 2022-03-25
 */
public interface FsArticleViewsMapper
{
    /**
     * 查询文章阅读
     *
     * @param viewId 文章阅读ID
     * @return 文章阅读
     */
    public FsArticleViews selectFsArticleViewsById(Long viewId);

    /**
     * 查询文章阅读列表
     *
     * @param fsArticleViews 文章阅读
     * @return 文章阅读集合
     */
    public List<FsArticleViews> selectFsArticleViewsList(FsArticleViews fsArticleViews);

    /**
     * 新增文章阅读
     *
     * @param fsArticleViews 文章阅读
     * @return 结果
     */
    public int insertFsArticleViews(FsArticleViews fsArticleViews);

    /**
     * 修改文章阅读
     *
     * @param fsArticleViews 文章阅读
     * @return 结果
     */
    public int updateFsArticleViews(FsArticleViews fsArticleViews);

    /**
     * 删除文章阅读
     *
     * @param viewId 文章阅读ID
     * @return 结果
     */
    public int deleteFsArticleViewsById(Long viewId);
    public int deleteFsArticleViewsByIds(Long[] viewIds);
    /**
     * 批量删除文章阅读
     *
     * @param viewIds 需要删除的数据ID
     * @return 结果
     */


    @Select("select u.user_id,u.avatar from fs_article_views v left join  fs_user u on u.user_id=v.user_id  where v.article_id=#{articleId} order by v.view_id desc  limit 3 ")
    List<FsArticleViewListQueryVO> selectFsArticleViewsTopByArticleId(Integer articleId);


    @Select({"<script> " +
            "select u.user_id,u.avatar,u.nickname from fs_article_views v left join  fs_user u on u.user_id=v.user_id   " +
            "where 1=1 " +
            "<if test = 'maps.articleId != null    '> " +
            "and v.article_id =#{maps.articleId} " +
            "</if>" +
            " order by v.view_id desc "+
            "</script>"})
    List<FsArticleViewListQueryVO> selectFsArticleViewsListQueryVO(@Param("maps") FsArticleViewListQueryParam param);
    @Select({"<script> " +
            "select v.*, a.title as article_title,  u.user_id,u.avatar,u.nickname from fs_article_views v left join fs_user u on u.user_id=v.user_id left join fs_article a on v.article_id=a.article_id   " +
            "where 1=1 " +
            "<if test = 'maps.articleTitle != null and  maps.articleTitle !=\"\"    '> " +
            "and a.title like CONCAT('%',#{maps.articleTitle},'%') " +
            "</if>" +
            " order by v.view_id desc "+
            "</script>"})
    List<FsArticleViewListVO> selectFsArticleViewsListVO(@Param("maps") FsArticleViewListParam param);
}
