<?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.KitchenSampleDishesRecordMapper">
    <resultMap type="com.bonus.canteen.core.kitchen.domain.KitchenSampleDishesRecord" id="KitchenSampleDishesRecordResult">
        <result property="recordId"    column="record_id"    />
        <result property="mealtimeType"    column="mealtime_type"    />
        <result property="deviceId"    column="device_id"    />
        <result property="stallId"    column="stall_id"    />
        <result property="canteenId"    column="canteen_id"    />
        <result property="dishesId"    column="dishes_id"    />
        <result property="imageUrl"    column="image_url"    />
        <result property="machineNo"    column="machine_no"    />
        <result property="machineSn"    column="machine_sn"    />
        <result property="sampleWeight"    column="sample_weight"    />
        <result property="sampleSaveTime"    column="sample_save_time"    />
        <result property="chefId"    column="chef_id"    />
        <result property="sampleSaveStaffId"    column="sample_save_staff_id"    />
        <result property="sampleTakeStaffId"    column="sample_take_staff_id"    />
        <result property="printRecordTime"    column="print_record_time"    />
        <result property="enterCabinetTime"    column="enter_cabinet_time"    />
        <result property="leaveCabinetTime"    column="leave_cabinet_time"    />
        <result property="expirationTime"    column="expiration_time"    />
        <result property="weightStandard"    column="weight_standard"    />
        <result property="validDuration"    column="valid_duration"    />
        <result property="durationStandard"    column="duration_standard"    />
        <result property="status"    column="status"    />
        <result property="cabinetNo"    column="cabinet_no"    />
        <result property="saveStatus"    column="save_status"    />
        <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="canteenName"    column="canteen_name"    />
        <result property="stallName"    column="stall_name"    />
        <result property="dishesName"    column="dishes_name"    />
        <result property="deviceName"    column="device_name"    />
        <result property="userName"    column="user_name"    />
    </resultMap>

    <sql id="selectKitchenSampleDishesRecordVo">
        select record_id, mealtime_type, ksdr.device_id, ksdr.stall_id, ksdr.canteen_id, ksdr.dishes_id,
               ksdr.image_url, machine_no, machine_sn, sample_weight, sample_save_time,
               chef_id, sample_save_staff_id, sample_take_staff_id, print_record_time,
               enter_cabinet_time, leave_cabinet_time, expiration_time, weight_standard,
               valid_duration, duration_standard, ksdr.status, cabinet_no, save_status,
               ksdr.create_by, ksdr.create_time, ksdr.update_by, ksdr.update_time,
               bc.canteen_name, bs.stall_name, bd.dishes_name, kdi.device_name, su.user_name
        from kitchen_sample_dishes_record ksdr
             left join basic_canteen bc on bc.canteen_id = ksdr.canteen_id
             left join basic_stall bs on bs.stall_id = ksdr.stall_id
             left join cook_dishes bd on bd.dishes_id = ksdr.dishes_id
             left join kitchen_device_info kdi on kdi.device_id = ksdr.device_id
             left join sys_user su on su.user_id = ksdr.sample_save_staff_id
    </sql>

    <select id="selectKitchenSampleDishesRecordList" parameterType="com.bonus.canteen.core.kitchen.domain.KitchenSampleDishesRecord" resultMap="KitchenSampleDishesRecordResult">
        <include refid="selectKitchenSampleDishesRecordVo"/>
        <where>  
            <if test="mealtimeType != null "> and mealtime_type = #{mealtimeType}</if>
            <if test="deviceId != null "> and ksdr.device_id = #{deviceId}</if>
            <if test="stallId != null "> and ksdr.stall_id = #{stallId}</if>
            <if test="canteenId != null "> and ksdr.canteen_id = #{canteenId}</if>
            <if test="dishesId != null "> and ksdr.dishes_id = #{dishesId}</if>
            <if test="imageUrl != null  and imageUrl != ''"> and ksdr.image_url = #{imageUrl}</if>
            <if test="machineNo != null  and machineNo != ''"> and machine_no = #{machineNo}</if>
            <if test="machineSn != null  and machineSn != ''"> and machine_sn = #{machineSn}</if>
            <if test="sampleWeight != null "> and sample_weight = #{sampleWeight}</if>
            <if test="sampleSaveTime != null "> and sample_save_time = #{sampleSaveTime}</if>
            <if test="chefId != null "> and chef_id = #{chefId}</if>
            <if test="sampleSaveStaffId != null  and sampleSaveStaffId != ''"> and sample_save_staff_id = #{sampleSaveStaffId}</if>
            <if test="sampleTakeStaffId != null "> and sample_take_staff_id = #{sampleTakeStaffId}</if>
            <if test="printRecordTime != null "> and print_record_time = #{printRecordTime}</if>
            <if test="enterCabinetTime != null "> and enter_cabinet_time = #{enterCabinetTime}</if>
            <if test="leaveCabinetTime != null "> and leave_cabinet_time = #{leaveCabinetTime}</if>
            <if test="expirationTime != null "> and expiration_time = #{expirationTime}</if>
            <if test="weightStandard != null "> and weight_standard = #{weightStandard}</if>
            <if test="validDuration != null "> and valid_duration = #{validDuration}</if>
            <if test="durationStandard != null "> and duration_standard = #{durationStandard}</if>
            <if test="status != null "> and ksdr.status = #{status}</if>
            <if test="cabinetNo != null "> and cabinet_no = #{cabinetNo}</if>
            <if test="saveStatus != null "> and save_status = #{saveStatus}</if>
            <if test="searchValue != null and searchValue != ''">
                and (ksdr.dishes_id like CONCAT('%',#{searchValue},'%')
                or bd.dishes_name like CONCAT('%',#{searchValue},'%')
                )
            </if>
            <if test="startDateTime != null">
                and ksdr.sample_save_time  <![CDATA[ >= ]]> #{startDateTime}
            </if>
            <if test="endDateTime != null">
                and ksdr.sample_save_time  <![CDATA[ <= ]]> #{endDateTime}
            </if>
        </where>
    </select>
    
    <select id="selectKitchenSampleDishesRecordByRecordId" parameterType="Long" resultMap="KitchenSampleDishesRecordResult">
        <include refid="selectKitchenSampleDishesRecordVo"/>
        where record_id = #{recordId}
    </select>
        
    <insert id="insertKitchenSampleDishesRecord" parameterType="com.bonus.canteen.core.kitchen.domain.KitchenSampleDishesRecord">
        insert into kitchen_sample_dishes_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="recordId != null">record_id,</if>
            <if test="mealtimeType != null">mealtime_type,</if>
            <if test="deviceId != null">device_id,</if>
            <if test="stallId != null">stall_id,</if>
            <if test="canteenId != null">canteen_id,</if>
            <if test="dishesId != null">dishes_id,</if>
            <if test="imageUrl != null and imageUrl != ''">image_url,</if>
            <if test="machineNo != null">machine_no,</if>
            <if test="machineSn != null">machine_sn,</if>
            <if test="sampleWeight != null">sample_weight,</if>
            <if test="sampleSaveTime != null">sample_save_time,</if>
            <if test="chefId != null">chef_id,</if>
            <if test="sampleSaveStaffId != null">sample_save_staff_id,</if>
            <if test="sampleTakeStaffId != null">sample_take_staff_id,</if>
            <if test="printRecordTime != null">print_record_time,</if>
            <if test="enterCabinetTime != null">enter_cabinet_time,</if>
            <if test="leaveCabinetTime != null">leave_cabinet_time,</if>
            <if test="expirationTime != null">expiration_time,</if>
            <if test="weightStandard != null">weight_standard,</if>
            <if test="validDuration != null">valid_duration,</if>
            <if test="durationStandard != null">duration_standard,</if>
            <if test="status != null">status,</if>
            <if test="cabinetNo != null">cabinet_no,</if>
            <if test="saveStatus != null">save_status,</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="recordId != null">#{recordId},</if>
            <if test="mealtimeType != null">#{mealtimeType},</if>
            <if test="deviceId != null">#{deviceId},</if>
            <if test="stallId != null">#{stallId},</if>
            <if test="canteenId != null">#{canteenId},</if>
            <if test="dishesId != null">#{dishesId},</if>
            <if test="imageUrl != null and imageUrl != ''">#{imageUrl},</if>
            <if test="machineNo != null">#{machineNo},</if>
            <if test="machineSn != null">#{machineSn},</if>
            <if test="sampleWeight != null">#{sampleWeight},</if>
            <if test="sampleSaveTime != null">#{sampleSaveTime},</if>
            <if test="chefId != null">#{chefId},</if>
            <if test="sampleSaveStaffId != null">#{sampleSaveStaffId},</if>
            <if test="sampleTakeStaffId != null">#{sampleTakeStaffId},</if>
            <if test="printRecordTime != null">#{printRecordTime},</if>
            <if test="enterCabinetTime != null">#{enterCabinetTime},</if>
            <if test="leaveCabinetTime != null">#{leaveCabinetTime},</if>
            <if test="expirationTime != null">#{expirationTime},</if>
            <if test="weightStandard != null">#{weightStandard},</if>
            <if test="validDuration != null">#{validDuration},</if>
            <if test="durationStandard != null">#{durationStandard},</if>
            <if test="status != null">#{status},</if>
            <if test="cabinetNo != null">#{cabinetNo},</if>
            <if test="saveStatus != null">#{saveStatus},</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="updateKitchenSampleDishesRecord" parameterType="com.bonus.canteen.core.kitchen.domain.KitchenSampleDishesRecord">
        update kitchen_sample_dishes_record
        <trim prefix="SET" suffixOverrides=",">
            <if test="mealtimeType != null">mealtime_type = #{mealtimeType},</if>
            <if test="deviceId != null">device_id = #{deviceId},</if>
            <if test="stallId != null">stall_id = #{stallId},</if>
            <if test="canteenId != null">canteen_id = #{canteenId},</if>
            <if test="dishesId != null">dishes_id = #{dishesId},</if>
            <if test="imageUrl != null and imageUrl != ''">image_url = #{imageUrl},</if>
            <if test="machineNo != null">machine_no = #{machineNo},</if>
            <if test="machineSn != null">machine_sn = #{machineSn},</if>
            <if test="sampleWeight != null">sample_weight = #{sampleWeight},</if>
            <if test="sampleSaveTime != null">sample_save_time = #{sampleSaveTime},</if>
            <if test="chefId != null">chef_id = #{chefId},</if>
            <if test="sampleSaveStaffId != null">sample_save_staff_id = #{sampleSaveStaffId},</if>
            <if test="sampleTakeStaffId != null">sample_take_staff_id = #{sampleTakeStaffId},</if>
            <if test="printRecordTime != null">print_record_time = #{printRecordTime},</if>
            <if test="enterCabinetTime != null">enter_cabinet_time = #{enterCabinetTime},</if>
            <if test="leaveCabinetTime != null">leave_cabinet_time = #{leaveCabinetTime},</if>
            <if test="expirationTime != null">expiration_time = #{expirationTime},</if>
            <if test="weightStandard != null">weight_standard = #{weightStandard},</if>
            <if test="validDuration != null">valid_duration = #{validDuration},</if>
            <if test="durationStandard != null">duration_standard = #{durationStandard},</if>
            <if test="status != null">status = #{status},</if>
            <if test="cabinetNo != null">cabinet_no = #{cabinetNo},</if>
            <if test="saveStatus != null">save_status = #{saveStatus},</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="deleteKitchenSampleDishesRecordByRecordId" parameterType="Long">
        delete from kitchen_sample_dishes_record where record_id = #{recordId}
    </delete>

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