<?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.ygtx.gxt.mapper.GxtFaultCodesMapper">
    
    <resultMap type="GxtFaultCodes" id="GxtFaultCodesResult">
        <result property="id"    column="id"    />
        <result property="faultCode"    column="fault_code"    />
        <result property="faultDescription"    column="fault_description"    />
        <result property="isActive"    column="is_active"    />
        <result property="faultBarcode"    column="fault_barcode"    />
        <result property="station"    column="station"    />
        <result property="model"    column="model"    />
        <result property="stationId"    column="station_id"    />
        <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="remark"    column="remark"    />
    </resultMap>

    <sql id="selectGxtFaultCodesVo">
        select id, fault_code, fault_description, is_active, fault_barcode, station, model, station_id, create_by, create_time, update_by, update_time, remark from gxt_fault_codes
    </sql>

    <select id="selectGxtFaultCodesList" parameterType="GxtFaultCodes" resultMap="GxtFaultCodesResult">
        <include refid="selectGxtFaultCodesVo"/>
        <where>  
            <if test="faultCode != null  and faultCode != ''"> and fault_code = #{faultCode}</if>
            <if test="faultDescription != null  and faultDescription != ''"> and fault_description = #{faultDescription}</if>
            <if test="isActive != null "> and is_active = #{isActive}</if>
            <if test="station != null  and station != ''"> and station = #{station}</if>
            <if test="model != null  and model != ''"> and model = #{model}</if>
            <if test="stationId != null  and stationId != ''"> and station_id = #{stationId}</if>
        </where>
    </select>
    
    <select id="selectGxtFaultCodesById" parameterType="Long" resultMap="GxtFaultCodesResult">
        <include refid="selectGxtFaultCodesVo"/>
        where id = #{id}
    </select>
    
    <select id="selectGxtFaultCodesByFaultCode" parameterType="String" resultMap="GxtFaultCodesResult">
        <include refid="selectGxtFaultCodesVo"/>
        where fault_code = #{faultCode}
    </select>

    <select id="selectGxtFaultCodesByStationModelBarcode" parameterType="GxtFaultCodes" resultMap="GxtFaultCodesResult">
        <include refid="selectGxtFaultCodesVo"/>
        where station = #{station} and model = #{model} and fault_barcode = #{faultBarcode}
    </select>
    
    <select id="selectGxtFaultCodesByStationModelFaultCode" parameterType="GxtFaultCodes" resultMap="GxtFaultCodesResult">
        <include refid="selectGxtFaultCodesVo"/>
        where station = #{station} and model = #{model} and fault_code = #{faultCode}
    </select>

    <insert id="insertGxtFaultCodes" parameterType="GxtFaultCodes" useGeneratedKeys="true" keyProperty="id">
        insert into gxt_fault_codes
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="faultCode != null and faultCode != ''">fault_code,</if>
            <if test="faultDescription != null and faultDescription != ''">fault_description,</if>
            <if test="isActive != null">is_active,</if>
            <if test="faultBarcode != null">fault_barcode,</if>
            <if test="station != null and station != ''">station,</if>
            <if test="model != null and model != ''">model,</if>
            <if test="stationId != null">station_id,</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>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="faultCode != null and faultCode != ''">#{faultCode},</if>
            <if test="faultDescription != null and faultDescription != ''">#{faultDescription},</if>
            <if test="isActive != null">#{isActive},</if>
            <if test="faultBarcode != null">#{faultBarcode},</if>
            <if test="station != null and station != ''">#{station},</if>
            <if test="model != null and model != ''">#{model},</if>
            <if test="stationId != null">#{stationId},</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>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateGxtFaultCodes" parameterType="GxtFaultCodes">
        update gxt_fault_codes
        <trim prefix="SET" suffixOverrides=",">
            <if test="faultCode != null">fault_code = #{faultCode},</if>
            <if test="faultDescription != null">fault_description = #{faultDescription},</if>
            <if test="isActive != null">is_active = #{isActive},</if>
            <if test="faultBarcode != null">fault_barcode = #{faultBarcode},</if>
            <if test="station != null and station != ''">station = #{station},</if>
            <if test="model != null and model != ''">model = #{model},</if>
            <if test="stationId != null">station_id = #{stationId},</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>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteGxtFaultCodesById" parameterType="Long">
        delete from gxt_fault_codes where id = #{id}
    </delete>

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