<?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.zehong.system.mapper.shelf.TShelfInfoMapper">
    
    <resultMap type="TShelfInfo" id="TShelfInfoResult">
        <result property="fShelfId"    column="f_shelf_id"    />
        <result property="fType"    column="f_type"    />
        <result property="fShelf"    column="f_shelf"    />
        <result property="fStatus"    column="f_status"    />
    </resultMap>

    <sql id="selectTShelfInfoVo">
        select f_shelf_id, f_type, f_shelf, f_status from t_shelf_info
    </sql>

    <select id="selectTShelfInfoList" parameterType="TShelfInfo" resultMap="TShelfInfoResult">
        <include refid="selectTShelfInfoVo"/>
        <where>  
            <if test="fType != null "> and f_type = #{fType}</if>
            <if test="fShelf != null  and fShelf != ''"> and f_shelf like (concat('%', #{fShelf}, '%'))</if>
            <if test="fStatus != null "> and f_status = #{fStatus}</if>
        </where>
    </select>
    
    <select id="selectTShelfInfoById" parameterType="Long" resultMap="TShelfInfoResult">
        <include refid="selectTShelfInfoVo"/>
        where f_shelf_id = #{fShelfId}
    </select>

    <select id="selectTShelfInfoByShelf" parameterType="String" resultMap="TShelfInfoResult">
        <include refid="selectTShelfInfoVo"/>
        where f_shelf = #{shelf}
    </select>
        
    <insert id="insertTShelfInfo" parameterType="TShelfInfo" useGeneratedKeys="true" keyProperty="fShelfId">
        insert into t_shelf_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="fType != null">f_type,</if>
            <if test="fShelf != null and fShelf != ''">f_shelf,</if>
            <if test="fStatus != null">f_status,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="fType != null">#{fType},</if>
            <if test="fShelf != null and fShelf != ''">#{fShelf},</if>
            <if test="fStatus != null">#{fStatus},</if>
         </trim>
    </insert>

    <update id="updateTShelfInfo" parameterType="TShelfInfo">
        update t_shelf_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="fType != null">f_type = #{fType},</if>
            <if test="fShelf != null and fShelf != ''">f_shelf = #{fShelf},</if>
            <if test="fStatus != null">f_status = #{fStatus},</if>
        </trim>
        where f_shelf_id = #{fShelfId}
    </update>

    <delete id="deleteTShelfInfoById" parameterType="Long">
        delete from t_shelf_info where f_shelf_id = #{fShelfId}
    </delete>

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