package com.fs.hisStore.mapper;

import java.util.List;
import com.fs.hisStore.domain.FsArticleScrm;
import com.fs.hisStore.param.FsArticleQueryParam;
import com.fs.hisStore.vo.FsArticleListQueryVO;
import com.fs.hisStore.vo.FsArticleVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * 文章Mapper接口
 * 
 * @author fs
 * @date 2022-03-25
 */
public interface FsArticleScrmMapper 
{
    /**
     * 查询文章
     * 
     * @param articleId 文章ID
     * @return 文章
     */
    public FsArticleScrm selectFsArticleById(Integer articleId);

    /**
     * 查询文章列表
     * 
     * @param fsArticle 文章
     * @return 文章集合
     */
    public List<FsArticleScrm> selectFsArticleList(FsArticleScrm fsArticle);

    /**
     * 新增文章
     * 
     * @param fsArticle 文章
     * @return 结果
     */
    public int insertFsArticle(FsArticleScrm fsArticle);

    /**
     * 修改文章
     * 
     * @param fsArticle 文章
     * @return 结果
     */
    public int updateFsArticle(FsArticleScrm fsArticle);

    /**
     * 删除文章
     * 
     * @param articleId 文章ID
     * @return 结果
     */
    public int deleteFsArticleById(Integer articleId);

    /**
     * 批量删除文章
     * 
     * @param articleIds 需要删除的数据ID
     * @return 结果
     */
    public int deleteFsArticleByIds(Integer[] articleIds);
    @Select({"<script> " +
            "select a.*,c.cate_name  from fs_article a left join fs_article_cate c on c.cate_id=a.cate_id " +
            "where 1=1 " +
            "<if test = 'maps.title != null and  maps.title !=\"\"    '> " +
            "and a.title like CONCAT('%',#{maps.title},'%') " +
            "</if>" +
            "<if test = 'maps.cateId != null    '> " +
            "and a.cate_id =#{maps.cateId} " +
            "</if>" +
            " order by a.sort desc "+
            "</script>"})
    List<FsArticleVO> selectFsArticleListVO(@Param("maps") FsArticleScrm fsArticle);
    @Select({"<script> " +
            "select a.* from fs_article a  " +
            "where 1=1 " +
            "<if test = 'maps.isTui != null    '> " +
            "and a.is_tui =#{maps.isTui} " +
            "</if>" +
            "<if test = 'maps.cateId != null and maps.cateId != 0    '> " +
            "and a.cate_id =#{maps.cateId} " +
            "</if>" +
            "<if test = 'maps.keyword != null and maps.keyword != \"\"    '> " +
            "and a.title like concat('%', #{maps.keyword}, '%') " +
            "</if>" +
            " order by a.sort desc "+
            "<if test = 'maps.limit != null    '> " +
            "limit #{maps.limit} " +
            "</if>" +
            "</script>"})
    List<FsArticleListQueryVO> selectFsArticleListQuery(@Param("maps") FsArticleQueryParam param);
    @Update("update fs_article set views=views+1  where article_id=#{articleId}")
    Integer updateViews(Long articleId);
}
