<?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.goafanti.common.dao.TOrderBillNewMapper">
  <resultMap id="BaseResultMap" type="com.goafanti.common.model.TOrderBillNew">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed Feb 19 08:54:03 CST 2020.
    -->
    <id column="bill_no" jdbcType="VARCHAR" property="billNo" />
    <result column="order_no" jdbcType="VARCHAR" property="orderNo" />
    <result column="creater" jdbcType="VARCHAR" property="creater" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
    <result column="payee_id" jdbcType="VARCHAR" property="payeeId" />
    <result column="payer_id" jdbcType="VARCHAR" property="payerId" />
    <result column="transaction_amount" jdbcType="DECIMAL" property="transactionAmount" />
    <result column="transaction_subject" jdbcType="INTEGER" property="transactionSubject" />
    <result column="transaction_channel" jdbcType="INTEGER" property="transactionChannel" />
    <result column="remarks" jdbcType="VARCHAR" property="remarks" />
    <result column="confirm_sign" jdbcType="INTEGER" property="confirmSign" />
    <result column="delete_sign" jdbcType="TINYINT" property="deleteSign" />
    <result column="financial_pay_no" jdbcType="VARCHAR" property="financialPayNo" />
    <result column="financial_pay_time" jdbcType="TIMESTAMP" property="financialPayTime" />
    <result column="type" jdbcType="INTEGER" property="type" />
    <result column="delete_time" jdbcType="TIMESTAMP" property="deleteTime" />
    <result column="refund_time" jdbcType="TIMESTAMP" property="refundTime" />
  </resultMap>
  <sql id="Example_Where_Clause">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed Feb 19 08:54:03 CST 2020.
    -->
    <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">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed Feb 19 08:54:03 CST 2020.
    -->
    <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">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed Feb 19 08:54:03 CST 2020.
    -->
    bill_no, order_no, creater, create_time, update_time, payee_id, payer_id, transaction_amount, 
    transaction_subject, transaction_channel, remarks, confirm_sign, delete_sign, financial_pay_no, 
    financial_pay_time, type, delete_time, refund_time
  </sql>
  <select id="selectByExample" parameterType="com.goafanti.common.model.TOrderBillNewExample" resultMap="BaseResultMap">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed Feb 19 08:54:03 CST 2020.
    -->
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from t_order_bill_new
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed Feb 19 08:54:03 CST 2020.
    -->
    select 
    <include refid="Base_Column_List" />
    from t_order_bill_new
    where bill_no = #{billNo,jdbcType=VARCHAR}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed Feb 19 08:54:03 CST 2020.
    -->
    delete from t_order_bill_new
    where bill_no = #{billNo,jdbcType=VARCHAR}
  </delete>
  <delete id="deleteByExample" parameterType="com.goafanti.common.model.TOrderBillNewExample">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed Feb 19 08:54:03 CST 2020.
    -->
    delete from t_order_bill_new
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.goafanti.common.model.TOrderBillNew">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed Feb 19 08:54:03 CST 2020.
    -->
    insert into t_order_bill_new (bill_no, order_no, creater, 
      create_time, update_time, payee_id, 
      payer_id, transaction_amount, transaction_subject, 
      transaction_channel, remarks, confirm_sign, 
      delete_sign, financial_pay_no, financial_pay_time, 
      type, delete_time, refund_time
      )
    values (#{billNo,jdbcType=VARCHAR}, #{orderNo,jdbcType=VARCHAR}, #{creater,jdbcType=VARCHAR}, 
      #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}, #{payeeId,jdbcType=VARCHAR}, 
      #{payerId,jdbcType=VARCHAR}, #{transactionAmount,jdbcType=DECIMAL}, #{transactionSubject,jdbcType=INTEGER}, 
      #{transactionChannel,jdbcType=INTEGER}, #{remarks,jdbcType=VARCHAR}, #{confirmSign,jdbcType=INTEGER}, 
      #{deleteSign,jdbcType=TINYINT}, #{financialPayNo,jdbcType=VARCHAR}, #{financialPayTime,jdbcType=TIMESTAMP}, 
      #{type,jdbcType=INTEGER}, #{deleteTime,jdbcType=TIMESTAMP}, #{refundTime,jdbcType=TIMESTAMP}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.goafanti.common.model.TOrderBillNew">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed Feb 19 08:54:03 CST 2020.
    -->
    insert into t_order_bill_new
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="billNo != null">
        bill_no,
      </if>
      <if test="orderNo != null">
        order_no,
      </if>
      <if test="creater != null">
        creater,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="updateTime != null">
        update_time,
      </if>
      <if test="payeeId != null">
        payee_id,
      </if>
      <if test="payerId != null">
        payer_id,
      </if>
      <if test="transactionAmount != null">
        transaction_amount,
      </if>
      <if test="transactionSubject != null">
        transaction_subject,
      </if>
      <if test="transactionChannel != null">
        transaction_channel,
      </if>
      <if test="remarks != null">
        remarks,
      </if>
      <if test="confirmSign != null">
        confirm_sign,
      </if>
      <if test="deleteSign != null">
        delete_sign,
      </if>
      <if test="financialPayNo != null">
        financial_pay_no,
      </if>
      <if test="financialPayTime != null">
        financial_pay_time,
      </if>
      <if test="type != null">
        type,
      </if>
      <if test="deleteTime != null">
        delete_time,
      </if>
      <if test="refundTime != null">
        refund_time,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="billNo != null">
        #{billNo,jdbcType=VARCHAR},
      </if>
      <if test="orderNo != null">
        #{orderNo,jdbcType=VARCHAR},
      </if>
      <if test="creater != null">
        #{creater,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateTime != null">
        #{updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="payeeId != null">
        #{payeeId,jdbcType=VARCHAR},
      </if>
      <if test="payerId != null">
        #{payerId,jdbcType=VARCHAR},
      </if>
      <if test="transactionAmount != null">
        #{transactionAmount,jdbcType=DECIMAL},
      </if>
      <if test="transactionSubject != null">
        #{transactionSubject,jdbcType=INTEGER},
      </if>
      <if test="transactionChannel != null">
        #{transactionChannel,jdbcType=INTEGER},
      </if>
      <if test="remarks != null">
        #{remarks,jdbcType=VARCHAR},
      </if>
      <if test="confirmSign != null">
        #{confirmSign,jdbcType=INTEGER},
      </if>
      <if test="deleteSign != null">
        #{deleteSign,jdbcType=TINYINT},
      </if>
      <if test="financialPayNo != null">
        #{financialPayNo,jdbcType=VARCHAR},
      </if>
      <if test="financialPayTime != null">
        #{financialPayTime,jdbcType=TIMESTAMP},
      </if>
      <if test="type != null">
        #{type,jdbcType=INTEGER},
      </if>
      <if test="deleteTime != null">
        #{deleteTime,jdbcType=TIMESTAMP},
      </if>
      <if test="refundTime != null">
        #{refundTime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.goafanti.common.model.TOrderBillNewExample" resultType="java.lang.Long">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed Feb 19 08:54:03 CST 2020.
    -->
    select count(*) from t_order_bill_new
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed Feb 19 08:54:03 CST 2020.
    -->
    update t_order_bill_new
    <set>
      <if test="record.billNo != null">
        bill_no = #{record.billNo,jdbcType=VARCHAR},
      </if>
      <if test="record.orderNo != null">
        order_no = #{record.orderNo,jdbcType=VARCHAR},
      </if>
      <if test="record.creater != null">
        creater = #{record.creater,jdbcType=VARCHAR},
      </if>
      <if test="record.createTime != null">
        create_time = #{record.createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.updateTime != null">
        update_time = #{record.updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.payeeId != null">
        payee_id = #{record.payeeId,jdbcType=VARCHAR},
      </if>
      <if test="record.payerId != null">
        payer_id = #{record.payerId,jdbcType=VARCHAR},
      </if>
      <if test="record.transactionAmount != null">
        transaction_amount = #{record.transactionAmount,jdbcType=DECIMAL},
      </if>
      <if test="record.transactionSubject != null">
        transaction_subject = #{record.transactionSubject,jdbcType=INTEGER},
      </if>
      <if test="record.transactionChannel != null">
        transaction_channel = #{record.transactionChannel,jdbcType=INTEGER},
      </if>
      <if test="record.remarks != null">
        remarks = #{record.remarks,jdbcType=VARCHAR},
      </if>
      <if test="record.confirmSign != null">
        confirm_sign = #{record.confirmSign,jdbcType=INTEGER},
      </if>
      <if test="record.deleteSign != null">
        delete_sign = #{record.deleteSign,jdbcType=TINYINT},
      </if>
      <if test="record.financialPayNo != null">
        financial_pay_no = #{record.financialPayNo,jdbcType=VARCHAR},
      </if>
      <if test="record.financialPayTime != null">
        financial_pay_time = #{record.financialPayTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.type != null">
        type = #{record.type,jdbcType=INTEGER},
      </if>
      <if test="record.deleteTime != null">
        delete_time = #{record.deleteTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.refundTime != null">
        refund_time = #{record.refundTime,jdbcType=TIMESTAMP},
      </if>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed Feb 19 08:54:03 CST 2020.
    -->
    update t_order_bill_new
    set bill_no = #{record.billNo,jdbcType=VARCHAR},
      order_no = #{record.orderNo,jdbcType=VARCHAR},
      creater = #{record.creater,jdbcType=VARCHAR},
      create_time = #{record.createTime,jdbcType=TIMESTAMP},
      update_time = #{record.updateTime,jdbcType=TIMESTAMP},
      payee_id = #{record.payeeId,jdbcType=VARCHAR},
      payer_id = #{record.payerId,jdbcType=VARCHAR},
      transaction_amount = #{record.transactionAmount,jdbcType=DECIMAL},
      transaction_subject = #{record.transactionSubject,jdbcType=INTEGER},
      transaction_channel = #{record.transactionChannel,jdbcType=INTEGER},
      remarks = #{record.remarks,jdbcType=VARCHAR},
      confirm_sign = #{record.confirmSign,jdbcType=INTEGER},
      delete_sign = #{record.deleteSign,jdbcType=TINYINT},
      financial_pay_no = #{record.financialPayNo,jdbcType=VARCHAR},
      financial_pay_time = #{record.financialPayTime,jdbcType=TIMESTAMP},
      type = #{record.type,jdbcType=INTEGER},
      delete_time = #{record.deleteTime,jdbcType=TIMESTAMP},
      refund_time = #{record.refundTime,jdbcType=TIMESTAMP}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.goafanti.common.model.TOrderBillNew">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed Feb 19 08:54:03 CST 2020.
    -->
    update t_order_bill_new
    <set>
      <if test="orderNo != null">
        order_no = #{orderNo,jdbcType=VARCHAR},
      </if>
      <if test="creater != null">
        creater = #{creater,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateTime != null">
        update_time = #{updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="payeeId != null">
        payee_id = #{payeeId,jdbcType=VARCHAR},
      </if>
      <if test="payerId != null">
        payer_id = #{payerId,jdbcType=VARCHAR},
      </if>
      <if test="transactionAmount != null">
        transaction_amount = #{transactionAmount,jdbcType=DECIMAL},
      </if>
      <if test="transactionSubject != null">
        transaction_subject = #{transactionSubject,jdbcType=INTEGER},
      </if>
      <if test="transactionChannel != null">
        transaction_channel = #{transactionChannel,jdbcType=INTEGER},
      </if>
      <if test="remarks != null">
        remarks = #{remarks,jdbcType=VARCHAR},
      </if>
      <if test="confirmSign != null">
        confirm_sign = #{confirmSign,jdbcType=INTEGER},
      </if>
      <if test="deleteSign != null">
        delete_sign = #{deleteSign,jdbcType=TINYINT},
      </if>
      <if test="financialPayNo != null">
        financial_pay_no = #{financialPayNo,jdbcType=VARCHAR},
      </if>
      <if test="financialPayTime != null">
        financial_pay_time = #{financialPayTime,jdbcType=TIMESTAMP},
      </if>
      <if test="type != null">
        type = #{type,jdbcType=INTEGER},
      </if>
      <if test="deleteTime != null">
        delete_time = #{deleteTime,jdbcType=TIMESTAMP},
      </if>
      <if test="refundTime != null">
        refund_time = #{refundTime,jdbcType=TIMESTAMP},
      </if>
    </set>
    where bill_no = #{billNo,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.goafanti.common.model.TOrderBillNew">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed Feb 19 08:54:03 CST 2020.
    -->
    update t_order_bill_new
    set order_no = #{orderNo,jdbcType=VARCHAR},
      creater = #{creater,jdbcType=VARCHAR},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      update_time = #{updateTime,jdbcType=TIMESTAMP},
      payee_id = #{payeeId,jdbcType=VARCHAR},
      payer_id = #{payerId,jdbcType=VARCHAR},
      transaction_amount = #{transactionAmount,jdbcType=DECIMAL},
      transaction_subject = #{transactionSubject,jdbcType=INTEGER},
      transaction_channel = #{transactionChannel,jdbcType=INTEGER},
      remarks = #{remarks,jdbcType=VARCHAR},
      confirm_sign = #{confirmSign,jdbcType=INTEGER},
      delete_sign = #{deleteSign,jdbcType=TINYINT},
      financial_pay_no = #{financialPayNo,jdbcType=VARCHAR},
      financial_pay_time = #{financialPayTime,jdbcType=TIMESTAMP},
      type = #{type,jdbcType=INTEGER},
      delete_time = #{deleteTime,jdbcType=TIMESTAMP},
      refund_time = #{refundTime,jdbcType=TIMESTAMP}
    where bill_no = #{billNo,jdbcType=VARCHAR}
  </update>
  <!-- 根据订单编号获得已交款 -->
  <select id="getAmountByOid" parameterType="java.lang.String" resultType="java.math.BigDecimal">
  	select ifnull(sum(transaction_amount),0) amout from t_order_bill_new
  	where delete_sign = 0 and order_no = #{_parameter,jdbcType=VARCHAR}
  </select>
  <!-- 根据流水编号获得流水详情 -->
  <select id="getOneRefundFlow" parameterType="java.lang.String" resultType="com.goafanti.common.model.TOrderBillNew">
  	select 
  	b.bill_no as billNo, b.order_no as orderNo, b.creater, b.create_time as createTime, b.update_time as updateTime, 
  	b.payee_id as payeeId, b.payer_id as payerId, b.transaction_amount as transactionAmount, 
    b.transaction_subject as transactionSubject, b.transaction_channel as transactionChannel,  
    b.remarks, b.confirm_sign confirmSign, b.delete_sign deleteSign, b.financial_pay_no as financialPayNo, 
    b.financial_pay_time as financialPayTimes, u.nickname as payerName, a.nickname as payeeName
     from t_order_bill_new b 
  	left join `user` u on b.payer_id = u.id
  	left join `user` a on b.payee_id = a.id
  	where b.delete_sign = 0 and bill_no = #{_parameter,jdbcType=VARCHAR}
  </select>
  <!-- 根据订单编号查看该订单相关的所有流水 -->
  <select id="getOneOrderAllRefundFlow" parameterType="java.lang.String" resultType="com.goafanti.common.model.TOrderBillNew">
  	select 
  	b.bill_no as billNo, b.order_no as orderNo, b.creater, b.create_time as createTime, b.update_time as updateTime, 
  	b.payee_id as payeeId, b.payer_id as payerId, b.transaction_amount as transactionAmount, 
    b.transaction_subject as transactionSubject, b.transaction_channel as transactionChannel,  
    b.remarks, b.confirm_sign confirmSign, b.delete_sign deleteSign, b.financial_pay_no as financialPayNo, 
    b.financial_pay_time as financialPayTimes, u.nickname as payerName, a.nickname as payeeName
     from t_order_bill_new b 
  	left join `user` u on b.payer_id = u.id
  	left join `user` a on b.payee_id = a.id
  	where b.delete_sign = 0 and order_no = #{_parameter,jdbcType=VARCHAR}
  </select>
  <!-- 查看自己创建的流水数据 -->
  <select id="myBillList" parameterType="Map" resultType="com.goafanti.common.model.TOrderBillNew">
	   select b.bill_no as billNo, b.order_no as orderNo, b.transaction_amount as transactionAmount,
		date_format(b.create_time, '%Y-%m-%d %H:%I:%S') as createTimes, b.payer_id as payerId, b.payee_id as payeeId,
		tm.buyer_name as payerName, b.remarks, o.contract_no contractNo, b.transaction_subject as transactionSubject,
		b.transaction_channel as transactionChannel, b.delete_sign deleteSign, date_format(b.financial_pay_time, '%Y-%m-%d') as financialPayTimes,
		b.financial_pay_no as financialPayNo, date_format(b.refund_time, '%Y-%m-%d') refundTimes, b.creater, ad.name as createrName,
		tm.salesman_name saleName, b.type, date_format(b.delete_time, '%Y-%m-%d %H:%I:%S') as deleteTimes
		from t_order_bill_new b 
		left join `user` u on b.payer_id = u.id 
		left join `user` a on b.payee_id = a.id 
		left join admin ad on b.creater = ad.id
		left join t_order_new o on o.order_no = b.order_no
		left join t_order_mid tm on tm.order_no=b.order_no
		left join department d on o.order_dep = d.id
	  	where 1=1 
	  	<if test="fids != null and fids.size() &gt; 0">
	  	and d.finance_id in 
	   <foreach close=")" collection="fids" index="" item="item" open="(" separator=",">
       		#{item}
     	</foreach>
		</if>
  	<if test="b.orderNo != null and b.orderNo != &quot;&quot;">
  	and b.order_no = #{b.orderNo,jdbcType=VARCHAR}
  	</if>
  	<if test="b.departmentId != null and b.departmentId != &quot;&quot;">
	and  o.order_dep = #{b.departmentId,jdbcType=VARCHAR}
	</if>
  	<if test="b.creater != null and b.creater != &quot;&quot;">
  	and b.creater = #{b.creater,jdbcType=VARCHAR}
  	</if>
  	<if test="b.payerName != null and b.payerName != &quot;&quot;">
  	<bind name="nn" value="'%' + b.payerName + '%'" />
  	and tm.buyer_name like #{nn,jdbcType=VARCHAR}
  	</if>
  	<if test="b.payeeName != null and b.payeeName != &quot;&quot;">
  	<bind name="n" value="'%' + b.payeeName + '%'" />
  	and a.nickname like #{n,jdbcType=VARCHAR}
  	</if>
  	<if test="b.startTime != null and b.startTime != &quot;&quot; and b.endTime != null and b.endTime != &quot;&quot;">
  	<bind name="a" value="b.startTime + ' 00:00:00'" />
  	<bind name="e" value="b.endTime + ' 23:59:59'" />
  	and b.create_time between #{a,jdbcType=VARCHAR} and #{e,jdbcType=VARCHAR}
  	</if>
  	order by b.create_time desc
  	<if test="page_sql!=null">
			${page_sql}
	</if>
  </select>
  <select id="myBillCount" parameterType="Map" resultType="java.lang.Integer">
  	select count(*)
  	from t_order_bill_new b 
		left join `user` u on b.payer_id = u.id 
		left join `user` a on b.payee_id = a.id 
		left join admin ad on b.creater = ad.id
		left join t_order_new o on o.order_no = b.order_no
		left join t_order_mid tm on tm.order_no=b.order_no
	  	left join department d on o.order_dep = d.id
	  	where 1=1 
	  	<if test="fids != null and fids.size() &gt; 0">
	  	and d.finance_id in 
	   <foreach close=")" collection="fids" index="" item="item" open="(" separator=",">
       		#{item}
     	</foreach>
		</if>
  	<if test="b.orderNo != null and b.orderNo != &quot;&quot;">
  	and b.order_no = #{b.orderNo,jdbcType=VARCHAR}
  	</if>
  	<if test="b.creater != null and b.creater != &quot;&quot;">
  	and b.creater = #{b.creater,jdbcType=VARCHAR}
  	</if>
  	<if test="b.departmentId != null and b.departmentId != &quot;&quot;">
	and  o.order_dep = #{b.departmentId,jdbcType=VARCHAR}
	</if>
  	<if test="b.payerName != null and b.payerName != &quot;&quot;">
  	<bind name="nn" value="'%' + b.payerName + '%'" />
  	and tm.buyer_name like #{nn,jdbcType=VARCHAR}
  	</if>
  	<if test="b.payeeName != null and b.payeeName != &quot;&quot;">
  	<bind name="n" value="'%' + b.payeeName + '%'" />
  	and a.nickname like #{n,jdbcType=VARCHAR}
  	</if>
  	<if test="b.startTime != null and b.startTime != &quot;&quot; and b.endTime != null and b.endTime != &quot;&quot;">
  	<bind name="a" value="b.startTime + ' 00:00:00'" />
  	<bind name="e" value="b.endTime + ' 23:59:59'" />
  	and b.create_time between #{a,jdbcType=VARCHAR} and #{e,jdbcType=VARCHAR}
  	</if>
  </select>
  <!-- 带条件的流水部门 -->
  <select id="getDeptBySome" parameterType="com.goafanti.common.model.TOrderBillNew" resultType="com.goafanti.common.model.TOrderBillNew">
  	select distinct
	  	d.id as departmentId, d.name as departmentName
	  	from t_order_bill_new b
	  	left join `user` u on b.payer_id = u.id
	  	left join `user` a on b.payee_id = a.id
	  	left join t_order_new o on o.order_no = b.order_no
	  	left join admin oa on oa.id = o.salesman_id 
	  	left join department d on oa.department_id = d.id
	  	where 
	  	b.delete_sign = 0 
	  	<if test="payerName != null and payerName != &quot;&quot;">
	  	<bind name="nn" value="'%' + payerName + '%'" />
	  	and u.nickname like #{nn,jdbcType=VARCHAR}
	  	</if>
	  	<if test="payeeName != null and payeeName != &quot;&quot;">
	  	<bind name="n" value="'%' + payeeName + '%'" />
	  	and a.nickname like #{n,jdbcType=VARCHAR}
	  	</if>
	  	<if test="startTime != null and startTime != &quot;&quot; and endTime != null and endTime != &quot;&quot;">
	  	<bind name="a" value="startTime + ' 00:00:00'" />
	  	<bind name="e" value="endTime + ' 23:59:59'" />
	  	and b.create_time between #{a,jdbcType=VARCHAR} and #{e,jdbcType=VARCHAR}
	  	</if>
  </select>
  <!-- 获得流水记录 -->
  <select id="getBillData" parameterType="com.goafanti.common.model.TOrderBillNew" resultType="com.goafanti.common.model.TOrderBillNew">
  select 
  	b.bill_no as billNo, b.order_no as orderNo, b.transaction_amount as transactionAmount,
  	u.nickname as payerName, a.nickname as payeeName, 
  	b.transaction_subject as transactionSubject, b.transaction_channel as transactionChannel, 
  	b.financial_pay_time as financialPayTimes,b.financial_pay_no as financialPayNo,
  	b.creater, ad.name as createrName, oa.name as saleName, b.create_time as createTime
  	from t_order_bill_new b
  	left join `user` u on b.payer_id = u.id
  	left join `user` a on b.payee_id = a.id
  	left join admin ad on b.creater = ad.id
  	left join t_order_new o on o.order_no = b.order_no
  	left join admin oa on oa.id = o.salesman_id
  	where b.delete_sign = 0 
  	<if test="payerName != null and payerName != &quot;&quot;">
  	<bind name="nn" value="'%' + payerName + '%'" />
  	and u.nickname like #{nn,jdbcType=VARCHAR}
  	</if>
  	<if test="payeeName != null and payeeName != &quot;&quot;">
  	<bind name="n" value="'%' + payeeName + '%'" />
  	and a.nickname like #{n,jdbcType=VARCHAR}
  	</if>
  	<if test="departmentId != null and departmentId != &quot;&quot; ">
  	and oa.department_id = #{departmentId,jdbcType=VARCHAR}
  	</if>
  	<if test="startTime != null and startTime != &quot;&quot; and endTime != null and endTime != &quot;&quot;">
  	<bind name="a" value="startTime + ' 00:00:00'" />
  	<bind name="e" value="endTime + ' 23:59:59'" />
  	and b.create_time between #{a,jdbcType=VARCHAR} and #{e,jdbcType=VARCHAR}
  	</if>
  	order by b.order_no, b.creater , b.financial_pay_time
 </select>
 <select id="conutAmountByOrderNo" resultType="java.math.BigDecimal">
 select ifnull(sum(a.transaction_amount),0) amount from t_order_bill_new a
where  a.order_no= #{orderNo,jdbcType=VARCHAR};
 </select>
 <select id="selectByOrderNo" resultType="com.goafanti.order.bo.BillBo">
 select date_format(a.financial_pay_time,'%Y-%m-%d') payTime,a.transaction_amount transactionAmount,b.name aName from t_order_bill_new a 
left join admin b on a.creater=b.id
where order_no= #{orderNo,jdbcType=VARCHAR};	
 </select>
 <insert id="insertBatch" parameterType="com.goafanti.common.model.TOrderBillNew">
    insert into t_order_bill_new (bill_no, order_no, creater, 
      create_time, update_time, payee_id, 
      payer_id, transaction_amount, transaction_subject, 
      transaction_channel, remarks, confirm_sign, 
      delete_sign, financial_pay_no, financial_pay_time, 
      type)values 
       <foreach collection="list" index="index" item="item" separator=",">
      	(#{item.billNo,jdbcType=VARCHAR}, #{item.orderNo,jdbcType=VARCHAR}, #{item.creater,jdbcType=VARCHAR}, 
      #{item.createTime,jdbcType=TIMESTAMP}, #{item.updateTime,jdbcType=TIMESTAMP}, #{item.payeeId,jdbcType=VARCHAR}, 
      #{item.payerId,jdbcType=VARCHAR}, #{item.transactionAmount,jdbcType=DECIMAL}, #{item.transactionSubject,jdbcType=INTEGER}, 
      #{item.transactionChannel,jdbcType=INTEGER}, #{item.remarks,jdbcType=VARCHAR}, #{item.confirmSign,jdbcType=INTEGER}, 
      #{item.deleteSign,jdbcType=TINYINT}, #{item.financialPayNo,jdbcType=VARCHAR}, #{item.financialPayTime,jdbcType=TIMESTAMP}, 
      #{item.type,jdbcType=INTEGER})
    </foreach>
  </insert>
</mapper>