<?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.fs.store.mapper.FsTestTempItemMapper">

    <resultMap type="FsTestTempItem" id="FsTestTempItemResult">
        <result property="itemId"    column="item_id"    />
        <result property="tempId"    column="temp_id"    />
        <result property="itemType"    column="item_type"    />
        <result property="title"    column="title"    />
        <result property="scoreJson"    column="score_json"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="sort"    column="sort"    />
    </resultMap>

    <sql id="selectFsTestTempItemVo">
        select item_id, temp_id, item_type, title, score_json, create_time, update_time, sort from fs_test_temp_item
    </sql>

    <select id="selectFsTestTempItemList" parameterType="FsTestTempItem" resultMap="FsTestTempItemResult">
        <include refid="selectFsTestTempItemVo"/>
        <where>
            <if test="tempId != null "> and temp_id = #{tempId}</if>
            <if test="itemType != null "> and item_type = #{itemType}</if>
            <if test="title != null  and title != ''"> and title like concat('%', #{title}, '%')</if>
            <if test="sort != null "> and sort = #{sort}</if>
        </where>
    </select>

    <select id="selectFsTestTempItemByItemId" parameterType="Long" resultMap="FsTestTempItemResult">
        <include refid="selectFsTestTempItemVo"/>
        where item_id = #{itemId}
    </select>

    <insert id="insertFsTestTempItem" parameterType="FsTestTempItem" useGeneratedKeys="true" keyProperty="itemId">
        insert into fs_test_temp_item
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="tempId != null">temp_id,</if>
            <if test="itemType != null">item_type,</if>
            <if test="title != null">title,</if>
            <if test="scoreJson != null">score_json,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="sort != null">sort,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="tempId != null">#{tempId},</if>
            <if test="itemType != null">#{itemType},</if>
            <if test="title != null">#{title},</if>
            <if test="scoreJson != null">#{scoreJson},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="sort != null">#{sort},</if>
         </trim>
    </insert>

    <update id="updateFsTestTempItem" parameterType="FsTestTempItem">
        update fs_test_temp_item
        <trim prefix="SET" suffixOverrides=",">
            <if test="tempId != null">temp_id = #{tempId},</if>
            <if test="itemType != null">item_type = #{itemType},</if>
            <if test="title != null">title = #{title},</if>
            <if test="scoreJson != null">score_json = #{scoreJson},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="sort != null">sort = #{sort},</if>
        </trim>
        where item_id = #{itemId}
    </update>

    <delete id="deleteFsTestTempItemByItemId" parameterType="Long">
        delete from fs_test_temp_item where item_id = #{itemId}
    </delete>

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