<?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.SsmTransactionRecordMapper">

    <resultMap type="com.ssm.manage.entity.TransactionRecord" id="TransactionRecordMap">
        <result property="id" column="id" jdbcType="INTEGER"/>
        <result property="storeId" column="store_id" jdbcType="INTEGER"/>
        <result property="storeName" column="store_name" jdbcType="VARCHAR"/>
        <result property="memberId" column="member_id" jdbcType="INTEGER"/>
        <result property="memberName" column="member_name" jdbcType="VARCHAR"/>
        <result property="memberIdentity" column="member_identity" jdbcType="VARCHAR"/>
        <result property="memberPhone" column="member_phone" jdbcType="VARCHAR"/>
        <result property="date" column="date" jdbcType="TIMESTAMP"/>
        <result property="type" column="type" jdbcType="INTEGER"/>
        <result property="docId" column="doc_id" jdbcType="INTEGER"/>
        <result property="docNum" column="doc_num" jdbcType="VARCHAR"/>
        <result property="docDate" column="doc_date" jdbcType="TIMESTAMP"/>
        <result property="accountId" column="account_id" jdbcType="INTEGER"/>
        <result property="accountName" column="account_name" jdbcType="VARCHAR"/>
        <result property="accountType" column="account_type" jdbcType="VARCHAR"/>
        <result property="cardMoney" column="card_money" jdbcType="NUMERIC"/>
        <result property="accountGiftSpendMoney" column="account_gift_spend_money" jdbcType="NUMERIC"/>
        <result property="accountSpendCount" column="account_spend_count" jdbcType="INTEGER"/>
        <result property="accountRestMoney" column="account_rest_money" jdbcType="NUMERIC"/>
        <result property="accountConsumeMoney" column="account_consume_money" jdbcType="NUMERIC"/>
        <result property="accountRestCount" column="account_rest_count" jdbcType="INTEGER"/>
        <result property="accountConsumeCount" column="account_consume_count" jdbcType="INTEGER"/>
        <result property="accountGiftRestMoney" column="account_gift_rest_money" jdbcType="NUMERIC"/>
        <result property="accountGiftRestCount" column="account_gift_rest_count" jdbcType="INTEGER"/>
        <result property="accountGiftConsumeMoney" column="account_gift_consume_money" jdbcType="NUMERIC"/>
        <result property="accountGiftConsumeCount" column="account_gift_consume_count" jdbcType="INTEGER"/>
        <result property="accountNum" column="account_num" jdbcType="VARCHAR"/>
        <result property="operationBy" column="operation_by" jdbcType="VARCHAR"/>
        <result property="docProjectId" column="doc_project_id" jdbcType="INTEGER"/>
        <result property="docProjectNum" column="doc_project_num" jdbcType="VARCHAR"/>
        <result property="docProjectName" column="doc_project_name" jdbcType="VARCHAR"/>
        <result property="docState" column="doc_state" jdbcType="INTEGER"/>
        <result property="quantity" column="quantity" jdbcType="INTEGER"/>
        <result property="price" column="price" jdbcType="NUMERIC"/>
        <result property="tradingMoney" column="trading_money" jdbcType="NUMERIC"/>
        <result property="debtMoney" column="debt_money" jdbcType="NUMERIC"/>
        <result property="cashMoney" column="cash_money" jdbcType="NUMERIC"/>
        <result property="accountInMoney" column="account_in_money" jdbcType="VARCHAR"/>
        <result property="accountInCount" column="account_in_count" jdbcType="INTEGER"/>
        <result property="tradeCount" column="trade_count" jdbcType="INTEGER"/>
        <result property="accountInGiftMoney" column="account_in_gift_money" jdbcType="NUMERIC"/>
    </resultMap>

    <!--查询单个-->
    <select id="queryByIds" resultMap="TransactionRecordMap">
        select
          id, store_id, store_name, member_id, member_name, member_identity, member_phone, date, type, doc_id, doc_num, doc_date, account_id, account_name, account_type, card_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, account_num, operation_by, doc_project_id, doc_project_num, doc_project_name, doc_state, quantity, price, trading_money, debt_money, cash_money, account_in_money, account_in_count
        from transaction_record
        where id = #{id}
    </select>

    <!--查询指定行数据-->
    <select id="queryAllByLimits" resultMap="TransactionRecordMap">
        select
          id, store_id, store_name, member_id, member_name, member_identity, member_phone, date, type, doc_id, doc_num, doc_date, account_id, account_name, account_type, card_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, account_num, operation_by, doc_project_id, doc_project_num, doc_project_name, doc_state, quantity, price, trading_money, debt_money, cash_money, account_in_money, account_in_count
        from transaction_record
        <where>
            <if test="id != null">
                and id = #{id}
            </if>
            <if test="storeId != null">
                and store_id = #{storeId}
            </if>
            <if test="storeName != null and storeName != ''">
                and store_name = #{storeName}
            </if>
            <if test="memberId != null">
                and member_id = #{memberId}
            </if>
            <if test="memberName != null and memberName != ''">
                and member_name = #{memberName}
            </if>
            <if test="memberIdentity != null and memberIdentity != ''">
                and member_identity = #{memberIdentity}
            </if>
            <if test="memberPhone != null and memberPhone != ''">
                and member_phone = #{memberPhone}
            </if>
            <if test="date != null">
                and date = #{date}
            </if>
            <if test="type != null">
                and type = #{type}
            </if>
            <if test="docId != null">
                and doc_id = #{docId}
            </if>
            <if test="docNum != null and docNum != ''">
                and doc_num = #{docNum}
            </if>
            <if test="docDate != null">
                and doc_date = #{docDate}
            </if>
            <if test="accountId != null">
                and account_id = #{accountId}
            </if>
            <if test="accountName != null and accountName != ''">
                and account_name = #{accountName}
            </if>
            <if test="accountType != null and accountType != ''">
                and account_type = #{accountType}
            </if>
            <if test="cardMoney != null">
                and card_money = #{cardMoney}
            </if>
            <if test="accountGiftSpendMoney != null">
                and account_gift_spend_money = #{accountGiftSpendMoney}
            </if>
            <if test="accountSpendCount != null">
                and account_spend_count = #{accountSpendCount}
            </if>
            <if test="accountRestMoney != null">
                and account_rest_money = #{accountRestMoney}
            </if>
            <if test="accountConsumeMoney != null">
                and account_consume_money = #{accountConsumeMoney}
            </if>
            <if test="accountRestCount != null">
                and account_rest_count = #{accountRestCount}
            </if>
            <if test="accountConsumeCount != null">
                and account_consume_count = #{accountConsumeCount}
            </if>
            <if test="accountGiftRestMoney != null">
                and account_gift_rest_money = #{accountGiftRestMoney}
            </if>
            <if test="accountGiftRestCount != null">
                and account_gift_rest_count = #{accountGiftRestCount}
            </if>
            <if test="accountGiftConsumeMoney != null">
                and account_gift_consume_money = #{accountGiftConsumeMoney}
            </if>
            <if test="accountGiftConsumeCount != null">
                and account_gift_consume_count = #{accountGiftConsumeCount}
            </if>
            <if test="accountNum != null and accountNum != ''">
                and account_num = #{accountNum}
            </if>
            <if test="operationBy != null and operationBy != ''">
                and operation_by = #{operationBy}
            </if>
            <if test="docProjectId != null">
                and doc_project_id = #{docProjectId}
            </if>
            <if test="docProjectNum != null and docProjectNum != ''">
                and doc_project_num = #{docProjectNum}
            </if>
            <if test="docProjectName != null and docProjectName != ''">
                and doc_project_name = #{docProjectName}
            </if>
            <if test="docState != null">
                and doc_state = #{docState}
            </if>
            <if test="quantity != null">
                and quantity = #{quantity}
            </if>
            <if test="price != null">
                and price = #{price}
            </if>
            <if test="tradingMoney != null">
                and trading_money = #{tradingMoney}
            </if>
            <if test="debtMoney != null">
                and debt_money = #{debtMoney}
            </if>
            <if test="cashMoney != null">
                and cash_money = #{cashMoney}
            </if>
            <if test="accountInMoney != null">
                and account_in_money = #{accountInMoney}
            </if>
            <if test="accountInCount != null">
                and account_in_count = #{accountInCount}
            </if>
        </where>
        limit #{pageable.offset}, #{pageable.pageSize}
    </select>

    <!--统计总行数-->
    <select id="counts" resultType="java.lang.Long">
        select count(1)
        from transaction_record
        <where>
            <if test="id != null">
                and id = #{id}
            </if>
            <if test="storeId != null">
                and store_id = #{storeId}
            </if>
            <if test="storeName != null and storeName != ''">
                and store_name = #{storeName}
            </if>
            <if test="memberId != null">
                and member_id = #{memberId}
            </if>
            <if test="memberName != null and memberName != ''">
                and member_name = #{memberName}
            </if>
            <if test="memberIdentity != null and memberIdentity != ''">
                and member_identity = #{memberIdentity}
            </if>
            <if test="memberPhone != null and memberPhone != ''">
                and member_phone = #{memberPhone}
            </if>
            <if test="date != null">
                and date = #{date}
            </if>
            <if test="type != null">
                and type = #{type}
            </if>
            <if test="docId != null">
                and doc_id = #{docId}
            </if>
            <if test="docNum != null and docNum != ''">
                and doc_num = #{docNum}
            </if>
            <if test="docDate != null">
                and doc_date = #{docDate}
            </if>
            <if test="accountId != null">
                and account_id = #{accountId}
            </if>
            <if test="accountName != null and accountName != ''">
                and account_name = #{accountName}
            </if>
            <if test="accountType != null and accountType != ''">
                and account_type = #{accountType}
            </if>
            <if test="cardMoney != null">
                and card_money = #{cardMoney}
            </if>
            <if test="accountGiftSpendMoney != null">
                and account_gift_spend_money = #{accountGiftSpendMoney}
            </if>
            <if test="accountSpendCount != null">
                and account_spend_count = #{accountSpendCount}
            </if>
            <if test="accountRestMoney != null">
                and account_rest_money = #{accountRestMoney}
            </if>
            <if test="accountConsumeMoney != null">
                and account_consume_money = #{accountConsumeMoney}
            </if>
            <if test="accountRestCount != null">
                and account_rest_count = #{accountRestCount}
            </if>
            <if test="accountConsumeCount != null">
                and account_consume_count = #{accountConsumeCount}
            </if>
            <if test="accountGiftRestMoney != null">
                and account_gift_rest_money = #{accountGiftRestMoney}
            </if>
            <if test="accountGiftRestCount != null">
                and account_gift_rest_count = #{accountGiftRestCount}
            </if>
            <if test="accountGiftConsumeMoney != null">
                and account_gift_consume_money = #{accountGiftConsumeMoney}
            </if>
            <if test="accountGiftConsumeCount != null">
                and account_gift_consume_count = #{accountGiftConsumeCount}
            </if>
            <if test="accountNum != null and accountNum != ''">
                and account_num = #{accountNum}
            </if>
            <if test="operationBy != null and operationBy != ''">
                and operation_by = #{operationBy}
            </if>
            <if test="docProjectId != null">
                and doc_project_id = #{docProjectId}
            </if>
            <if test="docProjectNum != null and docProjectNum != ''">
                and doc_project_num = #{docProjectNum}
            </if>
            <if test="docProjectName != null and docProjectName != ''">
                and doc_project_name = #{docProjectName}
            </if>
            <if test="docState != null">
                and doc_state = #{docState}
            </if>
            <if test="quantity != null">
                and quantity = #{quantity}
            </if>
            <if test="price != null">
                and price = #{price}
            </if>
            <if test="tradingMoney != null">
                and trading_money = #{tradingMoney}
            </if>
            <if test="debtMoney != null">
                and debt_money = #{debtMoney}
            </if>
            <if test="cashMoney != null">
                and cash_money = #{cashMoney}
            </if>
            <if test="accountInMoney != null">
                and account_in_money = #{accountInMoney}
            </if>
            <if test="accountInCount != null">
                and account_in_count = #{accountInCount}
            </if>
        </where>
    </select>

    <!--新增所有列-->
    <insert id="add">
        insert into transaction_record_${tab}(id,store_id, store_name, member_id, member_name, member_identity, member_phone, date, type, doc_id, doc_num, doc_date, account_id, account_name, account_type, card_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, account_num, operation_by, doc_project_id, doc_project_num, doc_project_name, doc_state, quantity, price, trading_money, debt_money, cash_money, account_in_money, account_in_count,trade_count,account_in_gift_money)
        values (#{id}, #{storeId}, #{storeName}, #{memberId}, #{memberName}, #{memberIdentity}, #{memberPhone}, #{date}, #{type}, #{docId}, #{docNum}, #{docDate}, #{accountId}, #{accountName}, #{accountType}, #{cardMoney}, #{accountGiftSpendMoney}, #{accountSpendCount}, #{accountRestMoney}, #{accountConsumeMoney}, #{accountRestCount}, #{accountConsumeCount}, #{accountGiftRestMoney}, #{accountGiftRestCount}, #{accountGiftConsumeMoney}, #{accountGiftConsumeCount}, #{accountNum}, #{operationBy}, #{docProjectId}, #{docProjectNum}, #{docProjectName}, #{docState}, #{quantity}, #{price}, #{tradingMoney}, #{debtMoney}, #{cashMoney}, #{accountInMoney}, #{accountInCount}, #{tradeCount}, #{accountInGiftMoney})
    </insert>

    <insert id="insertBatchs" keyProperty="id" useGeneratedKeys="true">
        insert into transaction_record(store_id, store_name, member_id, member_name, member_identity, member_phone, date, type, doc_id, doc_num, doc_date, account_id, account_name, account_type, card_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, account_num, operation_by, doc_project_id, doc_project_num, doc_project_name, doc_state, quantity, price, trading_money, debt_money, cash_money, account_in_money, account_in_count)
        values
        <foreach collection="entities" item="entity" separator=",">
        (#{entity.storeId}, #{entity.storeName}, #{entity.memberId}, #{entity.memberName}, #{entity.memberIdentity}, #{entity.memberPhone}, #{entity.date}, #{entity.type}, #{entity.docId}, #{entity.docNum}, #{entity.docDate}, #{entity.accountId}, #{entity.accountName}, #{entity.accountType}, #{entity.cardMoney}, #{entity.accountGiftSpendMoney}, #{entity.accountSpendCount}, #{entity.accountRestMoney}, #{entity.accountConsumeMoney}, #{entity.accountRestCount}, #{entity.accountConsumeCount}, #{entity.accountGiftRestMoney}, #{entity.accountGiftRestCount}, #{entity.accountGiftConsumeMoney}, #{entity.accountGiftConsumeCount}, #{entity.accountNum}, #{entity.operationBy}, #{entity.docProjectId}, #{entity.docProjectNum}, #{entity.docProjectName}, #{entity.docState}, #{entity.quantity}, #{entity.price}, #{entity.tradingMoney}, #{entity.debtMoney}, #{entity.cashMoney}, #{entity.accountInMoney}, #{entity.accountInCount})
        </foreach>
    </insert>

    <insert id="insertOrUpdateBatchs" keyProperty="id" useGeneratedKeys="true">
        insert into transaction_record(store_id, store_name, member_id, member_name, member_identity, member_phone, date, type, doc_id, doc_num, doc_date, account_id, account_name, account_type, card_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, account_num, operation_by, doc_project_id, doc_project_num, doc_project_name, doc_state, quantity, price, trading_money, debt_money, cash_money, account_in_money, account_in_count)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.storeId}, #{entity.storeName}, #{entity.memberId}, #{entity.memberName}, #{entity.memberIdentity}, #{entity.memberPhone}, #{entity.date}, #{entity.type}, #{entity.docId}, #{entity.docNum}, #{entity.docDate}, #{entity.accountId}, #{entity.accountName}, #{entity.accountType}, #{entity.cardMoney}, #{entity.accountGiftSpendMoney}, #{entity.accountSpendCount}, #{entity.accountRestMoney}, #{entity.accountConsumeMoney}, #{entity.accountRestCount}, #{entity.accountConsumeCount}, #{entity.accountGiftRestMoney}, #{entity.accountGiftRestCount}, #{entity.accountGiftConsumeMoney}, #{entity.accountGiftConsumeCount}, #{entity.accountNum}, #{entity.operationBy}, #{entity.docProjectId}, #{entity.docProjectNum}, #{entity.docProjectName}, #{entity.docState}, #{entity.quantity}, #{entity.price}, #{entity.tradingMoney}, #{entity.debtMoney}, #{entity.cashMoney}, #{entity.accountInMoney}, #{entity.accountInCount})
        </foreach>
        on duplicate key update
        store_id = values(store_id),
        store_name = values(store_name),
        member_id = values(member_id),
        member_name = values(member_name),
        member_identity = values(member_identity),
        member_phone = values(member_phone),
        date = values(date),
        type = values(type),
        doc_id = values(doc_id),
        doc_num = values(doc_num),
        doc_date = values(doc_date),
        account_id = values(account_id),
        account_name = values(account_name),
        account_type = values(account_type),
        card_money = values(card_money),
        account_gift_spend_money = values(account_gift_spend_money),
        account_spend_count = values(account_spend_count),
        account_rest_money = values(account_rest_money),
        account_consume_money = values(account_consume_money),
        account_rest_count = values(account_rest_count),
        account_consume_count = values(account_consume_count),
        account_gift_rest_money = values(account_gift_rest_money),
        account_gift_rest_count = values(account_gift_rest_count),
        account_gift_consume_money = values(account_gift_consume_money),
        account_gift_consume_count = values(account_gift_consume_count),
        account_num = values(account_num),
        operation_by = values(operation_by),
        doc_project_id = values(doc_project_id),
        doc_project_num = values(doc_project_num),
        doc_project_name = values(doc_project_name),
        doc_state = values(doc_state),
        quantity = values(quantity),
        price = values(price),
        trading_money = values(trading_money),
        debt_money = values(debt_money),
        cash_money = values(cash_money),
        account_in_money = values(account_in_money),
        account_in_count = values(account_in_count)
    </insert>

    <!--通过主键修改数据-->
    <update id="updates">
        update transaction_record
        <set>
            <if test="storeId != null">
                store_id = #{storeId},
            </if>
            <if test="storeName != null and storeName != ''">
                store_name = #{storeName},
            </if>
            <if test="memberId != null">
                member_id = #{memberId},
            </if>
            <if test="memberName != null and memberName != ''">
                member_name = #{memberName},
            </if>
            <if test="memberIdentity != null and memberIdentity != ''">
                member_identity = #{memberIdentity},
            </if>
            <if test="memberPhone != null and memberPhone != ''">
                member_phone = #{memberPhone},
            </if>
            <if test="date != null">
                date = #{date},
            </if>
            <if test="type != null">
                type = #{type},
            </if>
            <if test="docId != null">
                doc_id = #{docId},
            </if>
            <if test="docNum != null and docNum != ''">
                doc_num = #{docNum},
            </if>
            <if test="docDate != null">
                doc_date = #{docDate},
            </if>
            <if test="accountId != null">
                account_id = #{accountId},
            </if>
            <if test="accountName != null and accountName != ''">
                account_name = #{accountName},
            </if>
            <if test="accountType != null and accountType != ''">
                account_type = #{accountType},
            </if>
            <if test="cardMoney != null">
                card_money = #{cardMoney},
            </if>
            <if test="accountGiftSpendMoney != null">
                account_gift_spend_money = #{accountGiftSpendMoney},
            </if>
            <if test="accountSpendCount != null">
                account_spend_count = #{accountSpendCount},
            </if>
            <if test="accountRestMoney != null">
                account_rest_money = #{accountRestMoney},
            </if>
            <if test="accountConsumeMoney != null">
                account_consume_money = #{accountConsumeMoney},
            </if>
            <if test="accountRestCount != null">
                account_rest_count = #{accountRestCount},
            </if>
            <if test="accountConsumeCount != null">
                account_consume_count = #{accountConsumeCount},
            </if>
            <if test="accountGiftRestMoney != null">
                account_gift_rest_money = #{accountGiftRestMoney},
            </if>
            <if test="accountGiftRestCount != null">
                account_gift_rest_count = #{accountGiftRestCount},
            </if>
            <if test="accountGiftConsumeMoney != null">
                account_gift_consume_money = #{accountGiftConsumeMoney},
            </if>
            <if test="accountGiftConsumeCount != null">
                account_gift_consume_count = #{accountGiftConsumeCount},
            </if>
            <if test="accountNum != null and accountNum != ''">
                account_num = #{accountNum},
            </if>
            <if test="operationBy != null and operationBy != ''">
                operation_by = #{operationBy},
            </if>
            <if test="docProjectId != null">
                doc_project_id = #{docProjectId},
            </if>
            <if test="docProjectNum != null and docProjectNum != ''">
                doc_project_num = #{docProjectNum},
            </if>
            <if test="docProjectName != null and docProjectName != ''">
                doc_project_name = #{docProjectName},
            </if>
            <if test="docState != null">
                doc_state = #{docState},
            </if>
            <if test="quantity != null">
                quantity = #{quantity},
            </if>
            <if test="price != null">
                price = #{price},
            </if>
            <if test="tradingMoney != null">
                trading_money = #{tradingMoney},
            </if>
            <if test="debtMoney != null">
                debt_money = #{debtMoney},
            </if>
            <if test="cashMoney != null">
                cash_money = #{cashMoney},
            </if>
            <if test="accountInMoney != null">
                account_in_money = #{accountInMoney},
            </if>
            <if test="accountInCount != null">
                account_in_count = #{accountInCount},
            </if>
        </set>
        where id = #{id}
    </update>

    <!--通过主键删除-->
    <delete id="deleteByIds">
        delete from transaction_record where id = #{id}
    </delete>

</mapper>

