" ?>
-mapper.dtd" >
<mapper namespace="com.j1.soa.resource.order.oracle.dao.TpInfoMapper">
    <resultMap id="TpInfoResultMap" type="TpInfo">
        <result column="ID" jdbcType="DECIMAL" property="id" />
        <result column="AVAILABLE_BALANCE" jdbcType="DECIMAL" property="availableBalance" />
    </resultMap>

    <resultMap id="TpPolicyResultMap" type="TpInfo">
        <result column="END_DATE" jdbcType="VARCHAR" property="dueDate" />
        <result column="BALANCE" jdbcType="VARCHAR" property="dueAmount" />
    </resultMap>

    <resultMap id="TpConsumeRecordMap" type="TpConsumeRecord">
        <result column="POLICY_NO" jdbcType="VARCHAR" property="policyNo" />
        <result column="BUSINESS_ID" jdbcType="VARCHAR" property="businessId" />
        <result column="AMOUNT" jdbcType="VARCHAR" property="amount" />
        <result column="ADD_TIME" jdbcType="VARCHAR" property="amountTime" />
        <result column="OPERATION" jdbcType="VARCHAR" property="amountStatus" />
    </resultMap>

    <resultMap id="AmountSumMap" type="TpConsumeRecord">
        <result column="AMOUNT" jdbcType="VARCHAR" property="amount" />
        <result column="OPERATION" jdbcType="VARCHAR" property="amountStatus" />
    </resultMap>

    <sql id="be_fy">
        select *
        from (select row_.*, rownum rownum_
        from (
    </sql>
    <!-- 用于分页的尾部 -->
    <sql id="ed_fy">
        ) row_

        <![CDATA[
                 and    rownum <= #{offset}+#{pageSize}
                 ]]>
        )

        <![CDATA[
                 and    rownum_ > #{offset}
                 ]]>
    </sql>

    <select id="checkIsTp" parameterType="java.lang.Long" resultType="java.lang.Integer">
        select count(*)
        from fec.tp_account tpa
        where tpa.member_id = #{memberId,jdbcType=DECIMAL}
        and tpa.is_delete = 'N'
    </select>

    <select id="getTpInfo" parameterType="java.lang.Long" resultMap="TpInfoResultMap">
        select tpp.tp_account_id as id, sum(tpp.balance) as available_balance
          from fec.tp_account tpa, fec.tp_policy tpp
         where tpa.member_id = #{memberId,jdbcType=DECIMAL}
           and tpa.id = tpp.tp_account_id
           and tpa.is_delete = 'N'
         group by tpp.tp_account_id
    </select>

    <select id="getLimitPolicy" parameterType="java.lang.Long" resultMap="TpPolicyResultMap">
        select tpp.balance,tpp.end_date
        from fec.tp_policy tpp
        where tpp.tp_account_id = #{tpAccountId,jdbcType=DECIMAL}
         <![CDATA[ and TO_DATE(tpp.end_date, 'yyyy-mm-dd') <=
        TO_DATE(TO_CHAR(sysdate + interval '2' month, 'yyyy-mm-dd'),
        'yyyy-mm-dd')
        and TO_DATE(tpp.start_date, 'yyyy-mm-dd') <= TO_DATE(TO_CHAR(sysdate,'yyyy-mm-dd'), 'yyyy-mm-dd')
        and TO_DATE(tpp.end_date, 'yyyy-mm-dd') >=TO_DATE(TO_CHAR(sysdate, 'yyyy-mm-dd'), 'yyyy-mm-dd')
        and tpp.is_delete = 'N'
        ]]>
        order by tpp.end_date
    </select>

    <select id="getTpConsumeRecordList" parameterType="Pageable" resultMap="TpConsumeRecordMap">
        <include refid="be_fy"/>
        select tpo.policy_no,
               tpo.business_id,
               sum(tpo.amount) || '' as amount,
               tpo.add_time,
               tpo.OPERATION
        from fec.tp_policy_operation_log tpo,fec.tp_account tpa,fec.tp_policy tpp
        where tpa.id = tpp.tp_account_id
            and tpa.is_delete = 'N'
            and tpp.policy_no = tpo.policy_no
            and tpp.is_delete = 'N'
            and tpa.member_id = #{params.memberId}
            <if test="params.beginDate != null">
                <![CDATA[
                 and to_date(tpo.add_time,'yyyy-mm-dd hh24:mi:ss') >= TO_DATE(#{params.beginDate},'yyyy-mm-dd hh24:mi:ss')
                ]]>
            </if>
            <if test="params.endDate != null">
                <![CDATA[
                and to_date(tpo.add_time,'yyyy-mm-dd hh24:mi:ss') <= TO_DATE(#{params.endDate},'yyyy-mm-dd hh24:mi:ss')
                ]]>
            </if>
         group by tpo.policy_no, tpo.business_id, tpo.add_time, tpo.OPERATION
         order by tpo.add_time desc
        <include refid="ed_fy"/>
    </select>

    <select id="getTpConsumeRecordListCount" parameterType="TpConsumeRecord" resultType="Integer">
        )
          from
            (select tpo.policy_no,
            tpo.business_id,
            sum(tpo.amount) || '' as amount,
            tpo.add_time,
            tpo.OPERATION
            from fec.tp_policy_operation_log tpo,fec.tp_account tpa,fec.tp_policy tpp
            where tpa.id = tpp.tp_account_id
            and tpa.is_delete = 'N'
            and tpp.policy_no = tpo.policy_no
            and tpp.is_delete = 'N'
            and tpa.member_id = #{memberId}
            <if test="beginDate != null">
                <![CDATA[
                     and to_date(tpo.add_time,'yyyy-mm-dd hh24:mi:ss') >= TO_DATE(#{beginDate},'yyyy-mm-dd hh24:mi:ss')
                    ]]>
            </if>
            <if test="endDate != null">
                <![CDATA[
                    and to_date(tpo.add_time,'yyyy-mm-dd hh24:mi:ss') <= TO_DATE(#{endDate},'yyyy-mm-dd hh24:mi:ss')
                    ]]>
            </if>
            group by tpo.policy_no, tpo.business_id, tpo.add_time, tpo.OPERATION
            order by tpo.add_time desc)
    </select>

    <select id="getAmountSumByOperation" parameterType="TpConsumeRecord" resultMap="AmountSumMap">
        select sum(tpo.amount) || '' as amount, tpo.OPERATION
        from fec.tp_policy_operation_log tpo,
        fec.tp_account              tpa,
        fec.tp_policy               tpp
        where tpa.id = tpp.tp_account_id
        and tpa.is_delete = 'N'
        and tpp.policy_no = tpo.policy_no
        and tpp.is_delete = 'N'
        and tpa.member_id = #{memberId}
        <if test="beginDate != null">
            <![CDATA[
                     and to_date(tpo.add_time,'yyyy-mm-dd hh24:mi:ss') >= TO_DATE(#{beginDate},'yyyy-mm-dd hh24:mi:ss')
                    ]]>
        </if>
        <if test="endDate != null">
            <![CDATA[
                    and to_date(tpo.add_time,'yyyy-mm-dd hh24:mi:ss') <= TO_DATE(#{endDate},'yyyy-mm-dd hh24:mi:ss')
                    ]]>
        </if>
        group by tpo.OPERATION
    </select>

    <select id="getTpExceptionInfo" parameterType="Pageable" resultMap="TpConsumeRecordMap">
        <include refid="be_fy"/>
        '">
            select tpo.policy_no,
            tpo.business_id,
            sum(tpo.amount) || '' as amount,
            tpo.add_time,
            tpo.OPERATION
            from fec.tp_policy_operation_log tpo,
            fec.tp_account              tpa,
            fec.tp_policy               tpp
            where tpa.id = tpp.tp_account_id
            and tpa.is_delete = 'N'
            and tpp.policy_no = tpo.policy_no
            and tpp.is_delete = 'N'
            and tpa.member_id = #{params.memberId}
            and tpo.operation in (${params.amountStatus})
            group by tpo.policy_no, tpo.business_id, tpo.add_time, tpo.OPERATION
        </if>
        <if test="params.amountStatus == 'all'">
            select tpo.policy_no,
            tpo.business_id,
            sum(tpo.amount) || '' as amount,
            tpo.add_time,
            tpo.OPERATION
            from fec.tp_policy_operation_log tpo,
            fec.tp_account              tpa,
            fec.tp_policy               tpp
            where tpa.id = tpp.tp_account_id
            and tpa.is_delete = 'N'
            and tpp.policy_no = tpo.policy_no
            and tpp.is_delete = 'N'
            and tpa.member_id = #{params.memberId}
            ')
            group by tpo.policy_no, tpo.business_id, tpo.add_time, tpo.OPERATION
            union all
            select tpp.policy_no,
            'invalid' as business_id,
            tpp.balance || '',
            tpp.end_date as add_time,
            ' as OPERATION
            from fec.tp_account tpa, fec.tp_policy tpp
            where tpa.id = tpp.tp_account_id
            and tpa.is_delete = 'N'
            and tpp.is_delete = 'N'
            and tpa.member_id =  #{params.memberId}
        <![CDATA[
            and TO_DATE(tpp.end_date || '23:59:59', 'yyyy-mm-dd hh24:mi:ss') <
                to_date(to_char(sysdate, 'yyyy-mm-dd') || ' 23:59:59',
            'yyyy-mm-dd hh24:mi:ss')
            ]]>
        </if>
        '">
            select tpo.policy_no,
            tpo.business_id,
            sum(tpo.amount) || '' as amount,
            tpo.add_time,
            tpo.OPERATION
            from fec.tp_policy_operation_log tpo,
            fec.tp_account              tpa,
            fec.tp_policy               tpp
            where tpa.id = tpp.tp_account_id
            and tpa.is_delete = 'N'
            and tpp.policy_no = tpo.policy_no
            and tpp.is_delete = 'N'
            and tpa.member_id = #{params.memberId}
            ')
            group by tpo.policy_no, tpo.business_id, tpo.add_time, tpo.OPERATION
            UNION  ALL
            select tpp.policy_no,
            'invalid' as business_id,
            tpp.balance || '',
            tpp.end_date as add_time,
            ' as OPERATION
            from fec.tp_account tpa, fec.tp_policy tpp
            where tpa.id = tpp.tp_account_id
            and tpa.is_delete = 'N'
            and tpp.is_delete = 'N'
            and tpa.member_id =  #{params.memberId}
            <![CDATA[
            and TO_DATE(tpp.end_date || '23:59:59', 'yyyy-mm-dd hh24:mi:ss') <
                to_date(to_char(sysdate, 'yyyy-mm-dd') || ' 23:59:59',
            'yyyy-mm-dd hh24:mi:ss')
            ]]>
        </if>
        order by add_time desc
        <include refid="ed_fy"/>
    </select>

    <select id="getTpExceptionInfoCount" parameterType="TpConsumeRecord" resultType="Integer">
        )
        from
        (
        '">
            select tpo.policy_no,
            tpo.business_id,
            sum(tpo.amount) || '' as amount,
            tpo.add_time,
            tpo.OPERATION
            from fec.tp_policy_operation_log tpo,
            fec.tp_account              tpa,
            fec.tp_policy               tpp
            where tpa.id = tpp.tp_account_id
            and tpa.is_delete = 'N'
            and tpp.policy_no = tpo.policy_no
            and tpp.is_delete = 'N'
            and tpa.member_id = #{memberId}
            and tpo.operation in (${amountStatus})
            group by tpo.policy_no, tpo.business_id, tpo.add_time, tpo.OPERATION
        </if>
        <if test="amountStatus == 'all'">
            select tpo.policy_no,
            tpo.business_id,
            sum(tpo.amount) || '' as amount,
            tpo.add_time,
            tpo.OPERATION
            from fec.tp_policy_operation_log tpo,
            fec.tp_account              tpa,
            fec.tp_policy               tpp
            where tpa.id = tpp.tp_account_id
            and tpa.is_delete = 'N'
            and tpp.policy_no = tpo.policy_no
            and tpp.is_delete = 'N'
            and tpa.member_id = #{memberId}
            ')
            group by tpo.policy_no, tpo.business_id, tpo.add_time, tpo.OPERATION
            union all
            select tpp.policy_no,
            'invalid' as business_id,
            tpp.balance || '',
            tpp.end_date as add_time,
            ' as OPERATION
            from fec.tp_account tpa, fec.tp_policy tpp
            where tpa.id = tpp.tp_account_id
            and tpa.is_delete = 'N'
            and tpp.is_delete = 'N'
            and tpa.member_id =  #{memberId}
            <![CDATA[
            and TO_DATE(tpp.end_date || '23:59:59', 'yyyy-mm-dd hh24:mi:ss') <
                to_date(to_char(sysdate, 'yyyy-mm-dd') || ' 23:59:59',
            'yyyy-mm-dd hh24:mi:ss')
            ]]>
        </if>
        '">
            select tpo.policy_no,
            tpo.business_id,
            sum(tpo.amount) || '' as amount,
            tpo.add_time,
            tpo.OPERATION
            from fec.tp_policy_operation_log tpo,
            fec.tp_account              tpa,
            fec.tp_policy               tpp
            where tpa.id = tpp.tp_account_id
            and tpa.is_delete = 'N'
            and tpp.policy_no = tpo.policy_no
            and tpp.is_delete = 'N'
            and tpa.member_id = #{memberId}
            ')
            group by tpo.policy_no, tpo.business_id, tpo.add_time, tpo.OPERATION
            UNION  ALL
            select tpp.policy_no,
            'invalid' as business_id,
            tpp.balance || '',
            tpp.end_date as add_time,
            ' as OPERATION
            from fec.tp_account tpa, fec.tp_policy tpp
            where tpa.id = tpp.tp_account_id
            and tpa.is_delete = 'N'
            and tpp.is_delete = 'N'
            and tpa.member_id =  #{memberId}
            <![CDATA[
            and TO_DATE(tpp.end_date || '23:59:59', 'yyyy-mm-dd hh24:mi:ss') <
                to_date(to_char(sysdate, 'yyyy-mm-dd') || ' 23:59:59',
            'yyyy-mm-dd hh24:mi:ss')
            ]]>
        </if>
        order by add_time desc)
    </select>
</mapper>

UNION ALL的用法的更多相关文章

  1. 转 SQL Union和SQL Union All两者用法区别效率以及与order by 和 group by配合问题

    SQL Union和SQL Union All两者用法区别效率以及与order by 和 group by配合问题 SQL Union和SQL Union All用法 SQL UNION 操作符 UN ...

  2. Union all的用法实例sql

    ---Union all的用法实例sqlSELECT TOP (100) PERCENT ID, bid_user_id, UserName, amount, createtime, borrowTy ...

  3. struct与 union的基本用法

    结构体与联合体是C语言的常见数据类型,可对C的基本数据类型进行组合使之能表示复杂的数据结构,意义深远,是优异代码的必备工具.一.        struct与 union的基本用法,在语法上union ...

  4. mysql left join和union结合的用法

    left join和union结合的用法子查询union 然后加个括号设置个别名 (union自动去除 重复的 ) <pre>select o.nickName,o.sex,o.provi ...

  5. union与union all的用法给区别

    用法: 当我们需要把两个或多个sql联合起来查询就用到了union或者union all 区别: 这两者的区别就在于union会自动的把多个sql查出来重复的排除掉,而union all这是会全部显示 ...

  6. sql union和union all的用法及效率

    UNION指令的目的是将两个SQL语句的结果合并起来.从这个角度来看, 我们会产生这样的感觉,UNION跟JOIN似乎有些许类似,因为这两个指令都可以由多个表格中撷取资料. UNION的一个限制是两个 ...

  7. Phalapi 中Union和Union All的用法

    有时候在进行数据库查询的时候会用到union查询,但是查询的时候会发现两个limit只有一个是有效的,如下查询 select * from table where status = 0 limit 1 ...

  8. sql中union和union all的用法

    如果我们需要将两个select语句的结果作为一个整体显示出来,我们就需要用到union或者union all关键字.union(或称为联合)的作用是将多个结果合并在一起显示出来. union和unio ...

  9. union all 简单用法

    select Y.ID,sum(cast(Y.m as int)) as hefrom(select top 10 a.ID,a.AlarmSource as m from dbo.AlarmInfo ...

  10. group By 和 Union 、 Union all的用法

    我学习的是MySQL,学习写sql语句过程中遇到Group By 和 Union. 大家乐意看这两个链接,写的很好 Group By: www.cnblogs.com/rainman/archive/ ...

随机推荐

  1. Cocos Creator_发布到微信小游戏平台

    观看官方教程,地址 传送门: http://docs.cocos.com/creator/manual/zh/publish/publish-wechatgame.html CocosCreator接 ...

  2. Maven实战(八)——常用Maven插件介绍(下)

    我们都知道Maven本质上是一个插件框架,它的核心并不执行任何具体的构建任务,所有这些任务都交给插件来完成,例如编译源代码是由maven- compiler-plugin完成的.进一步说,每个任务对应 ...

  3. 一个封装不错的 TcpClient 类

    using System;using System.Net;using System.Net.Sockets;using System.Text;using System.Threading; nam ...

  4. parcel 中小型项目打包工具

    "0配置"打包器(bundler)Parcel Parcel官网(有中文文档) webpack 要有大量的配置,这样带来的成本就是复杂性--与此相对的,Parcel 带来了简洁性. ...

  5. db2删除表中数据

    DB2数据库系统建表后,难免会有将表中数据清空的需求,本文将为您介绍DB2数据库中四种数据删除的方法,供您参考,您可以根据实际情况来进行选择,希望能对有所帮助. 1. 使用 DELETE 语句,即: ...

  6. 【枚举】Consonant Fencity @upcexam5110

    时间限制: 3 Sec 内存限制: 512 MB 题目描述 There are two kinds of sounds in spoken languages: vowels and consonan ...

  7. 【想法题】Knot Puzzle @AtCoder Grand Contest 002 C/upcexam5583

    时间限制: 2 Sec 内存限制: 256 MB 题目描述 We have N pieces of ropes, numbered 1 through N. The length of piece i ...

  8. SQL批量更新数据

    SQL批量更新数据 step1:导入Excel数据, 具体见百度.注意点:一列中含有float型数据和文本数据的时候,导入要将Excel中的表格属性改成文本,或在数字项目前加个单引号.   step2 ...

  9. 《2019测试面试题-上海悠悠.pdf》

    前言 面试测试岗位一般会有笔试题,笔试题考SQL和编程基础比较多,小编最近收集了多家公司的测试面试题,整理成一个文档供大家参考. 2018年下半年一直不太平,听到最多的就是"p2p暴雷&qu ...

  10. 07、RDD持久化

    为了避免多次计算同一个RDD(如上面的同一result RDD就调用了两次Action操作),可以让Spark对数据进行持久化.当我们让Spark持久化存储一个RDD时,计算出RDD的节点会分别保存它 ...