<?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.jsowell.pile.mapper.ClearingWithdrawInfoMapper">
  <resultMap id="BaseResultMap" type="com.jsowell.pile.domain.ClearingWithdrawInfo">
    <!--@mbg.generated-->
    <!--@Table clearing_withdraw_info-->
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="merchant_id" jdbcType="VARCHAR" property="merchantId" />
    <result column="order_no" jdbcType="VARCHAR" property="orderNo" />
    <result column="withdraw_code" jdbcType="VARCHAR" property="withdrawCode" />
    <result column="withdraw_status" jdbcType="VARCHAR" property="withdrawStatus" />
    <result column="withdraw_amt" jdbcType="DECIMAL" property="withdrawAmt" />
    <result column="fee_amt" jdbcType="DECIMAL" property="feeAmt" />
    <result column="credited_amt" jdbcType="DECIMAL" property="creditedAmt" />
    <result column="application_time" jdbcType="TIMESTAMP" property="applicationTime" />
    <result column="arrival_time" jdbcType="TIMESTAMP" property="arrivalTime" />
    <result column="create_by" jdbcType="VARCHAR" property="createBy" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="update_by" jdbcType="VARCHAR" property="updateBy" />
    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
    <result column="del_flag" jdbcType="VARCHAR" property="delFlag" />
  </resultMap>
  <sql id="Base_Column_List">
    <!--@mbg.generated-->
    id, merchant_id, order_no, withdraw_code, withdraw_status, withdraw_amt, fee_amt, 
    credited_amt, application_time, arrival_time, create_by, create_time, update_by, 
    update_time, del_flag
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    <!--@mbg.generated-->
    select 
    <include refid="Base_Column_List" />
    from clearing_withdraw_info
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    <!--@mbg.generated-->
    delete from clearing_withdraw_info
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.jsowell.pile.domain.ClearingWithdrawInfo" useGeneratedKeys="true">
    <!--@mbg.generated-->
    insert into clearing_withdraw_info (merchant_id, order_no, withdraw_code, 
      withdraw_status, withdraw_amt, fee_amt, 
      credited_amt, application_time, arrival_time, 
      create_by, create_time, update_by, 
      update_time, del_flag)
    values (#{merchantId,jdbcType=VARCHAR}, #{orderNo,jdbcType=VARCHAR}, #{withdrawCode,jdbcType=VARCHAR}, 
      #{withdrawStatus,jdbcType=VARCHAR}, #{withdrawAmt,jdbcType=DECIMAL}, #{feeAmt,jdbcType=DECIMAL}, 
      #{creditedAmt,jdbcType=DECIMAL}, #{applicationTime,jdbcType=TIMESTAMP}, #{arrivalTime,jdbcType=TIMESTAMP}, 
      #{createBy,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{updateBy,jdbcType=VARCHAR}, 
      #{updateTime,jdbcType=TIMESTAMP}, #{delFlag,jdbcType=VARCHAR})
  </insert>
  <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.jsowell.pile.domain.ClearingWithdrawInfo" useGeneratedKeys="true">
    <!--@mbg.generated-->
    insert into clearing_withdraw_info
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="merchantId != null">
        merchant_id,
      </if>
      <if test="orderNo != null">
        order_no,
      </if>
      <if test="withdrawCode != null">
        withdraw_code,
      </if>
      <if test="withdrawStatus != null">
        withdraw_status,
      </if>
      <if test="withdrawAmt != null">
        withdraw_amt,
      </if>
      <if test="feeAmt != null">
        fee_amt,
      </if>
      <if test="creditedAmt != null">
        credited_amt,
      </if>
      <if test="applicationTime != null">
        application_time,
      </if>
      <if test="arrivalTime != null">
        arrival_time,
      </if>
      <if test="createBy != null">
        create_by,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="updateBy != null">
        update_by,
      </if>
      <if test="updateTime != null">
        update_time,
      </if>
      <if test="delFlag != null">
        del_flag,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="merchantId != null">
        #{merchantId,jdbcType=VARCHAR},
      </if>
      <if test="orderNo != null">
        #{orderNo,jdbcType=VARCHAR},
      </if>
      <if test="withdrawCode != null">
        #{withdrawCode,jdbcType=VARCHAR},
      </if>
      <if test="withdrawStatus != null">
        #{withdrawStatus,jdbcType=VARCHAR},
      </if>
      <if test="withdrawAmt != null">
        #{withdrawAmt,jdbcType=DECIMAL},
      </if>
      <if test="feeAmt != null">
        #{feeAmt,jdbcType=DECIMAL},
      </if>
      <if test="creditedAmt != null">
        #{creditedAmt,jdbcType=DECIMAL},
      </if>
      <if test="applicationTime != null">
        #{applicationTime,jdbcType=TIMESTAMP},
      </if>
      <if test="arrivalTime != null">
        #{arrivalTime,jdbcType=TIMESTAMP},
      </if>
      <if test="createBy != null">
        #{createBy,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateBy != null">
        #{updateBy,jdbcType=VARCHAR},
      </if>
      <if test="updateTime != null">
        #{updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="delFlag != null">
        #{delFlag,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.jsowell.pile.domain.ClearingWithdrawInfo">
    <!--@mbg.generated-->
    update clearing_withdraw_info
    <set>
      <if test="merchantId != null">
        merchant_id = #{merchantId,jdbcType=VARCHAR},
      </if>
      <if test="orderNo != null">
        order_no = #{orderNo,jdbcType=VARCHAR},
      </if>
      <if test="withdrawCode != null">
        withdraw_code = #{withdrawCode,jdbcType=VARCHAR},
      </if>
      <if test="withdrawStatus != null">
        withdraw_status = #{withdrawStatus,jdbcType=VARCHAR},
      </if>
      <if test="withdrawAmt != null">
        withdraw_amt = #{withdrawAmt,jdbcType=DECIMAL},
      </if>
      <if test="feeAmt != null">
        fee_amt = #{feeAmt,jdbcType=DECIMAL},
      </if>
      <if test="creditedAmt != null">
        credited_amt = #{creditedAmt,jdbcType=DECIMAL},
      </if>
      <if test="applicationTime != null">
        application_time = #{applicationTime,jdbcType=TIMESTAMP},
      </if>
      <if test="arrivalTime != null">
        arrival_time = #{arrivalTime,jdbcType=TIMESTAMP},
      </if>
      <if test="createBy != null">
        create_by = #{createBy,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateBy != null">
        update_by = #{updateBy,jdbcType=VARCHAR},
      </if>
      <if test="updateTime != null">
        update_time = #{updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="delFlag != null">
        del_flag = #{delFlag,jdbcType=VARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.jsowell.pile.domain.ClearingWithdrawInfo">
    <!--@mbg.generated-->
    update clearing_withdraw_info
    set merchant_id = #{merchantId,jdbcType=VARCHAR},
      order_no = #{orderNo,jdbcType=VARCHAR},
      withdraw_code = #{withdrawCode,jdbcType=VARCHAR},
      withdraw_status = #{withdrawStatus,jdbcType=VARCHAR},
      withdraw_amt = #{withdrawAmt,jdbcType=DECIMAL},
      fee_amt = #{feeAmt,jdbcType=DECIMAL},
      credited_amt = #{creditedAmt,jdbcType=DECIMAL},
      application_time = #{applicationTime,jdbcType=TIMESTAMP},
      arrival_time = #{arrivalTime,jdbcType=TIMESTAMP},
      create_by = #{createBy,jdbcType=VARCHAR},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      update_by = #{updateBy,jdbcType=VARCHAR},
      update_time = #{updateTime,jdbcType=TIMESTAMP},
      del_flag = #{delFlag,jdbcType=VARCHAR}
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateBatch" parameterType="java.util.List">
    <!--@mbg.generated-->
    update clearing_withdraw_info
    <trim prefix="set" suffixOverrides=",">
      <trim prefix="merchant_id = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.merchantId,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="order_no = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.orderNo,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="withdraw_code = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.withdrawCode,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="withdraw_status = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.withdrawStatus,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="withdraw_amt = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.withdrawAmt,jdbcType=DECIMAL}
        </foreach>
      </trim>
      <trim prefix="fee_amt = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.feeAmt,jdbcType=DECIMAL}
        </foreach>
      </trim>
      <trim prefix="credited_amt = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.creditedAmt,jdbcType=DECIMAL}
        </foreach>
      </trim>
      <trim prefix="application_time = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.applicationTime,jdbcType=TIMESTAMP}
        </foreach>
      </trim>
      <trim prefix="arrival_time = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.arrivalTime,jdbcType=TIMESTAMP}
        </foreach>
      </trim>
      <trim prefix="create_by = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.createBy,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="create_time = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.createTime,jdbcType=TIMESTAMP}
        </foreach>
      </trim>
      <trim prefix="update_by = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.updateBy,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="update_time = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.updateTime,jdbcType=TIMESTAMP}
        </foreach>
      </trim>
      <trim prefix="del_flag = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.delFlag,jdbcType=VARCHAR}
        </foreach>
      </trim>
    </trim>
    where id in
    <foreach close=")" collection="list" item="item" open="(" separator=", ">
      #{item.id,jdbcType=INTEGER}
    </foreach>
  </update>
  <insert id="batchInsert" keyColumn="id" keyProperty="id" parameterType="map" useGeneratedKeys="true">
    <!--@mbg.generated-->
    insert into clearing_withdraw_info
    (merchant_id, order_no, withdraw_code, withdraw_status, withdraw_amt, fee_amt, credited_amt, 
      application_time, arrival_time, create_by, create_time, update_by, update_time, 
      del_flag)
    values
    <foreach collection="list" item="item" separator=",">
      (#{item.merchantId,jdbcType=VARCHAR}, #{item.orderNo,jdbcType=VARCHAR}, #{item.withdrawCode,jdbcType=VARCHAR}, 
        #{item.withdrawStatus,jdbcType=VARCHAR}, #{item.withdrawAmt,jdbcType=DECIMAL}, 
        #{item.feeAmt,jdbcType=DECIMAL}, #{item.creditedAmt,jdbcType=DECIMAL}, #{item.applicationTime,jdbcType=TIMESTAMP}, 
        #{item.arrivalTime,jdbcType=TIMESTAMP}, #{item.createBy,jdbcType=VARCHAR}, #{item.createTime,jdbcType=TIMESTAMP}, 
        #{item.updateBy,jdbcType=VARCHAR}, #{item.updateTime,jdbcType=TIMESTAMP}, #{item.delFlag,jdbcType=VARCHAR}
        )
    </foreach>
  </insert>
  <insert id="insertOrUpdate" keyColumn="id" keyProperty="id" parameterType="com.jsowell.pile.domain.ClearingWithdrawInfo" useGeneratedKeys="true">
    <!--@mbg.generated-->
    insert into clearing_withdraw_info
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      merchant_id,
      order_no,
      withdraw_code,
      withdraw_status,
      withdraw_amt,
      fee_amt,
      credited_amt,
      application_time,
      arrival_time,
      create_by,
      create_time,
      update_by,
      update_time,
      del_flag,
    </trim>
    values
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=INTEGER},
      </if>
      #{merchantId,jdbcType=VARCHAR},
      #{orderNo,jdbcType=VARCHAR},
      #{withdrawCode,jdbcType=VARCHAR},
      #{withdrawStatus,jdbcType=VARCHAR},
      #{withdrawAmt,jdbcType=DECIMAL},
      #{feeAmt,jdbcType=DECIMAL},
      #{creditedAmt,jdbcType=DECIMAL},
      #{applicationTime,jdbcType=TIMESTAMP},
      #{arrivalTime,jdbcType=TIMESTAMP},
      #{createBy,jdbcType=VARCHAR},
      #{createTime,jdbcType=TIMESTAMP},
      #{updateBy,jdbcType=VARCHAR},
      #{updateTime,jdbcType=TIMESTAMP},
      #{delFlag,jdbcType=VARCHAR},
    </trim>
    on duplicate key update 
    <trim suffixOverrides=",">
      <if test="id != null">
        id = #{id,jdbcType=INTEGER},
      </if>
      merchant_id = #{merchantId,jdbcType=VARCHAR},
      order_no = #{orderNo,jdbcType=VARCHAR},
      withdraw_code = #{withdrawCode,jdbcType=VARCHAR},
      withdraw_status = #{withdrawStatus,jdbcType=VARCHAR},
      withdraw_amt = #{withdrawAmt,jdbcType=DECIMAL},
      fee_amt = #{feeAmt,jdbcType=DECIMAL},
      credited_amt = #{creditedAmt,jdbcType=DECIMAL},
      application_time = #{applicationTime,jdbcType=TIMESTAMP},
      arrival_time = #{arrivalTime,jdbcType=TIMESTAMP},
      create_by = #{createBy,jdbcType=VARCHAR},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      update_by = #{updateBy,jdbcType=VARCHAR},
      update_time = #{updateTime,jdbcType=TIMESTAMP},
      del_flag = #{delFlag,jdbcType=VARCHAR},
    </trim>
  </insert>
  <insert id="insertOrUpdateSelective" keyColumn="id" keyProperty="id" parameterType="com.jsowell.pile.domain.ClearingWithdrawInfo" useGeneratedKeys="true">
    <!--@mbg.generated-->
    insert into clearing_withdraw_info
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="merchantId != null">
        merchant_id,
      </if>
      <if test="orderNo != null">
        order_no,
      </if>
      <if test="withdrawCode != null">
        withdraw_code,
      </if>
      <if test="withdrawStatus != null">
        withdraw_status,
      </if>
      <if test="withdrawAmt != null">
        withdraw_amt,
      </if>
      <if test="feeAmt != null">
        fee_amt,
      </if>
      <if test="creditedAmt != null">
        credited_amt,
      </if>
      <if test="applicationTime != null">
        application_time,
      </if>
      <if test="arrivalTime != null">
        arrival_time,
      </if>
      <if test="createBy != null">
        create_by,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="updateBy != null">
        update_by,
      </if>
      <if test="updateTime != null">
        update_time,
      </if>
      <if test="delFlag != null">
        del_flag,
      </if>
    </trim>
    values
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=INTEGER},
      </if>
      <if test="merchantId != null">
        #{merchantId,jdbcType=VARCHAR},
      </if>
      <if test="orderNo != null">
        #{orderNo,jdbcType=VARCHAR},
      </if>
      <if test="withdrawCode != null">
        #{withdrawCode,jdbcType=VARCHAR},
      </if>
      <if test="withdrawStatus != null">
        #{withdrawStatus,jdbcType=VARCHAR},
      </if>
      <if test="withdrawAmt != null">
        #{withdrawAmt,jdbcType=DECIMAL},
      </if>
      <if test="feeAmt != null">
        #{feeAmt,jdbcType=DECIMAL},
      </if>
      <if test="creditedAmt != null">
        #{creditedAmt,jdbcType=DECIMAL},
      </if>
      <if test="applicationTime != null">
        #{applicationTime,jdbcType=TIMESTAMP},
      </if>
      <if test="arrivalTime != null">
        #{arrivalTime,jdbcType=TIMESTAMP},
      </if>
      <if test="createBy != null">
        #{createBy,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateBy != null">
        #{updateBy,jdbcType=VARCHAR},
      </if>
      <if test="updateTime != null">
        #{updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="delFlag != null">
        #{delFlag,jdbcType=VARCHAR},
      </if>
    </trim>
    on duplicate key update 
    <trim suffixOverrides=",">
      <if test="id != null">
        id = #{id,jdbcType=INTEGER},
      </if>
      <if test="merchantId != null">
        merchant_id = #{merchantId,jdbcType=VARCHAR},
      </if>
      <if test="orderNo != null">
        order_no = #{orderNo,jdbcType=VARCHAR},
      </if>
      <if test="withdrawCode != null">
        withdraw_code = #{withdrawCode,jdbcType=VARCHAR},
      </if>
      <if test="withdrawStatus != null">
        withdraw_status = #{withdrawStatus,jdbcType=VARCHAR},
      </if>
      <if test="withdrawAmt != null">
        withdraw_amt = #{withdrawAmt,jdbcType=DECIMAL},
      </if>
      <if test="feeAmt != null">
        fee_amt = #{feeAmt,jdbcType=DECIMAL},
      </if>
      <if test="creditedAmt != null">
        credited_amt = #{creditedAmt,jdbcType=DECIMAL},
      </if>
      <if test="applicationTime != null">
        application_time = #{applicationTime,jdbcType=TIMESTAMP},
      </if>
      <if test="arrivalTime != null">
        arrival_time = #{arrivalTime,jdbcType=TIMESTAMP},
      </if>
      <if test="createBy != null">
        create_by = #{createBy,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateBy != null">
        update_by = #{updateBy,jdbcType=VARCHAR},
      </if>
      <if test="updateTime != null">
        update_time = #{updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="delFlag != null">
        del_flag = #{delFlag,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>

  <select id="selectByWithdrawCode" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from clearing_withdraw_info
    where del_flag = '0'
    and withdraw_code = #{withdrawCode,jdbcType=VARCHAR}
  </select>

  <select id="selectWithdrawInfoByOrderCode" resultType="com.jsowell.pile.vo.web.ClearingBillVO">
    select
      t1.clearing_bill_code as clearingBillCode,
        t3.withdraw_code as withdrawCode,
        t3.withdraw_status as withdrawStatus
    from clearing_bill_info t1
    left join clearing_bill_detail t2 on t2.clearing_bill_code = t1.clearing_bill_code and t2.del_flag = '0'
    left join clearing_withdraw_info t3 on t3.withdraw_code = t1.withdraw_code and t3.del_flag = '0'
    where t1.del_flag = '0'
    and t2.order_code = #{orderCode,jdbcType=VARCHAR}
  </select>

  <select id="selectWithdrawInfoByOrderCodeList" resultType="com.jsowell.pile.vo.web.ClearingBillVO">
    select
    t1.clearing_bill_code as clearingBillCode,
    t2.order_code as orderCode,
    t5.settle_amount as settleAmount,
    t3.withdraw_code as withdrawCode,
    t3.withdraw_status as withdrawStatus,
    t4.payment_id as paymentId
    from clearing_bill_info t1
    left join clearing_bill_detail t2 on t2.clearing_bill_code = t1.clearing_bill_code and t2.del_flag = '0'
    left join clearing_withdraw_info t3 on t3.withdraw_code = t1.withdraw_code and t3.del_flag = '0'
    left join adapay_callback_record t4 on t4.order_code = t2.order_code and t4.del_flag = '0'
    left join order_basic_info t5 on t5.order_code = t2.order_code and t5.del_flag = '0'
    where t1.del_flag = '0'
    and t2.order_code in
    <foreach close=")" collection="orderCodeList" item="orderCode" open="(" separator=",">
      #{orderCode,jdbcType=VARCHAR}
    </foreach>
  </select>

  <select id="selectByMerchantId" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from clearing_withdraw_info
    where del_flag = '0'
    and merchant_id = #{merchantId,jdbcType=VARCHAR}
  </select>
</mapper>