<?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.yijia.customer.mapper.CustomerManageMapper">
    
    <resultMap type="CustomerManage" id="CustomerManageResult">
        <result property="id"    column="id"    />
        <result property="memberId"    column="member_id"    />
        <result property="customerName"    column="customer_name"    />
        <result property="commendMan"    column="commend_man"    />
        <result property="memberGrade"    column="member_grade"    />
        <result property="phoneNumber"    column="phone_number"    />
        <result property="carNumber"    column="car_number"    />
        <result property="oils"    column="oils"    />
        <result property="balance"    column="balance"    />
        <result property="integral"    column="integral"    />
        <result property="specialCarType"    column="special_car_type"    />
        <result property="regtime"    column="regtime"    />
        <result property="stationId"    column="station_id"    />
        <result property="stationNam"    column="station_nam"    />
    </resultMap>

    <sql id="selectCustomerManageVo">
        select id, member_id, customer_name, commend_man, member_grade, phone_number, car_number, oils, balance, integral, special_car_type, regtime, station_id, station_nam from customer_manage
    </sql>

    <select id="selectCustomerManageList" parameterType="CustomerManage" resultMap="CustomerManageResult">
        <include refid="selectCustomerManageVo"/>
        <where>  
            <if test="memberId != null  and memberId != ''"> and member_id = #{memberId}</if>
            <if test="customerName != null  and customerName != ''"> and customer_name like concat('%', #{customerName}, '%')</if>
            <if test="commendMan != null  and commendMan != ''"> and commend_man = #{commendMan}</if>
            <if test="memberGrade != null  and memberGrade != ''"> and member_grade = #{memberGrade}</if>
            <if test="phoneNumber != null  and phoneNumber != ''"> and phone_number = #{phoneNumber}</if>
            <if test="carNumber != null  and carNumber != ''"> and car_number = #{carNumber}</if>
            <if test="oils != null  and oils != ''"> and oils = #{oils}</if>
            <if test="balance != null  and balance != ''"> and balance = #{balance}</if>
            <if test="integral != null  and integral != ''"> and integral = #{integral}</if>
            <if test="specialCarType != null  and specialCarType != ''"> and special_car_type = #{specialCarType}</if>
            <if test="regtime != null "> and regtime = #{regtime}</if>
            <if test="stationId != null "> and station_id = #{stationId}</if>
            <if test="stationNam != null  and stationNam != ''"> and station_nam = #{stationNam}</if>
        </where>
    </select>
    
    <select id="selectCustomerManageById" parameterType="Long" resultMap="CustomerManageResult">
        <include refid="selectCustomerManageVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertCustomerManage" parameterType="CustomerManage">
        insert into customer_manage
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="memberId != null">member_id,</if>
            <if test="customerName != null">customer_name,</if>
            <if test="commendMan != null">commend_man,</if>
            <if test="memberGrade != null">member_grade,</if>
            <if test="phoneNumber != null">phone_number,</if>
            <if test="carNumber != null">car_number,</if>
            <if test="oils != null">oils,</if>
            <if test="balance != null">balance,</if>
            <if test="integral != null">integral,</if>
            <if test="specialCarType != null">special_car_type,</if>
            <if test="regtime != null">regtime,</if>
            <if test="stationId != null">station_id,</if>
            <if test="stationNam != null">station_nam,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="memberId != null">#{memberId},</if>
            <if test="customerName != null">#{customerName},</if>
            <if test="commendMan != null">#{commendMan},</if>
            <if test="memberGrade != null">#{memberGrade},</if>
            <if test="phoneNumber != null">#{phoneNumber},</if>
            <if test="carNumber != null">#{carNumber},</if>
            <if test="oils != null">#{oils},</if>
            <if test="balance != null">#{balance},</if>
            <if test="integral != null">#{integral},</if>
            <if test="specialCarType != null">#{specialCarType},</if>
            <if test="regtime != null">#{regtime},</if>
            <if test="stationId != null">#{stationId},</if>
            <if test="stationNam != null">#{stationNam},</if>
         </trim>
    </insert>

    <update id="updateCustomerManage" parameterType="CustomerManage">
        update customer_manage
        <trim prefix="SET" suffixOverrides=",">
            <if test="memberId != null">member_id = #{memberId},</if>
            <if test="customerName != null">customer_name = #{customerName},</if>
            <if test="commendMan != null">commend_man = #{commendMan},</if>
            <if test="memberGrade != null">member_grade = #{memberGrade},</if>
            <if test="phoneNumber != null">phone_number = #{phoneNumber},</if>
            <if test="carNumber != null">car_number = #{carNumber},</if>
            <if test="oils != null">oils = #{oils},</if>
            <if test="balance != null">balance = #{balance},</if>
            <if test="integral != null">integral = #{integral},</if>
            <if test="specialCarType != null">special_car_type = #{specialCarType},</if>
            <if test="regtime != null">regtime = #{regtime},</if>
            <if test="stationId != null">station_id = #{stationId},</if>
            <if test="stationNam != null">station_nam = #{stationNam},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteCustomerManageById" parameterType="Long">
        delete from customer_manage where id = #{id}
    </delete>

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