<?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.muyu.platform.mapper.WarnLogsMapper">
    
    <resultMap type="WarnLogs" id="WarnLogsResult">
        <result property="id"    column="id"    />
        <result property="vin"    column="vin"    />
        <result property="warnRuleId"    column="warn_rule_id"    />
        <result property="startTime"    column="start_time"    />
        <result property="endTime"    column="end_time"    />
        <result property="maxValue"    column="max_value"    />
        <result property="minValue"    column="min_value"    />
        <result property="avgValue"    column="avg_value"    />
        <result property="medianValue"    column="median_value"    />
        <result property="status"    column="status"    />
    </resultMap>

    <sql id="selectWarnLogsVo">
        select id, vin, warn_rule_id, start_time, end_time, max_value, min_value, avg_value, median_value, status from warn_logs
    </sql>

    <select id="selectWarnLogsList" parameterType="WarnLogs" resultMap="WarnLogsResult">
        <include refid="selectWarnLogsVo"/>
        <where>  
            <if test="vin != null  and vin != ''"> and vin = #{vin}</if>
            <if test="warnRuleId != null "> and warn_rule_id = #{warnRuleId}</if>
            <if test="startTime != null "> and start_time = #{startTime}</if>
            <if test="endTime != null "> and end_time = #{endTime}</if>
            <if test="maxValue != null "> and max_value = #{maxValue}</if>
            <if test="minValue != null "> and min_value = #{minValue}</if>
            <if test="avgValue != null "> and avg_value = #{avgValue}</if>
            <if test="medianValue != null "> and median_value = #{medianValue}</if>
            <if test="status != null "> and status = #{status}</if>
        </where>
    </select>
    
    <select id="selectWarnLogsById" parameterType="Long" resultMap="WarnLogsResult">
        <include refid="selectWarnLogsVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertWarnLogs" parameterType="WarnLogs" useGeneratedKeys="true" keyProperty="id">
        insert into warn_logs
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="vin != null">vin,</if>
            <if test="warnRuleId != null">warn_rule_id,</if>
            <if test="startTime != null">start_time,</if>
            <if test="endTime != null">end_time,</if>
            <if test="maxValue != null">max_value,</if>
            <if test="minValue != null">min_value,</if>
            <if test="avgValue != null">avg_value,</if>
            <if test="medianValue != null">median_value,</if>
            <if test="status != null">status,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="vin != null">#{vin},</if>
            <if test="warnRuleId != null">#{warnRuleId},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="maxValue != null">#{maxValue},</if>
            <if test="minValue != null">#{minValue},</if>
            <if test="avgValue != null">#{avgValue},</if>
            <if test="medianValue != null">#{medianValue},</if>
            <if test="status != null">#{status},</if>
         </trim>
    </insert>

    <update id="updateWarnLogs" parameterType="WarnLogs">
        update warn_logs
        <trim prefix="SET" suffixOverrides=",">
            <if test="vin != null">vin = #{vin},</if>
            <if test="warnRuleId != null">warn_rule_id = #{warnRuleId},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
            <if test="maxValue != null">max_value = #{maxValue},</if>
            <if test="minValue != null">min_value = #{minValue},</if>
            <if test="avgValue != null">avg_value = #{avgValue},</if>
            <if test="medianValue != null">median_value = #{medianValue},</if>
            <if test="status != null">status = #{status},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteWarnLogsById" parameterType="Long">
        delete from warn_logs where id = #{id}
    </delete>

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