<?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.yonge.cooleshow.biz.dal.mapper.TenantAccountRecordMapper">

	 
    
    <!-- 表字段 -->
    <sql id="baseColumns">
         t.id_ AS id
        , t.tenant_id_ AS tenantId
        , t.trans_amount_ AS transAmount
        , t.in_or_out_ AS inOrOut
        , t.post_status_ AS postStatus
        , t.biz_type_ AS bizType
        , t.biz_id_ AS bizId
        , t.biz_name_ AS bizName
        , t.order_no_ AS orderNo
        , t.create_time_ AS createTime
        , t.update_time_ AS updateTime
        , t.err_flag_ AS errFlag
        , t.err_msg_ AS errMsg
        </sql> 
    
    <sql id="selectSql">
        <where>
            <if test="param.orderNo != null and param.orderNo != ''">
                AND t.order_no_ = #{param.orderNo}
            </if>
            <if test="param.bizId != null">
                AND t.biz_id_ = #{param.bizId}
            </if>
            <if test="param.inOrOut != null and param.inOrOut != ''">
                and t.in_or_out_ = #{param.inOrOut}
            </if>
            <if test="param.bizType != null">
                and t.biz_type_ = #{param.bizType}
            </if>

            <if test="param.postStatus != null">
                and t.post_status_ = #{param.postStatus}
            </if>

            <if test="param.startDate != null">
                and t.update_time_ &gt;= #{param.startDate}
            </if>
            <if test="param.endDate != null">
                and t.update_time_ &lt;= #{param.endDate}
            </if>
            <if test="param.tenantId != null">
                and t.tenant_id_ = #{param.tenantId}
            </if>

        </where>
    </sql>
    <select id="selectPage" resultType="com.yonge.cooleshow.biz.dal.wrapper.TenantAccountRecordWrapper$TenantAccountRecord">
		SELECT
            t.*
		FROM tenant_account_record t
        <include refid="selectSql"/>
	</select>

    <select id="getStatistics"
            resultType="com.yonge.cooleshow.biz.dal.wrapper.TenantAccountRecordWrapper$TenantAccountRecordStat">
        SELECT
        sum(if(t.in_or_out_ = 'IN' and t.post_status_ = 'RECORDED',t.trans_amount_,0)) transAmountIn,
        sum(if(t.in_or_out_ = 'IN' and t.post_status_ = 'WAIT',t.trans_amount_,0)) transAmountOut,
        sum(if(t.in_or_out_ = 'OUT' and t.post_status_ = 'RECORDED',t.trans_amount_,0)) amountOut
        FROM tenant_account_record t
        <include refid="selectSql"/>
    </select>
</mapper>