package com.fs.his.mapper;

import java.util.List;
import com.fs.his.domain.FsArticle;
import com.fs.his.param.FsArticleListUParam;
import com.fs.his.vo.FsArticleListUVO;
import com.fs.his.vo.FsArticleListVO;
import com.fs.his.vo.FsArticleVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * 文章Mapper接口
 *
 * @author fs
 * @date 2023-07-04
 */
public interface FsArticleMapper
{
    /**
     * 查询文章
     *
     * @param articleId 文章主键
     * @return 文章
     */
    public FsArticle selectFsArticleByArticleId(Long articleId);

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

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

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

    /**
     * 删除文章
     *
     * @param articleId 文章主键
     * @return 结果
     */
    public int deleteFsArticleByArticleId(Long articleId);

    /**
     * 批量删除文章
     *
     * @param articleIds 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteFsArticleByArticleIds(Long[] articleIds);

    List<FsArticleListUVO> selectFsArticleListUVO(@Param("maps")FsArticleListUParam param);

    @Update("update fs_article set views=views+1 where article_id=#{articleId}")
    int updateFsArticleViews(Long articleId);



    @Select({"<script> " +
             "SELECT fa.*,fac.cate_name  FROM fs_article fa LEFT JOIN fs_article_cate fac ON fa.cate_id=fac.cate_id"+
            "<where>  \n" +
            "            <if test=\"cateId != null \"> and fa.cate_id = #{cateId}</if>\n" +
            "            <if test=\"title != null  and title != ''\"> and fa.title like concat('%', #{title}, '%')</if>\n" +
            "            <if test=\"imageUrl != null  and imageUrl != ''\"> and fa.image_url = #{imageUrl}</if>\n" +
            "            <if test=\"isTui != null \"> and fa.is_tui = #{isTui}</if>\n" +
            "            <if test=\"isNews != null \"> and fa.is_news = #{isNews}</if>\n" +
            "            <if test=\"contents != null  and contents != ''\"> and fa.contents = #{contents}</if>\n" +
            "            <if test=\"views != null \"> and fa.views = #{views}</if>\n" +
            "            <if test=\"sort != null \"> and fa.sort = #{sort}</if>\n" +
            "            <if test=\"publishTime != null \"> and DATE(fa.publish_time) = DATE(#{publishTime})</if>\n" +
            "        </where>\n" +
            "        order by fa.article_id desc"+
            "</script>"})

    List<FsArticleListVO> selectFsArticleListVO(FsArticle fsArticle);
}
