<?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.platform.yijia.dao.CustomerPointsRecordMapper">
  <!--返回结果-->
  <resultMap id="BaseResultMap" type="com.platform.yijia.pojo.CustomerPointsRecord">
    <id     column="id"              jdbcType="INTEGER"    property="id" />
    <result column="union_id"        jdbcType="VARCHAR"    property="unionId" />
    <result column="customer_name"   jdbcType="VARCHAR"    property="customerName" />
    <result column="record_type"     jdbcType="VARCHAR"    property="recordType" />
    <result column="integral"        jdbcType="INTEGER"    property="integral" />
    <result column="station_id"      jdbcType="INTEGER"    property="stationId" />
    <result column="station_name"    jdbcType="VARCHAR"    property="stationName" />
    <result column="create_time"     jdbcType="TIMESTAMP"  property="createTime" />
    <result column="order_no"        jdbcType="VARCHAR"    property="orderNo" />
  </resultMap>

  <!--查询列-->
  <sql id="Base_Column_List">
    id, union_id, customer_name, record_type, integral, station_id, station_name,
    create_time,order_no
  </sql>

  <!--查询客户积分记录信息-->
  <select id="getCustomerPointsRecordList" resultMap="BaseResultMap" parameterType="com.platform.yijia.pojo.CustomerPointsRecord">
    SELECT
        <include refid="Base_Column_List" />
    FROM customer_points_record
    <where>
        <if test="unionId !=null and unionId !=''">
          union_id = #{unionId}
        </if>
        <if test="stationId !=null and stationId !=''">
          AND station_id = #{stationId}
        </if>
        <if test="createTime !=null">
          <![CDATA[ AND create_time >=  #{createTime}  ]]>
        </if>
    </where>
    ORDER BY create_time DESC
  </select>

  <!--插入客户积分记录表-->
  <insert id="insertCustomerPointsRecordInfo" parameterType="com.platform.yijia.pojo.CustomerPoints">
    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="stationId !=null">
        station_id,
      </if>
      <if test="stationName !=null">
        station_name,
      </if>
      <if test="createTime !=null">
        create_time,
      </if>
      <if test="orderNo !=null">
        order_no,
      </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="stationId !=null">
        #{stationId},
      </if>
      <if test="stationName !=null">
        #{stationName},
      </if>
      <if test="createTime !=null">
        #{createTime},
      </if>
      <if test="orderNo !=null">
        #{orderNo},
      </if>
    </trim>
  </insert>

</mapper>
