<?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.cook.mapper.CookRecipeBindDeviceMapper">
    <resultMap type="com.bonus.canteen.core.cook.domain.CookRecipeBindDevice" id="CookRecipeBindDeviceResult">
        <result property="id"    column="id"    />
        <result property="deviceId"    column="device_id"    />
        <result property="canteenId"    column="canteen_id"    />
        <result property="stallId"    column="stall_id"    />
        <result property="recipeId"    column="recipe_id"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectCookRecipeBindDeviceVo">
        select id, device_id, canteen_id, stall_id, recipe_id, create_by, create_time, update_by, update_time from cook_recipe_bind_device
    </sql>

    <select id="selectCookRecipeBindDeviceList" parameterType="com.bonus.canteen.core.cook.domain.CookRecipeBindDevice" resultMap="CookRecipeBindDeviceResult">
        <include refid="selectCookRecipeBindDeviceVo"/>
        <where>  
            <if test="deviceId != null "> and device_id = #{deviceId}</if>
            <if test="canteenId != null "> and canteen_id = #{canteenId}</if>
            <if test="stallId != null "> and stall_id = #{stallId}</if>
            <if test="recipeId != null "> and recipe_id = #{recipeId}</if>
        </where>
    </select>
    
    <select id="selectCookRecipeBindDeviceById" parameterType="Long" resultMap="CookRecipeBindDeviceResult">
        <include refid="selectCookRecipeBindDeviceVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertCookRecipeBindDevice" parameterType="com.bonus.canteen.core.cook.domain.CookRecipeBindDevice" useGeneratedKeys="true" keyProperty="id">
        insert into cook_recipe_bind_device
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="deviceId != null">device_id,</if>
            <if test="canteenId != null">canteen_id,</if>
            <if test="stallId != null">stall_id,</if>
            <if test="recipeId != null">recipe_id,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="deviceId != null">#{deviceId},</if>
            <if test="canteenId != null">#{canteenId},</if>
            <if test="stallId != null">#{stallId},</if>
            <if test="recipeId != null">#{recipeId},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateCookRecipeBindDevice" parameterType="com.bonus.canteen.core.cook.domain.CookRecipeBindDevice">
        update cook_recipe_bind_device
        <trim prefix="SET" suffixOverrides=",">
            <if test="deviceId != null">device_id = #{deviceId},</if>
            <if test="canteenId != null">canteen_id = #{canteenId},</if>
            <if test="stallId != null">stall_id = #{stallId},</if>
            <if test="recipeId != null">recipe_id = #{recipeId},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteCookRecipeBindDeviceById" parameterType="Long">
        delete from cook_recipe_bind_device where id = #{id}
    </delete>

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