<?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.yd.dal.mapper.customer.AclCustomerMembershipMapper">
  <resultMap id="BaseResultMap" type="com.yd.dal.entity.customer.AclCustomerMembership">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="customer_id" jdbcType="BIGINT" property="customerId" />
    <result column="customer_name" jdbcType="VARCHAR" property="customerName" />
    <result column="voucher_id" jdbcType="BIGINT" property="voucherId" />
    <result column="purchase_date" jdbcType="TIMESTAMP" property="purchaseDate" />
    <result column="approve_date" jdbcType="TIMESTAMP" property="approveDate" />
    <result column="purchase_amount" jdbcType="DECIMAL" property="purchaseAmount" />
    <result column="valid_from" jdbcType="DATE" property="validFrom" />
    <result column="valid_to" jdbcType="DATE" property="validTo" />
    <result column="is_active" jdbcType="INTEGER" property="isActive" />
    <result column="created_at" jdbcType="TIMESTAMP" property="createdAt" />
    <result column="created_by" jdbcType="BIGINT" property="createdBy" />
    <result column="order_id" jdbcType="BIGINT" property="orderId" />
    <result column="customer_level" jdbcType="INTEGER" property="customerLevel" />
    <result column="plan_id" jdbcType="BIGINT" property="planId" />
  </resultMap>
  <sql id="Base_Column_List">
    id, customer_id, customer_name, voucher_id, purchase_date, approve_date, purchase_amount, 
    valid_from, valid_to, is_active, created_at, created_by, order_id, customer_level, 
    plan_id
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from ag_acl_customer_membership
    where id = #{id,jdbcType=BIGINT}
  </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    delete from ag_acl_customer_membership
    where id = #{id,jdbcType=BIGINT}
  </delete>
  <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.yd.dal.entity.customer.AclCustomerMembership" useGeneratedKeys="true">
    insert into ag_acl_customer_membership (customer_id, customer_name, voucher_id, 
      purchase_date, approve_date, purchase_amount, 
      valid_from, valid_to, is_active, 
      created_at, created_by, order_id, 
      customer_level, plan_id)
    values (#{customerId,jdbcType=BIGINT}, #{customerName,jdbcType=VARCHAR}, #{voucherId,jdbcType=BIGINT}, 
      #{purchaseDate,jdbcType=TIMESTAMP}, #{approveDate,jdbcType=TIMESTAMP}, #{purchaseAmount,jdbcType=DECIMAL}, 
      #{validFrom,jdbcType=DATE}, #{validTo,jdbcType=DATE}, #{isActive,jdbcType=INTEGER}, 
      #{createdAt,jdbcType=TIMESTAMP}, #{createdBy,jdbcType=BIGINT}, #{orderId,jdbcType=BIGINT}, 
      #{customerLevel,jdbcType=INTEGER}, #{planId,jdbcType=BIGINT})
  </insert>
  <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.yd.dal.entity.customer.AclCustomerMembership" useGeneratedKeys="true">
    insert into ag_acl_customer_membership
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="customerId != null">
        customer_id,
      </if>
      <if test="customerName != null">
        customer_name,
      </if>
      <if test="voucherId != null">
        voucher_id,
      </if>
      <if test="purchaseDate != null">
        purchase_date,
      </if>
      <if test="approveDate != null">
        approve_date,
      </if>
      <if test="purchaseAmount != null">
        purchase_amount,
      </if>
      <if test="validFrom != null">
        valid_from,
      </if>
      <if test="validTo != null">
        valid_to,
      </if>
      <if test="isActive != null">
        is_active,
      </if>
      <if test="createdAt != null">
        created_at,
      </if>
      <if test="createdBy != null">
        created_by,
      </if>
      <if test="orderId != null">
        order_id,
      </if>
      <if test="customerLevel != null">
        customer_level,
      </if>
      <if test="planId != null">
        plan_id,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="customerId != null">
        #{customerId,jdbcType=BIGINT},
      </if>
      <if test="customerName != null">
        #{customerName,jdbcType=VARCHAR},
      </if>
      <if test="voucherId != null">
        #{voucherId,jdbcType=BIGINT},
      </if>
      <if test="purchaseDate != null">
        #{purchaseDate,jdbcType=TIMESTAMP},
      </if>
      <if test="approveDate != null">
        #{approveDate,jdbcType=TIMESTAMP},
      </if>
      <if test="purchaseAmount != null">
        #{purchaseAmount,jdbcType=DECIMAL},
      </if>
      <if test="validFrom != null">
        #{validFrom,jdbcType=DATE},
      </if>
      <if test="validTo != null">
        #{validTo,jdbcType=DATE},
      </if>
      <if test="isActive != null">
        #{isActive,jdbcType=INTEGER},
      </if>
      <if test="createdAt != null">
        #{createdAt,jdbcType=TIMESTAMP},
      </if>
      <if test="createdBy != null">
        #{createdBy,jdbcType=BIGINT},
      </if>
      <if test="orderId != null">
        #{orderId,jdbcType=BIGINT},
      </if>
      <if test="customerLevel != null">
        #{customerLevel,jdbcType=INTEGER},
      </if>
      <if test="planId != null">
        #{planId,jdbcType=BIGINT},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.yd.dal.entity.customer.AclCustomerMembership">
    update ag_acl_customer_membership
    <set>
      <if test="customerId != null">
        customer_id = #{customerId,jdbcType=BIGINT},
      </if>
      <if test="customerName != null">
        customer_name = #{customerName,jdbcType=VARCHAR},
      </if>
      <if test="voucherId != null">
        voucher_id = #{voucherId,jdbcType=BIGINT},
      </if>
      <if test="purchaseDate != null">
        purchase_date = #{purchaseDate,jdbcType=TIMESTAMP},
      </if>
      <if test="approveDate != null">
        approve_date = #{approveDate,jdbcType=TIMESTAMP},
      </if>
      <if test="purchaseAmount != null">
        purchase_amount = #{purchaseAmount,jdbcType=DECIMAL},
      </if>
      <if test="validFrom != null">
        valid_from = #{validFrom,jdbcType=DATE},
      </if>
      <if test="validTo != null">
        valid_to = #{validTo,jdbcType=DATE},
      </if>
      <if test="isActive != null">
        is_active = #{isActive,jdbcType=INTEGER},
      </if>
      <if test="createdAt != null">
        created_at = #{createdAt,jdbcType=TIMESTAMP},
      </if>
      <if test="createdBy != null">
        created_by = #{createdBy,jdbcType=BIGINT},
      </if>
      <if test="orderId != null">
        order_id = #{orderId,jdbcType=BIGINT},
      </if>
      <if test="customerLevel != null">
        customer_level = #{customerLevel,jdbcType=INTEGER},
      </if>
      <if test="planId != null">
        plan_id = #{planId,jdbcType=BIGINT},
      </if>
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.yd.dal.entity.customer.AclCustomerMembership">
    update ag_acl_customer_membership
    set customer_id = #{customerId,jdbcType=BIGINT},
      customer_name = #{customerName,jdbcType=VARCHAR},
      voucher_id = #{voucherId,jdbcType=BIGINT},
      purchase_date = #{purchaseDate,jdbcType=TIMESTAMP},
      approve_date = #{approveDate,jdbcType=TIMESTAMP},
      purchase_amount = #{purchaseAmount,jdbcType=DECIMAL},
      valid_from = #{validFrom,jdbcType=DATE},
      valid_to = #{validTo,jdbcType=DATE},
      is_active = #{isActive,jdbcType=INTEGER},
      created_at = #{createdAt,jdbcType=TIMESTAMP},
      created_by = #{createdBy,jdbcType=BIGINT},
      order_id = #{orderId,jdbcType=BIGINT},
      customer_level = #{customerLevel,jdbcType=INTEGER},
      plan_id = #{planId,jdbcType=BIGINT}
    where id = #{id,jdbcType=BIGINT}
  </update>
  <select id="selectByCustomerMembership" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from ag_acl_customer_membership
    <where>
      <if test="id != null">
        id = #{id,jdbcType=BIGINT}
      </if>
      <if test="customerId != null">
        and customer_id = #{customerId,jdbcType=BIGINT}
      </if>
      <if test="customerName != null">
        and customer_name = #{customerName,jdbcType=VARCHAR}
      </if>
      <if test="voucherId != null">
        and voucher_id = #{voucherId,jdbcType=BIGINT}
      </if>
      <if test="purchaseDate != null">
        and purchase_date = #{purchaseDate,jdbcType=TIMESTAMP}
      </if>
      <if test="approveDate != null">
        and approve_date = #{approveDate,jdbcType=TIMESTAMP}
      </if>
      <if test="purchaseAmount != null">
        and purchase_amount = #{purchaseAmount,jdbcType=DECIMAL}
      </if>
      <if test="validFrom != null">
        and valid_from = #{validFrom,jdbcType=DATE}
      </if>
      <if test="validTo != null">
        and valid_to = #{validTo,jdbcType=DATE}
      </if>
      <if test="isActive != null">
        and is_active = #{isActive,jdbcType=INTEGER}
      </if>
      <if test="createdAt != null">
        and created_at = #{createdAt,jdbcType=TIMESTAMP}
      </if>
      <if test="createdBy != null">
        and created_by = #{createdBy,jdbcType=BIGINT}
      </if>
      <if test="orderId != null">
        and order_id = #{orderId,jdbcType=BIGINT}
      </if>
      <if test="customerLevel != null">
        and customer_level = #{customerLevel,jdbcType=INTEGER}
      </if>
      <if test="planId != null">
        and plan_id = #{planId,jdbcType=BIGINT}
      </if>
    </where>
  </select>
</mapper>