<?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.ContentMapper">

    <resultMap type="Content" id="ContentResult">
        <result property="id"    column="id"    />
        <result property="type"    column="type"    />
        <result property="title"    column="title"    />
        <result property="content"    column="content"    />
        <result property="image"    column="image"    />
        <result property="link"    column="link"    />
        <result property="sort"    column="sort"    />
        <result property="status"    column="status"    />
        <result property="createdAt"    column="created_at"    />
        <result property="updatedAt"    column="updated_at"    />
        <result property="deletedAt"    column="deleted_at"    />
    </resultMap>

    <sql id="selectContentVo">
        select id, type, title, content, image, link, sort, status, created_at, updated_at, deleted_at from content
    </sql>

    <select id="selectContentList" parameterType="Content" resultMap="ContentResult">
        <include refid="selectContentVo"/>
        <where>
            <if test="title != null  and title != ''"> and title like concat('%', #{title}, '%') </if>
            <if test="content != null  and content != ''"> and content = #{content}</if>
            <if test="image != null  and image != ''"> and image = #{image}</if>
        </where>
    </select>

    <select id="selectContentById" parameterType="Long" resultMap="ContentResult">
        <include refid="selectContentVo"/>
        where id = #{id}
    </select>

    <insert id="insertContent" parameterType="Content" useGeneratedKeys="true" keyProperty="id">
        insert into content
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="type != null">type,</if>
            <if test="title != null and title != ''">title,</if>
            <if test="content != null">content,</if>
            <if test="image != null">image,</if>
            <if test="link != null">link,</if>
            <if test="sort != null">sort,</if>
            <if test="status != null">status,</if>
            <if test="createdAt != null">created_at,</if>
            <if test="updatedAt != null">updated_at,</if>
            <if test="deletedAt != null">deleted_at,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="type != null">#{type},</if>
            <if test="title != null and title != ''">#{title},</if>
            <if test="content != null">#{content},</if>
            <if test="image != null">#{image},</if>
            <if test="link != null">#{link},</if>
            <if test="sort != null">#{sort},</if>
            <if test="status != null">#{status},</if>
            <if test="createdAt != null">#{createdAt},</if>
            <if test="updatedAt != null">#{updatedAt},</if>
            <if test="deletedAt != null">#{deletedAt},</if>
        </trim>
    </insert>

    <update id="updateContent" parameterType="Content">
        update content
        <trim prefix="SET" suffixOverrides=",">
            <if test="type != null">type = #{type},</if>
            <if test="title != null and title != ''">title = #{title},</if>
            <if test="content != null">content = #{content},</if>
            <if test="image != null">image = #{image},</if>
            <if test="link != null">link = #{link},</if>
            <if test="sort != null">sort = #{sort},</if>
            <if test="status != null">status = #{status},</if>
            <if test="createdAt != null">created_at = #{createdAt},</if>
            <if test="updatedAt != null">updated_at = #{updatedAt},</if>
            <if test="deletedAt != null">deleted_at = #{deletedAt},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteContentById" parameterType="Long">
        delete from content where id = #{id}
    </delete>

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