package com.fs.hisStore.mapper;

import com.fs.hisStore.domain.FsDoctorArticleScrm;
import com.fs.hisStore.param.FsDoctorArticleListUParam;
import com.fs.hisStore.vo.FsDoctorArticleListUVO;
import com.fs.hisStore.vo.FsDoctorArticleListVO;
import com.fs.hisStore.vo.FsDoctorArticleUVO;
import com.fs.hisStore.vo.FsDoctorArticleVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 医生文章Mapper接口
 *
 * @author fs
 * @date 2023-06-05
 */
public interface FsDoctorArticleScrmMapper
{
    /**
     * 查询医生文章
     *
     * @param articleId 医生文章主键
     * @return 医生文章
     */
    public FsDoctorArticleScrm selectFsDoctorArticleByArticleId(Long articleId);

    /**
     * 查询医生文章列表
     *
     * @param fsDoctorArticle 医生文章
     * @return 医生文章集合
     */
    public List<FsDoctorArticleScrm> selectFsDoctorArticleList(FsDoctorArticleScrm fsDoctorArticle);

    /**
     * 新增医生文章
     *
     * @param fsDoctorArticle 医生文章
     * @return 结果
     */
    public int insertFsDoctorArticle(FsDoctorArticleScrm fsDoctorArticle);

    /**
     * 修改医生文章
     *
     * @param fsDoctorArticle 医生文章
     * @return 结果
     */
    public int updateFsDoctorArticle(FsDoctorArticleScrm fsDoctorArticle);

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

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


    @Select({"<script> " +
            "select ar.* FROM fs_doctor_article ar "+
            "<where>  \n" +
            "            <if test=\"cateId != null \"> and ar.cate_id = #{cateId}</if>\n" +
            "            <if test=\"title != null  and title != ''\"> and ar.title = #{title}</if>\n" +
            "            <if test=\"views != null \"> and ar.views = #{views}</if>\n" +
            "            <if test=\"status != null \"> and ar.status = #{status}</if>\n" +
            "        </where> "+
            " ORDER BY ar.article_id desc"+
            "</script>"})

    List<FsDoctorArticleListVO> selectFsDoctorArticleListVO(FsDoctorArticleScrm fsDoctorArticle);
    @Select("select *  FROM fs_doctor_article  where  article_id =#{articleId}")
    FsDoctorArticleVO selectFsDoctorArticleVOByArticleId(Long articleId);
    @Select({"<script> " +
            "select a.article_id,a.image_url,a.title,a.views,a.doctor_id  from fs_doctor_article a    " +
            "where a.status=1  " +
            "<if test = 'maps.keyword != null     '> " +
            "and a.title like CONCAT('%',#{maps.keyword},'%')" +
            "</if>"+
            "<if test = 'maps.cateId != null and maps.cateId!=0    '> " +
            "and a.cate_id = #{maps.cateId} " +
            "</if>" +
            " order by a.create_time desc "+
            "</script>"})
    List<FsDoctorArticleListUVO> selectFsDoctorArticleListUVO(@Param("maps") FsDoctorArticleListUParam param);
    @Update("update fs_doctor_article set views=views+1 where article_id=#{articleId}")
    int updateViews(Long articleId);
    @Select({"<script> " +
            "select a.article_id,a.image_url,a.title,a.video_url,a.create_time,a.content,a.views,a.doctor_id,video_type  from fs_doctor_article a     " +
            "where a.article_id = #{articleId} " +
            "</script>"})
    FsDoctorArticleUVO selectFsDoctorArticleUVOByArticleId(Long articleId);

}
