<?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.order.persistent.mapper.OrderRefundTransactionMapper">
  <resultMap id="BaseResultMap" type="com.neusoft.smart.pos.order.persistent.domain.OrderRefundTransaction">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="refund_number" jdbcType="VARCHAR" property="refundNumber" />
    <result column="original_order_number" jdbcType="VARCHAR" property="originalOrderNumber" />
    <result column="item_number" jdbcType="VARCHAR" property="itemNumber" />
    <result column="unit_price" jdbcType="DECIMAL" property="unitPrice" />
    <result column="quantity" jdbcType="INTEGER" property="quantity" />
    <result column="final_price" jdbcType="DECIMAL" property="finalPrice" />
    <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_by" jdbcType="VARCHAR" property="updatedBy" />
    <result column="updated_at" jdbcType="TIMESTAMP" property="updatedAt" />
    <result column="item_name" jdbcType="VARCHAR" property="itemName" />
  </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, refund_number, original_order_number, item_number, unit_price, quantity, final_price, 
    version, created_at, created_by, updated_by, updated_at, item_name
  </sql>
  <select id="selectByExample" parameterType="com.neusoft.smart.pos.order.persistent.domain.OrderRefundTransactionExample" resultMap="BaseResultMap">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from order_refund_transaction
    <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.Long" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from order_refund_transaction
    where id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    delete from order_refund_transaction
    where id = #{id,jdbcType=BIGINT}
  </delete>
  <delete id="deleteByExample" parameterType="com.neusoft.smart.pos.order.persistent.domain.OrderRefundTransactionExample">
    delete from order_refund_transaction
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.neusoft.smart.pos.order.persistent.domain.OrderRefundTransaction" useGeneratedKeys="true">
    insert into order_refund_transaction (refund_number, original_order_number, 
      item_number, unit_price, quantity, 
      final_price, version, created_at, 
      created_by, updated_by, updated_at, 
      item_name)
    values (#{refundNumber,jdbcType=VARCHAR}, #{originalOrderNumber,jdbcType=VARCHAR}, 
      #{itemNumber,jdbcType=VARCHAR}, #{unitPrice,jdbcType=DECIMAL}, #{quantity,jdbcType=INTEGER}, 
      #{finalPrice,jdbcType=DECIMAL}, #{version,jdbcType=INTEGER}, #{createdAt,jdbcType=TIMESTAMP}, 
      #{createdBy,jdbcType=VARCHAR}, #{updatedBy,jdbcType=VARCHAR}, #{updatedAt,jdbcType=TIMESTAMP}, 
      #{itemName,jdbcType=VARCHAR})
  </insert>
  <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.neusoft.smart.pos.order.persistent.domain.OrderRefundTransaction" useGeneratedKeys="true">
    insert into order_refund_transaction
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="refundNumber != null">
        refund_number,
      </if>
      <if test="originalOrderNumber != null">
        original_order_number,
      </if>
      <if test="itemNumber != null">
        item_number,
      </if>
      <if test="unitPrice != null">
        unit_price,
      </if>
      <if test="quantity != null">
        quantity,
      </if>
      <if test="finalPrice != null">
        final_price,
      </if>
      <if test="version != null">
        version,
      </if>
      <if test="createdAt != null">
        created_at,
      </if>
      <if test="createdBy != null">
        created_by,
      </if>
      <if test="updatedBy != null">
        updated_by,
      </if>
      <if test="updatedAt != null">
        updated_at,
      </if>
      <if test="itemName != null">
        item_name,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="refundNumber != null">
        #{refundNumber,jdbcType=VARCHAR},
      </if>
      <if test="originalOrderNumber != null">
        #{originalOrderNumber,jdbcType=VARCHAR},
      </if>
      <if test="itemNumber != null">
        #{itemNumber,jdbcType=VARCHAR},
      </if>
      <if test="unitPrice != null">
        #{unitPrice,jdbcType=DECIMAL},
      </if>
      <if test="quantity != null">
        #{quantity,jdbcType=INTEGER},
      </if>
      <if test="finalPrice != null">
        #{finalPrice,jdbcType=DECIMAL},
      </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="updatedBy != null">
        #{updatedBy,jdbcType=VARCHAR},
      </if>
      <if test="updatedAt != null">
        #{updatedAt,jdbcType=TIMESTAMP},
      </if>
      <if test="itemName != null">
        #{itemName,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.neusoft.smart.pos.order.persistent.domain.OrderRefundTransactionExample" resultType="java.lang.Integer">
    select count(*) from order_refund_transaction
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    update order_refund_transaction
    <set>
      <if test="record.id != null">
        id = #{record.id,jdbcType=BIGINT},
      </if>
      <if test="record.refundNumber != null">
        refund_number = #{record.refundNumber,jdbcType=VARCHAR},
      </if>
      <if test="record.originalOrderNumber != null">
        original_order_number = #{record.originalOrderNumber,jdbcType=VARCHAR},
      </if>
      <if test="record.itemNumber != null">
        item_number = #{record.itemNumber,jdbcType=VARCHAR},
      </if>
      <if test="record.unitPrice != null">
        unit_price = #{record.unitPrice,jdbcType=DECIMAL},
      </if>
      <if test="record.quantity != null">
        quantity = #{record.quantity,jdbcType=INTEGER},
      </if>
      <if test="record.finalPrice != null">
        final_price = #{record.finalPrice,jdbcType=DECIMAL},
      </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.updatedBy != null">
        updated_by = #{record.updatedBy,jdbcType=VARCHAR},
      </if>
      <if test="record.updatedAt != null">
        updated_at = #{record.updatedAt,jdbcType=TIMESTAMP},
      </if>
      <if test="record.itemName != null">
        item_name = #{record.itemName,jdbcType=VARCHAR},
      </if>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">
    update order_refund_transaction
    set id = #{record.id,jdbcType=BIGINT},
      refund_number = #{record.refundNumber,jdbcType=VARCHAR},
      original_order_number = #{record.originalOrderNumber,jdbcType=VARCHAR},
      item_number = #{record.itemNumber,jdbcType=VARCHAR},
      unit_price = #{record.unitPrice,jdbcType=DECIMAL},
      quantity = #{record.quantity,jdbcType=INTEGER},
      final_price = #{record.finalPrice,jdbcType=DECIMAL},
      version = #{record.version,jdbcType=INTEGER},
      created_at = #{record.createdAt,jdbcType=TIMESTAMP},
      created_by = #{record.createdBy,jdbcType=VARCHAR},
      updated_by = #{record.updatedBy,jdbcType=VARCHAR},
      updated_at = #{record.updatedAt,jdbcType=TIMESTAMP},
      item_name = #{record.itemName,jdbcType=VARCHAR}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.neusoft.smart.pos.order.persistent.domain.OrderRefundTransaction">
    update order_refund_transaction
    <set>
      <if test="refundNumber != null">
        refund_number = #{refundNumber,jdbcType=VARCHAR},
      </if>
      <if test="originalOrderNumber != null">
        original_order_number = #{originalOrderNumber,jdbcType=VARCHAR},
      </if>
      <if test="itemNumber != null">
        item_number = #{itemNumber,jdbcType=VARCHAR},
      </if>
      <if test="unitPrice != null">
        unit_price = #{unitPrice,jdbcType=DECIMAL},
      </if>
      <if test="quantity != null">
        quantity = #{quantity,jdbcType=INTEGER},
      </if>
      <if test="finalPrice != null">
        final_price = #{finalPrice,jdbcType=DECIMAL},
      </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="updatedBy != null">
        updated_by = #{updatedBy,jdbcType=VARCHAR},
      </if>
      <if test="updatedAt != null">
        updated_at = #{updatedAt,jdbcType=TIMESTAMP},
      </if>
      <if test="itemName != null">
        item_name = #{itemName,jdbcType=VARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.neusoft.smart.pos.order.persistent.domain.OrderRefundTransaction">
    update order_refund_transaction
    set refund_number = #{refundNumber,jdbcType=VARCHAR},
      original_order_number = #{originalOrderNumber,jdbcType=VARCHAR},
      item_number = #{itemNumber,jdbcType=VARCHAR},
      unit_price = #{unitPrice,jdbcType=DECIMAL},
      quantity = #{quantity,jdbcType=INTEGER},
      final_price = #{finalPrice,jdbcType=DECIMAL},
      version = #{version,jdbcType=INTEGER},
      created_at = #{createdAt,jdbcType=TIMESTAMP},
      created_by = #{createdBy,jdbcType=VARCHAR},
      updated_by = #{updatedBy,jdbcType=VARCHAR},
      updated_at = #{updatedAt,jdbcType=TIMESTAMP},
      item_name = #{itemName,jdbcType=VARCHAR}
    where id = #{id,jdbcType=BIGINT}
  </update>
  <insert id="batchInsert">
    <if test="items.get(0) != null">
            insert into order_refund_transaction  (refund_number, original_order_number, 
        item_number, unit_price, quantity, 
        final_price, version, created_at, 
        created_by, updated_by, updated_at, 
        item_name)
      values
      <foreach collection="items" item="item" index="index" separator=",">
      (#{item.refundNumber,jdbcType=VARCHAR}, #{item.originalOrderNumber,jdbcType=VARCHAR}, 
        #{item.itemNumber,jdbcType=VARCHAR}, #{item.unitPrice,jdbcType=DECIMAL}, #{item.quantity,jdbcType=INTEGER}, 
        #{item.finalPrice,jdbcType=DECIMAL}, #{item.version,jdbcType=INTEGER}, #{item.createdAt,jdbcType=TIMESTAMP}, 
        #{item.createdBy,jdbcType=VARCHAR}, #{item.updatedBy,jdbcType=VARCHAR}, #{item.updatedAt,jdbcType=TIMESTAMP}, 
        #{item.itemName,jdbcType=VARCHAR})
      </foreach>
    </if>
  </insert>
</mapper>