<?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.jianshui.platform.mapper.VehicleCodeMapper">
    
    <resultMap type="VehicleCode" id="VehicleCodeResult">
        <result property="id"    column="id"    />
        <result property="vehicleCode"    column="vehicle_code"    />
        <result property="vehicleType"    column="vehicle_type"    />
        <result property="brandModel"    column="brand_model"    />
        <result property="origin"    column="origin"    />
        <result property="manufacturerName"    column="manufacturer_name"    />
        <result property="taxCategoryCode"    column="tax_category_code"    />
        <result property="taxCategoryCodeId"    column="tax_category_code_id"    />
        <result property="taxCategoryAbbreviation"    column="tax_category_abbreviation"    />
        <result property="isQualifiedForDiscount"    column="is_qualified_for_discount"    />
        <result property="discountPolicyType"    column="discount_policy_type"    />
        <result property="status"    column="status"    />
        <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="selectVehicleCodeVo">
        select id, vehicle_code, vehicle_type, brand_model, origin, manufacturer_name, tax_category_code, tax_category_code_id, tax_category_abbreviation, is_qualified_for_discount, discount_policy_type, status, create_by, create_time, update_by, update_time, remark from vehicle_code
    </sql>

    <select id="selectVehicleCodeList" parameterType="VehicleCode" resultMap="VehicleCodeResult">
        <include refid="selectVehicleCodeVo"/>
        <where>  
            <if test="vehicleCode != null  and vehicleCode != ''"> and vehicle_code = #{vehicleCode}</if>
            <if test="vehicleType != null  and vehicleType != ''"> and vehicle_type = #{vehicleType}</if>
            <if test="brandModel != null  and brandModel != ''"> and brand_model = #{brandModel}</if>
            <if test="origin != null  and origin != ''"> and origin = #{origin}</if>
            <if test="manufacturerName != null  and manufacturerName != ''"> and manufacturer_name like concat('%', #{manufacturerName}, '%')</if>
            <if test="taxCategoryCode != null  and taxCategoryCode != ''"> and tax_category_code = #{taxCategoryCode}</if>
            <if test="taxCategoryCodeId != null "> and tax_category_code_id = #{taxCategoryCodeId}</if>
            <if test="taxCategoryAbbreviation != null  and taxCategoryAbbreviation != ''"> and tax_category_abbreviation = #{taxCategoryAbbreviation}</if>
            <if test="isQualifiedForDiscount != null  and isQualifiedForDiscount != ''"> and is_qualified_for_discount = #{isQualifiedForDiscount}</if>
            <if test="discountPolicyType != null  and discountPolicyType != ''"> and discount_policy_type = #{discountPolicyType}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
        </where>
    </select>
    
    <select id="selectVehicleCodeById" parameterType="Long" resultMap="VehicleCodeResult">
        <include refid="selectVehicleCodeVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertVehicleCode" parameterType="VehicleCode" useGeneratedKeys="true" keyProperty="id">
        insert into vehicle_code
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="vehicleCode != null and vehicleCode != ''">vehicle_code,</if>
            <if test="vehicleType != null">vehicle_type,</if>
            <if test="brandModel != null">brand_model,</if>
            <if test="origin != null">origin,</if>
            <if test="manufacturerName != null">manufacturer_name,</if>
            <if test="taxCategoryCode != null">tax_category_code,</if>
            <if test="taxCategoryCodeId != null">tax_category_code_id,</if>
            <if test="taxCategoryAbbreviation != null">tax_category_abbreviation,</if>
            <if test="isQualifiedForDiscount != null">is_qualified_for_discount,</if>
            <if test="discountPolicyType != null">discount_policy_type,</if>
            <if test="status != null">status,</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="vehicleCode != null and vehicleCode != ''">#{vehicleCode},</if>
            <if test="vehicleType != null">#{vehicleType},</if>
            <if test="brandModel != null">#{brandModel},</if>
            <if test="origin != null">#{origin},</if>
            <if test="manufacturerName != null">#{manufacturerName},</if>
            <if test="taxCategoryCode != null">#{taxCategoryCode},</if>
            <if test="taxCategoryCodeId != null">#{taxCategoryCodeId},</if>
            <if test="taxCategoryAbbreviation != null">#{taxCategoryAbbreviation},</if>
            <if test="isQualifiedForDiscount != null">#{isQualifiedForDiscount},</if>
            <if test="discountPolicyType != null">#{discountPolicyType},</if>
            <if test="status != null">#{status},</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="updateVehicleCode" parameterType="VehicleCode">
        update vehicle_code
        <trim prefix="SET" suffixOverrides=",">
            <if test="vehicleCode != null and vehicleCode != ''">vehicle_code = #{vehicleCode},</if>
            <if test="vehicleType != null">vehicle_type = #{vehicleType},</if>
            <if test="brandModel != null">brand_model = #{brandModel},</if>
            <if test="origin != null">origin = #{origin},</if>
            <if test="manufacturerName != null">manufacturer_name = #{manufacturerName},</if>
            <if test="taxCategoryCode != null">tax_category_code = #{taxCategoryCode},</if>
            <if test="taxCategoryCodeId != null">tax_category_code_id = #{taxCategoryCodeId},</if>
            <if test="taxCategoryAbbreviation != null">tax_category_abbreviation = #{taxCategoryAbbreviation},</if>
            <if test="isQualifiedForDiscount != null">is_qualified_for_discount = #{isQualifiedForDiscount},</if>
            <if test="discountPolicyType != null">discount_policy_type = #{discountPolicyType},</if>
            <if test="status != null">status = #{status},</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="deleteVehicleCodeById" parameterType="Long">
        delete from vehicle_code where id = #{id}
    </delete>

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