<?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.KitchenSampleCabinetRecordMapper">
    <resultMap type="com.bonus.canteen.core.kitchen.domain.KitchenSampleCabinetRecord" id="KitchenSampleCabinetRecordResult">
        <result property="recordId"    column="record_id"    />
        <result property="deviceId"    column="device_id"    />
        <result property="openCabinetTemp"    column="open_cabinet_temp"    />
        <result property="closeCabinetTemp"    column="close_cabinet_temp"    />
        <result property="staffId"    column="staff_id"    />
        <result property="openCabinetTime"    column="open_cabinet_time"    />
        <result property="closeCabinetTime"    column="close_cabinet_time"    />
        <result property="operateType"    column="operate_type"    />
        <result property="actionType"    column="action_type"    />
        <result property="operatePhoto"    column="operate_photo"    />
        <result property="operateDate"    column="operate_date"    />
        <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="deviceName"    column="device_name"    />
        <result property="canteenName"    column="canteen_name"    />
        <result property="nickName"    column="nick_name"    />
    </resultMap>

    <sql id="selectKitchenSampleCabinetRecordVo">
        select record_id, kscr.device_id, open_cabinet_temp, close_cabinet_temp, kscr.staff_id,
               open_cabinet_time, close_cabinet_time, operate_type, action_type,
               operate_photo, operate_date, kscr.create_by, kscr.create_time, kscr.update_by, kscr.update_time,
               kdi.device_name, bc.canteen_name, su.nick_name
        from kitchen_sample_cabinet_record kscr
        left join kitchen_device_info kdi on kdi.device_id = kscr.device_id
        left join basic_canteen bc on bc.canteen_id = kdi.canteen_id
        left join kitchen_staff_info ksi on ksi.staff_id = kscr.staff_id
        left join sys_user su on su.user_id = ksi.user_id
    </sql>

    <select id="selectKitchenSampleCabinetRecordList" parameterType="com.bonus.canteen.core.kitchen.domain.KitchenSampleCabinetRecord" resultMap="KitchenSampleCabinetRecordResult">
        <include refid="selectKitchenSampleCabinetRecordVo"/>
        <where>  
            <if test="deviceId != null "> and kscr.device_id = #{deviceId}</if>
            <if test="openCabinetTemp != null "> and open_cabinet_temp = #{openCabinetTemp}</if>
            <if test="closeCabinetTemp != null "> and close_cabinet_temp = #{closeCabinetTemp}</if>
            <if test="staffId != null "> and kscr.staff_id = #{staffId}</if>
            <if test="openCabinetTime != null "> and open_cabinet_time = #{openCabinetTime}</if>
            <if test="closeCabinetTime != null "> and close_cabinet_time = #{closeCabinetTime}</if>
            <if test="operateType != null "> and operate_type = #{operateType}</if>
            <if test="actionType != null "> and action_type = #{actionType}</if>
            <if test="operatePhoto != null  and operatePhoto != ''"> and operate_photo = #{operatePhoto}</if>
            <if test="operateDate != null "> and operate_date = #{operateDate}</if>
            <if test="searchValue != null and searchValue != ''">
                and (kscr.device_id like CONCAT('%',#{searchValue},'%')
                or kdi.device_name like CONCAT('%',#{searchValue},'%')
                )
            </if>
            <if test="staffName != null and staffName != ''">
                and (su.nick_name like CONCAT('%',#{staffName},'%')
                )
            </if>
            <if test="startDateTime != null">
                and kscr.operate_date  <![CDATA[ >= ]]> #{startDateTime}
            </if>
            <if test="endDateTime != null">
                and kscr.operate_date  <![CDATA[ <= ]]> #{endDateTime}
            </if>
        </where>
    </select>
    
    <select id="selectKitchenSampleCabinetRecordByRecordId" parameterType="Long" resultMap="KitchenSampleCabinetRecordResult">
        <include refid="selectKitchenSampleCabinetRecordVo"/>
        where record_id = #{recordId}
    </select>
        
    <insert id="insertKitchenSampleCabinetRecord" parameterType="com.bonus.canteen.core.kitchen.domain.KitchenSampleCabinetRecord" useGeneratedKeys="true" keyProperty="recordId">
        insert into kitchen_sample_cabinet_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="deviceId != null">device_id,</if>
            <if test="openCabinetTemp != null">open_cabinet_temp,</if>
            <if test="closeCabinetTemp != null">close_cabinet_temp,</if>
            <if test="staffId != null">staff_id,</if>
            <if test="openCabinetTime != null">open_cabinet_time,</if>
            <if test="closeCabinetTime != null">close_cabinet_time,</if>
            <if test="operateType != null">operate_type,</if>
            <if test="actionType != null">action_type,</if>
            <if test="operatePhoto != null">operate_photo,</if>
            <if test="operateDate != null">operate_date,</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="openCabinetTemp != null">#{openCabinetTemp},</if>
            <if test="closeCabinetTemp != null">#{closeCabinetTemp},</if>
            <if test="staffId != null">#{staffId},</if>
            <if test="openCabinetTime != null">#{openCabinetTime},</if>
            <if test="closeCabinetTime != null">#{closeCabinetTime},</if>
            <if test="operateType != null">#{operateType},</if>
            <if test="actionType != null">#{actionType},</if>
            <if test="operatePhoto != null">#{operatePhoto},</if>
            <if test="operateDate != null">#{operateDate},</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="updateKitchenSampleCabinetRecord" parameterType="com.bonus.canteen.core.kitchen.domain.KitchenSampleCabinetRecord">
        update kitchen_sample_cabinet_record
        <trim prefix="SET" suffixOverrides=",">
            <if test="deviceId != null">device_id = #{deviceId},</if>
            <if test="openCabinetTemp != null">open_cabinet_temp = #{openCabinetTemp},</if>
            <if test="closeCabinetTemp != null">close_cabinet_temp = #{closeCabinetTemp},</if>
            <if test="staffId != null">staff_id = #{staffId},</if>
            <if test="openCabinetTime != null">open_cabinet_time = #{openCabinetTime},</if>
            <if test="closeCabinetTime != null">close_cabinet_time = #{closeCabinetTime},</if>
            <if test="operateType != null">operate_type = #{operateType},</if>
            <if test="actionType != null">action_type = #{actionType},</if>
            <if test="operatePhoto != null">operate_photo = #{operatePhoto},</if>
            <if test="operateDate != null">operate_date = #{operateDate},</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 record_id = #{recordId}
    </update>

    <delete id="deleteKitchenSampleCabinetRecordByRecordId" parameterType="Long">
        delete from kitchen_sample_cabinet_record where record_id = #{recordId}
    </delete>

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