<?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="org.springblade.imports.mapper.FctStandingBookAgainMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="org.springblade.imports.entity.FctStandingBookAgain">
        <result column="DID" property="dId" />
        <result column="THEMONTH" property="themonth" />
        <result column="SPNAME" property="spname" />
        <result column="IN_MONEY" property="inMoney" />
        <result column="IN_NUM" property="inNum" />
        <result column="IN_GIFTCARD_NUM" property="inGiftcardNum" />
        <result column="IN_PRICE" property="inPrice" />
        <result column="OUT_PRICE" property="outPrice" />
        <result column="OUT_MONEY" property="outMoney" />
        <result column="SALE_PRICE" property="salePrice" />
        <result column="ACCOUNT_NUM" property="accountNum" />
        <result column="SALE_GIFTCARD_NUM" property="saleGiftcardNum" />
        <result column="ACCOUNT_MONEY" property="accountMoney" />
        <result column="SYSTEM_NUM" property="systemNum" />
        <result column="BALANCE_MONEY" property="balanceMoney" />
        <result column="BALANCE_NORMAL_CARD" property="balanceNormalCard" />
        <result column="BALANCE_GIFTCARD" property="balanceGiftcard" />
        <result column="OUT_CHANNEL" property="outChannel" />
        <result column="COUT_TIME" property="coutTime" />
        <result column="IN_TIME" property="inTime" />
        <result column="MCOMMENT" property="mcomment" />
        <result column="ACCOUNTID" property="accountId" />
        <result column="ACCOUNTNAME" property="accountName" />
        <result column="IMPORTTIME" property="importTime" />
        <result column="PTYPE" property="ptype" />
        <result column="RITYPE" property="ritype" />
        <result column="CONTRACTID" property="contractid" />
        <result column="SUPPLIERID" property="supplierid" />
        <result column="SUPPLIER" property="supplier" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        DID, THEMONTH, SPNAME, IN_MONEY, IN_NUM, IN_GIFTCARD_NUM, IN_PRICE, OUT_PRICE,OUT_MONEY, SALE_PRICE, ACCOUNT_NUM, SALE_GIFTCARD_NUM, ACCOUNT_MONEY, SYSTEM_NUM, BALANCE_MONEY, BALANCE_NORMAL_CARD, BALANCE_GIFTCARD, OUT_CHANNEL,IN_TIME ,COUT_TIME, MCOMMENT, ACCOUNTID, ACCOUNTNAME, IMPORTTIME, PTYPE, RITYPE, CONTRACTID, SUPPLIERID,SUPPLIER
    </sql>

    <select id="getPageByQuery" resultType="org.springblade.imports.entity.FctStandingBookAgain">
        select
        DID,
        THEMONTH,
        SPNAME,
        NVL(IN_MONEY,0) as IN_MONEY,
        NVL(IN_NUM,0) as IN_NUM,
        NVL(IN_GIFTCARD_NUM,0) as IN_GIFTCARD_NUM,
        NVL(IN_PRICE,0) as IN_PRICE,
        NVL(OUT_PRICE,0) as OUT_PRICE,
        NVL(OUT_MONEY,0) as OUT_MONEY,
        NVL(SALE_PRICE,0) as SALE_PRICE,
        NVL(ACCOUNT_NUM,0) as ACCOUNT_NUM,
        NVL(SALE_GIFTCARD_NUM,0) as SALE_GIFTCARD_NUM,
        NVL(ACCOUNT_MONEY,0) as ACCOUNT_MONEY,
        NVL(BALANCE_MONEY,0) as BALANCE_MONEY,
        NVL(BALANCE_NORMAL_CARD,0) BALANCE_NORMAL_CARD,
        NVL(BALANCE_GIFTCARD,0) BALANCE_GIFTCARD,
        NVL(SYSTEM_NUM,0) SYSTEM_NUM,
        OUT_CHANNEL,
        COUT_TIME,
        IN_TIME,
        MCOMMENT,
        ACCOUNTID,
        ACCOUNTNAME,
        IMPORTTIME,
        PTYPE,
        RITYPE,
        CONTRACTID,
        SUPPLIERID,
        SUPPLIER
        from FCT_STANDING_BOOK_AGAIN where 1=1
        <if test="query.channelName != null and query.channelName != ''">
            and regexp_like(OUT_CHANNEL,#{query.channelName})
        </if>
        <if test="query.productName != null and query.productName != ''">
            and regexp_like(SPNAME,#{query.productName})
        </if>
        <if test="query.accountName != null and query.accountName != ''">
            and regexp_like(ACCOUNTNAME,#{query.accountName})
        </if>
        <if test="query.supplier != null and query.supplier != ''">
            and SUPPLIER = #{query.supplier}
        </if>
        <if test="query.ptype != null and query.ptype != ''">
            and RITYPE = #{query.ptype}
        </if>
        <if test="query.qytype != null and query.qytype != ''">
            and PTYPE = #{query.qytype}
        </if>
        <if test="query.cpId != null and query.cpId != ''">
            and SUPPLIERID = #{query.cpId}
        </if>
        <if test="query.contractId != null and query.contractId != ''">
            and CONTRACTID = #{query.contractId}
        </if>
        <if test="query.inOut != null and query.inOut == 1">
            and (IN_MONEY <![CDATA[>]]> 0 or IN_NUM  <![CDATA[>]]> 0 or IN_GIFTCARD_NUM <![CDATA[>]]> 0 or IN_PRICE <![CDATA[>]]> 0)
            /*and (IN_MONEY is not null or IN_NUM is not null or IN_GIFTCARD_NUM is not null or IN_PRICE is not null)*/
        </if>
        <if test="query.inOut != null and query.inOut == 2">
            and (IN_MONEY is null or IN_MONEY = 0) and (IN_NUM is null or IN_NUM = 0) and (IN_GIFTCARD_NUM is null or IN_GIFTCARD_NUM = 0) and (IN_PRICE is null or IN_PRICE = 0)
            /*and IN_MONEY is null and IN_NUM is null and IN_GIFTCARD_NUM is null and IN_PRICE is null*/
        </if>
        <if test="query.startTime != null and query.startTime != ''">
            and THEMONTH <![CDATA[>=]]> #{query.startTime}
        </if>
        <if test="query.endTime != null and query.endTime != ''">
            and THEMONTH <![CDATA[<=]]> #{query.endTime}
        </if>
        order by DID
    </select>

    <select id="getListByQuery" resultType="org.springblade.imports.entity.FctStandingBookAgain">
        select *
        from FCT_STANDING_BOOK_AGAIN where 1=1
        <if test="query.channelName != null and query.channelName != ''">
            and regexp_like(OUT_CHANNEL,#{query.channelName})
        </if>
        <if test="query.productName != null and query.productName != ''">
            and regexp_like(SPNAME,#{query.productName})
        </if>
        <if test="query.accountName != null and query.accountName != ''">
            and regexp_like(ACCOUNTNAME,#{query.accountName})
        </if>
        <if test="query.supplier != null and query.supplier != ''">
            and SUPPLIER = #{query.supplier}
        </if>
        <if test="query.ptype != null and query.ptype != ''">
            and RITYPE = #{query.ptype}
        </if>
        <if test="query.qytype != null and query.qytype != ''">
            and PTYPE = #{query.qytype}
        </if>
        <if test="query.cpId != null and query.cpId != ''">
            and SUPPLIERID = #{query.cpId}
        </if>
        <if test="query.contractId != null and query.contractId != ''">
            and CONTRACTID = #{query.contractId}
        </if>
        <if test="query.inOut != null and query.inOut == 1">
            and (IN_MONEY <![CDATA[>]]> 0 or IN_NUM  <![CDATA[>]]> 0 or IN_GIFTCARD_NUM <![CDATA[>]]> 0 or IN_PRICE <![CDATA[>]]> 0)
        </if>
        <if test="query.inOut != null and query.inOut == 2">
            and (IN_MONEY is null or IN_MONEY = 0) and (IN_NUM is null or IN_NUM = 0) and (IN_GIFTCARD_NUM is null or IN_GIFTCARD_NUM = 0) and (IN_PRICE is null or IN_PRICE = 0)
        </if>
        <if test="query.startTime != null and query.startTime != ''">
            and THEMONTH <![CDATA[>=]]> #{query.startTime}
        </if>
        <if test="query.endTime != null and query.endTime != ''">
            and THEMONTH <![CDATA[<=]]> #{query.endTime}
        </if>
        order by DID
    </select>

    <select id="getDid" resultType="java.lang.Long">
        SELECT
            *
        FROM(
        select * from  FCT_STANDING_BOOK_AGAIN ORDER BY did DESC) a where ROWNUM = 1
    </select>

</mapper>
