<?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.KitchenStaffIllegalWarningMapper">
    <resultMap type="com.bonus.canteen.core.kitchen.domain.KitchenStaffIllegalWarning" id="KitchenStaffIllegalWarningResult">
        <result property="illegalWarningId"    column="illegal_warning_id"    />
        <result property="staffId"    column="staff_id"    />
        <result property="deviceId"    column="device_id"    />
        <result property="imgUrl"    column="img_url"    />
        <result property="recordDesc"    column="record_desc"    />
        <result property="recordTime"    column="record_time"    />
        <result property="illegalWarningType"    column="illegal_warning_type"    />
        <result property="handleState"    column="handle_state"    />
        <result property="handleTime"    column="handle_time"    />
        <result property="handlerPerson"    column="handler_person"    />
        <result property="notifyState"    column="notify_state"    />
        <result property="notifyDesc"    column="notify_desc"    />
        <result property="alarmType"    column="alarm_type"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="nickName"    column="nick_name"    />
        <result property="userId"    column="user_id"    />
        <result property="canteenName"    column="canteen_name"    />
    </resultMap>

    <sql id="selectKitchenStaffIllegalWarningVo">
        select illegal_warning_id, ksiw.staff_id, device_id, ksiw.img_url, record_desc, record_time,
               illegal_warning_type, handle_state, handle_time, handler_person, notify_state,
               notify_desc, alarm_type, ksiw.create_by, ksiw.create_time, ksiw.update_by, ksiw.update_time,
               su.nick_name, su.user_id, bc.canteen_name
        from kitchen_staff_illegal_warning ksiw
            left join kitchen_staff_info ksi on ksiw.staff_id = ksi.staff_id
            left join sys_user su on su.user_id = ksi.user_id
            left join basic_canteen bc on bc.canteen_id = ksi.canteen_id
    </sql>

    <select id="selectKitchenStaffIllegalWarningList" parameterType="com.bonus.canteen.core.kitchen.domain.KitchenStaffIllegalWarning" resultMap="KitchenStaffIllegalWarningResult">
        <include refid="selectKitchenStaffIllegalWarningVo"/>
        <where>  
            <if test="staffId != null "> and ksiw.staff_id = #{staffId}</if>
            <if test="deviceId != null "> and device_id = #{deviceId}</if>
            <if test="imgUrl != null  and imgUrl != ''"> and ksiw.img_url = #{imgUrl}</if>
            <if test="recordDesc != null  and recordDesc != ''"> and record_desc like CONCAT('%',#{recordDesc},'%')</if>
            <if test="recordTime != null "> and record_time = #{recordTime}</if>
            <if test="illegalWarningType != null "> and illegal_warning_type = #{illegalWarningType}</if>
            <if test="handleState != null "> and handle_state = #{handleState}</if>
            <if test="handleTime != null "> and handle_time = #{handleTime}</if>
            <if test="handlerPerson != null  and handlerPerson != ''"> and handler_person = #{handlerPerson}</if>
            <if test="notifyState != null "> and notify_state = #{notifyState}</if>
            <if test="notifyDesc != null  and notifyDesc != ''"> and notify_desc = #{notifyDesc}</if>
            <if test="alarmType != null "> and alarm_type = #{alarmType}</if>
            <if test="searchValue != null and searchValue != ''">
                and (su.nick_name like CONCAT('%',#{searchValue},'%')
                or su.phonenumber = #{encryptedSearchValue}
                or su.user_id like CONCAT('%',#{searchValue},'%')
                )
            </if>
            <if test="startDateTime != null">
                and ksiw.record_time  <![CDATA[ >= ]]> #{startDateTime}
            </if>
            <if test="endDateTime != null">
                and ksiw.record_time  <![CDATA[ <= ]]> #{endDateTime}
            </if>
        </where>
    </select>
    
    <select id="selectKitchenStaffIllegalWarningByIllegalWarningId" parameterType="Long" resultMap="KitchenStaffIllegalWarningResult">
        <include refid="selectKitchenStaffIllegalWarningVo"/>
        where illegal_warning_id = #{illegalWarningId}
    </select>
        
    <insert id="insertKitchenStaffIllegalWarning" parameterType="com.bonus.canteen.core.kitchen.domain.KitchenStaffIllegalWarning" useGeneratedKeys="true" keyProperty="illegalWarningId">
        insert into kitchen_staff_illegal_warning
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="staffId != null">staff_id,</if>
            <if test="deviceId != null">device_id,</if>
            <if test="imgUrl != null and imgUrl != ''">img_url,</if>
            <if test="recordDesc != null and recordDesc != ''">record_desc,</if>
            <if test="recordTime != null">record_time,</if>
            <if test="illegalWarningType != null">illegal_warning_type,</if>
            <if test="handleState != null">handle_state,</if>
            <if test="handleTime != null">handle_time,</if>
            <if test="handlerPerson != null">handler_person,</if>
            <if test="notifyState != null">notify_state,</if>
            <if test="notifyDesc != null">notify_desc,</if>
            <if test="alarmType != null">alarm_type,</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="deviceId != null">#{deviceId},</if>
            <if test="imgUrl != null and imgUrl != ''">#{imgUrl},</if>
            <if test="recordDesc != null and recordDesc != ''">#{recordDesc},</if>
            <if test="recordTime != null">#{recordTime},</if>
            <if test="illegalWarningType != null">#{illegalWarningType},</if>
            <if test="handleState != null">#{handleState},</if>
            <if test="handleTime != null">#{handleTime},</if>
            <if test="handlerPerson != null">#{handlerPerson},</if>
            <if test="notifyState != null">#{notifyState},</if>
            <if test="notifyDesc != null">#{notifyDesc},</if>
            <if test="alarmType != null">#{alarmType},</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="updateKitchenStaffIllegalWarning" parameterType="com.bonus.canteen.core.kitchen.domain.KitchenStaffIllegalWarning">
        update kitchen_staff_illegal_warning
        <trim prefix="SET" suffixOverrides=",">
            <if test="staffId != null">staff_id = #{staffId},</if>
            <if test="deviceId != null">device_id = #{deviceId},</if>
            <if test="imgUrl != null and imgUrl != ''">img_url = #{imgUrl},</if>
            <if test="recordDesc != null and recordDesc != ''">record_desc = #{recordDesc},</if>
            <if test="recordTime != null">record_time = #{recordTime},</if>
            <if test="illegalWarningType != null">illegal_warning_type = #{illegalWarningType},</if>
            <if test="handleState != null">handle_state = #{handleState},</if>
            <if test="handleTime != null">handle_time = #{handleTime},</if>
            <if test="handlerPerson != null">handler_person = #{handlerPerson},</if>
            <if test="notifyState != null">notify_state = #{notifyState},</if>
            <if test="notifyDesc != null">notify_desc = #{notifyDesc},</if>
            <if test="alarmType != null">alarm_type = #{alarmType},</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 illegal_warning_id = #{illegalWarningId}
    </update>

    <delete id="deleteKitchenStaffIllegalWarningByIllegalWarningId" parameterType="Long">
        delete from kitchen_staff_illegal_warning where illegal_warning_id = #{illegalWarningId}
    </delete>

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