<?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.kitchen.mapper.KitchenStaffDevicePrivilegeMapper">
    <resultMap type="com.bonus.canteen.core.kitchen.domain.KitchenStaffDevicePrivilege" id="KitchenStaffDevicePrivilegeResult">
        <result property="id"    column="id"    />
        <result property="staffId"    column="staff_id"    />
        <result property="deviceType"    column="device_type"    />
        <result property="deviceId"    column="device_id"    />
        <result property="privilegeName"    column="privilege_name"    />
        <result property="privilegeValue"    column="privilege_value"    />
        <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="selectKitchenStaffDevicePrivilegeVo">
        select id, staff_id, device_type, device_id, privilege_name, privilege_value, create_by, create_time, update_by, update_time from kitchen_staff_device_privilege
    </sql>

    <select id="selectKitchenStaffDevicePrivilegeList" parameterType="com.bonus.canteen.core.kitchen.domain.KitchenStaffDevicePrivilege" resultMap="KitchenStaffDevicePrivilegeResult">
        <include refid="selectKitchenStaffDevicePrivilegeVo"/>
        <where>  
            <if test="staffId != null "> and staff_id = #{staffId}</if>
            <if test="deviceId != null "> and device_id = #{deviceId}</if>
            <if test="privilegeName != null  and privilegeName != ''"> and privilege_name like concat('%', #{privilegeName}, '%')</if>
            <if test="privilegeValue != null  and privilegeValue != ''"> and privilege_value = #{privilegeValue}</if>
        </where>
    </select>
    
    <select id="selectKitchenStaffDevicePrivilegeById" parameterType="Long" resultMap="KitchenStaffDevicePrivilegeResult">
        <include refid="selectKitchenStaffDevicePrivilegeVo"/>
        where id = #{id}
    </select>

    <select id="selectKitchenStaffDevicePrivilegeByStaffId" parameterType="Long" resultMap="KitchenStaffDevicePrivilegeResult">
        <include refid="selectKitchenStaffDevicePrivilegeVo"/>
        where staff_id = #{staffId}
    </select>
        
    <insert id="insertKitchenStaffDevicePrivilege" parameterType="com.bonus.canteen.core.kitchen.domain.KitchenStaffDevicePrivilege" useGeneratedKeys="true" keyProperty="id">
        insert into kitchen_staff_device_privilege
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="staffId != null">staff_id,</if>
            <if test="deviceType != null">device_type,</if>
            <if test="deviceId != null">device_id,</if>
            <if test="privilegeName != null">privilege_name,</if>
            <if test="privilegeValue != null">privilege_value,</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="staffId != null">#{staffId},</if>
            <if test="deviceType != null">#{deviceType},</if>
            <if test="deviceId != null">#{deviceId},</if>
            <if test="privilegeName != null">#{privilegeName},</if>
            <if test="privilegeValue != null">#{privilegeValue},</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="updateKitchenStaffDevicePrivilege" parameterType="com.bonus.canteen.core.kitchen.domain.KitchenStaffDevicePrivilege">
        update kitchen_staff_device_privilege
        <trim prefix="SET" suffixOverrides=",">
            <if test="staffId != null">staff_id = #{staffId},</if>
            <if test="deviceType != null">device_type = #{deviceType},</if>
            <if test="deviceId != null">device_id = #{deviceId},</if>
            <if test="privilegeName != null">privilege_name = #{privilegeName},</if>
            <if test="privilegeValue != null">privilege_value = #{privilegeValue},</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="deleteKitchenStaffDevicePrivilegeById" parameterType="Long">
        delete from kitchen_staff_device_privilege where id = #{id}
    </delete>

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

    <delete id="deleteKitchenStaffDevicePrivilegeByStaffId" parameterType="Long">
        delete from kitchen_staff_device_privilege where staff_id = #{staffId}
    </delete>

    <delete id="deleteKitchenStaffDevicePrivilegeByStaffIds">
        delete from kitchen_staff_device_privilege where staff_id in
        <foreach item="staffId" collection="array" open="(" separator="," close=")">
            #{staffId}
        </foreach>
    </delete>

</mapper>