<?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.system.mapper.XysArticleMapper">
    
    <resultMap type="XysArticle" id="XysArticleResult">
        <result property="id"    column="id"    />
        <result property="title"    column="title"    />
        <result property="coverImg"    column="cover_img"    />
        <result property="content"    column="content"    />
        <result property="articleCat"    column="article_cat"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="remark"    column="remark"    />
        <result property="delFlag"    column="del_flag"    />
    </resultMap>

    <sql id="selectXysArticleVo">
        select id, title, cover_img, content, article_cat, create_time, create_by, update_time, update_by, remark, del_flag from xys_article
    </sql>

    <select id="selectXysArticleList" parameterType="XysArticle" resultMap="XysArticleResult">
        <include refid="selectXysArticleVo"/>
        <where>  
            <if test="title != null  and title != ''"> and title = #{title}</if>
            <if test="articleCat != null "> and article_cat = #{articleCat}</if>
        </where>
    </select>
    
    <select id="selectXysArticleById" parameterType="Long" resultMap="XysArticleResult">
        <include refid="selectXysArticleVo"/>
        where id = #{id}
    </select>

    <insert id="insertXysArticle" parameterType="XysArticle" useGeneratedKeys="true" keyProperty="id">
        insert into xys_article
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="title != null">title,</if>
            <if test="coverImg != null">cover_img,</if>
            <if test="content != null">content,</if>
            <if test="articleCat != null">article_cat,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="remark != null">remark,</if>
            <if test="delFlag != null">del_flag,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="title != null">#{title},</if>
            <if test="coverImg != null">#{coverImg},</if>
            <if test="content != null">#{content},</if>
            <if test="articleCat != null">#{articleCat},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="remark != null">#{remark},</if>
            <if test="delFlag != null">#{delFlag},</if>
         </trim>
    </insert>

    <update id="updateXysArticle" parameterType="XysArticle">
        update xys_article
        <trim prefix="SET" suffixOverrides=",">
            <if test="title != null">title = #{title},</if>
            <if test="coverImg != null">cover_img = #{coverImg},</if>
            <if test="content != null">content = #{content},</if>
            <if test="articleCat != null">article_cat = #{articleCat},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteXysArticleById" parameterType="Long">
        delete from xys_article where id = #{id}
    </delete>

    <delete id="deleteXysArticleByIds" parameterType="String">
        delete from xys_article where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>