<?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.KitchenDeviceLifeMapper">
    <resultMap type="com.bonus.canteen.core.kitchen.domain.KitchenDeviceLife" id="KitchenDeviceLifeResult">
        <result property="id"    column="id"    />
        <result property="deviceId"    column="device_id"    />
        <result property="installTime"    column="install_time"    />
        <result property="lifeType"    column="life_type"    />
        <result property="lifeRemaining"    column="life_remaining"    />
        <result property="lifeWarning"    column="life_warning"    />
        <result property="lifeEndTime"    column="life_end_time"    />
        <result property="lifeWarningTime"    column="life_warning_time"    />
        <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="selectKitchenDeviceLifeVo">
        select id, device_id, install_time, life_type, life_remaining, life_warning, life_end_time, life_warning_time, create_by, create_time, update_by, update_time from kitchen_device_life
    </sql>

    <select id="selectKitchenDeviceLifeList" parameterType="com.bonus.canteen.core.kitchen.domain.KitchenDeviceLife" resultMap="KitchenDeviceLifeResult">
        <include refid="selectKitchenDeviceLifeVo"/>
        <where>  
            <if test="deviceId != null "> and device_id = #{deviceId}</if>
            <if test="installTime != null "> and install_time = #{installTime}</if>
            <if test="lifeType != null "> and life_type = #{lifeType}</if>
            <if test="lifeRemaining != null "> and life_remaining = #{lifeRemaining}</if>
            <if test="lifeWarning != null "> and life_warning = #{lifeWarning}</if>
            <if test="lifeEndTime != null "> and life_end_time = #{lifeEndTime}</if>
            <if test="lifeWarningTime != null "> and life_warning_time = #{lifeWarningTime}</if>
        </where>
    </select>
    
    <select id="selectKitchenDeviceLifeById" parameterType="Long" resultMap="KitchenDeviceLifeResult">
        <include refid="selectKitchenDeviceLifeVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertKitchenDeviceLife" parameterType="com.bonus.canteen.core.kitchen.domain.KitchenDeviceLife" useGeneratedKeys="true" keyProperty="id">
        insert into kitchen_device_life
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="deviceId != null">device_id,</if>
            <if test="installTime != null">install_time,</if>
            <if test="lifeType != null">life_type,</if>
            <if test="lifeRemaining != null">life_remaining,</if>
            <if test="lifeWarning != null">life_warning,</if>
            <if test="lifeEndTime != null">life_end_time,</if>
            <if test="lifeWarningTime != null">life_warning_time,</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="installTime != null">#{installTime},</if>
            <if test="lifeType != null">#{lifeType},</if>
            <if test="lifeRemaining != null">#{lifeRemaining},</if>
            <if test="lifeWarning != null">#{lifeWarning},</if>
            <if test="lifeEndTime != null">#{lifeEndTime},</if>
            <if test="lifeWarningTime != null">#{lifeWarningTime},</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="updateKitchenDeviceLife" parameterType="com.bonus.canteen.core.kitchen.domain.KitchenDeviceLife">
        update kitchen_device_life
        <trim prefix="SET" suffixOverrides=",">
            <if test="deviceId != null">device_id = #{deviceId},</if>
            <if test="installTime != null">install_time = #{installTime},</if>
            <if test="lifeType != null">life_type = #{lifeType},</if>
            <if test="lifeRemaining != null">life_remaining = #{lifeRemaining},</if>
            <if test="lifeWarning != null">life_warning = #{lifeWarning},</if>
            <if test="lifeEndTime != null">life_end_time = #{lifeEndTime},</if>
            <if test="lifeWarningTime != null">life_warning_time = #{lifeWarningTime},</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="deleteKitchenDeviceLifeById" parameterType="Long">
        delete from kitchen_device_life where id = #{id}
    </delete>

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