package com.fs.his.mapper;

import java.util.List;
import com.fs.his.domain.FsDoctorArticle;
import com.fs.his.param.FsDoctorArticleListDParam;
import com.fs.his.param.FsDoctorArticleListUParam;
import com.fs.his.vo.*;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

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

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

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

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

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

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




    @Select({"<script> " +
            "select ar.*,doc.doctor_name FROM fs_doctor_article ar LEFT JOIN fs_doctor doc ON ar.doctor_id=doc.doctor_id"+
            "<where>  \n" +
            "            <if test=\"doctorId != null \"> and ar.doctor_id = #{doctorId}</if>\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(FsDoctorArticle fsDoctorArticle);
    @Select("select ar.*,doc.doctor_name FROM fs_doctor_article ar LEFT JOIN fs_doctor doc ON ar.doctor_id=doc.doctor_id where  article_id =#{articleId}")
    FsDoctorArticleVO selectFsDoctorArticleVOByArticleId(Long articleId);
    @Select({"<script> " +
            "select a.article_id,a.image_url,a.title,a.views,a.doctor_id,d.doctor_name,d.avatar,d.position  from fs_doctor_article a left join fs_doctor d on d.doctor_id=a.doctor_id    " +
            "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>" +
            "<if test = 'maps.doctorId != null     '> " +
            "and a.doctor_id = #{maps.doctorId} " +
            "</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,d.doctor_name,d.avatar,d.position  from fs_doctor_article a left join fs_doctor d on d.doctor_id=a.doctor_id    " +
            "where a.article_id = #{articleId} " +
            "</script>"})
    FsDoctorArticleUVO selectFsDoctorArticleUVOByArticleId(Long articleId);
    @Select({"<script> " +
            "select a.* from fs_doctor_article a     " +
            "where 1=1  " +
            "<if test = 'maps.keyword != null     '> " +
            "and a.title like CONCAT('%',#{maps.keyword},'%')" +
            "</if>"+
            "<if test = 'maps.doctorId != null     '> " +
            "and a.doctor_id = #{maps.doctorId} " +
            "</if>" +
            "<if test = 'maps.cateId != null     '> " +
            "and a.cate_id = #{maps.cateId} " +
            "</if>" +
            " order by a.create_time desc "+
            "</script>"})
    List<FsDoctorArticleListDVO> selectFsDoctorArticleListDVO(@Param("maps") FsDoctorArticleListDParam param);
    @Select("select * from fs_doctor_article WHERE title=#{typeName} limit 1")
    FsDoctorArticle selectFsDoctorArticleByArticleByNameBodyUrl(String typeName);
}
