<?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.ssm.manage.mapper.AccountTradeRecordMapper">
  <resultMap id="BaseResultMap" type="com.ssm.manage.entity.AccountTradeRecord">
    <!--
      WARNING - @mbg.generated
    -->
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="store_id" jdbcType="BIGINT" property="storeId" />
    <result column="store_name" jdbcType="VARCHAR" property="storeName" />
    <result column="member_id" jdbcType="BIGINT" property="memberId" />
    <result column="member_name" jdbcType="VARCHAR" property="memberName" />
    <result column="member_identity" jdbcType="VARCHAR" property="memberIdentity" />
    <result column="member_phone" jdbcType="VARCHAR" property="memberPhone" />
    <result column="account_id" jdbcType="BIGINT" property="accountId" />
    <result column="account_name" jdbcType="VARCHAR" property="accountName" />
    <result column="account_type" jdbcType="VARCHAR" property="accountType" />
    <result column="doc_id" jdbcType="BIGINT" property="docId" />
    <result column="doc_num" jdbcType="VARCHAR" property="docNum" />
    <result column="input_date" jdbcType="TIMESTAMP" property="inputDate" />
    <result column="doc_type" jdbcType="VARCHAR" property="docType" />
    <result column="trade_id" jdbcType="BIGINT" property="tradeId" />
    <result column="trade_name" jdbcType="VARCHAR" property="tradeName" />
    <result column="trade_money" jdbcType="DECIMAL" property="tradeMoney" />
    <result column="trade_count" jdbcType="INTEGER" property="tradeCount" />
    <result column="account_in_money" jdbcType="DECIMAL" property="accountInMoney" />
    <result column="account_in_count" jdbcType="INTEGER" property="accountInCount" />
    <result column="account_spend_money" jdbcType="DECIMAL" property="accountSpendMoney" />
    <result column="account_gift_spend_money" jdbcType="DECIMAL" property="accountGiftSpendMoney" />
    <result column="account_spend_count" jdbcType="INTEGER" property="accountSpendCount" />
    <result column="account_rest_money" jdbcType="DECIMAL" property="accountRestMoney" />
    <result column="account_consume_money" jdbcType="DECIMAL" property="accountConsumeMoney" />
    <result column="account_rest_count" jdbcType="INTEGER" property="accountRestCount" />
    <result column="account_consume_count" jdbcType="INTEGER" property="accountConsumeCount" />
    <result column="account_gift_rest_money" jdbcType="DECIMAL" property="accountGiftRestMoney" />
    <result column="account_gift_rest_count" jdbcType="INTEGER" property="accountGiftRestCount" />
    <result column="account_gift_consume_money" jdbcType="DECIMAL" property="accountGiftConsumeMoney" />
    <result column="account_gift_consume_count" jdbcType="INTEGER" property="accountGiftConsumeCount" />
    <result column="order_statu" jdbcType="INTEGER" property="orderStatu" />
    <result column="payment_amount" jdbcType="DECIMAL" property="paymentAmount" />
    <result column="debt_money" jdbcType="DECIMAL" property="debtMoney" />
    <result column="input_by" jdbcType="VARCHAR" property="inputBy" />
    <result column="price" jdbcType="DECIMAL" property="price" />
    <result column="gift_in_menoy" jdbcType="DECIMAL" property="giftInMenoy" />
    <result column="card_money" jdbcType="DECIMAL" property="cardMoney" />
    <result column="cash_money" jdbcType="DECIMAL" property="cashMoney" />
    <result column="is_addition" jdbcType="INTEGER" property="isAddition" />
      <result column="addition_date" jdbcType="TIMESTAMP" property="additionDate" />
  </resultMap>

  <sql id="BaseColumnList">
    id,
    store_id,
    store_name,
    member_id,
    member_name,
    member_identity,
    member_phone,
    account_id,
    account_name,
    account_type,
    doc_id,
    doc_num,
    input_date,
    doc_type,
    trade_id,
    trade_name,
    trade_money,
    trade_count,
    account_in_money,
    account_in_count,
    account_spend_money,
    account_gift_spend_money,
    account_spend_count,
    account_rest_money,
    account_consume_money,
    account_rest_count,
    account_consume_count,
    account_gift_rest_money,
    account_gift_rest_count,
    account_gift_consume_money,
    account_gift_consume_count,
    order_statu,
    payment_amount,
    debt_money,
    input_by,
    price,
    gift_in_menoy,
    card_money,
    cash_money,
    is_addition,
    addition_date
  </sql>

  <select id="createTable" parameterType="java.lang.String">
    create table if not exists account_trade_record_${tab} like account_trade_record;
  </select>

  <insert id="addRecord1" parameterType="com.ssm.manage.entity.AccountTradeRecord">
    insert into account_trade_record_${tab}
    (id,
    store_id,
    store_name,
    member_id,
    member_name,
    member_identity,
    member_phone,
    account_id,
    account_name,
    account_type,
    doc_id,
    doc_num,
    input_date,
    doc_type,
    trade_id,
    trade_name,
    trade_money,
    trade_count,
    account_in_money,
    account_in_count,
    account_spend_money,
    account_spend_count,
    account_rest_money,
    account_consume_money,
    account_rest_count,
    account_consume_count,
     order_statu,
     payment_amount,
     debt_money,
     input_by,
     price,
     card_money,
     cash_money,
     is_addition,
     addition_date
    ) values
    (
    #{id,jdbcType = BIGINT },
    #{storeId,jdbcType = BIGINT },
    #{storeName,jdbcType = VARCHAR },
    #{memberId,jdbcType = BIGINT },
    #{memberName,jdbcType = VARCHAR },
    #{memberIdentity,jdbcType = VARCHAR },
    #{memberPhone,jdbcType = VARCHAR },
    #{accountId,jdbcType = BIGINT },
    #{accountName,jdbcType = VARCHAR },
    #{accountType,jdbcType = VARCHAR },
    #{docId,jdbcType = BIGINT },
    #{docNum,jdbcType = VARCHAR },
    #{inputDate,jdbcType = TIMESTAMP },
    #{docType,jdbcType = VARCHAR },
    #{tradeId,jdbcType = BIGINT },
    #{tradeName,jdbcType = VARCHAR },
    #{tradeMoney,jdbcType = DECIMAL },
    #{tradeCount,jdbcType = INTEGER },
    #{accountInMoney,jdbcType = DECIMAL },
    #{accountInCount,jdbcType = INTEGER },
    #{accountSpendMoney,jdbcType = DECIMAL },
    #{accountSpendCount,jdbcType = INTEGER },
    #{accountRestMoney,jdbcType = DECIMAL },
    #{accountConsumeMoney,jdbcType = DECIMAL },
    #{accountRestCount,jdbcType = INTEGER },
    #{accountConsumeCount,jdbcType = INTEGER },
    #{orderStatu,jdbcType = INTEGER },
    #{paymentAmount,jdbcType = DECIMAL },
    #{debtMoney,jdbcType = DECIMAL },
    #{inputBy,jdbcType = VARCHAR },
    #{price,jdbcType = DECIMAL },
    #{cardMoney,jdbcType = DECIMAL },
    #{cashMoney,jdbcType = DECIMAL },
    #{isAddition,jdbcType = DECIMAL },
    #{additionDate,jdbcType = DECIMAL }
   )
  </insert>
