<?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.crm.manager.dao.mapper.TradeSwapsMapper">

    <select id="countSearch" parameterType="com.crm.rely.backend.core.entity.base.BaseIbReportListEntity" resultType="Integer">
        select count(id)
        from trade_swaps ts
        <where>
            <if test="ticket != null and ticket > 0">
                and ts.ticket = #{ticket}
            </if>
            <if test="startDate != null">
                and ts.add_time <![CDATA[ >= ]]> #{startDate}
            </if>
            <if test="endDate != null">
                and ts.add_time <![CDATA[ < ]]> #{endDate}
            </if>
            <if test="platform != null and platform != ''">
                and ts.platform = #{platform}
            </if>
        </where>
    </select>


    <select id="pageSearch" parameterType="com.crm.rely.backend.core.entity.base.BaseIbReportListEntity" resultType="com.crm.rely.backend.core.pojo.view.TradeSwapsView">
        select ts.*
        from trade_swaps ts
        <where>
            <if test="ticket != null and ticket > 0">
                and ts.ticket = #{ticket}
            </if>
            <if test="startDate != null">
                and ts.add_time <![CDATA[ >= ]]> #{startDate}
            </if>
            <if test="endDate != null">
                and ts.add_time <![CDATA[ < ]]> #{endDate}
            </if>
            <if test="platform != null and platform != ''">
                and ts.platform = #{platform}
            </if>
        </where>
        order by ts.add_time desc
        <if test="page != null">
            limit #{page.offset},#{page.row}
        </if>
    </select>


    <select id="sumSearch" parameterType="com.crm.rely.backend.core.entity.base.BaseIbReportListEntity" resultType="com.crm.rely.backend.core.pojo.view.TradeSwapsView">
        select sum(ts.amount) `amount`
        from trade_swaps ts
        <where>
            <if test="ticket != null and ticket > 0">
                and ts.ticket = #{ticket}
            </if>
            <if test="startDate != null">
                and ts.add_time <![CDATA[ >= ]]> #{startDate}
            </if>
            <if test="endDate != null">
                and ts.add_time <![CDATA[ < ]]> #{endDate}
            </if>
            <if test="platform != null and platform != ''">
                and ts.platform = #{platform}
            </if>
        </where>
    </select>

</mapper>