<?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.bonus.canteen.core.supply.mapper.SupplyWarehouseFetchUserMapper">
    <resultMap type="com.bonus.canteen.core.supply.domain.SupplyWarehouseFetchUser" id="SupplyWarehouseFetchUserResult">
        <result property="id"    column="id"    />
        <result property="warehouseId"    column="warehouse_id"    />
        <result property="canteenId"    column="canteen_id"    />
        <result property="stallId"    column="stall_id"    />
        <result property="fetchUserId"    column="fetch_user_id"    />
    </resultMap>

    <sql id="selectSupplyWarehouseFetchUserVo">
        select id, warehouse_id, canteen_id, stall_id, fetch_user_id from supply_warehouse_fetch_user
    </sql>

    <select id="selectSupplyWarehouseFetchUserList" parameterType="com.bonus.canteen.core.supply.domain.SupplyWarehouseFetchUser" resultMap="SupplyWarehouseFetchUserResult">
        <include refid="selectSupplyWarehouseFetchUserVo"/>
        <where>  
            <if test="warehouseId != null "> and warehouse_id = #{warehouseId}</if>
            <if test="canteenId != null "> and canteen_id = #{canteenId}</if>
            <if test="stallId != null "> and stall_id = #{stallId}</if>
            <if test="fetchUserId != null "> and fetch_user_id = #{fetchUserId}</if>
        </where>
    </select>
    
    <select id="selectSupplyWarehouseFetchUserById" parameterType="Long" resultMap="SupplyWarehouseFetchUserResult">
        <include refid="selectSupplyWarehouseFetchUserVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertSupplyWarehouseFetchUser" parameterType="com.bonus.canteen.core.supply.domain.SupplyWarehouseFetchUser" useGeneratedKeys="true" keyProperty="id">
        insert into supply_warehouse_fetch_user
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="warehouseId != null">warehouse_id,</if>
            <if test="canteenId != null">canteen_id,</if>
            <if test="stallId != null">stall_id,</if>
            <if test="fetchUserId != null">fetch_user_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="warehouseId != null">#{warehouseId},</if>
            <if test="canteenId != null">#{canteenId},</if>
            <if test="stallId != null">#{stallId},</if>
            <if test="fetchUserId != null">#{fetchUserId},</if>
         </trim>
    </insert>

    <update id="updateSupplyWarehouseFetchUser" parameterType="com.bonus.canteen.core.supply.domain.SupplyWarehouseFetchUser">
        update supply_warehouse_fetch_user
        <trim prefix="SET" suffixOverrides=",">
            <if test="warehouseId != null">warehouse_id = #{warehouseId},</if>
            <if test="canteenId != null">canteen_id = #{canteenId},</if>
            <if test="stallId != null">stall_id = #{stallId},</if>
            <if test="fetchUserId != null">fetch_user_id = #{fetchUserId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSupplyWarehouseFetchUserById" parameterType="Long">
        delete from supply_warehouse_fetch_user where id = #{id}
    </delete>

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