<?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.breakdown.mapper.SysCarFaultMapper">

    <resultMap type="com.muyu.breakdown.domain.SysCarFault" id="SysCarFaultResult">
        <result property="id"    column="id"    />
        <result property="faultCode"    column="fault_code"    />
        <result property="faultName"    column="fault_name"    />
        <result property="typeId"    column="type_id"    />
        <result property="carVin"    column="car_vin"    />
        <result property="faultLabel"    column="fault_label"    />
        <result property="faultGroup"    column="fault_group"    />
        <result property="faultBit"    column="fault_bit"    />
        <result property="faultValue"    column="fault_value"    />
        <result property="faultRank"    column="fault_rank"    />
        <result property="faultDesc"    column="fault_desc"    />
        <result property="faultMinThreshold"    column="fault_min_threshold"    />
        <result property="faultMaxThreshold"    column="fault_max_threshold"    />
        <result property="status"    column="status"    />
        <result property="warnStatus"    column="warn_status"    />
        <result property="remark"    column="remark"    />
        <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="selectSysCarFaultVo">
        select id, fault_code, fault_name, type_id, car_vin, fault_label, fault_group, fault_bit, fault_value, fault_rank, fault_desc, fault_min_threshold, fault_max_threshold, status, warn_status, remark, create_by, create_time, update_by, update_time from sys_car_fault
    </sql>

    <select id="selectSysCarFaultList" parameterType="com.muyu.breakdown.domain.SysCarFault" resultMap="SysCarFaultResult">
        <include refid="selectSysCarFaultVo"/>
        <where>
            <if test="faultCode != null  and faultCode != ''"> and fault_code = #{faultCode}</if>
            <if test="faultBit != null  and faultBit != ''"> and fault_bit = #{faultBit}</if>
            <if test="faultRank != null "> and fault_rank = #{faultRank}</if>
        </where>
    </select>

    <select id="selectSysCarFaultById" parameterType="Long" resultMap="SysCarFaultResult">
        <include refid="selectSysCarFaultVo"/>
        where id = #{id}
    </select>

    <insert id="insertSysCarFault" parameterType="com.muyu.breakdown.domain.SysCarFault" useGeneratedKeys="true" keyProperty="id">
        insert into sys_car_fault
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="faultCode != null and faultCode != ''">fault_code,</if>
            <if test="faultName != null">fault_name,</if>
            <if test="typeId != null">type_id,</if>
            <if test="carVin != null">car_vin,</if>
            <if test="faultLabel != null">fault_label,</if>
            <if test="faultGroup != null">fault_group,</if>
            <if test="faultBit != null">fault_bit,</if>
            <if test="faultValue != null">fault_value,</if>
            <if test="faultRank != null">fault_rank,</if>
            <if test="faultDesc != null">fault_desc,</if>
            <if test="faultMinThreshold != null">fault_min_threshold,</if>
            <if test="faultMaxThreshold != null">fault_max_threshold,</if>
            <if test="status != null">status,</if>
            <if test="warnStatus != null">warn_status,</if>
            <if test="remark != null">remark,</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="faultCode != null and faultCode != ''">#{faultCode},</if>
            <if test="faultName != null">#{faultName},</if>
            <if test="typeId != null">#{typeId},</if>
            <if test="carVin != null">#{carVin},</if>
            <if test="faultLabel != null">#{faultLabel},</if>
            <if test="faultGroup != null">#{faultGroup},</if>
            <if test="faultBit != null">#{faultBit},</if>
            <if test="faultValue != null">#{faultValue},</if>
            <if test="faultRank != null">#{faultRank},</if>
            <if test="faultDesc != null">#{faultDesc},</if>
            <if test="faultMinThreshold != null">#{faultMinThreshold},</if>
            <if test="faultMaxThreshold != null">#{faultMaxThreshold},</if>
            <if test="status != null">#{status},</if>
            <if test="warnStatus != null">#{warnStatus},</if>
            <if test="remark != null">#{remark},</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="updateSysCarFault" parameterType="com.muyu.breakdown.domain.SysCarFault">
        update sys_car_fault
        <trim prefix="SET" suffixOverrides=",">
            <if test="faultCode != null and faultCode != ''">fault_code = #{faultCode},</if>
            <if test="faultName != null">fault_name = #{faultName},</if>
            <if test="typeId != null">type_id = #{typeId},</if>
            <if test="carVin != null">car_vin = #{carVin},</if>
            <if test="faultLabel != null">fault_label = #{faultLabel},</if>
            <if test="faultGroup != null">fault_group = #{faultGroup},</if>
            <if test="faultBit != null">fault_bit = #{faultBit},</if>
            <if test="faultValue != null">fault_value = #{faultValue},</if>
            <if test="faultRank != null">fault_rank = #{faultRank},</if>
            <if test="faultDesc != null">fault_desc = #{faultDesc},</if>
            <if test="faultMinThreshold != null">fault_min_threshold = #{faultMinThreshold},</if>
            <if test="faultMaxThreshold != null">fault_max_threshold = #{faultMaxThreshold},</if>
            <if test="status != null">status = #{status},</if>
            <if test="warnStatus != null">warn_status = #{warnStatus},</if>
            <if test="remark != null">remark = #{remark},</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="deleteSysCarFaultById" parameterType="Long">
        delete from sys_car_fault where id = #{id}
    </delete>

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