<?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.integral.mapper.CustomerPointsRecordMapper">

    <resultMap type="CustomerPointsRecord" id="CustomerPointsRecordResult">
        <result property="id"    column="id"    />
        <result property="unionId"    column="union_id"    />
        <result property="customerName"    column="customer_name"    />
        <result property="recordType"    column="record_type"    />
        <result property="integral"    column="integral"    />
        <result property="createTime"    column="create_time"    />
        <result property="stationId"    column="station_id"    />
        <result property="stationName"    column="station_name"    />
    </resultMap>
    <sql id="selectCustomerPointsRecordVo">
        select id, union_id, customer_name, record_type, integral, create_time, station_id, station_name from customer_points_record
    </sql>

    <select id="selectCustomerPointsRecordList" parameterType="CustomerPointsRecord" resultMap="CustomerPointsRecordResult">
        <include refid="selectCustomerPointsRecordVo"/>
        <where>
            <if test="unionId != null  and unionId != ''"> and union_id = #{unionId}</if>
            <if test="customerName != null  and customerName != ''"> and customer_name like concat('%', #{customerName}, '%')</if>
            <if test="recordType != null  and recordType != ''"> and record_type = #{recordType}</if>
            <if test="integral != null "> and integral = #{integral}</if>
            <if test="stationId != null "> and station_id = #{stationId}</if>
            <if test="stationIdList != null ">
                and station_id in
                <foreach item="item" index="index" collection="stationIdList"
                         open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
        </where>
        order by  id desc
    </select>

    <select id="selectCustomerPointsRecordById" parameterType="Long" resultMap="CustomerPointsRecordResult">
        <include refid="selectCustomerPointsRecordVo"/>
        where id = #{id}
    </select>

    <insert id="insertCustomerPointsRecord" parameterType="CustomerPointsRecord" useGeneratedKeys="true" keyProperty="id">
        insert into customer_points_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="unionId != null">union_id,</if>
            <if test="customerName != null">customer_name,</if>
            <if test="recordType != null">record_type,</if>
            <if test="integral != null">integral,</if>
            <if test="createTime != null">create_time,</if>
            <if test="stationId != null">station_id,</if>
            <if test="stationName != null">station_name,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="unionId != null">#{unionId},</if>
            <if test="customerName != null">#{customerName},</if>
            <if test="recordType != null">#{recordType},</if>
            <if test="integral != null">#{integral},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="stationId != null">#{stationId},</if>
            <if test="stationName != null">#{stationName},</if>
         </trim>
    </insert>

    <update id="updateCustomerPointsRecord" parameterType="CustomerPointsRecord">
        update customer_points_record
        <trim prefix="SET" suffixOverrides=",">
            <if test="unionId != null">union_id = #{unionId},</if>
            <if test="customerName != null">customer_name = #{customerName},</if>
            <if test="recordType != null">record_type = #{recordType},</if>
            <if test="integral != null">integral = #{integral},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="stationId != null">station_id = #{stationId},</if>
            <if test="stationName != null">station_name = #{stationName},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteCustomerPointsRecordById" parameterType="Long">
        delete from customer_points_record where id = #{id}
    </delete>

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

</mapper>
