<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.ss.article.mapper.SmArticleMapper">

    <resultMap type="SmArticle" id="SmArticleResult" autoMapping="true">
        <result property="articleId"    column="article_id"    />
        <result property="classifyId"    column="classify_id"    />
        <result property="title"    column="title"    />
        <result property="logo"    column="logo"    />
        <result property="masterPicture"    column="master_picture"    />
        <result property="tag"    column="tag"    />
        <result property="isHot"    column="is_hot"    />
        <result property="introduction"    column="introduction"    />
        <result property="content"    column="content"    />
        <result property="author"    column="author"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
        <association property="classify"    javaType="SmArticleClassify"   resultMap="classifyResult" />
    </resultMap>

    <resultMap id="classifyResult" type="SmArticleClassify">
        <id     property="classifyId"    column="classify_id"     />
        <result property="parentId"  column="parent_id"   />
        <result property="classifyName"  column="classify_name"   />
        <result property="ancestors" column="ancestors"   />
        <result property="orderNum"  column="order_num"   />
        <result property="status"    column="dept_status" />
    </resultMap>

    <sql id="selectSmArticleVo">
        select
            sa.article_id,
            sa.classify_id,
            sa.title,
            sa.logo,
            sa.master_picture,
            sa.tag,
            sa.is_hot,
            sa.introduction,
            sa.content,
            sa.author,
            sa.create_by,
            sa.create_time,
            sa.update_by,
            sa.update_time,
            sa.remark
        from sm_article sa
    </sql>

    <select id="selectSmArticleList" parameterType="SmArticleQuery" resultMap="SmArticleResult">
        select a.article_id,
               a.classify_id,
               a.title,
               a.logo,
               a.master_picture,
               a.tag,
               a.is_hot,
               a.introduction,
               a.author,
               a.create_by,
               a.create_time,
               a.update_by,
               a.update_time,
               a.remark,
               sc.classify_name
        from sm_article a
            left join sm_article_classify sc on sc.classify_id = a.classify_id
        <where>
            <if test="classifyId != null  and classifyId != ''"> and a.classify_id = #{classifyId}</if>
            <if test="title != null  and title != ''"> and a.title like concat('%', #{title}, '%')</if>
            <if test="isHot != null  and isHot != ''"> and a.is_hot = #{isHot}</if>
            <if test="articleIds != null and articleIds.size() > 0">
                and a.article_id in
                <foreach collection="articleIds" item="item" separator="," open="(" close=")">
                    #{item}
                </foreach>
            </if>
        </where>
        order by a.create_time desc
    </select>

    <select id="selectSmArticleByArticleId" parameterType="Long" resultMap="SmArticleResult">
        <include refid="selectSmArticleVo"/>
        where sa.article_id = #{articleId}
    </select>

    <insert id="insertSmArticle" parameterType="SmArticle">
        insert into sm_article
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="articleId != null">article_id,</if>
            <if test="classifyId != null and classifyId != ''">classify_id,</if>
            <if test="title != null and title != ''">title,</if>
            <if test="logo != null">logo,</if>
            <if test="masterPicture != null">master_picture,</if>
            <if test="tag != null">tag,</if>
            <if test="isHot != null">is_hot,</if>
            <if test="introduction != null">introduction,</if>
            <if test="content != null">content,</if>
            <if test="author != null">author,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="articleId != null">#{articleId},</if>
            <if test="classifyId != null and classifyId != ''">#{classifyId},</if>
            <if test="title != null and title != ''">#{title},</if>
            <if test="logo != null">#{logo},</if>
            <if test="masterPicture != null">#{masterPicture},</if>
            <if test="tag != null">#{tag},</if>
            <if test="isHot != null">#{isHot},</if>
            <if test="introduction != null">#{introduction},</if>
            <if test="content != null">#{content},</if>
            <if test="author != null">#{author},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateSmArticle" parameterType="SmArticle">
        update sm_article
        <trim prefix="SET" suffixOverrides=",">
            <if test="classifyId != null and classifyId != ''">classify_id = #{classifyId},</if>
            <if test="title != null and title != ''">title = #{title},</if>
            <if test="logo != null">logo = #{logo},</if>
            <if test="masterPicture != null">master_picture = #{masterPicture},</if>
            <if test="tag != null">tag = #{tag},</if>
            <if test="isHot != null">is_hot = #{isHot},</if>
            <if test="introduction != null">introduction = #{introduction},</if>
            <if test="content != null">content = #{content},</if>
            <if test="author != null">author = #{author},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where article_id = #{articleId}
    </update>

    <delete id="deleteSmArticleByArticleId" parameterType="Long">
        delete from sm_article where article_id = #{articleId}
    </delete>

    <delete id="deleteSmArticleByArticleIds" parameterType="String">
        delete from sm_article where article_id in
        <foreach item="articleId" collection="array" open="(" separator="," close=")">
            #{articleId}
        </foreach>
    </delete>


</mapper>
