<?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.agri.system.mapper.SysAutoTermMapper">
    
    <resultMap type="SysAutoTerm" id="SysAutoTermResult">
        <result property="id"    column="id"    />
        <result property="imei"    column="imei"    />
        <result property="roller"    column="roller"    />
        <result property="startTime"    column="start_time"    />
        <result property="endTime"    column="end_time"    />
        <result property="temp"    column="temp"    />
        <result property="vent"    column="vent"    />
        <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="selectSysAutoTermVo">
        select id, imei, roller, start_time, end_time, temp, vent, create_by, create_time, update_by, update_time from sys_auto_term
    </sql>

    <select id="selectSysAutoTermList" parameterType="SysAutoTerm" resultMap="SysAutoTermResult">
        <include refid="selectSysAutoTermVo"/>
        <where>  
            <if test="imei != null  and imei != ''"> and imei like concat('%', #{imei}, '%')</if>
            <if test="roller != null  and roller != ''"> and roller = #{roller}</if>
            <if test="startTime != null "> and start_time &gt;= #{startTime}</if>
            <if test="endTime != null "> and end_time &lt;= #{endTime}</if>
        </where>
    </select>
    
    <select id="selectSysAutoTermById" parameterType="String" resultMap="SysAutoTermResult">
        <include refid="selectSysAutoTermVo"/>
        where id = #{id}
    </select>

    <insert id="insertSysAutoTerm" parameterType="SysAutoTerm" useGeneratedKeys="true" keyProperty="id">
        insert into sys_auto_term
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="imei != null and imei != ''">imei,</if>
            <if test="roller != null and roller != ''">roller,</if>
            <if test="startTime != null">start_time,</if>
            <if test="endTime != null">end_time,</if>
            <if test="temp != null">temp,</if>
            <if test="vent != null">vent,</if>
    create_by,
    create_time,
    update_by,
    update_time,
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="imei != null and imei != ''">#{imei},</if>
            <if test="roller != null and roller != ''">#{roller},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="temp != null">#{temp},</if>
            <if test="vent != null">#{vent},</if>
        #{createBy},
        #{createTime},
        #{updateBy},
        #{updateTime},
         </trim>
    </insert>

    <update id="updateSysAutoTerm" parameterType="SysAutoTerm">
        update sys_auto_term
        <trim prefix="SET" suffixOverrides=",">
            <if test="imei != null and imei != ''">imei = #{imei},</if>
            <if test="roller != null and roller != ''">roller = #{roller},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
            <if test="temp != null">temp = #{temp},</if>
            <if test="vent != null">vent = #{vent},</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="deleteSysAutoTermById" parameterType="String">
        delete from sys_auto_term where id = #{id}
    </delete>

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