<insert id="addRecord" parameterType="com.ssm.manage.entity.AccountTradeRecord">
    insert into account_trade_record_${tab}
    (id,
    store_id,
    store_name,
    member_id,
    member_name,
    member_identity,
    member_phone,
    account_id,
    account_name,
    account_type,
    doc_id,
    doc_num,
    input_date,
    doc_type,
    trade_id,
    trade_name,
    trade_money,
    trade_count,
    account_in_money,
    account_in_count,
    account_spend_money,
    account_gift_spend_money,
    account_spend_count,
    account_rest_money,
    account_consume_money,
    account_rest_count,
    account_consume_count,
    account_gift_rest_money,
    account_gift_rest_count,
    account_gift_consume_money,
    account_gift_consume_count,
     order_statu,
     payment_amount,
     debt_money,
     input_by,
     price,
     gift_in_menoy,
     card_money,
     cash_money,
     is_addition,
     addition_date
    ) values
    (
    #{id,jdbcType = BIGINT },
    #{storeId,jdbcType = BIGINT },
    #{storeName,jdbcType = VARCHAR },
    #{memberId,jdbcType = BIGINT },
    #{memberName,jdbcType = VARCHAR },
    #{memberIdentity,jdbcType = VARCHAR },
    #{memberPhone,jdbcType = VARCHAR },
    #{accountId,jdbcType = BIGINT },
    #{accountName,jdbcType = VARCHAR },
    #{accountType,jdbcType = VARCHAR },
    #{docId,jdbcType = BIGINT },
    #{docNum,jdbcType = VARCHAR },
    #{inputDate,jdbcType = TIMESTAMP },
    #{docType,jdbcType = VARCHAR },
    #{tradeId,jdbcType = BIGINT },
    #{tradeName,jdbcType = VARCHAR },
    #{tradeMoney,jdbcType = DECIMAL },
    #{tradeCount,jdbcType = INTEGER },
    #{accountInMoney,jdbcType = DECIMAL },
    #{accountInCount,jdbcType = INTEGER },
    #{accountSpendMoney,jdbcType = DECIMAL },
    #{accountGiftSpendMoney,jdbcType = DECIMAL },
    #{accountSpendCount,jdbcType = INTEGER },
    #{accountRestMoney,jdbcType = DECIMAL },
    #{accountConsumeMoney,jdbcType = DECIMAL },
    #{accountRestCount,jdbcType = INTEGER },
    #{accountConsumeCount,jdbcType = INTEGER },
    #{accountGiftRestMoney,jdbcType = DECIMAL },
    #{accountGiftRestCount,jdbcType = DECIMAL },
    #{accountGiftConsumeMoney,jdbcType = INTEGER },
    #{accountGiftConsumeCount,jdbcType = INTEGER },
    #{orderStatu,jdbcType = INTEGER },
    #{paymentAmount,jdbcType = DECIMAL },
    #{debtMoney,jdbcType = DECIMAL },
    #{inputBy,jdbcType = VARCHAR },
    #{price,jdbcType = DECIMAL },
    #{giftInMenoy,jdbcType = DECIMAL },
    #{cardMoney,jdbcType = DECIMAL },
    #{cashMoney,jdbcType = DECIMAL },
    #{isAddition,jdbcType = DECIMAL },
    #{additionDate,jdbcType = DECIMAL }
   )
  </insert>

  <select id="selectList" parameterType="com.ssm.manage.query.AccountTradeRecordRequest" resultMap="BaseResultMap">
    select <include refid="BaseColumnList"/> from account_trade_record_${tab}
    <where>
      <if test="storeId != null">
        and store_id = #{storeId, jdbcType = BIGINT}
      </if>
      <if test="memberId != null">
        and member_id = #{memberId, jdbcType = BIGINT}
      </if>
      <if test="docId != null">
        and doc_id = #{docId, jdbcType = BIGINT}
      </if>
      <if test="memberPhone != null">
        and member_phone = #{memberPhone, jdbcType = VARCHAR}
      </if>
      <if test="accountId != null">
        and account_id = #{accountId, jdbcType = BIGINT}
      </if>
      <if test="accountType != null">
        and account_type = #{accountType, jdbcType = VARCHAR}
      </if>
      <if test="tradeId != null">
        and trade_id = #{tradeId, jdbcType = BIGINT}
      </if>
      <if test="tradeName != null">
        and trade_name like concat('%',concat(#{tradeName, jdbcType = VARCHAR}, '%'))
      </if>
      <if test="docType != null">
        and doc_type = #{docType, jdbcType = VARCHAR}
      </if>
      <if test="date != null">
        and input_date like concat(#{date, jdbcType = VARCHAR},'%')
      </if>
      <if test="orderStatu != null">
        and order_statu = #{orderStatu, jdbcType =BIGINT}
      </if>
        <if test="docNum != null">
        and doc_num = #{docNum,jdbcType=VARCHAR}
      </if>
      <if test="docTypes != null">
        and doc_type in
        <foreach close=")" collection="docTypes" index="index" item="item" open="(" separator=",">
        #{item,jdbcType=BIGINT}
      </foreach>
      </if>
    </where>
    order by input_date desc
  </select>

 <select id="selectById" parameterType="com.ssm.manage.query.AccountTradeRecordRequest" resultMap="BaseResultMap">
    select <include refid="BaseColumnList"/> from account_trade_record_${tab}
    <where>
        <if test="storeId != null">
            and id = #{Id, jdbcType = BIGINT}
        </if>
      <if test="storeId != null">
        and store_id = #{storeId, jdbcType = BIGINT}
      </if>
      <if test="memberId != null">
        and member_id = #{memberId, jdbcType = BIGINT}
      </if>
      <if test="docId != null">
        and doc_id = #{docId, jdbcType = BIGINT}
      </if>
      <if test="memberPhone != null">
        and member_phone = #{memberPhone, jdbcType = VARCHAR}
      </if>
      <if test="accountId != null">
        and account_id = #{accountId, jdbcType = BIGINT}
      </if>
      <if test="accountType != null">
        and account_type = #{accountType, jdbcType = VARCHAR}
      </if>
      <if test="tradeId != null">
        and trade_id = #{tradeId, jdbcType = BIGINT}
      </if>
      <if test="tradeName != null">
        and trade_name like concat('%',concat(#{tradeName, jdbcType = VARCHAR}, '%'))
      </if>
      <if test="docType != null">
        and doc_type = #{docType, jdbcType = VARCHAR}
      </if>
      <if test="date != null">
        and input_date like concat(#{date, jdbcType = VARCHAR},'%')
      </if>
      <if test="orderStatu != null">
        and order_statu = #{orderStatu, jdbcType =BIGINT}
      </if>
      <if test="docTypes != null">
        and doc_type in
        <foreach close=")" collection="docTypes" index="index" item="item" open="(" separator=",">
        #{item,jdbcType=BIGINT}
      </foreach>
      </if>
    </where>
    order by input_date desc
  </select>

  <select id="selectLists" parameterType="com.ssm.manage.query.AccountTradeRecordRequest" resultMap="BaseResultMap">
    select * from (select <include refid="BaseColumnList"/> from account_trade_record_${tab}
    <where>
<!--      <if test="storeId != null">-->
<!--        and store_id = #{storeId, jdbcType = BIGINT}-->
<!--      </if>-->
      <if test="memberId != null">
        and member_id = #{memberId, jdbcType = BIGINT}
      </if>
      <if test="docId != null">
        and doc_id = #{docId, jdbcType = BIGINT}
      </if>
      <if test="memberPhone != null">
        and member_phone = #{memberPhone, jdbcType = VARCHAR}
      </if>
      <if test="accountId != null">
        and account_id = #{accountId, jdbcType = BIGINT}
      </if>
      <if test="accountType != null">
        and account_type = #{accountType, jdbcType = VARCHAR}
      </if>
      <if test="tradeId != null">
        and trade_id = #{tradeId, jdbcType = BIGINT}
      </if>
      <if test="tradeName != null">
        and trade_name like concat('%',concat(#{tradeName, jdbcType = VARCHAR}, '%'))
      </if>
      <if test="docType != null">
        and doc_type = #{docType, jdbcType = VARCHAR}
      </if>
      <if test="date != null">
        and input_date like concat(#{date, jdbcType = VARCHAR},'%')
      </if>
      <if test="docTypes != null">
        and doc_type in
        <foreach close=")" collection="docTypes" index="index" item="item" open="(" separator=",">
          #{item,jdbcType=BIGINT}
        </foreach>
      </if>
      <if test="storeIdl != null">
        and store_id in
        <foreach close=")" collection="storeIdl" index="index" item="item" open="(" separator=",">
          #{item,jdbcType=BIGINT}
        </foreach>
      </if>
    </where>
        union
    select <include refid="BaseColumnList"/> from account_trade_record_${tab1}
    <where>
<!--      <if test="storeId != null">-->
<!--        and store_id = #{storeId, jdbcType = BIGINT}-->
<!--      </if>-->
      <if test="memberId != null">
        and member_id = #{memberId, jdbcType = BIGINT}
      </if>
      <if test="docId != null">
        and doc_id = #{docId, jdbcType = BIGINT}
      </if>
      <if test="memberPhone != null">
        and member_phone = #{memberPhone, jdbcType = VARCHAR}
      </if>
      <if test="accountId != null">
        and account_id = #{accountId, jdbcType = BIGINT}
      </if>
      <if test="accountType != null">
        and account_type = #{accountType, jdbcType = VARCHAR}
      </if>
      <if test="tradeId != null">
        and trade_id = #{tradeId, jdbcType = BIGINT}
      </if>
      <if test="tradeName != null">
        and trade_name like concat('%',concat(#{tradeName, jdbcType = VARCHAR}, '%'))
      </if>
      <if test="docType != null">
        and doc_type = #{docType, jdbcType = VARCHAR}
      </if>
      <if test="date != null">
        and input_date like concat(#{date, jdbcType = VARCHAR},'%')
      </if>
      <if test="docTypes != null">
        and doc_type in
        <foreach close=")" collection="docTypes" index="index" item="item" open="(" separator=",">
          #{item,jdbcType=BIGINT}
        </foreach>
      </if>
      <if test="storeIdl != null">
        and store_id in
        <foreach close=")" collection="storeIdl" index="index" item="item" open="(" separator=",">
          #{item,jdbcType=BIGINT}
        </foreach>
      </if>
    </where>
            union
    select <include refid="BaseColumnList"/> from account_trade_record_${tab2}
    <where>
<!--      <if test="storeId != null">-->
<!--        and store_id = #{storeId, jdbcType = BIGINT}-->
<!--      </if>-->
      <if test="memberId != null">
        and member_id = #{memberId, jdbcType = BIGINT}
      </if>
      <if test="docId != null">
        and doc_id = #{docId, jdbcType = BIGINT}
      </if>
      <if test="memberPhone != null">
        and member_phone = #{memberPhone, jdbcType = VARCHAR}
      </if>
      <if test="accountId != null">
        and account_id = #{accountId, jdbcType = BIGINT}
      </if>
      <if test="accountType != null">
        and account_type = #{accountType, jdbcType = VARCHAR}
      </if>
      <if test="tradeId != null">
        and trade_id = #{tradeId, jdbcType = BIGINT}
      </if>
      <if test="tradeName != null">
        and trade_name like concat('%',concat(#{tradeName, jdbcType = VARCHAR}, '%'))
      </if>
      <if test="docType != null">
        and doc_type = #{docType, jdbcType = VARCHAR}
      </if>
      <if test="date != null">
        and input_date like concat(#{date, jdbcType = VARCHAR},'%')
      </if>
      <if test="docTypes != null">
        and doc_type in
        <foreach close=")" collection="docTypes" index="index" item="item" open="(" separator=",">
          #{item,jdbcType=BIGINT}
        </foreach>
      </if>
      <if test="storeIdl != null">
        and store_id in
        <foreach close=")" collection="storeIdl" index="index" item="item" open="(" separator=",">
          #{item,jdbcType=BIGINT}
        </foreach>
      </if>
    </where>
      union
      select <include refid="BaseColumnList"/> from account_trade_record_${tab3}
      <where>
          <!--      <if test="storeId != null">-->
          <!--        and store_id = #{storeId, jdbcType = BIGINT}-->
          <!--      </if>-->
          <if test="memberId != null">
              and member_id = #{memberId, jdbcType = BIGINT}
          </if>
          <if test="docId != null">
              and doc_id = #{docId, jdbcType = BIGINT}
          </if>
          <if test="memberPhone != null">
              and member_phone = #{memberPhone, jdbcType = VARCHAR}
          </if>
          <if test="accountId != null">
              and account_id = #{accountId, jdbcType = BIGINT}
          </if>
          <if test="accountType != null">
              and account_type = #{accountType, jdbcType = VARCHAR}
          </if>
          <if test="tradeId != null">
              and trade_id = #{tradeId, jdbcType = BIGINT}
          </if>
          <if test="tradeName != null">
              and trade_name like concat('%',concat(#{tradeName, jdbcType = VARCHAR}, '%'))
          </if>
          <if test="docType != null">
              and doc_type = #{docType, jdbcType = VARCHAR}
          </if>
          <if test="date != null">
              and input_date like concat(#{date, jdbcType = VARCHAR},'%')
          </if>
          <if test="docTypes != null">
              and doc_type in
              <foreach close=")" collection="docTypes" index="index" item="item" open="(" separator=",">
                  #{item,jdbcType=BIGINT}
              </foreach>
          </if>
          <if test="storeIdl != null">
              and store_id in
              <foreach close=")" collection="storeIdl" index="index" item="item" open="(" separator=",">
                  #{item,jdbcType=BIGINT}
              </foreach>
          </if>
      </where>
      union
      select <include refid="BaseColumnList"/> from account_trade_record_${tab4}
      <where>
          <!--      <if test="storeId != null">-->
          <!--        and store_id = #{storeId, jdbcType = BIGINT}-->
          <!--      </if>-->
          <if test="memberId != null">
              and member_id = #{memberId, jdbcType = BIGINT}
          </if>
          <if test="docId != null">
              and doc_id = #{docId, jdbcType = BIGINT}
          </if>
          <if test="memberPhone != null">
              and member_phone = #{memberPhone, jdbcType = VARCHAR}
          </if>
          <if test="accountId != null">
              and account_id = #{accountId, jdbcType = BIGINT}
          </if>
          <if test="accountType != null">
              and account_type = #{accountType, jdbcType = VARCHAR}
          </if>
          <if test="tradeId != null">
              and trade_id = #{tradeId, jdbcType = BIGINT}
          </if>
          <if test="tradeName != null">
              and trade_name like concat('%',concat(#{tradeName, jdbcType = VARCHAR}, '%'))
          </if>
          <if test="docType != null">
              and doc_type = #{docType, jdbcType = VARCHAR}
          </if>
          <if test="date != null">
              and input_date like concat(#{date, jdbcType = VARCHAR},'%')
          </if>
          <if test="docTypes != null">
              and doc_type in
              <foreach close=")" collection="docTypes" index="index" item="item" open="(" separator=",">
                  #{item,jdbcType=BIGINT}
              </foreach>
          </if>
          <if test="storeIdl != null">
              and store_id in
              <foreach close=")" collection="storeIdl" index="index" item="item" open="(" separator=",">
                  #{item,jdbcType=BIGINT}
              </foreach>
          </if>
      </where>
      union
      select <include refid="BaseColumnList"/> from account_trade_record_${tab5}
      <where>
          <!--      <if test="storeId != null">-->
          <!--        and store_id = #{storeId, jdbcType = BIGINT}-->
          <!--      </if>-->
          <if test="memberId != null">
              and member_id = #{memberId, jdbcType = BIGINT}
          </if>
          <if test="docId != null">
              and doc_id = #{docId, jdbcType = BIGINT}
          </if>
          <if test="memberPhone != null">
              and member_phone = #{memberPhone, jdbcType = VARCHAR}
          </if>
          <if test="accountId != null">
              and account_id = #{accountId, jdbcType = BIGINT}
          </if>
          <if test="accountType != null">
              and account_type = #{accountType, jdbcType = VARCHAR}
          </if>
          <if test="tradeId != null">
              and trade_id = #{tradeId, jdbcType = BIGINT}
          </if>
          <if test="tradeName != null">
              and trade_name like concat('%',concat(#{tradeName, jdbcType = VARCHAR}, '%'))
          </if>
          <if test="docType != null">
              and doc_type = #{docType, jdbcType = VARCHAR}
          </if>
          <if test="date != null">
              and input_date like concat(#{date, jdbcType = VARCHAR},'%')
          </if>
          <if test="docTypes != null">
              and doc_type in
              <foreach close=")" collection="docTypes" index="index" item="item" open="(" separator=",">
                  #{item,jdbcType=BIGINT}
              </foreach>
          </if>
          <if test="storeIdl != null">
              and store_id in
              <foreach close=")" collection="storeIdl" index="index" item="item" open="(" separator=",">
                  #{item,jdbcType=BIGINT}
              </foreach>
          </if>
      </where>
            ) a
    order by a.input_date desc
  </select>


  <insert id="insertBatch" parameterType="java.util.Map">
    insert into account_trade_record_${tab}
    (<include refid="BaseColumnList"/>) values
    <foreach collection="list"  separator="," item="item">
        (
        #{item.id },
      #{item.storeId},
      #{item.storeName},
      #{item.memberId},
      #{item.memberName},
      #{item.memberIdentity},
      #{item.memberPhone},
      #{item.accountId},
      #{item.accountName},
      #{item.accountType},
      #{item.docId},
      #{item.docNum},
      #{item.inputDate},
      #{item.docType},
      #{item.tradeId},
      #{item.tradeName},
      #{item.tradeMoney},
      #{item.tradeCount},
      #{item.accountInMoney},
      #{item.accountInCount},
      #{item.accountSpendMoney},
      #{item.accountGiftSpendMoney},
      #{item.accountSpendCount},
      #{item.accountRestMoney},
      #{item.accountConsumeMoney},
      #{item.accountRestCount},
      #{item.accountConsumeCount},
      #{item.accountGiftRestMoney},
      #{item.accountGiftRestCount},
      #{item.accountGiftConsumeMoney},
      #{item.accountGiftConsumeCount},
      #{item.orderStatu},
      #{item.paymentAmount},
      #{item.debtMoney},
      #{item.inputBy},
      #{item.price},
      #{item.giftInMenoy},
      #{item.cardMoney},
      #{item.cashMoney},
     0,null    )

    </foreach>
  </insert>



    <select id="selectListNew" parameterType="com.ssm.manage.query.AccountTradeRecordRequest" resultMap="BaseResultMap">
        select input_date,trade_id,doc_type,order_statu,storeId,docId from account_trade_record_${tab}
        <where>
            <if test="storeId != null">
                and store_id = #{storeId, jdbcType = BIGINT}
            </if>
            <if test="memberId != null">
                and member_id = #{memberId, jdbcType = BIGINT}
            </if>
            <if test="docId != null">
                and doc_id = #{docId, jdbcType = BIGINT}
            </if>
            <if test="memberPhone != null">
                and member_phone = #{memberPhone, jdbcType = VARCHAR}
            </if>
            <if test="accountId != null">
                and account_id = #{accountId, jdbcType = BIGINT}
            </if>
            <if test="accountType != null">
                and account_type = #{accountType, jdbcType = VARCHAR}
            </if>
            <if test="tradeId != null">
                and trade_id = #{tradeId, jdbcType = BIGINT}
            </if>
            <if test="tradeName != null">
                and trade_name like concat('%',concat(#{tradeName, jdbcType = VARCHAR}, '%'))
            </if>
            <if test="docType != null">
                and doc_type = #{docType, jdbcType = VARCHAR}
            </if>
            <if test="date != null">
                and input_date like concat(#{date, jdbcType = VARCHAR},'%')
            </if>
            <if test="orderStatu != null">
                and order_statu = #{orderStatu, jdbcType =BIGINT}
            </if>
            <if test="docTypes != null">
                and doc_type in
                <foreach close=")" collection="docTypes" index="index" item="item" open="(" separator=",">
                    #{item,jdbcType=BIGINT}
                </foreach>
            </if>
        </where>
        group by trade_id,doc_type,store_id
        order by input_date desc
    </select>

    <select id="selectListsNew" parameterType="com.ssm.manage.query.AccountTradeRecordRequest" resultMap="BaseResultMap">
        select * from (select <include refid="BaseColumnList"/> from account_trade_record_${tab}
        <where>
            <!--      <if test="storeId != null">-->
            <!--        and store_id = #{storeId, jdbcType = BIGINT}-->
            <!--      </if>-->
            <if test="memberId != null">
                and member_id = #{memberId, jdbcType = BIGINT}
            </if>
            <if test="docId != null">
                and doc_id = #{docId, jdbcType = BIGINT}
            </if>
            <if test="memberPhone != null">
                and member_phone = #{memberPhone, jdbcType = VARCHAR}
            </if>
            <if test="accountId != null">
                and account_id = #{accountId, jdbcType = BIGINT}
            </if>
            <if test="accountType != null">
                and account_type = #{accountType, jdbcType = VARCHAR}
            </if>
            <if test="tradeId != null">
                and trade_id = #{tradeId, jdbcType = BIGINT}
            </if>
            <if test="tradeName != null">
                and trade_name like concat('%',concat(#{tradeName, jdbcType = VARCHAR}, '%'))
            </if>
            <if test="docType != null">
                and doc_type = #{docType, jdbcType = VARCHAR}
            </if>
            <if test="date != null">
                and input_date like concat(#{date, jdbcType = VARCHAR},'%')
            </if>
            <if test="docTypes != null">
                and doc_type in
                <foreach close=")" collection="docTypes" index="index" item="item" open="(" separator=",">
                    #{item,jdbcType=BIGINT}
                </foreach>
            </if>
            <if test="storeIdl != null">
                and store_id in
                <foreach close=")" collection="storeIdl" index="index" item="item" open="(" separator=",">
                    #{item,jdbcType=BIGINT}
                </foreach>
            </if>
        </where>
        union
        select <include refid="BaseColumnList"/> from account_trade_record_${tab1}
        <where>
            <!--      <if test="storeId != null">-->
            <!--        and store_id = #{storeId, jdbcType = BIGINT}-->
            <!--      </if>-->
            <if test="memberId != null">
                and member_id = #{memberId, jdbcType = BIGINT}
            </if>
            <if test="docId != null">
                and doc_id = #{docId, jdbcType = BIGINT}
            </if>
            <if test="memberPhone != null">
                and member_phone = #{memberPhone, jdbcType = VARCHAR}
            </if>
            <if test="accountId != null">
                and account_id = #{accountId, jdbcType = BIGINT}
            </if>
            <if test="accountType != null">
                and account_type = #{accountType, jdbcType = VARCHAR}
            </if>
            <if test="tradeId != null">
                and trade_id = #{tradeId, jdbcType = BIGINT}
            </if>
            <if test="tradeName != null">
                and trade_name like concat('%',concat(#{tradeName, jdbcType = VARCHAR}, '%'))
            </if>
            <if test="docType != null">
                and doc_type = #{docType, jdbcType = VARCHAR}
            </if>
            <if test="date != null">
                and input_date like concat(#{date, jdbcType = VARCHAR},'%')
            </if>
            <if test="docTypes != null">
                and doc_type in
                <foreach close=")" collection="docTypes" index="index" item="item" open="(" separator=",">
                    #{item,jdbcType=BIGINT}
                </foreach>
            </if>
            <if test="storeIdl != null">
                and store_id in
                <foreach close=")" collection="storeIdl" index="index" item="item" open="(" separator=",">
                    #{item,jdbcType=BIGINT}
                </foreach>
            </if>
        </where>union
        select <include refid="BaseColumnList"/> from account_trade_record_${tab2}
        <where>
            <!--      <if test="storeId != null">-->
            <!--        and store_id = #{storeId, jdbcType = BIGINT}-->
            <!--      </if>-->
            <if test="memberId != null">
                and member_id = #{memberId, jdbcType = BIGINT}
            </if>
            <if test="docId != null">
                and doc_id = #{docId, jdbcType = BIGINT}
            </if>
            <if test="memberPhone != null">
                and member_phone = #{memberPhone, jdbcType = VARCHAR}
            </if>
            <if test="accountId != null">
                and account_id = #{accountId, jdbcType = BIGINT}
            </if>
            <if test="accountType != null">
                and account_type = #{accountType, jdbcType = VARCHAR}
            </if>
            <if test="tradeId != null">
                and trade_id = #{tradeId, jdbcType = BIGINT}
            </if>
            <if test="tradeName != null">
                and trade_name like concat('%',concat(#{tradeName, jdbcType = VARCHAR}, '%'))
            </if>
            <if test="docType != null">
                and doc_type = #{docType, jdbcType = VARCHAR}
            </if>
            <if test="date != null">
                and input_date like concat(#{date, jdbcType = VARCHAR},'%')
            </if>
            <if test="docTypes != null">
                and doc_type in
                <foreach close=")" collection="docTypes" index="index" item="item" open="(" separator=",">
                    #{item,jdbcType=BIGINT}
                </foreach>
            </if>
            <if test="storeIdl != null">
                and store_id in
                <foreach close=")" collection="storeIdl" index="index" item="item" open="(" separator=",">
                    #{item,jdbcType=BIGINT}
                </foreach>
            </if>
        </where>) a
        order by a.input_date desc
    </select>



    <select id="retransmission" resultMap="BaseResultMap">
        select * from account_trade_record_${tab} where doc_id = #{id, jdbcType = BIGINT}
    </select>
    <select id="selectListByMonthly" resultMap="BaseResultMap">
        select * from account_trade_record_${tab} where store_id in <foreach collection="storeIds" open="(" close=")" separator="," item="item">#{item}</foreach>
                                                    and  doc_type = #{docType}
                                                    and account_id is not null
    </select>
</mapper>