<?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.neusoft.smart.pos.card.persistent.mapper.CardOrderMapper">
  <resultMap id="BaseResultMap" type="com.neusoft.smart.pos.card.persistent.domain.CardOrder">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="out_trade_id" jdbcType="VARCHAR" property="outTradeId" />
    <result column="buyer_card_id" jdbcType="INTEGER" property="buyerCardId" />
    <result column="seller_card_id" jdbcType="INTEGER" property="sellerCardId" />
    <result column="order_type" jdbcType="CHAR" property="orderType" />
    <result column="card_trade_num" jdbcType="VARCHAR" property="cardTradeNum" />
    <result column="pay_amount" jdbcType="DECIMAL" property="payAmount" />
    <result column="refunded_amount" jdbcType="DECIMAL" property="refundedAmount" />
    <result column="pay_type" jdbcType="CHAR" property="payType" />
    <result column="point" jdbcType="INTEGER" property="point" />
    <result column="pay_status" jdbcType="VARCHAR" property="payStatus" />
    <result column="pay_time" jdbcType="TIMESTAMP" property="payTime" />
    <result column="version" jdbcType="INTEGER" property="version" />
    <result column="created_at" jdbcType="TIMESTAMP" property="createdAt" />
    <result column="created_by" jdbcType="VARCHAR" property="createdBy" />
    <result column="updated_at" jdbcType="TIMESTAMP" property="updatedAt" />
    <result column="updated_by" jdbcType="VARCHAR" property="updatedBy" />
    <result column="description" jdbcType="VARCHAR" property="description" />
  </resultMap>
  <sql id="Example_Where_Clause">
    <where>
      <foreach collection="oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Update_By_Example_Where_Clause">
    <where>
      <foreach collection="example.oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Base_Column_List">
    id, out_trade_id, buyer_card_id, seller_card_id, order_type, card_trade_num, pay_amount, 
    refunded_amount, pay_type, point, pay_status, pay_time, version, created_at, created_by, 
    updated_at, updated_by, description
  </sql>
  <select id="selectByExample" parameterType="com.neusoft.smart.pos.card.persistent.domain.CardOrderExample" resultMap="BaseResultMap">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from card_order
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
    <if test="offset != null and limit != null">
      limit ${offset}, ${limit}
    </if>
  </select>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from card_order
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from card_order
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <delete id="deleteByExample" parameterType="com.neusoft.smart.pos.card.persistent.domain.CardOrderExample">
    delete from card_order
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.neusoft.smart.pos.card.persistent.domain.CardOrder" useGeneratedKeys="true">
    insert into card_order (out_trade_id, buyer_card_id, seller_card_id, 
      order_type, card_trade_num, pay_amount, 
      refunded_amount, pay_type, point, 
      pay_status, pay_time, version, 
      created_at, created_by, updated_at, 
      updated_by, description)
    values (#{outTradeId,jdbcType=VARCHAR}, #{buyerCardId,jdbcType=INTEGER}, #{sellerCardId,jdbcType=INTEGER}, 
      #{orderType,jdbcType=CHAR}, #{cardTradeNum,jdbcType=VARCHAR}, #{payAmount,jdbcType=DECIMAL}, 
      #{refundedAmount,jdbcType=DECIMAL}, #{payType,jdbcType=CHAR}, #{point,jdbcType=INTEGER}, 
      #{payStatus,jdbcType=VARCHAR}, #{payTime,jdbcType=TIMESTAMP}, #{version,jdbcType=INTEGER}, 
      #{createdAt,jdbcType=TIMESTAMP}, #{createdBy,jdbcType=VARCHAR}, #{updatedAt,jdbcType=TIMESTAMP}, 
      #{updatedBy,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR})
  </insert>
  <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.neusoft.smart.pos.card.persistent.domain.CardOrder" useGeneratedKeys="true">
    insert into card_order
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="outTradeId != null">
        out_trade_id,
      </if>
      <if test="buyerCardId != null">
        buyer_card_id,
      </if>
      <if test="sellerCardId != null">
        seller_card_id,
      </if>
      <if test="orderType != null">
        order_type,
      </if>
      <if test="cardTradeNum != null">
        card_trade_num,
      </if>
      <if test="payAmount != null">
        pay_amount,
      </if>
      <if test="refundedAmount != null">
        refunded_amount,
      </if>
      <if test="payType != null">
        pay_type,
      </if>
      <if test="point != null">
        point,
      </if>
      <if test="payStatus != null">
        pay_status,
      </if>
      <if test="payTime != null">
        pay_time,
      </if>
      <if test="version != null">
        version,
      </if>
      <if test="createdAt != null">
        created_at,
      </if>
      <if test="createdBy != null">
        created_by,
      </if>
      <if test="updatedAt != null">
        updated_at,
      </if>
      <if test="updatedBy != null">
        updated_by,
      </if>
      <if test="description != null">
        description,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="outTradeId != null">
        #{outTradeId,jdbcType=VARCHAR},
      </if>
      <if test="buyerCardId != null">
        #{buyerCardId,jdbcType=INTEGER},
      </if>
      <if test="sellerCardId != null">
        #{sellerCardId,jdbcType=INTEGER},
      </if>
      <if test="orderType != null">
        #{orderType,jdbcType=CHAR},
      </if>
      <if test="cardTradeNum != null">
        #{cardTradeNum,jdbcType=VARCHAR},
      </if>
      <if test="payAmount != null">
        #{payAmount,jdbcType=DECIMAL},
      </if>
      <if test="refundedAmount != null">
        #{refundedAmount,jdbcType=DECIMAL},
      </if>
      <if test="payType != null">
        #{payType,jdbcType=CHAR},
      </if>
      <if test="point != null">
        #{point,jdbcType=INTEGER},
      </if>
      <if test="payStatus != null">
        #{payStatus,jdbcType=VARCHAR},
      </if>
      <if test="payTime != null">
        #{payTime,jdbcType=TIMESTAMP},
      </if>
      <if test="version != null">
        #{version,jdbcType=INTEGER},
      </if>
      <if test="createdAt != null">
        #{createdAt,jdbcType=TIMESTAMP},
      </if>
      <if test="createdBy != null">
        #{createdBy,jdbcType=VARCHAR},
      </if>
      <if test="updatedAt != null">
        #{updatedAt,jdbcType=TIMESTAMP},
      </if>
      <if test="updatedBy != null">
        #{updatedBy,jdbcType=VARCHAR},
      </if>
      <if test="description != null">
        #{description,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.neusoft.smart.pos.card.persistent.domain.CardOrderExample" resultType="java.lang.Integer">
    select count(*) from card_order
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    update card_order
    <set>
      <if test="record.id != null">
        id = #{record.id,jdbcType=INTEGER},
      </if>
      <if test="record.outTradeId != null">
        out_trade_id = #{record.outTradeId,jdbcType=VARCHAR},
      </if>
      <if test="record.buyerCardId != null">
        buyer_card_id = #{record.buyerCardId,jdbcType=INTEGER},
      </if>
      <if test="record.sellerCardId != null">
        seller_card_id = #{record.sellerCardId,jdbcType=INTEGER},
      </if>
      <if test="record.orderType != null">
        order_type = #{record.orderType,jdbcType=CHAR},
      </if>
      <if test="record.cardTradeNum != null">
        card_trade_num = #{record.cardTradeNum,jdbcType=VARCHAR},
      </if>
      <if test="record.payAmount != null">
        pay_amount = #{record.payAmount,jdbcType=DECIMAL},
      </if>
      <if test="record.refundedAmount != null">
        refunded_amount = #{record.refundedAmount,jdbcType=DECIMAL},
      </if>
      <if test="record.payType != null">
        pay_type = #{record.payType,jdbcType=CHAR},
      </if>
      <if test="record.point != null">
        point = #{record.point,jdbcType=INTEGER},
      </if>
      <if test="record.payStatus != null">
        pay_status = #{record.payStatus,jdbcType=VARCHAR},
      </if>
      <if test="record.payTime != null">
        pay_time = #{record.payTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.version != null">
        version = #{record.version,jdbcType=INTEGER},
      </if>
      <if test="record.createdAt != null">
        created_at = #{record.createdAt,jdbcType=TIMESTAMP},
      </if>
      <if test="record.createdBy != null">
        created_by = #{record.createdBy,jdbcType=VARCHAR},
      </if>
      <if test="record.updatedAt != null">
        updated_at = #{record.updatedAt,jdbcType=TIMESTAMP},
      </if>
      <if test="record.updatedBy != null">
        updated_by = #{record.updatedBy,jdbcType=VARCHAR},
      </if>
      <if test="record.description != null">
        description = #{record.description,jdbcType=VARCHAR},
      </if>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">
    update card_order
    set id = #{record.id,jdbcType=INTEGER},
      out_trade_id = #{record.outTradeId,jdbcType=VARCHAR},
      buyer_card_id = #{record.buyerCardId,jdbcType=INTEGER},
      seller_card_id = #{record.sellerCardId,jdbcType=INTEGER},
      order_type = #{record.orderType,jdbcType=CHAR},
      card_trade_num = #{record.cardTradeNum,jdbcType=VARCHAR},
      pay_amount = #{record.payAmount,jdbcType=DECIMAL},
      refunded_amount = #{record.refundedAmount,jdbcType=DECIMAL},
      pay_type = #{record.payType,jdbcType=CHAR},
      point = #{record.point,jdbcType=INTEGER},
      pay_status = #{record.payStatus,jdbcType=VARCHAR},
      pay_time = #{record.payTime,jdbcType=TIMESTAMP},
      version = #{record.version,jdbcType=INTEGER},
      created_at = #{record.createdAt,jdbcType=TIMESTAMP},
      created_by = #{record.createdBy,jdbcType=VARCHAR},
      updated_at = #{record.updatedAt,jdbcType=TIMESTAMP},
      updated_by = #{record.updatedBy,jdbcType=VARCHAR},
      description = #{record.description,jdbcType=VARCHAR}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.neusoft.smart.pos.card.persistent.domain.CardOrder">
    update card_order
    <set>
      <if test="outTradeId != null">
        out_trade_id = #{outTradeId,jdbcType=VARCHAR},
      </if>
      <if test="buyerCardId != null">
        buyer_card_id = #{buyerCardId,jdbcType=INTEGER},
      </if>
      <if test="sellerCardId != null">
        seller_card_id = #{sellerCardId,jdbcType=INTEGER},
      </if>
      <if test="orderType != null">
        order_type = #{orderType,jdbcType=CHAR},
      </if>
      <if test="cardTradeNum != null">
        card_trade_num = #{cardTradeNum,jdbcType=VARCHAR},
      </if>
      <if test="payAmount != null">
        pay_amount = #{payAmount,jdbcType=DECIMAL},
      </if>
      <if test="refundedAmount != null">
        refunded_amount = #{refundedAmount,jdbcType=DECIMAL},
      </if>
      <if test="payType != null">
        pay_type = #{payType,jdbcType=CHAR},
      </if>
      <if test="point != null">
        point = #{point,jdbcType=INTEGER},
      </if>
      <if test="payStatus != null">
        pay_status = #{payStatus,jdbcType=VARCHAR},
      </if>
      <if test="payTime != null">
        pay_time = #{payTime,jdbcType=TIMESTAMP},
      </if>
      <if test="version != null">
        version = #{version,jdbcType=INTEGER},
      </if>
      <if test="createdAt != null">
        created_at = #{createdAt,jdbcType=TIMESTAMP},
      </if>
      <if test="createdBy != null">
        created_by = #{createdBy,jdbcType=VARCHAR},
      </if>
      <if test="updatedAt != null">
        updated_at = #{updatedAt,jdbcType=TIMESTAMP},
      </if>
      <if test="updatedBy != null">
        updated_by = #{updatedBy,jdbcType=VARCHAR},
      </if>
      <if test="description != null">
        description = #{description,jdbcType=VARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.neusoft.smart.pos.card.persistent.domain.CardOrder">
    update card_order
    set out_trade_id = #{outTradeId,jdbcType=VARCHAR},
      buyer_card_id = #{buyerCardId,jdbcType=INTEGER},
      seller_card_id = #{sellerCardId,jdbcType=INTEGER},
      order_type = #{orderType,jdbcType=CHAR},
      card_trade_num = #{cardTradeNum,jdbcType=VARCHAR},
      pay_amount = #{payAmount,jdbcType=DECIMAL},
      refunded_amount = #{refundedAmount,jdbcType=DECIMAL},
      pay_type = #{payType,jdbcType=CHAR},
      point = #{point,jdbcType=INTEGER},
      pay_status = #{payStatus,jdbcType=VARCHAR},
      pay_time = #{payTime,jdbcType=TIMESTAMP},
      version = #{version,jdbcType=INTEGER},
      created_at = #{createdAt,jdbcType=TIMESTAMP},
      created_by = #{createdBy,jdbcType=VARCHAR},
      updated_at = #{updatedAt,jdbcType=TIMESTAMP},
      updated_by = #{updatedBy,jdbcType=VARCHAR},
      description = #{description,jdbcType=VARCHAR}
    where id = #{id,jdbcType=INTEGER}
  </update>
  <insert id="batchInsert">
    <if test="items.get(0) != null">
            insert into card_order  (out_trade_id, buyer_card_id, seller_card_id, 
        order_type, card_trade_num, pay_amount, 
        refunded_amount, pay_type, point, 
        pay_status, pay_time, version, 
        created_at, created_by, updated_at, 
        updated_by, description)
      values
      <foreach collection="items" item="item" index="index" separator=",">
      (#{item.outTradeId,jdbcType=VARCHAR}, #{item.buyerCardId,jdbcType=INTEGER}, #{item.sellerCardId,jdbcType=INTEGER}, 
        #{item.orderType,jdbcType=CHAR}, #{item.cardTradeNum,jdbcType=VARCHAR}, #{item.payAmount,jdbcType=DECIMAL}, 
        #{item.refundedAmount,jdbcType=DECIMAL}, #{item.payType,jdbcType=CHAR}, #{item.point,jdbcType=INTEGER}, 
        #{item.payStatus,jdbcType=VARCHAR}, #{item.payTime,jdbcType=TIMESTAMP}, #{item.version,jdbcType=INTEGER}, 
        #{item.createdAt,jdbcType=TIMESTAMP}, #{item.createdBy,jdbcType=VARCHAR}, #{item.updatedAt,jdbcType=TIMESTAMP}, 
        #{item.updatedBy,jdbcType=VARCHAR}, #{item.description,jdbcType=VARCHAR})
      </foreach>
    </if>
  </insert>
</mapper>