<?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.jsowell.pile.mapper.MemberPlateNumberRelationMapper">

    <resultMap type="com.jsowell.pile.domain.MemberPlateNumberRelation" id="MemberLicensePlateNumberRelationResult">
        <result property="id"    column="id"    />
        <result property="memberId"    column="member_id"    />
        <result property="phoneNumber"    column="phone_number"    />
        <result property="licensePlateNumber"    column="license_plate_number"    />
        <result property="vinCode"    column="vin_code"    />
        <result property="vinStatus"    column="vin_status"    />
        <result property="createTime"    column="create_time"    />
        <result property="delFlag"    column="del_flag"    />
    </resultMap>

    <sql id="selectMemberLicensePlateNumberRelationVo">
        select id, member_id, phone_number, license_plate_number, vin_code, vin_status, create_time from member_plate_number_relation where del_flag = '0'
    </sql>

    <sql id="Base_Column_List">
        <!--@mbg.generated PileBillingTemplate-->
        id, member_id, phone_number, license_plate_number, vin_code, vin_status, create_time, del_flag
    </sql>

    <select id="selectMemberPlateNumberRelationList" parameterType="com.jsowell.pile.domain.MemberPlateNumberRelation" resultMap="MemberLicensePlateNumberRelationResult">
        select
            <include refid="Base_Column_List"/>
        from
            member_plate_number_relation
        where del_flag = '0'
        <if test="memberId != null  and memberId != ''"> and member_id = #{memberId}</if>
        <if test="phoneNumber != null  and phoneNumber != ''"> and phone_number = #{phoneNumber}</if>
        <if test="licensePlateNumber != null  and licensePlateNumber != ''"> and license_plate_number = #{licensePlateNumber}</if>
    </select>

    <select id="selectMemberPlateNumberRelationById" parameterType="Integer" resultMap="MemberLicensePlateNumberRelationResult">
        <include refid="selectMemberLicensePlateNumberRelationVo"/>
        where id = #{id}
    </select>

    <insert id="insertMemberPlateNumberRelation" parameterType="com.jsowell.pile.domain.MemberPlateNumberRelation" useGeneratedKeys="true" keyProperty="id">
        insert into member_plate_number_relation
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="memberId != null">member_id,</if>
            <if test="phoneNumber != null">phone_number,</if>
            <if test="licensePlateNumber != null">license_plate_number,</if>
            <if test="vinCode != null">vin_code,</if>
            <if test="vinStatus != null">vin_status,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="memberId != null">#{memberId},</if>
            <if test="phoneNumber != null">#{phoneNumber},</if>
            <if test="licensePlateNumber != null">#{licensePlateNumber},</if>
            <if test="vinCode != null">#{vinCode},</if>
            <if test="vinStatus != null">#{vinStatus},</if>
        </trim>
    </insert>

    <update id="updateMemberPlateNumberRelation" parameterType="com.jsowell.pile.domain.MemberPlateNumberRelation">
        update member_plate_number_relation
        <trim prefix="SET" suffixOverrides=",">
            <if test="memberId != null">member_id = #{memberId},</if>
            <if test="phoneNumber != null">phone_number = #{phoneNumber},</if>
            <if test="licensePlateNumber != null">license_plate_number = #{licensePlateNumber},</if>
            <if test="vinCode != null">vin_code = #{vinCode},</if>
            <if test="vinStatus != null">vin_status = #{vinStatus},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteMemberLicensePlateNumberRelationById" parameterType="Integer">
        delete from member_plate_number_relation where id = #{id}
    </delete>

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

    <update id="deleteCarNoByParams" parameterType="com.jsowell.pile.dto.BindingCarNoDTO">
        update member_plate_number_relation
        set del_flag = '1'
        where id in
        <foreach collection="collection" item="id" open="(" separator="," close=")">
            #{id,jdbcType=INTEGER}
        </foreach>
    </update>

    <update id="unbindingPlateNumber" parameterType="com.jsowell.pile.domain.MemberPlateNumberRelation">
        update member_plate_number_relation
        set del_flag = '1'
        where member_id = #{memberId,jdbcType=VARCHAR}
        and license_plate_number = #{plateNumber,jdbcType=VARCHAR}
    </update>

    <update id="updatePlateNumber">
        update member_plate_number_relation set license_plate_number = #{licensePlateNumber,jdbcType=VARCHAR}
        where id = #{id,jdbcType=INTEGER}
    </update>

    <select id="getMemberPlateInfoByVinCode" resultMap="MemberLicensePlateNumberRelationResult">
        select
        <include refid="Base_Column_List"/>
        from member_plate_number_relation
        where
            vin_code = #{vinCode,jdbcType=VARCHAR}
        and del_flag = '0'
    </select>
</mapper>