<?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.liquidnet.service.account.funding.mapper.FinAccountBillMapper" >
  <resultMap id="BaseResultMap" type="com.liquidnet.service.account.funding.entity.FinAccountBill" >
    <result column="FAB0" property="billNo" jdbcType="VARCHAR" />
    <result column="FAB1" property="accNo" jdbcType="VARCHAR" />
    <result column="FAB2" property="walletId" jdbcType="VARCHAR" />
    <result column="FAB3" property="finId" jdbcType="VARCHAR" />
    <result column="FAB4" property="category" jdbcType="VARCHAR" />
    <result column="FAB5" property="amount" jdbcType="DECIMAL" />
    <result column="FAB6" property="transNo" jdbcType="VARCHAR" />
    <result column="FAB7" property="accStatus" jdbcType="INTEGER" />
    <result column="FAB8" property="tracingNo" jdbcType="VARCHAR" />
    <result column="FAB9" property="tracingTime" jdbcType="TIMESTAMP" />
    <result column="FAB10" property="createTime" jdbcType="TIMESTAMP" />
    <result column="FAB11" property="remark" jdbcType="VARCHAR" />
  </resultMap>
  <sql id="Example_Where_Clause" >
    <where >
      <foreach collection="oredCriteria" item="criteria" separator="or" >
        <if test="criteria.valid" >
          <trim prefix="(" suffix=")" prefixOverrides="and" >
            <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 collection="criterion.value" item="listItem" open="(" close=")" 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="(" suffix=")" prefixOverrides="and" >
            <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 collection="criterion.value" item="listItem" open="(" close=")" separator="," >
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Base_Column_List" >
    FAB0, FAB1, FAB2, FAB3, FAB4, FAB5, FAB6, FAB7, FAB8,
    FAB9, FAB10, FAB11
  </sql>
  <select id="selectByExample" resultMap="BaseResultMap" parameterType="com.liquidnet.service.account.funding.entity.FinAccountBillExample" >
    select
    <if test="distinct" >
      distinct
    </if>
    <include refid="Base_Column_List" />
    from FIN_AC_N02
    <if test="_parameter != null" >
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null" >
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String" >
    select
    <include refid="Base_Column_List" />
    from FIN_AC_N02
    where FAB0 = #{billId,jdbcType=VARCHAR}
  </select>
  <insert id="insert" parameterType="com.liquidnet.service.account.funding.entity.FinAccountBill" >
    insert into FIN_AC_N02 (FAB0, FAB1, FAB2,
      FAB3, FAB4, FAB5,
      FAB6, FAB7, FAB8,
      FAB9, FAB10, FAB11)
    values (#{billNo,jdbcType=VARCHAR}, #{accNo,jdbcType=VARCHAR}, #{walletId,jdbcType=VARCHAR},
      #{finId,jdbcType=VARCHAR}, #{category,jdbcType=VARCHAR}, #{amount,jdbcType=DECIMAL},
      #{transNo,jdbcType=VARCHAR}, #{accStatus,jdbcType=INTEGER}, #{tracingNo,jdbcType=VARCHAR},
      #{tracingTime,jdbcType=TIMESTAMP}, #{createTime,jdbcType=TIMESTAMP}, #{remark,jdbcType=VARCHAR})
  </insert>
  <insert id="insertSelective" parameterType="com.liquidnet.service.account.funding.entity.FinAccountBill" >
    insert into FIN_AC_N02
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="billNo != null" >
        FAB0,
      </if>
      <if test="accNo != null" >
        FAB1,
      </if>
      <if test="walletId != null" >
        FAB2,
      </if>
      <if test="finId != null" >
        FAB3,
      </if>
      <if test="category != null" >
        FAB4,
      </if>
      <if test="amount != null" >
        FAB5,
      </if>
      <if test="transNo != null" >
        FAB6,
      </if>
      <if test="accStatus != null" >
        FAB7,
      </if>
      <if test="tracingNo != null" >
        FAB8,
      </if>
      <if test="tracingTime != null" >
        FAB9,
      </if>
      <if test="createTime != null" >
        FAB10,
      </if>
      <if test="remark != null" >
        FAB11,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="billNo != null" >
        #{billNo,jdbcType=VARCHAR},
      </if>
      <if test="accNo != null" >
        #{accNo,jdbcType=VARCHAR},
      </if>
      <if test="walletId != null" >
        #{walletId,jdbcType=VARCHAR},
      </if>
      <if test="finId != null" >
        #{finId,jdbcType=VARCHAR},
      </if>
      <if test="category != null" >
        #{category,jdbcType=VARCHAR},
      </if>
      <if test="amount != null" >
        #{amount,jdbcType=DECIMAL},
      </if>
      <if test="transNo != null" >
        #{transNo,jdbcType=VARCHAR},
      </if>
      <if test="accStatus != null" >
        #{accStatus,jdbcType=INTEGER},
      </if>
      <if test="tracingNo != null" >
        #{tracingNo,jdbcType=VARCHAR},
      </if>
      <if test="tracingTime != null" >
        #{tracingTime,jdbcType=TIMESTAMP},
      </if>
      <if test="createTime != null" >
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="remark != null" >
        #{remark,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.liquidnet.service.account.funding.entity.FinAccountBillExample" resultType="java.lang.Integer" >
    select count(*) from FIN_AC_N02
    <if test="_parameter != null" >
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map" >
    update FIN_AC_N02
    <set >
      <if test="record.billNo != null" >
        FAB0 = #{record.billNo,jdbcType=VARCHAR},
      </if>
      <if test="record.accNo != null" >
        FAB1 = #{record.accNo,jdbcType=VARCHAR},
      </if>
      <if test="record.walletId != null" >
        FAB2 = #{record.walletId,jdbcType=VARCHAR},
      </if>
      <if test="record.finId != null" >
        FAB3 = #{record.finId,jdbcType=VARCHAR},
      </if>
      <if test="record.category != null" >
        FAB4 = #{record.category,jdbcType=VARCHAR},
      </if>
      <if test="record.amount != null" >
        FAB5 = #{record.amount,jdbcType=DECIMAL},
      </if>
      <if test="record.transNo != null" >
        FAB6 = #{record.transNo,jdbcType=VARCHAR},
      </if>
      <if test="record.accStatus != null" >
        FAB7 = #{record.accStatus,jdbcType=INTEGER},
      </if>
      <if test="record.tracingNo != null" >
        FAB8 = #{record.tracingNo,jdbcType=VARCHAR},
      </if>
      <if test="record.tracingTime != null" >
        FAB9 = #{record.tracingTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.createTime != null" >
        FAB10 = #{record.createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.remark != null" >
        FAB11 = #{record.remark,jdbcType=VARCHAR},
      </if>
    </set>
    <if test="_parameter != null" >
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map" >
    update FIN_AC_N02
    set FAB0 = #{record.billNo,jdbcType=VARCHAR},
      FAB1 = #{record.accNo,jdbcType=VARCHAR},
      FAB2 = #{record.walletId,jdbcType=VARCHAR},
      FAB3 = #{record.finId,jdbcType=VARCHAR},
      FAB4 = #{record.category,jdbcType=VARCHAR},
      FAB5 = #{record.amount,jdbcType=DECIMAL},
      FAB6 = #{record.transNo,jdbcType=VARCHAR},
      FAB7 = #{record.accStatus,jdbcType=INTEGER},
      FAB8 = #{record.tracingNo,jdbcType=VARCHAR},
      FAB9 = #{record.tracingTime,jdbcType=TIMESTAMP},
      FAB10 = #{record.createTime,jdbcType=TIMESTAMP},
      FAB11 = #{record.remark,jdbcType=VARCHAR}
    <if test="_parameter != null" >
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.liquidnet.service.account.funding.entity.FinAccountBill" >
    update FIN_AC_N02
    <set >
      <if test="accNo != null" >
        FAB1 = #{accNo,jdbcType=VARCHAR},
      </if>
      <if test="walletId != null" >
        FAB2 = #{walletId,jdbcType=VARCHAR},
      </if>
      <if test="finId != null" >
        FAB3 = #{finId,jdbcType=VARCHAR},
      </if>
      <if test="category != null" >
        FAB4 = #{category,jdbcType=VARCHAR},
      </if>
      <if test="amount != null" >
        FAB5 = #{amount,jdbcType=DECIMAL},
      </if>
      <if test="transNo != null" >
        FAB6 = #{transNo,jdbcType=VARCHAR},
      </if>
      <if test="accStatus != null" >
        FAB7 = #{accStatus,jdbcType=INTEGER},
      </if>
      <if test="tracingNo != null" >
        FAB8 = #{tracingNo,jdbcType=VARCHAR},
      </if>
      <if test="tracingTime != null" >
        FAB9 = #{tracingTime,jdbcType=TIMESTAMP},
      </if>
      <if test="createTime != null" >
        FAB10 = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="remark != null" >
        FAB11 = #{remark,jdbcType=VARCHAR},
      </if>
    </set>
    where FAB0 = #{billNo,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.liquidnet.service.account.funding.entity.FinAccountBill" >
    update FIN_AC_N02
    set FAB1 = #{accNo,jdbcType=VARCHAR},
      FAB2 = #{walletId,jdbcType=VARCHAR},
      FAB3 = #{finId,jdbcType=VARCHAR},
      FAB4 = #{category,jdbcType=VARCHAR},
      FAB5 = #{amount,jdbcType=DECIMAL},
      FAB6 = #{transNo,jdbcType=VARCHAR},
      FAB7 = #{accStatus,jdbcType=INTEGER},
      FAB8 = #{tracingNo,jdbcType=VARCHAR},
      FAB9 = #{tracingTime,jdbcType=TIMESTAMP},
      FAB10 = #{createTime,jdbcType=TIMESTAMP},
      FAB11 = #{remark,jdbcType=VARCHAR}
    where FAB0 = #{billId,jdbcType=VARCHAR}
  </update>


  <select id="selectByAccNoForGroup" resultType="com.liquidnet.service.account.funding.vo.AccountBalanceInfo">
    SELECT
    FAB1 accNo, SUM(FAB5) balance
    FROM ${tSeq}
    <where>
      <if test="list != null and list.size > 0">
        AND FAB1 IN
        <foreach collection="list" item="obj" index="idx" open="(" close=")" separator=",">
          #{obj,jdbcType=VARCHAR}
        </foreach>
      </if>
    </where>
    GROUP BY FAB1
  </select>
  <select id="selectCurrentBalance" resultType="java.math.BigDecimal">
    SELECT
    FAB1 accNo, SUM(FAB5) balance
    FROM ${tSeq}
    <where>
        AND FAB0 <![CDATA[<=]]> #{billNo,jdbcType=VARCHAR}
        AND FAB1 = #{accNo,jdbcType=VARCHAR}
    </where>
    GROUP BY FAB1
  </select>
</mapper>
