<?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="cn.roadm.mapper.InternationalMapper">

    <select id="queryAllInterPriceGroups" resultType="cn.roadm.bo.InterPriceGroupDTO">
        select * from inter_sms_price_group
    </select>

    <resultMap type="InternationalCode" id="InternationalCodeResultMap">
        <id column="id" property="id"/>
        <result column="inter_name" property="interName"/>
        <result column="chinese" property="chinese"/>
        <result column="inter_code" property="interCode"/>
        <result column="simple_code" property="simpleCode"/>
        <result column="create_time" property="createTime"/>
    </resultMap>

    <resultMap type="TaskInfo" id="taskResultMap">
        <result column="sp_id" property="sp_id" />
        <result column="sp_name" property="sp_name" />
        <result column="price" property="price" />
        <result column="channelid" property="channelid" />
        <result column="chinese" property="chinese" />
        <result column="allnumber" property="allnumber" />
        <result column="succ" property="succ" />
        <result column="fail" property="fail" />
        <result column="arrive_succ" property="arrive_succ" />
        <result column="arrive_fail" property="arrive_fail" />
        <result column="unRecMsgnum" property="unRecMsgnum" />
        <result column="stat_time" property="stat_time"/>
        <result column="country_code" property="chinese"/>
    </resultMap>

    <resultMap type="InternationalTaskDetailInfo" id="TaskDetailInfoResultMap">
        <id column="id" property="id" />
        <result column="taskid" property="taskid" />
        <result column="res_result" property="res_result" />
        <result column="res_desc" property="res_desc" />
        <result column="callmdn" property="callmdn" />
        <result column="res_content" property="res_content" />
        <result column="sp_id" property="sp_id" />
        <result column="send_time" property="send_time" />
        <result column="create_time" property="createtime" />
        <result column="status" property="status" />
        <result column="result" property="result" />
        <result column="stat_desc" property="stat_desc" />
        <result column="arrive_time" property="arrive_time" />
        <result column="sp_name" property="sp_name" />
        <result column="pa_dec" property="pa_dsc" />
        <result column="num" property="num" />
        <result column="countrycode" property="chinese" />
    </resultMap>


    <resultMap type="SpInfo" id="spInfoAndSpmoney">
        <result column="spid" property="spid"/>
        <result column="sp_name" property="sp_name"/>
        <result column="currency" property="currency"/>
        <result column="fee_type" property="feetype"/>
        <result column="effect_month" property="effect_month"/>
        <result column="money" property="money"/>
        <result column="use_money" property="useMoney"/>
        <result column="billing_account_id" property="billingAccountId"/>
        <result column="billing_spid" property="billingAccountSpId"/>
        <result column="billing_sp_name" property="billingAccountSpName"/>
    </resultMap>

    <resultMap type="ChargeRecord" id="ChargeRecordResult">
        <id column="id" property="id"/>
        <result column="sp_name" property="sp_name"/>
        <result column="chargeopeartor" property="operator"/>
        <result column="chargeaftermoney" property="chargeAfterMoney"/>
        <result column="amount" property="amount"/>
        <result column="sp_id" property="sp_id"/>
        <result column="type" property="type"/>
        <result column="descption" property="descption"/>
        <result column="currency" property="currency"/>
    </resultMap>

     <resultMap type="TaskInfo" id="interAuditTaskMap">
        <id column="id" property="task_id" />
        <result column="content" property="content" />
        <result column="createtime" property="beginTime" />
        <result column="createid" property="createid" />
        <result column="total" property="total" />
        <result column="allnumber" property="allnumber" />
        <result column="task_type" property="task_type" />
        <result column="status" property="status" />
        <result column="send_type" property="send_type" />
        <result column="sp_id" property="sp_id" />
        <result column="sp_name" property="sp_name" />
        <result column="audit_result" property="audit_result" />
        <result column="mdns" property="mdns" />
        <result column="country" property="chinese" />
    </resultMap>

    <select id="listPageInternationalCode" parameterType="InternationalCode" resultMap="InternationalCodeResultMap">
        SELECT id, inter_name, chinese, inter_code, simple_code, create_time
        FROM inter_code
        <where>
            <if test="chinese != null and chinese != ''">
                and chinese like concat('%',#{chinese},'%')
            </if>
            <if test="interCode != null and interCode != ''">
                and inter_code = #{interCode}
            </if>
            <if test="simpleCode != null and simpleCode != ''">
                and simple_code = #{simpleCode}
            </if>
        </where>
    </select>

    <select id="getInternationalCodeAll"  resultMap="InternationalCodeResultMap">
        SELECT id, inter_name, chinese, inter_code, simple_code, create_time
        FROM inter_code
    </select>

    <select id="getInternationalCodeById" parameterType="int" resultMap="InternationalCodeResultMap">
        select
        id, inter_name, chinese, inter_code, simple_code
        from inter_code
        where id=#{id}
    </select>

    <insert id="insertInternationalCode" useGeneratedKeys="true" keyProperty="id" parameterType="InternationalCode">
        insert into inter_code
        (inter_name, chinese, inter_code, simple_code, create_time)
        values
        (#{interName}, #{chinese}, #{interCode}, #{simpleCode}, sysdate())
    </insert>

    <update id="updateInternationalCode" parameterType="InternationalCode">
        update inter_code set
        inter_name=#{interName},
        chinese=#{chinese},
        inter_code=#{interCode},
        simple_code=#{simpleCode}
        where id=#{id}
    </update>

    <delete id="deleteInternationalCode" parameterType="int">
        delete from inter_code where id = #{id}
    </delete>

    <insert  id="addInternationalCodeBatch" useGeneratedKeys="true" keyProperty="id"  parameterType="java.util.List">
        insert into inter_code (inter_name, chinese, inter_code, simple_code, create_time)
        values
        <foreach collection="list" item="item"  index="index"  separator="," >
            (#{item.interName}, #{item.chinese}, #{item.interCode}, #{item.simpleCode}, sysdate())
        </foreach>
    </insert>

    <select id="exportInternationalCode" parameterType="InternationalCode" resultType="Map">
        SELECT id, inter_name, chinese, inter_code, simple_code, date_format(create_time, '%Y-%m-%d %H:%i:%S') create_time
        FROM inter_code
        <where>
            <if test="chinese != null and chinese != ''">
                and chinese like concat('%',#{chinese},'%')
            </if>
            <if test="interCode != null and interCode != ''">
                and inter_code = #{interCode}
            </if>
            <if test="simpleCode != null and simpleCode != ''">
                and simple_code = #{simpleCode}
            </if>
        </where>
    </select>

    <select id="getCountryTaskTotal"
        parameterType="TaskInfo" resultType="TaskInfo">
        SELECT
        CONCAT(Round(sum(spp.arrive_succ)/sum(spp.submit_succ)*100,2),'%') sp_succ_percent,
        sum( spp.submit_succ ) succ,
        sum( IFNULL( spp.submit_fail, 0 ) ) fail,
        sum( spp.arrive_succ ) arrive_succ,
        sum( spp.arrive_fail ) arrive_fail
        FROM
            inter_sp_country_summary spp, sms_sp_info sp
        WHERE
            spp.spid=sp.id
        <if test="createTime!=null and createTime!=''">
            and spp.stat_time&gt;=str_to_date(#{createTime},'%Y-%m-%d')
        </if>
        <if test="createTime1!=null and createTime1!=''">
            and
            spp.stat_time&lt;DATE_ADD(str_to_date(#{createTime1},'%Y-%m-%d'),INTERVAL
            1 DAY)
        </if>
        <if test="sp_saler!=null and sp_saler!=''">
            and sp.sp_saler =#{sp_saler}
        </if>
        <if test="sp_name!=null and sp_name!=''">
            and sp.sp_name like CONCAT('%',#{sp_name},'%')
        </if>
        <if test="sp_id!=null and sp_id>0">
            and spp.spid=#{sp_id}
        </if>
        <if test="sp_type!=null and sp_type>0">
            and sp.sp_type =#{sp_type}
        </if>
        <if test="chinese!=null and chinese!=''">
            and spp.country_code like CONCAT('%',#{chinese},'%')
        </if>
        <if test="type_channel!=null and type_channel!='' and channelid!=null and channelid >=0">
            and spp.channelid=#{channelid}
        </if>
    </select>

    <select id="listPageCountryTaskTotal"
        parameterType="TaskInfo" resultMap="taskResultMap">
        <if test="(type_country!=null and type_country!='') and (type_sp!=null and type_sp!='')">
            SELECT
            inter.sp_name,
            inter.sp_id,
            inter.country_code,
            p.price,
            <if test="type_channel!=null and type_channel!=''">
                inter.channelid,
            </if>
            <if test="type_day!=null and type_day!=''">
                inter.stat_time,
            </if>
            inter.succ,
            inter.fail,
            inter.arrive_succ,
            inter.arrive_fail
            FROM
            (
        </if>
        SELECT
        <if test="(type_sp!=null and type_sp!='') or (sp_name!=null and sp_name!='')">
            sp.sp_name,
        </if>
        <if test="(type_sp!=null and type_sp!='') or (sp_id!=null and sp_id>0)">
            sp.id sp_id,
        </if>
        <if test="(type_country!=null and type_country!='') or (chinese!=null and chinese!='')">
            spp.country_code,
        </if>
        <if test="(type_country!=null and type_country!='') and (type_sp!=null and type_sp!='')">
            sp.inter_price_group,
        </if>
        <if test="type_channel!=null and type_channel!=''">
            spp.channelid,
        </if>
         <if test="type_day!=null and type_day!=''">
            spp.stat_time,
         </if>
        sum( spp.submit_succ ) succ,
        sum( IFNULL( spp.submit_fail, 0 ) ) fail,
        sum( spp.arrive_succ ) arrive_succ,
        sum( spp.arrive_fail ) arrive_fail
        FROM
            inter_sp_country_summary spp, sms_sp_info sp, sms_send_channel_info sc
        WHERE
            spp.spid=sp.id and sc.id=spp.channelid
        <if test="createTime!=null and createTime!=''">
            and spp.stat_time&gt;=str_to_date(#{createTime},'%Y-%m-%d')
        </if>
        <if test="createTime1!=null and createTime1!=''">
            and
            spp.stat_time&lt;DATE_ADD(str_to_date(#{createTime1},'%Y-%m-%d'),INTERVAL
            1 DAY)
        </if>
        <if test="chinese!=null and chinese!=''">
            and spp.country_code like CONCAT('%',#{chinese},'%')
        </if>
        <if test="type_channel!=null and type_channel!='' and channelid!=null and channelid >=0">
            and spp.channelid=#{channelid}
        </if>
        <if test="type_channel!=null and type_channel!='' and channel_name!=null and channel_name !=''">
            and sc.CHANNEL_NAME like CONCAT('%', #{channel_name}, '%')
        </if>
        <if test="sp_saler!=null and sp_saler!=''">
            and sp.sp_saler =#{sp_saler}
        </if>
         <if test="sp_name!=null and sp_name!=''">
            and sp.sp_name like CONCAT('%',#{sp_name},'%')
        </if>
        <if test="sp_id!=null and sp_id>0">
            and spp.spid=#{sp_id}
        </if>
        <if test="sp_type!=null and sp_type>0">
            and sp.sp_type =#{sp_type}
        </if>
        <trim prefix="group by" suffixOverrides=",">
            <if test="(type_sp!=null and type_sp!='') or (sp_name!=null and sp_name!='')">
                sp.sp_name,
            </if>
            <if test="(type_sp!=null and type_sp!='') or (sp_id!=null and sp_id>0)">
                sp.id,
            </if>
            <if test="(type_country!=null and type_country!='') or (chinese!=null and chinese!='')">
                spp.country_code,
            </if>
            <if test="type_channel!=null and type_channel!=''">
                spp.channelid,
            </if>
            <if test="type_day!=null and type_day!=''">
                spp.stat_time,
            </if>
        </trim>
            order by sum(spp.submit_succ) desc
        <if test="(type_country!=null and type_country!='') and (type_sp!=null and type_sp!='')">
            ) inter
            LEFT JOIN inter_sms_price p ON inter.inter_price_group = p.gid AND inter.country_code = p.country
            ORDER BY inter.succ desc
        </if>
    </select>

    <select id="exportCountryTotalList"
        parameterType="TaskInfo" resultType="Map">
        <if test="(type_country!=null and type_country!='') and (type_sp!=null and type_sp!='')">
            SELECT
            inter.SP_NAME SP_NAME,
            inter.SP_ID SP_ID,
            inter.CHINESE CHINESE,
            p.price PRICE,
            <if test="type_channel!=null and type_channel!=''">
                inter.CHANNELID CHANNELID,
            </if>
            <if test="type_day!=null and type_day!=''">
                inter.STAT_TIME STAT_TIME,
            </if>
            <if test="type_operate!=null and type_operate!=''">
                inter.operateOtype operateOtype,
            </if>
            inter.SP_SUCC_PERCENT SP_SUCC_PERCENT,
            inter.SUCC SUCC,
            inter.FAIL FAIL,
            inter.ARRIVE_SUCC ARRIVE_SUCC,
            inter.ARRIVE_FAIL ARRIVE_FAIL
            FROM
            (
        </if>
        SELECT
        <if test="(type_sp!=null and type_sp!='') or (sp_name!=null and sp_name!='')">
            sp.sp_name SP_NAME,
        </if>
        <if test="(type_sp!=null and type_sp!='') or (sp_id!=null and sp_id>0)">
            sp.id SP_ID,
        </if>
        <if test="type_channel!=null and type_channel!=''">
            sc.channel_name CHANNELID,
        </if>
        <if test="(type_country!=null and type_country!='') and (type_sp!=null and type_sp!='')">
            sp.inter_price_group,
        </if>
        <if test="(type_country!=null and type_country!='') or (chinese!=null and chinese!='')">
            spp.country_code CHINESE,
        </if>
         <if test="type_day!=null and type_day!=''">
            date_format(spp.stat_time,'%Y-%m-%d') STAT_TIME,
         </if>
        <if test="type_operate!=null and type_operate!=''">
            spp.otype operateOtype,
        </if>
        CONCAT(Round(sum(spp.arrive_succ)/sum(spp.submit_succ)*100,2),'%') SP_SUCC_PERCENT,
        sum( spp.submit_succ ) SUCC,
        sum( IFNULL( spp.submit_fail, 0 ) ) FAIL,
        sum( spp.arrive_succ ) ARRIVE_SUCC,
        sum( spp.arrive_fail ) ARRIVE_FAIL
        FROM
            inter_sp_country_summary spp, sms_sp_info sp, sms_send_channel_info sc
        WHERE
            spp.spid=sp.id and sc.id=spp.channelid
        <if test="createTime!=null and createTime!=''">
            and spp.stat_time&gt;=str_to_date(#{createTime},'%Y-%m-%d')
        </if>
        <if test="createTime1!=null and createTime1!=''">
            and
            spp.stat_time&lt;DATE_ADD(str_to_date(#{createTime1},'%Y-%m-%d'),INTERVAL
            1 DAY)
        </if>
        <if test="chinese!=null and chinese!=''">
            and spp.country_code like CONCAT('%',#{chinese},'%')
        </if>
        <if test="type_channel!=null and type_channel!='' and channelid!=null and channelid >=0">
            and spp.channelid=#{channelid}
        </if>
        <if test="type_channel!=null and type_channel!='' and channel_name!=null and channel_name !=''">
            and sc.CHANNEL_NAME like CONCAT('%', #{channel_name}, '%')
        </if>
        <if test="type_operate!=null and type_operate!='' and operateOtypeSelect!=null">
            and spp.otype = #{operateOtypeSelect}
        </if>
        <if test="sp_saler!=null and sp_saler!=''">
            and sp.sp_saler =#{sp_saler}
        </if>
         <if test="sp_name!=null and sp_name!=''">
            and sp.sp_name like CONCAT('%',#{sp_name},'%')
        </if>
        <if test="sp_id!=null and sp_id>0">
            and spp.spid=#{sp_id}
        </if>
        <if test="sp_type!=null and sp_type>0">
            and sp.sp_type =#{sp_type}
        </if>
        <trim prefix="group by" suffixOverrides=",">
            <if test="(type_sp!=null and type_sp!='') or (sp_name!=null and sp_name!='')">
                sp.sp_name,
            </if>
            <if test="(type_sp!=null and type_sp!='') or (sp_id!=null and sp_id>0)">
                sp.id,
            </if>
             <if test="type_channel!=null and type_channel!=''">
                spp.channelid,
            </if>
            <if test="(type_country!=null and type_country!='') or (chinese!=null and chinese!='')">
                spp.country_code,
            </if>
            <if test="type_day!=null and type_day!=''">
                spp.stat_time,
            </if>
            <if test="type_operate!=null and type_operate!=''">
                spp.otype,
            </if>
        </trim>
        order by sum(spp.submit_succ) desc
        <if test="(type_country!=null and type_country!='') and (type_sp!=null and type_sp!='')">
            ) inter
            LEFT JOIN inter_sms_price p ON inter.inter_price_group = p.gid AND inter.CHINESE = p.country
            ORDER BY inter.SUCC desc
        </if>
    </select>

    <select id="listSpInterTaskTotalCount" parameterType="TaskInfo"
        resultMap="taskResultMap">
        select
        sum(IFNULL(tk.allnumber,0)) allnumber,
        sum(IFNULL(tk.succ,0)) succ,
        sum(IFNULL(tk.fail,0)) fail,
        sum(IFNULL(tk.arrive_succ,0)) arrive_succ,
        <!-- sum(IFNULL(tk.allnumber-tk.arrive_succ-tk.arrive_fail,0)) unRecMsgnum, -->
        sum(IFNULL(tk.allnumber,0))-sum(IFNULL(tk.arrive_succ,0))-sum(IFNULL(tk.arrive_fail,0)) unRecMsgnum,
        sum(IFNULL(tk.arrive_fail,0)) arrive_fail
        from inter_sp_summary tk, sms_sp_info sp
        where tk.spid = sp.id

         <if test="sp_name!=null and sp_name!=''">
            and sp.sp_name like CONCAT('%',#{sp_name},'%')
        </if>
        <if test="sp_id!=null and sp_id>0">
            and tk.spid=#{sp_id}
        </if>
        <if test="sp_saler!=null and sp_saler!=''">
            and sp.sp_saler =#{sp_saler}
        </if>
        <if test="sp_type!=null and sp_type>0">
            and sp.sp_type =#{sp_type}
        </if>

        <if test="createTime!=null and createTime!=''">
            and tk.stat_time&gt;=str_to_date(#{createTime},'%Y-%m-%d')
        </if>
        <if test="createTime1!=null and createTime1!=''">
            and
            tk.stat_time&lt;DATE_ADD(str_to_date(#{createTime1},'%Y-%m-%d'),INTERVAL 1 DAY)
        </if>
    </select>

    <select id="listPageSpInterTaskTotal" parameterType="TaskInfo"
        resultMap="taskResultMap">
        select sp.id sp_id,
        sp.sp_name,
        sum(tk.allnumber) allnumber,
        sum(tk.succ) succ,
        sum(IFNULL(tk.fail,0)) fail,
        sum(tk.arrive_succ) arrive_succ,
        <!-- sum(tk.allnumber-asa.total-tk.arrive_succ-tk.arrive_fail) unRecMsgnum, -->
        sum(tk.arrive_fail) arrive_fail
        from sms_sp_info sp left join  inter_sp_summary tk on tk.spid = sp.id

        where 1=1

        <if test="sp_name!=null and sp_name!=''">
            and sp.sp_name like CONCAT('%',#{sp_name},'%')
        </if>
        <if test="sp_id!=null and sp_id>0">
            and tk.spid=#{sp_id}
        </if>
        <if test="sp_saler!=null and sp_saler!=''">
            and sp.sp_saler =#{sp_saler}
        </if>
        <if test="sp_type!=null and sp_type>0">
            and sp.sp_type =#{sp_type}
        </if>
        <if test="createTime!=null and createTime!=''">
            and tk.stat_time&gt;=str_to_date(#{createTime},'%Y-%m-%d')
        </if>
        <if test="createTime1!=null and createTime1!=''">
            and
            tk.stat_time&lt;DATE_ADD(str_to_date(#{createTime1},'%Y-%m-%d'),INTERVAL 1 DAY)
        </if>
        group by sp.id, sp.sp_name
        order by sum(tk.allnumber) desc

    </select>


    <select id="exportSpInterTotalList" parameterType="TaskInfo"
        resultType="Map">
        select sp.id sp_id,
        sp.sp_name,
        sum(tk.allnumber) allnumber,
        sum(tk.succ) succ,
        sum(IFNULL(tk.fail,0)) fail,
        sum(tk.arrive_succ) arrive_succ,

        sum(IFNULL(tk.succ,0))+sum(IFNULL(tk.fail,0))-sum(IFNULL(tk.arrive_succ,0))-sum(IFNULL(tk.arrive_fail,0)) unRecMsgnum,
        <!-- asa.wait_audit+scs.crontab total, -->
        sum(tk.arrive_fail) arrive_fail
        from sms_sp_info sp left join inter_sp_summary tk on tk.spid = sp.id
        where 1=1
        <if test="sp_name!=null and sp_name!=''">
            and sp.sp_name like CONCAT('%',#{sp_name},'%')
        </if>
        <if test="sp_id!=null and sp_id>0">
            and tk.spid=#{sp_id}
        </if>
        <if test="sp_saler!=null and sp_saler!=''">
            and sp.sp_saler =#{sp_saler}
        </if>
        <if test="sp_type!=null and sp_type>0">
            and sp.sp_type =#{sp_type}
        </if>
        <if test="createTime!=null and createTime!=''">
            and tk.stat_time&gt;=str_to_date(#{createTime},'%Y-%m-%d')
        </if>
        <if test="createTime1!=null and createTime1!=''">
            and
            tk.stat_time&lt;DATE_ADD(str_to_date(#{createTime1},'%Y-%m-%d'),INTERVAL 1 DAY)
        </if>
        group by sp.id, sp.sp_name
        order by sp.id
    </select>

    <select id="searchPageInterTaskDetailByContent"  parameterType="InternationalTaskDetailInfo" resultMap="TaskDetailInfoResultMap">
        SELECT
            a1.id,
            a1.taskid,
            a1.sp_id,
            sc.CHANNEL_NAME AS pa_dec,
            sp.sp_name,
            a1.mdn,
            a1.callmdn,
            a1.send_time,
            a1.res_desc,
            a1.num,
            a1.channelid,
            a1.`STATUS`,
            a1.res_content,
            b1.result,
            b1.stat_desc,
            b1.arrive_time,
            a1.countrycode
        FROM
            (
            SELECT
                a.id,
                a.RES_CONTENT,
                a.SIGN,
                a.TASKID,
                a.MDN,
                a.NUM,
                a.SEND_TIME,
                a.SP_ID,
                a.CALLMDN,
                a.RES_DESC,
                a.CHANNELID,
                a.`STATUS`,
                a.COUNTRYCODE
            FROM
                inter_submit a
            <where>
                <if test="content!=null and content!=''">
                    AND a.RES_CONTENT LIKE concat('%',#{content},'%')
                </if>
                <if test="mdn!=null and mdn!=''">
                    and a.mdn=#{mdn}
                </if>

                <if test="sign !=null and sign !=''">
                    and a.sign=#{sign}
                </if>
                <if test="sp_id!=null and sp_id>0">
                    and a.sp_id=#{sp_id}
                </if>
                <if test="taskid!=null and taskid>0">
                    <choose>
                        <when test="taskid.toString().length()&lt;18">
                             and a.taskid like CONCAT(#{taskid},'%')
                        </when>
                        <otherwise>
                           and a.taskid=#{taskid}
                        </otherwise>
                    </choose>
                </if>
                <if test="channelid!=null and channelid >=0">
                    and a.channelid=#{channelid}
                </if>
                <if test="createtime!=null and createtime!=''">
                    and a.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d %H:%i:%s')
                    and a.taskid &gt; CONCAT(DATE_FORMAT(#{createtime},'%y%m%d'),'000000000000')
                </if>
                <if test="endtime!=null and endtime!=''">
                    and a.create_time&lt;DATE_ADD(str_to_date(#{endtime},'%Y-%m-%d %H:%i:%s'),INTERVAL 5 SECOND)
                </if>
                <if test="chinese != null and  chinese != ''">
                    and a.countrycode like concat('%',#{chinese},'%')
                </if>
            </where>
            ) a1,
            (
            SELECT
                b.SP_ID,
                b.taskid,
                b.mdn,
                b.num,
                b.STAT_DESC,
                b.CHANNELID,
                b.RESULT result,
                b.arrive_time
            FROM
                inter_arrive b
            <where>
                <if test="stat_desc!=null and stat_desc!=''">
                    and b.stat_desc=#{stat_desc}
                </if>
                <if test="mdn!=null and mdn!=''">
                    and b.mdn=#{mdn}
                </if>

                <if test="sign !=null and sign !=''">
                    and b.sign=#{sign}
                </if>
                <if test="sp_id!=null and sp_id>0">
                    and b.sp_id=#{sp_id}
                </if>
                <if test="taskid!=null and taskid>0">
                    <choose>
                        <when test="taskid.toString().length()&lt;18">
                             and b.taskid like CONCAT(#{taskid},'%')
                        </when>
                        <otherwise>
                           and b.taskid=#{taskid}
                        </otherwise>
                    </choose>
                </if>
                <if test="channelid!=null and channelid >=0">
                    and b.channelid=#{channelid}
                </if>
                 <if test='res_result=="2"'>
                    and b.result= 0
                </if>
                <if test='res_result=="3"'>
                    and b.result != 0
                </if>
                <if test="createtime!=null and createtime!=''">
                    and b.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d %H:%i:%s')
                    and b.taskid &gt; CONCAT(DATE_FORMAT(#{createtime},'%y%m%d'),'000000000000')
                </if>

                <if test="endtime!=null and endtime!=''">
                    and b.create_time&lt;DATE_ADD(str_to_date(#{endtime},'%Y-%m-%d %H:%i:%s'),INTERVAL 5 SECOND)
                </if>
                <if test="chinese != null and  chinese != ''">
                    and b.countrycode like concat('%',#{chinese},'%')
                </if>
            </where>
            ) b1,sms_sp_info sp,sms_send_channel_info sc
        <where>
            a1.TASKID = b1.TASKID
            AND a1.mdn = b1.mdn
            AND a1.num = b1.num
            and a1.SP_ID=sp.id
            and a1.SP_ID=b1.SP_ID
            and a1.channelid=b1.channelid
            and a1.channelid=sc.id
            <if test="sp_name!=null and sp_name!=''">
                and sp.sp_name like CONCAT('%',#{sp_name},'%')
            </if>
        </where>
    </select>

    <select id="exportInterTaskDetailCount"  parameterType="InternationalTaskDetailInfo" resultType="Long">
        SELECT
            count(*)
        FROM
            (
            SELECT
                a.id,
                a.RES_CONTENT,
                a.SIGN,
                a.TASKID,
                a.MDN,
                a.NUM,
                a.SEND_TIME,
                a.SP_ID,
                a.CALLMDN,
                a.RES_DESC,
                a.CHANNELID,
                a.`STATUS`,
                a.COUNTRYCODE
            FROM
                inter_submit a
            <where>
                <if test="content!=null and content!=''">
                    AND a.RES_CONTENT LIKE concat('%',#{content},'%')
                </if>
                <if test="mdn!=null and mdn!=''">
                    and a.mdn=#{mdn}
                </if>

                <if test="sign !=null and sign !=''">
                    and a.sign=#{sign}
                </if>
                <if test="sp_id!=null and sp_id>0">
                    and a.sp_id=#{sp_id}
                </if>
                <if test="taskid!=null and taskid>0">
                    <choose>
                        <when test="taskid.toString().length()&lt;18">
                             and a.taskid like CONCAT(#{taskid},'%')
                        </when>
                        <otherwise>
                           and a.taskid=#{taskid}
                        </otherwise>
                    </choose>
                </if>
                <if test='res_result=="0"'>
	                and a.res_result= 0
	            </if>
	            <if test='res_result=="1"'>
	                and a.res_result != 0
	            </if>
                <if test="channelid!=null and channelid >=0">
                    and a.channelid=#{channelid}
                </if>
                <if test="createtime!=null and createtime!=''">
                    and a.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d %H:%i:%s')
                    and a.taskid &gt; CONCAT(DATE_FORMAT(#{createtime},'%y%m%d'),'000000000000')
                </if>
                <if test="endtime!=null and endtime!=''">
                    and a.create_time&lt;DATE_ADD(str_to_date(#{endtime},'%Y-%m-%d %H:%i:%s'),INTERVAL 5 SECOND)
                </if>
                <if test="chinese != null and  chinese != ''">
                    and a.countrycode like concat('%',#{chinese},'%')
                </if>
            </where>
            ) a1,
            (
            SELECT
                b.SP_ID,
                b.taskid,
                b.mdn,
                b.num,
                b.STAT_DESC,
                b.CHANNELID,
                b.RESULT result,
                b.arrive_time
            FROM
                inter_arrive b
            <where>
                <if test="stat_desc!=null and stat_desc!=''">
                    and b.stat_desc=#{stat_desc}
                </if>
                <if test="mdn!=null and mdn!=''">
                    and b.mdn=#{mdn}
                </if>

                <if test="sign !=null and sign !=''">
                    and b.sign=#{sign}
                </if>
                <if test="sp_id!=null and sp_id>0">
                    and b.sp_id=#{sp_id}
                </if>
                <if test="taskid!=null and taskid>0">
                    <choose>
                        <when test="taskid.toString().length()&lt;18">
                             and b.taskid like CONCAT(#{taskid},'%')
                        </when>
                        <otherwise>
                           and b.taskid=#{taskid}
                        </otherwise>
                    </choose>
                </if>
                <if test="channelid!=null and channelid >=0">
                    and b.channelid=#{channelid}
                </if>
                <if test='res_result=="2"'>
                    and b.result= 0
                </if>
                <if test='res_result=="3"'>
                    and b.result != 0
                </if>
                <if test="createtime!=null and createtime!=''">
                    and b.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d %H:%i:%s')
                    and b.taskid &gt; CONCAT(DATE_FORMAT(#{createtime},'%y%m%d'),'000000000000')
                </if>

                <if test="endtime!=null and endtime!=''">
                    and b.create_time&lt;DATE_ADD(str_to_date(#{endtime},'%Y-%m-%d %H:%i:%s'),INTERVAL 5 SECOND)
                </if>
                <if test="chinese != null and  chinese != ''">
                    and b.countrycode like concat('%',#{chinese},'%')
                </if>
            </where>
            ) b1,sms_sp_info sp,sms_send_channel_info sc
        <where>
            a1.TASKID = b1.TASKID
            AND a1.mdn = b1.mdn
            AND a1.num = b1.num
            and a1.SP_ID=sp.id
            and a1.SP_ID=b1.SP_ID
            and a1.channelid=b1.channelid
            and a1.channelid=sc.id
            <if test="sp_name!=null and sp_name!=''">
                and sp.sp_name like CONCAT('%',#{sp_name},'%')
            </if>
        </where>
    </select>

    <select id="exportInterTaskDetail"  parameterType="InternationalTaskDetailInfo" resultType="Map">
        SELECT
            a1.id,
            a1.taskid,
            a1.sp_id,
            sc.CHANNEL_NAME AS pa_dec,
            sp.sp_name,
            a1.mdn,
            a1.callmdn,
            a1.send_time,
            a1.res_desc,
            a1.num,
            a1.channelid,
            a1.`STATUS`,
            a1.res_content,
            a1.res_result,
            b1.result,
            b1.stat_desc,
            b1.arrive_time,
            a1.countrycode
        FROM
            (
            SELECT
                a.id,
                a.RES_CONTENT,
                a.SIGN,
                a.TASKID,
                a.MDN,
                a.NUM,
                a.SEND_TIME,
                a.SP_ID,
                a.CALLMDN,
                a.RES_DESC,
                a.res_result,
                a.CHANNELID,
                a.`STATUS`,
                a.COUNTRYCODE
            FROM
                inter_submit a
            <where>
                <if test="content!=null and content!=''">
                    AND a.RES_CONTENT LIKE concat('%',#{content},'%')
                </if>
                <if test="mdn!=null and mdn!=''">
                    and a.mdn=#{mdn}
                </if>

                <if test="sign !=null and sign !=''">
                    and a.sign=#{sign}
                </if>
                <if test="sp_id!=null and sp_id>0">
                    and a.sp_id=#{sp_id}
                </if>
                <if test="taskid!=null and taskid>0">
                    <choose>
                        <when test="taskid.toString().length()&lt;18">
                             and a.taskid like CONCAT(#{taskid},'%')
                        </when>
                        <otherwise>
                           and a.taskid=#{taskid}
                        </otherwise>
                    </choose>
                </if>
                <if test='res_result=="0"'>
                    and a.res_result= 0
                </if>
                <if test='res_result=="1"'>
                    and a.res_result != 0
                </if>
                <if test="channelid!=null and channelid >=0">
                    and a.channelid=#{channelid}
                </if>
                <if test="createtime!=null and createtime!=''">
                    and a.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d %H:%i:%s')
                    and a.taskid &gt; CONCAT(DATE_FORMAT(#{createtime},'%y%m%d'),'000000000000')
                </if>
                <if test="endtime!=null and endtime!=''">
                    and a.create_time&lt;DATE_ADD(str_to_date(#{endtime},'%Y-%m-%d %H:%i:%s'),INTERVAL 5 SECOND)
                </if>
                <if test="chinese != null and  chinese != ''">
	                and a.countrycode like concat('%',#{chinese},'%')
	            </if>
            </where>
            ) a1,
            (
            SELECT
                b.SP_ID,
                b.taskid,
                b.mdn,
                b.num,
                b.STAT_DESC,
                b.CHANNELID,
                b.RESULT result,
                b.arrive_time
            FROM
                inter_arrive b
            <where>
                <if test="stat_desc!=null and stat_desc!=''">
                    and b.stat_desc=#{stat_desc}
                </if>
                <if test="mdn!=null and mdn!=''">
                    and b.mdn=#{mdn}
                </if>

                <if test="sign !=null and sign !=''">
                    and b.sign=#{sign}
                </if>
                <if test="sp_id!=null and sp_id>0">
                    and b.sp_id=#{sp_id}
                </if>
                <if test="taskid!=null and taskid>0">
                    <choose>
                        <when test="taskid.toString().length()&lt;18">
                             and b.taskid like CONCAT(#{taskid},'%')
                        </when>
                        <otherwise>
                           and b.taskid=#{taskid}
                        </otherwise>
                    </choose>
                </if>
                <if test="channelid!=null and channelid >=0">
                    and b.channelid=#{channelid}
                </if>
                <if test='res_result=="2"'>
                    and b.result= 0
                </if>
                <if test='res_result=="3"'>
                    and b.result != 0
                </if>
                <if test="createtime!=null and createtime!=''">
                    and b.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d %H:%i:%s')
                    and b.taskid &gt; CONCAT(DATE_FORMAT(#{createtime},'%y%m%d'),'000000000000')
                </if>

                <if test="endtime!=null and endtime!=''">
                    and b.create_time&lt;DATE_ADD(str_to_date(#{endtime},'%Y-%m-%d %H:%i:%s'),INTERVAL 5 SECOND)
                </if>
                <if test="chinese != null and  chinese != ''">
                    and b.countrycode like concat('%',#{chinese},'%')
                </if>
            </where>
            ) b1, sms_sp_info sp, sms_send_channel_info sc
        where
            a1.TASKID = b1.TASKID
            and a1.mdn = b1.mdn
            and a1.num = b1.num
            and a1.channelid=b1.channelid
            and a1.SP_ID=b1.SP_ID
            and a1.SP_ID=sp.id
            and a1.channelid=sc.id
		<if test="sp_name!=null and sp_name!=''">
		    and sp.sp_name like CONCAT('%',#{sp_name},'%')
		</if>
	    <if test="endId != null">
	       and a1.id &lt;  #{endId}
	    </if>
        ORDER BY a1.id DESC
        <if test="exportExcelSize != null ">
            limit #{exportExcelSize}
        </if>
    </select>

    <select id="searchPageInterTaskDetailInfoForStatDesc" parameterType="InternationalTaskDetailInfo"
        resultMap="TaskDetailInfoResultMap">

        select st.id,
        st.taskid,
        st.sp_id,
        sc.CHANNEL_NAME as pa_dec,
        sp.sp_name,
        st.mdn,
        st.callmdn,
        st.num,
        st.RESULT result,
       <!--  IFNULL(r.receipt_desc,st.stat_desc) stat_desc, -->
        st.stat_desc,
        st.status,
        <!-- st.arrive_time -->
        st.channelid,
        DATE_FORMAT(str_to_date(st.arrive_time,'%Y%m%d%H%i%s'),'%Y-%m-%d %H:%i:%s') arrive_time,
        st.countrycode
        from inter_arrive st
        LEFT JOIN sms_sp_info sp
        ON st.sp_id = sp.id
        LEFT JOIN sms_send_channel_info sc
        ON st.CHANNELID = sc.id
        <!-- LEFT JOIN receipt_code r
        ON st.stat_desc = r.stat_desc -->
        <where>
            <if test="mdn!=null and mdn!=''">
                and st.mdn=#{mdn}
            </if>

            <if test="sign !=null and sign !=''">
                and st.sign=#{sign}
            </if>
            <if test="sp_id!=null and sp_id>0">
                and st.sp_id=#{sp_id}
            </if>
            <if test="taskid!=null and taskid>0">
                <choose>
                    <when test="taskid.toString().length()&lt;18">
                         and st.taskid like CONCAT(#{taskid},'%')
                    </when>
                    <otherwise>
                       and st.taskid=#{taskid}
                    </otherwise>
                </choose>
            </if>
            <if test="channelid!=null and channelid >=0">
                and st.channelid=#{channelid}
            </if>
            <if test="stat_desc!=null and stat_desc!=''">
                and st.stat_desc=#{stat_desc}
            </if>
          <if test="sp_name!=null and sp_name!=''">
              and sp.sp_name like CONCAT('%',#{sp_name},'%')
          </if>
          <if test="sp_saler!=null and sp_saler!=''">
              and sp.sp_saler =#{sp_saler}
          </if>
          <if test='res_result=="2"'>
              and st.result= 0
          </if>
          <if test='res_result=="3"'>
              and st.result != 0
          </if>
          <if test="createtime!=null and createtime!=''">
              and st.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d %H:%i:%s')
          </if>

          <if test="endtime!=null and endtime!=''">
              and st.create_time&lt;DATE_ADD(str_to_date(#{endtime},'%Y-%m-%d %H:%i:%s'),INTERVAL 5 SECOND)
          </if>
           <if test="chinese != null and  chinese != ''">
                and st.countrycode like concat('%',#{chinese},'%')
            </if>
        </where>
        order by st.id desc
    </select>

    <select id="getInterTaskDetailFromSubmit" parameterType="InternationalTaskDetailInfo"
        resultMap="TaskDetailInfoResultMap">
        select
        st.id,
        st.res_desc,
        st.send_time,
        st.res_content
        from inter_submit st
        where taskid=#{taskid} and mdn=#{mdn} and num=#{num}
        <if test="createtime!=null and createtime!=''">
            and st.create_time&gt;=DATE_ADD(str_to_date(#{createtime},'%Y-%m-%d %H:%i:%s'),INTERVAL -3 DAY)
        </if>

        <if test="endtime!=null and endtime!=''">
            and st.create_time&lt;DATE_ADD(str_to_date(#{endtime},'%Y-%m-%d %H:%i:%s'),INTERVAL 5 SECOND)
        </if>
        limit 1
    </select>

    <select id="searchPageInterTaskNoReportDetailInfo" parameterType="InternationalTaskDetailInfo"
        resultMap="TaskDetailInfoResultMap">

        SELECT st.id,
        st.taskid,
        st.sp_id,
        sp.sp_name,
        st.mdn,
        st.callmdn,
        st.send_time,
        st.res_desc,
        st.num,
        st.channelid,
        st.status,
        st.res_content,
        st.countrycode
        FROM inter_submit st, sms_sp_info sp
        WHERE st.sp_id = sp.id
        <if test="mdn!=null and mdn!=''">
            and st.mdn=#{mdn}
        </if>

        <if test="sign !=null and sign !=''">
            and st.sign=#{sign}
        </if>
        <if test="sp_id!=null and sp_id>0">
            and st.sp_id=#{sp_id}
        </if>
        <if test="taskid!=null and taskid>0">
            <choose>
                <when test="taskid.toString().length()&lt;18">
                     and st.taskid like CONCAT(#{taskid},'%')
                </when>
                <otherwise>
                   and st.taskid=#{taskid}
                </otherwise>
            </choose>
        </if>
        <if test="channelid!=null and channelid >=0">
            and st.channelid=#{channelid}
        </if>
        <if test="sp_name!=null and sp_name!=''">
            and sp.sp_name like CONCAT('%',#{sp_name},'%')
        </if>
        <if test="sp_saler!=null and sp_saler!=''">
            and sp.sp_saler =#{sp_saler}
        </if>
        <if test="createtime!=null and createtime!=''">
            and st.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d %H:%i:%s')
        </if>

        <if test="endtime!=null and endtime!=''">
            and st.create_time&lt;DATE_ADD(str_to_date(#{endtime},'%Y-%m-%d %H:%i:%s'),INTERVAL 5 SECOND)
        </if>
         <if test="chinese != null and  chinese != ''">
            and st.countrycode like concat('%',#{chinese},'%')
        </if>
        <if test="content!=null and content!=''">
            and st.res_content like concat('%',#{content},'%')
        </if>
        and st.taskid not in(
        select b.taskid
        from inter_arrive b
        where
        st.TASKID=b.TASKID and st.mdn=b.mdn and st.num=b.num
        <if test="mdn!=null and mdn!=''">
            and st.mdn=#{mdn}
        </if>

        <if test="sign !=null and sign !=''">
            and st.sign=#{sign}
        </if>
        <if test="sp_id!=null and sp_id>0">
            and st.sp_id=#{sp_id}
        </if>
        <if test="taskid!=null and taskid>0">
            <choose>
                <when test="taskid.toString().length()&lt;18">
                     and st.taskid like CONCAT(#{taskid},'%')
                </when>
                <otherwise>
                   and st.taskid=#{taskid}
                </otherwise>
            </choose>
        </if>
        <if test="channelid!=null and channelid >=0">
            and st.channelid=#{channelid}
        </if>
        <if test="sp_name!=null and sp_name!=''">
            and sp.sp_name like CONCAT('%',#{sp_name},'%')
        </if>
        <if test="sp_saler!=null and sp_saler!=''">
            and sp.sp_saler =#{sp_saler}
        </if>
        <if test="createtime!=null and createtime!=''">
            and st.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d %H:%i:%s')
        </if>

        <if test="endtime!=null and endtime!=''">
            and st.create_time&lt;DATE_ADD(str_to_date(#{endtime},'%Y-%m-%d %H:%i:%s'),INTERVAL 3 DAY)
        </if>
        <if test="chinese != null and  chinese != ''">
            and st.countrycode like concat('%',#{chinese},'%')
        </if>
        )
        order by st.id desc
    </select>

    <select id="exportInterTaskNoReportCount" parameterType="InternationalTaskDetailInfo"
        resultType="Long">

        SELECT count(*)
        FROM inter_submit st, sms_sp_info sp
        WHERE st.sp_id = sp.id
        <if test="mdn!=null and mdn!=''">
            and st.mdn=#{mdn}
        </if>

        <if test="sign !=null and sign !=''">
            and st.sign=#{sign}
        </if>
        <if test="sp_id!=null and sp_id>0">
            and st.sp_id=#{sp_id}
        </if>
        <if test="taskid!=null and taskid>0">
            <choose>
                <when test="taskid.toString().length()&lt;18">
                     and st.taskid like CONCAT(#{taskid},'%')
                </when>
                <otherwise>
                   and st.taskid=#{taskid}
                </otherwise>
            </choose>
        </if>
        <if test="channelid!=null and channelid >=0">
            and st.channelid=#{channelid}
        </if>
        <if test="sp_name!=null and sp_name!=''">
            and sp.sp_name like CONCAT('%',#{sp_name},'%')
        </if>
        <if test="sp_saler!=null and sp_saler!=''">
            and sp.sp_saler =#{sp_saler}
        </if>
        <if test="createtime!=null and createtime!=''">
            and st.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d %H:%i:%s')
        </if>

        <if test="endtime!=null and endtime!=''">
            and st.create_time&lt;DATE_ADD(str_to_date(#{endtime},'%Y-%m-%d %H:%i:%s'),INTERVAL 5 SECOND)
        </if>
         <if test="chinese != null and  chinese != ''">
            and st.countrycode like concat('%',#{chinese},'%')
        </if>
        <if test="content!=null and content!=''">
            and st.res_content like concat('%',#{content},'%')
        </if>
        and st.taskid not in(
        select b.taskid
        from inter_arrive b
        where
        st.TASKID=b.TASKID and st.mdn=b.mdn and st.num=b.num
        <if test="mdn!=null and mdn!=''">
            and st.mdn=#{mdn}
        </if>

        <if test="sign !=null and sign !=''">
            and st.sign=#{sign}
        </if>
        <if test="sp_id!=null and sp_id>0">
            and st.sp_id=#{sp_id}
        </if>
        <if test="taskid!=null and taskid>0">
            <choose>
                <when test="taskid.toString().length()&lt;18">
                     and st.taskid like CONCAT(#{taskid},'%')
                </when>
                <otherwise>
                   and st.taskid=#{taskid}
                </otherwise>
            </choose>
        </if>
        <if test="channelid!=null and channelid >=0">
            and st.channelid=#{channelid}
        </if>
        <if test="sp_name!=null and sp_name!=''">
            and sp.sp_name like CONCAT('%',#{sp_name},'%')
        </if>
        <if test="sp_saler!=null and sp_saler!=''">
            and sp.sp_saler =#{sp_saler}
        </if>
        <if test="createtime!=null and createtime!=''">
            and st.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d %H:%i:%s')
        </if>

        <if test="endtime!=null and endtime!=''">
            and st.create_time&lt;DATE_ADD(str_to_date(#{endtime},'%Y-%m-%d %H:%i:%s'),INTERVAL 3 DAY)
        </if>
        <if test="chinese != null and  chinese != ''">
            and st.countrycode like concat('%',#{chinese},'%')
        </if>
        )
    </select>

    <select id="exportInterTaskNoReportDetailInfo" parameterType="InternationalTaskDetailInfo"
        resultType="Map">

        SELECT st.id,
        st.taskid,
        st.sp_id,
        sp.sp_name,
        st.mdn,
        st.callmdn,
        st.send_time,
        st.res_desc,
        st.num,
        st.channelid,
        st.status,
        st.res_content,
        st.countrycode
        FROM inter_submit st, sms_sp_info sp
        WHERE st.sp_id = sp.id
        <if test="mdn!=null and mdn!=''">
            and st.mdn=#{mdn}
        </if>

        <if test="sign !=null and sign !=''">
            and st.sign=#{sign}
        </if>
        <if test="sp_id!=null and sp_id>0">
            and st.sp_id=#{sp_id}
        </if>
        <if test="taskid!=null and taskid>0">
            <choose>
                <when test="taskid.toString().length()&lt;18">
                     and st.taskid like CONCAT(#{taskid},'%')
                </when>
                <otherwise>
                   and st.taskid=#{taskid}
                </otherwise>
            </choose>
        </if>
        <if test="channelid!=null and channelid >=0">
            and st.channelid=#{channelid}
        </if>
        <if test="sp_name!=null and sp_name!=''">
            and sp.sp_name like CONCAT('%',#{sp_name},'%')
        </if>
        <if test="sp_saler!=null and sp_saler!=''">
            and sp.sp_saler =#{sp_saler}
        </if>
        <if test="createtime!=null and createtime!=''">
            and st.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d %H:%i:%s')
        </if>

        <if test="endtime!=null and endtime!=''">
            and st.create_time&lt;DATE_ADD(str_to_date(#{endtime},'%Y-%m-%d %H:%i:%s'),INTERVAL 5 SECOND)
        </if>
         <if test="chinese != null and  chinese != ''">
            and st.countrycode like concat('%',#{chinese},'%')
        </if>
        <if test="content!=null and content!=''">
            and st.res_content like concat('%',#{content},'%')
        </if>
        and st.taskid not in(
        select b.taskid
        from inter_arrive b
        where
        st.TASKID=b.TASKID and st.mdn=b.mdn and st.num=b.num
        <if test="mdn!=null and mdn!=''">
            and st.mdn=#{mdn}
        </if>

        <if test="sign !=null and sign !=''">
            and st.sign=#{sign}
        </if>
        <if test="sp_id!=null and sp_id>0">
            and st.sp_id=#{sp_id}
        </if>
        <if test="taskid!=null and taskid>0">
            <choose>
                <when test="taskid.toString().length()&lt;18">
                     and st.taskid like CONCAT(#{taskid},'%')
                </when>
                <otherwise>
                   and st.taskid=#{taskid}
                </otherwise>
            </choose>
        </if>
        <if test="channelid!=null and channelid >=0">
            and st.channelid=#{channelid}
        </if>
        <if test="sp_name!=null and sp_name!=''">
            and sp.sp_name like CONCAT('%',#{sp_name},'%')
        </if>
        <if test="sp_saler!=null and sp_saler!=''">
            and sp.sp_saler =#{sp_saler}
        </if>
        <if test="createtime!=null and createtime!=''">
            and st.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d %H:%i:%s')
        </if>

        <if test="endtime!=null and endtime!=''">
            and st.create_time&lt;DATE_ADD(str_to_date(#{endtime},'%Y-%m-%d %H:%i:%s'),INTERVAL 3 DAY)
        </if>
        <if test="chinese != null and  chinese != ''">
            and st.countrycode like concat('%',#{chinese},'%')
        </if>
        )
        <if test="endId != null">
            and st.id &lt;  #{endId}
        </if>
        ORDER BY st.id DESC
        <if test="exportExcelSize != null ">
            limit #{exportExcelSize}
        </if>
    </select>

    <select id="searchPageInterTaskDetailInfo" parameterType="InternationalTaskDetailInfo"
        resultMap="TaskDetailInfoResultMap">

        select st.id,
        st.taskid,
        st.sp_id,
        sc.CHANNEL_NAME as pa_dec,
        sp.sp_name,
        st.mdn,
        st.callmdn,
        st.send_time,
        st.res_desc,
        st.num,
        <!-- st.REPORT_RESULT result, -->
        <!-- IFNULL(r.receipt_desc,st.stat_desc) stat_desc, -->
        <!-- st.stat_desc, -->
        st.channelid,
        st.status,
        st.res_content,
        st.countrycode
       <!--  st.arrive_time -->
        from inter_submit st
        LEFT JOIN sms_sp_info sp
        ON st.sp_id = sp.id
        LEFT JOIN sms_send_channel_info sc
        ON st.CHANNELID = sc.id
       <!--  LEFT JOIN receipt_code r
        ON st.stat_desc = r.stat_desc -->
        <where>
            <if test="mdn!=null and mdn!=''">
                and st.mdn=#{mdn}
            </if>
            <if test="sp_id!=null and sp_id>0">
                and st.sp_id=#{sp_id}
            </if>
            <if test="taskid!=null and taskid>0">
               <choose>
                     <when test="taskid.toString().length()&lt;18">
                         and st.taskid like CONCAT(#{taskid},'%')
                    </when>
                    <otherwise>
                       and st.taskid=#{taskid}
                    </otherwise>
                </choose>
            </if>
            <if test="channelid !=null and channelid>=0">
                and st.channelid=#{channelid}
            </if>
             <if test="sign!=null and sign!=''">
                and st.sign=#{sign}
            </if>
            <if test="sp_name!=null and sp_name!=''">
                and sp.sp_name like CONCAT('%',#{sp_name},'%')
            </if>
             <if test="sp_saler!=null and sp_saler!=''">
                and sp.sp_saler =#{sp_saler}
            </if>
            <if test='res_result=="0"'>
                and st.res_result= 0
            </if>
            <if test='res_result=="1"'>
                and st.res_result != 0
            </if>

            <if test="createtime!=null and createtime!=''">
                and st.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d %H:%i:%s')
            </if>

            <if test="endtime!=null and endtime!=''">
                and st.create_time&lt;DATE_ADD(str_to_date(#{endtime},'%Y-%m-%d %H:%i:%s'),INTERVAL 5 SECOND)
            </if>
            <if test="content!=null and content!=''">
                and res_content like concat('%',#{content},'%')
            </if>
            <if test="chinese != null and  chinese != ''">
                and st.countrycode like concat('%',#{chinese},'%')
            </if>
        </where>
        order by st.id desc
    </select>

    <select id="getInterTaskDetailFromArrive" parameterType="InternationalTaskDetailInfo"
        resultMap="TaskDetailInfoResultMap">
        select
        st.result result,
        st.stat_desc stat_desc,
        st.channelid,
        st.callmdn,
        <!-- DATE_FORMAT(str_to_date(st.arrive_time,'%Y%m%d%H%i%s'),'%Y-%m-%d %H:%i:%s') arrive_time -->
        st.arrive_time
        from inter_arrive st
        where taskid=#{taskid} and mdn=#{mdn} and num=#{num}
        <if test="createtime!=null and createtime!=''">
            and st.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d %H:%i:%s')
        </if>

        <if test="endtime!=null and endtime!=''">
            and st.create_time&lt;DATE_ADD(str_to_date(#{endtime},'%Y-%m-%d %H:%i:%s'),INTERVAL 3 DAY)
        </if>
        limit 1
    </select>

    <select id="getInterTaskDetailById" parameterType="int"
        resultMap="TaskDetailInfoResultMap">
        select st.id,
        st.taskid,
        st.sp_id,
        sc.CHANNEL_NAME as pa_dec,
        sp.sp_name,
        st.mdn,
        st.res_content,
        st.callmdn,
        st.send_time,
        st.num,
        st.messageid msgid,
        st.res_desc,
        st.countrycode
        from inter_submit st
        left join  sms_sp_info sp on st.sp_id = sp.id
        left join  sms_send_channel_info sc on st.CHANNELID = sc.id
        where st.id=#{id}
    </select>

    <select id="listPageInterSpCharge" parameterType="SpInfo" resultMap="spInfoAndSpmoney">
        select sp.id spid,sp.sp_name,sp.currency,sm.money,sm.use_money,sm.billing_account_id,
               billing_sp.id as billing_spid,billing_sp.sp_name as billing_sp_name
        from sms_sp_info sp
        left join sms_sp_money sm
        on sp.id=sm.spid
        left join sms_sp_info billing_sp
        on sm.billing_account_id = billing_sp.id
        where sp.inter_sms_flag = 1 and sp.is_api_billing = 0 and sp.status != 2
        <if test="spid!=null and spid!=''">
            and sp.id=#{spid}
        </if>
        <if test="sp_name!=null and sp_name!=''">
            and sp.sp_name like CONCAT('%',#{sp_name},'%')
        </if>
        <if test="sp_saler!=null and sp_saler!=''">
            and sp.sp_saler =#{sp_saler}
        </if>
    </select>

    <select id="getInterChargeCountById" parameterType="SpCharge" resultType="int">
        select count(id) from sms_sp_money
        <where>
            <if test="sp_id!=null and sp_id>0">
                spid = #{sp_id}
            </if>
        </where>
    </select>

    <insert id="insertInterSpCharge" useGeneratedKeys="true" keyProperty="id" parameterType="cn.roadm.bo.SpMoney">
        insert into sms_sp_money
        (spid,money,use_money,billing_account_id)
        values (#{spId},#{money},0,#{billingAccountId,jdbcType=INTEGER})
    </insert>

    <update id="updateInterSpCharge" parameterType="cn.roadm.bo.SpMoney">
        update sms_sp_money c
        set c.money = c.money + #{money}
        <if test="billingAccountId != null">
            ,c.billing_account_id = #{billingAccountId,jdbcType=INTEGER}
        </if>
        where c.spid = #{spId}
    </update>

    <update id="updateInterSpChargeReduce" parameterType="cn.roadm.bo.SpMoney">
        update sms_sp_money c
        set c.money =c.money - #{money}
        where c.spid = #{spId}
    </update>

    <update id="updateBillingAccountId" parameterType="cn.roadm.bo.SpMoney">
        update sms_sp_money
        set billing_account_id = #{billingAccountId,jdbcType=INTEGER}
        where spid = #{spId}
    </update>

    <insert id="insertInterSpChargeRecord" useGeneratedKeys="true" keyProperty="id" parameterType="ChargeRecord">
        insert into inter_charge_record
        (sp_id,charge_time,chargeopeartor,amount,descption,type,chargeaftermoney,charge_mode)
        VALUES (#{sp_id},NOW(),#{operator},#{amount},#{descption},#{type},#{chargeAfterMoney},#{charge_mode})
    </insert>

    <select id="listPageInterChargeRecord" parameterType="ChargeRecord" resultMap="ChargeRecordResult">
        select sd.id,
        sd.charge_time,
        sd.sp_id,
        sd.chargeaftermoney,
        sd.chargeopeartor,
        sd.amount,
        sd.type,
        sd.descption,
        sp.sp_name,
        sp.currency
        from
        inter_charge_record sd, sms_sp_info sp
        where sp.id = sd.sp_id
        and sp.status!=2
        <if test="currency != null and currency != ''">
            <choose>
                <when test='currency == "¥"'>
                    and (sp.currency is null or sp.currency = '' or sp.currency = '¥')
                </when>
                <otherwise>
                    and sp.currency = #{currency}
                </otherwise>
            </choose>
        </if>
        <if test="sp_id!=null and sp_id!=0">
            and sp.id=#{sp_id}
        </if>
        <if test="createTime!=null and createTime!=''">
            and sd.charge_time&gt;=str_to_date(#{createTime},'%Y-%m-%d')
        </if>
        <if test="createTime1!=null and createTime1!=''">
            and
            sd.charge_time&lt;=DATE_ADD(str_to_date(#{createTime1},'%Y-%m-%d'),INTERVAL 1 DAY)
        </if>
        <if test="sp_name!=null and sp_name!=''">
            and sp.sp_name like CONCAT('%',#{sp_name},'%')
        </if>
        <if test="sp_saler!=null and sp_saler!=''">
            and sp.sp_saler =#{sp_saler}
        </if>

        order by sd.charge_time desc
    </select>

    <select id="exportInterSpChargeRecord" parameterType="ChargeRecord" resultType="Map">
        select sd.id,
        date_format(sd.charge_time,'%Y-%m-%d %H:%i:%S') charge_time,
        sd.sp_id,
        sd.chargeaftermoney,
        sd.chargeopeartor,
        sd.amount,
        case
        when sd.type=1 then '充值'
        when sd.type=2 then '扣减'
        else '其他类型'
        end type,
        sd.descption,
        sp.sp_name
        from
        inter_charge_record sd, sms_sp_info sp
        where sp.id = sd.sp_id
        and sp.status!=2
        <if test="sp_id!=null and sp_id!=0">
            and sp.id=#{sp_id}
        </if>
        <if test="createTime!=null and createTime!=''">
            and sd.charge_time&gt;=str_to_date(#{createTime},'%Y-%m-%d')
        </if>
        <if test="createTime1!=null and createTime1!=''">
            and
            sd.charge_time&lt;=DATE_ADD(str_to_date(#{createTime1},'%Y-%m-%d'),INTERVAL 1 DAY)
        </if>
        <if test="sp_name!=null and sp_name!=''">
            and sp.sp_name like CONCAT('%',#{sp_name},'%')
        </if>
        <if test="sp_saler!=null and sp_saler!=''">
            and sp.sp_saler =#{sp_saler}
        </if>

        order by sd.charge_time desc
    </select>

    <select id="getInterChargeAmountBymonth" parameterType="ChargeRecord" resultType="java.math.BigDecimal">
        select IFNULL(sum(sd.amount),0) amount
        from inter_charge_record sd,sms_sp_info sp
        where sp.id=sd.sp_id
        and sp.status != 2
        and sd.type = 1
        <choose>
            <when test='currency == "¥"'>
                and (sp.currency is null or sp.currency = '' or sp.currency = '¥')
            </when>
            <otherwise>
                and sp.currency = #{currency}
            </otherwise>
        </choose>
        <if test="sp_name!=null and sp_name !=''">
            and sp.sp_name like CONCAT('%',#{sp_name},'%')
        </if>
        <if test="sp_id!=null and sp_id>0">
            and sd.sp_id = #{sp_id}
        </if>
        <if test="sp_saler!=null and sp_saler!=''">
            and sp.sp_saler =#{sp_saler}
        </if>
        <if test="createTime!=null and createTime!=''">
            and sd.charge_time&gt;=str_to_date(#{createTime},'%Y-%m-%d')
        </if>
        <if test="createTime1!=null and createTime1!=''">
            and
            sd.charge_time&lt;=DATE_ADD(str_to_date(#{createTime1},'%Y-%m-%d'),INTERVAL 1 DAY)
        </if>
    </select>

    <select id="getInterReduceAmountBymonth" parameterType="ChargeRecord" resultType="java.math.BigDecimal">

        select IFNULL(sum(sd.amount),0) amount
        from inter_charge_record sd,sms_sp_info sp
        where sp.id=sd.sp_id
        and sp.status != 2
        and sd.type = 2
        <choose>
            <when test='currency == "¥"'>
                and (sp.currency is null or sp.currency = '' or sp.currency = '¥')
            </when>
            <otherwise>
                and sp.currency = #{currency}
            </otherwise>
        </choose>
        <if test="sp_name!=null and sp_name !=''">
            and sp.sp_name like CONCAT('%',#{sp_name},'%')
        </if>
        <if test="sp_id!=null and sp_id>0">
            and sd.sp_id = #{sp_id}
        </if>
        <if test="sp_saler!=null and sp_saler!=''">
            and sp.sp_saler =#{sp_saler}
        </if>
        <if test="createTime!=null and createTime!=''">
            and sd.charge_time&gt;=str_to_date(#{createTime},'%Y-%m-%d')
        </if>
        <if test="createTime1!=null and createTime1!=''">
            and
            sd.charge_time&lt;=DATE_ADD(str_to_date(#{createTime1},'%Y-%m-%d'),INTERVAL 1 DAY)
        </if>
    </select>

    <select id="listInterChannelTotalList" resultType="Map">
        select a.id channelid,a.channel_name channelName
        from sms_send_channel_info a
        where IS_SUPPORT_INTERNATIONAL = 1
        order by a.id
    </select>

    <select id="listPageCountryPriceGroup" parameterType="CountryPriceGroup" resultType="CountryPriceGroup">
        SELECT id, name, createtime, remark, COALESCE(currency, '¥') as currency
        FROM inter_sms_price_group
        <where>
            <if test="name != null and name != ''">
                and name like concat('%',#{name},'%')
            </if>
        </where>
        ORDER BY createtime DESC
    </select>

    <select id="listCountryPriceGroup" parameterType="CountryPriceGroup" resultType="CountryPriceGroup">
        SELECT id, name, createtime, remark
        FROM inter_sms_price_group
        <where>
            <if test="name != null and name != ''">
                and name like concat('%',#{name},'%')
            </if>
        </where>
    </select>

    <insert id="insertCountryPriceGroup" useGeneratedKeys="true" keyProperty="id" parameterType="CountryPriceGroup">
        insert into inter_sms_price_group
        (name, createtime, remark,currency)
        values (#{name}, now(), #{remark}, #{currency})
    </insert>


    <select id="listPageCountryPrice" parameterType="CountryPrice" resultType="CountryPrice">
        select a.id, a.country chinese, a.price, a.modifytime, a.createtime, a.currency
        from inter_sms_price a
        where a.gid = #{gid}
        <if test="chinese != null and chinese != ''">
            and a.country like CONCAT('%',#{chinese},'%')
        </if>
        order by a.createtime desc
    </select>

    <select id="listAllCountryPrice" parameterType="CountryPrice" resultType="CountryPrice">
        select a.country chinese, a.price,a.currency
        from inter_sms_price a
        where a.gid = #{gid}
    </select>

    <select id="getCountryPriceById" parameterType="int" resultType="CountryPrice">
        select
        id, gid, country, price, currency
        from inter_sms_price
        where id=#{id}
    </select>

    <select id="getCountryPriceGroupById" parameterType="int" resultType="CountryPriceGroup">
        select
        id, name, createtime, remark, currency
        from inter_sms_price_group
        where id=#{id}
    </select>

    <select id="getChineseByInterCode" parameterType="String" resultType="String">
        select
        chinese
        from inter_code
        where inter_code=#{inter_code}
    </select>

    <select id="getCountryPriceCountByCountry" parameterType="CountryPrice" resultType="int">
        select
        count(id)
        from inter_sms_price
        where gid = #{gid} and country=#{country}
    </select>

    <insert id="insertCountryPrice" useGeneratedKeys="true" keyProperty="id" parameterType="CountryPrice">
        insert into inter_sms_price
        (gid, country, price, createtime,currency) values
        (#{gid}, #{country}, #{price}, now(), #{currency})
    </insert>

    <update id="updateCountryPrice" parameterType="CountryPrice">
        update inter_sms_price set
        price=#{price},
        modifytime=now(),
        currency=#{currency}
        where id=#{id}
    </update>

    <update id="updateCountryGroupName" parameterType="CountryPriceGroup" >
        update inter_sms_price_group set
        name=#{name},
        remark=#{remark},
        currency=#{currency}
        where id=#{id}
    </update>

    <update id="updateCountryAllPrice" parameterType="CountryPriceGroup" >
        update inter_sms_price set
        currency=#{currency}
        where gid=#{id}
    </update>

    <delete id="deleteCountryPrice" parameterType="int">
        delete from inter_sms_price where id = #{id}
    </delete>

    <select id="getCountryPriceGroupUsedCount" parameterType="int" resultType="int">
        select count(id)
        from sms_sp_info
        where inter_price_group=#{gid} and status != 2
    </select>

    <delete id="deleteCountryPriceGroup" parameterType="int">
        delete from inter_sms_price_group where id = #{id}
    </delete>

    <delete id="deleteCountryPriceByGid" parameterType="int">
        delete from inter_sms_price where gid = #{gid}
    </delete>

    <select id="listPageInterApiAuditTask" parameterType="TaskInfo"
        resultMap="interAuditTaskMap">
        select ak.id,
        ak.sp_id,
        ak.content,
        ak.createtime,
        ak.total,
        ak.allnumber,
        ak.task_type,
        ak.status,
        ak.audit_reason,
        ak.intermdns,
        ak.extendaccessnum,
        ak.country,
        s.sp_name,
        s.platform,
        s.sp_desc
        from
        inter_api_audit_task ak, sms_sp_info s
        where s.id=ak.sp_id and ak.status=1
        <if test="platform!=null and platform!='' and platform >0">
            and s.platform =#{platform}
        </if>
        <if test="sp_name!=null and sp_name!=''">
            and s.sp_name like CONCAT('%',#{sp_name},'%')
        </if>
        <if test="sp_id!=null and sp_id>0">
            and s.id =#{sp_id}
        </if>
        <if test="content!=null and content!=''">
            and ak.content like CONCAT('%',#{content},'%')
        </if>
        <if test="sign!=null and sign!=''">
            and ak.sign=#{sign,jdbcType=VARCHAR}
        </if>
        <if test="intermdns!=null and intermdns!=''">
            and ak.intermdns  like CONCAT('%',#{intermdns},'%')
        </if>
        <if test="chinese!=null and chinese!=''">
            and ak.country  like CONCAT('%',#{chinese},'%')
        </if>
        <if test="send_type!=null and send_type>0">
            and ak.send_type =#{send_type}
        </if>
        <if test="task_id!=null and task_id>0">
            and ak.id =#{task_id}
        </if>
        <if test="createTime!=null and createTime!=''">
            and ak.createtime&gt;=str_to_date(#{createTime},'%Y-%m-%d %H:%i:%S')
        </if>

        <if test="createTime1!=null and createTime1!=''">
            and ak.createtime&lt;=str_to_date(#{createTime1},'%Y-%m-%d %H:%i:%S')
        </if>
    </select>

    <select id="getInterApiAuditTask" parameterType="TaskInfo"
        resultMap="interAuditTaskMap">
        select ak.id,
        ak.sp_id,
        ak.intermdns,
        ak.content
        from
        inter_api_audit_task ak
        where ak.status=1
        <if test="task_id!=null and task_id>0">
            and ak.id = #{task_id}
        </if>
        <if test="intermdns!=null and intermdns != ''">
            and ak.intermdns = #{intermdns}
        </if>
    </select>

    <select id="getInterApiAuditTaskByContent" parameterType="TaskInfo" resultMap="interAuditTaskMap">
        select tk.id,
        tk.intermdns
        from inter_api_audit_task tk
        where tk.status = 1
        <if test="sp_id!=null and sp_id>0">
            and tk.sp_id=#{sp_id}
        </if>
        <if test="content!=null and content!=''">
            and tk.content = #{content}
        </if>
        limit 0,10000
    </select>

    <select id="getInterApiAuditTaskByCondition" parameterType="TaskInfo" resultMap="interAuditTaskMap">
        select tk.id,
        tk.intermdns
        from inter_api_audit_task tk
        where tk.status = 1
        <if test="task_id!=null and task_id>0">
            and tk.id =#{task_id}
        </if>
        <if test="sp_id!=null and sp_id>0">
            and tk.sp_id=#{sp_id}
        </if>
        <if test="sign!=null and sign!=''">
            and tk.sign=#{sign,jdbcType=VARCHAR}
        </if>
        <if test="content!=null and content!=''">
            and tk.content like CONCAT('%',#{content},'%')
        </if>
        <if test="intermdns!=null and intermdns!=''">
            and tk.intermdns  like CONCAT('%',#{intermdns},'%')
        </if>
        <if test="createTime!=null and createTime!=''">
            and tk.createtime&gt;=str_to_date(#{createTime},'%Y-%m-%d %H:%i:%S')
        </if>
        <if test="createTime1!=null and createTime1!=''">
            and tk.createtime&lt;=str_to_date(#{createTime1},'%Y-%m-%d %H:%i:%S')
        </if>
        <if test="chinese!=null and chinese!=''">
            and tk.country  like CONCAT('%',#{chinese},'%')
        </if>
        <if test="limit_num!=null and limit_num>0">
            limit #{limit_num}
        </if>
    </select>

    <update id="updateInterApiAuditTask" parameterType="TaskInfo">
        update
        inter_api_audit_task set
        status = #{status},operator=#{operator}
        where
        id=#{task_id} and intermdns = #{intermdns} and status =1
    </update>

    <select id="waitApiAuditCount" parameterType="TaskInfo"
        resultType="Integer">
        select sum(api.allnumber) wait_audit  from inter_api_audit_task api
        where api.status = 1 and api.sp_id=#{sp_id}
        <if test="createTime!=null and createTime!=''">
            and api.createtime&gt;=str_to_date(#{createTime},'%Y-%m-%d')
        </if>
        <if test="createTime1!=null and createTime1!=''">
            and api.createtime&lt;DATE_ADD(str_to_date(#{createTime1},'%Y-%m-%d'),INTERVAL 1 DAY)
        </if>
    </select>

    <select id="listPageInterPriceRecord" resultType="cn.roadm.bo.PriceRecord">
        SELECT
        <if test="groupBySpid == 'true'">
        sp.id spid,
        sp.sp_name,
        </if>
        <if test="groupByCountry == 'true'">
        iscs.country_code country,
        </if>
        <if test="groupByChannel == 'true'">
        iscs.channelid channelid,
        ssci.channel_name channel_name,
        </if>
        <if test="groupBySupplier == 'true'">
        iscs.supplier_name supplier_name,
        </if>
        <if test="groupByDate == 'true'">
        DATE(iscs.stat_time) stat_time,
        </if>
        <choose>
            <when test="groupByCountry == 'true'">
                sum(ifnull(isp.price, 0)*iscs.succ*sp.inter_price_rate* fr.floating_rate) interIncome,
                sum(ifnull(ss.cost, 0)*iscs.succ*sp.inter_price_rate * ss.ss_floating_rate) interCost,
                sum(iscs.succ) num,
                max(isp.price) price, -- 聚合后的单价（一个国家可能对应多个sp定价，取MAX）
                max(ss.cost) cost_price, -- 聚合后的成本单价
                max(sp.inter_price_rate) interPriceRate,
                max(isp.currency) income_currency,
                max(fr.floating_rate) income_rate,
                max(ss.currency) cost_currency,
                max(ss.ss_floating_rate) cost_rate
            </when>
            <otherwise>
                sum(ifnull(isp.price, 0)*iscs.succ*sp.inter_price_rate* fr.floating_rate) interIncome,
                sum(ifnull(ss.cost, 0)*iscs.succ*sp.inter_price_rate * ss.ss_floating_rate) interCost,
                sum(iscs.succ) num,
                null price,
                null cost_price,
                null interPriceRate,
                null income_currency,
                null income_rate,
                null cost_currency,
                null cost_rate
            </otherwise>
        </choose>
        FROM
        (
        SELECT
        <choose>
            <when test="queryType == 'arrive'">
                sum(ifnull(i.arrive_succ, 0)) succ,
            </when>
            <otherwise>
                sum(ifnull(i.submit_succ, 0)) succ,
            </otherwise>
        </choose>
        i.spid,
        i.country_code,
        i.channelid,
        cs.supplier_name,
        i.stat_time
        FROM
        inter_sp_country_summary i
            left join sms_send_channel_info ssci on i.channelid = ssci.id
            left join channel_supplier cs on ssci.supplier_id = cs.id
        <where>
            <if test="createtime!=null and createtime!=''">
                and i.stat_time &gt;= #{createtime}
            </if>
            <if test="createtime1!=null and createtime1!=''">
                and i.stat_time &lt; DATE_ADD(str_to_date(#{createtime1},'%Y-%m-%d %H:%i:%s'),INTERVAL 1 DAY)
            </if>
            <if test="country!=null and country!=''">
                and i.country_code=#{country}
            </if>
            <if test="spid!=null and spid!=''">
                and i.spid=#{spid}
            </if>
        </where>
        GROUP BY i.spid,i.country_code,i.channelid,cs.supplier_name,i.stat_time
        ) iscs
        inner join sms_sp_info sp on iscs.spid=sp.id and sp.status=1
        left join sms_send_channel_info ssci on iscs.channelid = ssci.id
        left join inter_sms_price isp on isp.gid=sp.inter_price_group and isp.country=iscs.country_code
        left join inter_sms_floating_rate fr ON IFNULL(isp.currency, '¥') = fr.currency
        left join (select sci.id, sp.country, sp.price cost, sp.currency, isfr.floating_rate ss_floating_rate from
        sms_send_channel_info sci
        inner join inter_sms_price sp on sci.inter_price_group = sp.gid
        INNER JOIN inter_sms_floating_rate isfr ON sp.currency = isfr.currency) ss on iscs.channelid = ss.id and
        ss.country=iscs.country_code
        <where>
            <if test="sp_type!=null and sp_type>0">
                and sp.sp_type =#{sp_type}
            </if>
            <if test="sp_name!=null and sp_name!=''">
                and sp.sp_name like concat('%',#{sp_name},'%')
            </if>
            <if test="spid!=null and spid!=''">
                and sp.id=#{spid}
            </if>
        </where>
        GROUP BY
        <trim suffixOverrides=",">
            <if test="groupBySpid == 'true'">
                sp.id, sp.sp_name,
            </if>
            <if test="groupByCountry == 'true'">
                iscs.country_code,
            </if>
            <if test="groupByChannel == 'true'">
                iscs.channelid, ssci.channel_name,
            </if>
            <if test="groupBySupplier == 'true'">
                iscs.supplier_name,
            </if>
            <if test="groupByDate == 'true'">
                DATE(iscs.stat_time),
            </if>
        </trim>
        <if test="orderType=='ASC'">
            <if test="col=='num'">
                order by num
            </if>
            <if test="col=='gross'">
                order by interIncome-interCost
            </if>
        </if>
        <if test="orderType=='DESC'">
            <if test="col=='num'">
                order by num DESC
            </if>
            <if test="col=='gross'">
                order by interIncome-interCost DESC
            </if>
        </if>
    </select>

    <select id="getInterPriceRecordTotal" resultType="cn.roadm.bo.PriceRecord">
        SELECT
        sum(ifnull(isp.price, 0)*iscs.succ*sp.inter_price_rate*fr.floating_rate) interIncome,
        sum(ifnull(ss.cost, 0)*iscs.succ*sp.inter_price_rate*fr.floating_rate) interCost,
        sum(iscs.succ) num
        FROM
        (
        SELECT
        <choose>
            <when test="queryType == 'arrive'">
                sum(ifnull(arrive_succ, 0)) succ,
            </when>
            <otherwise>
                sum(ifnull(submit_succ, 0)) succ,
            </otherwise>
        </choose>
        spid,
        country_code,
        channelid
        FROM
        inter_sp_country_summary
        <where>
            <if test="createtime!=null and createtime!=''">
                and stat_time &gt;= #{createtime}
            </if>
            <if test="createtime1!=null and createtime1!=''">
                and stat_time &lt; DATE_ADD(str_to_date(#{createtime1},'%Y-%m-%d %H:%i:%s'),INTERVAL 1 DAY)
            </if>
            <if test="country!=null and country!=''">
                and country_code=#{country}
            </if>
            <if test="spid!=null and spid!=''">
                and spid=#{spid}
            </if>
        </where>
        GROUP BY spid,country_code,channelid
        ) iscs
        inner join sms_sp_info sp on iscs.spid=sp.id and sp.status=1
        left join inter_sms_price isp on isp.gid=sp.inter_price_group and isp.country=iscs.country_code
        left join (
        select sci.id , sp.country , sp.price cost from
        sms_send_channel_info sci
        inner join inter_sms_price sp on sci.inter_price_group = sp.gid) ss on iscs.channelid = ss.id and ss.country=iscs.country_code
        INNER JOIN inter_sms_floating_rate fr ON ifnull(isp.currency, '¥') = fr.currency
        <where>
            <if test="sp_type!=null and sp_type>0">
                and sp.sp_type =#{sp_type}
            </if>
            <if test="sp_name!=null and sp_name!=''">
                and sp.sp_name like concat('%',#{sp_name},'%')
            </if>
            <if test="spid!=null and spid!=''">
                and sp.id=#{spid}
            </if>
        </where>
    </select>

    <select id="searchCountPageInterTaskDetailByContent" resultType="java.lang.Long">
        SELECT count(1) FROM
            (
            SELECT
                a.id,
                a.RES_CONTENT,
                a.SIGN,
                a.TASKID,
                a.MDN,
                a.NUM,
                a.SEND_TIME,
                a.SP_ID,
                a.CALLMDN,
                a.RES_DESC,
                a.CHANNELID,
                a.`STATUS`,
                a.COUNTRYCODE
            FROM
                inter_submit a
            <where>
                <if test="content!=null and content!=''">
                    AND a.RES_CONTENT LIKE concat('%',#{content},'%')
                </if>
                <if test="mdn!=null and mdn!=''">
                    and a.mdn=#{mdn}
                </if>

                <if test="sign !=null and sign !=''">
                    and a.sign=#{sign}
                </if>
                <if test="sp_id!=null and sp_id>0">
                    and a.sp_id=#{sp_id}
                </if>
                <if test="taskid!=null and taskid>0">
                    <choose>
                        <when test="taskid.toString().length()&lt;18">
                             and a.taskid like CONCAT(#{taskid},'%')
                        </when>
                        <otherwise>
                           and a.taskid=#{taskid}
                        </otherwise>
                    </choose>
                </if>
                <if test="channelid!=null and channelid >=0">
                    and a.channelid=#{channelid}
                </if>
                <if test="createtime!=null and createtime!=''">
                    and a.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d %H:%i:%s')
                    and a.taskid &gt; CONCAT(DATE_FORMAT(#{createtime},'%y%m%d'),'000000000000')
                </if>
                <if test="endtime!=null and endtime!=''">
                    and a.create_time&lt;DATE_ADD(str_to_date(#{endtime},'%Y-%m-%d %H:%i:%s'),INTERVAL 5 SECOND)
                </if>
                <if test="chinese != null and  chinese != ''">
                    and a.countrycode like concat('%',#{chinese},'%')
                </if>
            </where>
            ) a1,
            (
            SELECT
                b.SP_ID,
                b.taskid,
                b.mdn,
                b.num,
                b.STAT_DESC,
                b.CHANNELID,
                b.RESULT result,
                b.arrive_time
            FROM
                inter_arrive b
            <where>
                <if test="stat_desc!=null and stat_desc!=''">
                    and b.stat_desc=#{stat_desc}
                </if>
                <if test="mdn!=null and mdn!=''">
                    and b.mdn=#{mdn}
                </if>

                <if test="sign !=null and sign !=''">
                    and b.sign=#{sign}
                </if>
                <if test="sp_id!=null and sp_id>0">
                    and b.sp_id=#{sp_id}
                </if>
                <if test="taskid!=null and taskid>0">
                    <choose>
                        <when test="taskid.toString().length()&lt;18">
                             and b.taskid like CONCAT(#{taskid},'%')
                        </when>
                        <otherwise>
                           and b.taskid=#{taskid}
                        </otherwise>
                    </choose>
                </if>
                <if test="channelid!=null and channelid >=0">
                    and b.channelid=#{channelid}
                </if>
                 <if test='res_result=="2"'>
                    and b.result= 0
                </if>
                <if test='res_result=="3"'>
                    and b.result != 0
                </if>
                <if test="createtime!=null and createtime!=''">
                    and b.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d %H:%i:%s')
                    and b.taskid &gt; CONCAT(DATE_FORMAT(#{createtime},'%y%m%d'),'000000000000')
                </if>

                <if test="endtime!=null and endtime!=''">
                    and b.create_time&lt;DATE_ADD(str_to_date(#{endtime},'%Y-%m-%d %H:%i:%s'),INTERVAL 5 SECOND)
                </if>
                <if test="chinese != null and  chinese != ''">
                    and b.countrycode like concat('%',#{chinese},'%')
                </if>
            </where>
            ) b1,sms_sp_info sp,sms_send_channel_info sc
        <where>
            a1.TASKID = b1.TASKID
            AND a1.mdn = b1.mdn
            AND a1.num = b1.num
            and a1.SP_ID=sp.id
            and a1.SP_ID=b1.SP_ID
            and a1.channelid=b1.channelid
            and a1.channelid=sc.id
            <if test="sp_name!=null and sp_name!=''">
                and sp.sp_name like CONCAT('%',#{sp_name},'%')
            </if>
        </where>
    </select>

    <select id="searchCountPageInterTaskDetailInfoForStatDesc" resultType="java.lang.Long">
           select count(1) from inter_arrive st
        LEFT JOIN sms_sp_info sp
        ON st.sp_id = sp.id
        LEFT JOIN sms_send_channel_info sc
        ON st.CHANNELID = sc.id

        <where>
            <if test="mdn!=null and mdn!=''">
                and st.mdn=#{mdn}
            </if>

            <if test="sign !=null and sign !=''">
                and st.sign=#{sign}
            </if>
            <if test="sp_id!=null and sp_id>0">
                and st.sp_id=#{sp_id}
            </if>
            <if test="taskid!=null and taskid>0">
                <choose>
                    <when test="taskid.toString().length()&lt;18">
                         and st.taskid like CONCAT(#{taskid},'%')
                    </when>
                    <otherwise>
                       and st.taskid=#{taskid}
                    </otherwise>
                </choose>
            </if>
            <if test="channelid!=null and channelid >=0">
                and st.channelid=#{channelid}
            </if>
            <if test="stat_desc!=null and stat_desc!=''">
                and st.stat_desc=#{stat_desc}
            </if>
          <if test="sp_name!=null and sp_name!=''">
              and sp.sp_name like CONCAT('%',#{sp_name},'%')
          </if>
          <if test="sp_saler!=null and sp_saler!=''">
              and sp.sp_saler =#{sp_saler}
          </if>
          <if test='res_result=="2"'>
              and st.result= 0
          </if>
          <if test='res_result=="3"'>
              and st.result != 0
          </if>
          <if test="createtime!=null and createtime!=''">
              and st.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d %H:%i:%s')
          </if>

          <if test="endtime!=null and endtime!=''">
              and st.create_time&lt;DATE_ADD(str_to_date(#{endtime},'%Y-%m-%d %H:%i:%s'),INTERVAL 5 SECOND)
          </if>
           <if test="chinese != null and  chinese != ''">
                and st.countrycode like concat('%',#{chinese},'%')
            </if>
        </where>
    </select>

    <select id="searchCountPageInterTaskNoReportDetailInfo" resultType="java.lang.Long">
         SELECT count(1) FROM inter_submit st, sms_sp_info sp
        WHERE st.sp_id = sp.id
        <if test="mdn!=null and mdn!=''">
            and st.mdn=#{mdn}
        </if>

        <if test="sign !=null and sign !=''">
            and st.sign=#{sign}
        </if>
        <if test="sp_id!=null and sp_id>0">
            and st.sp_id=#{sp_id}
        </if>
        <if test="taskid!=null and taskid>0">
            <choose>
                <when test="taskid.toString().length()&lt;18">
                     and st.taskid like CONCAT(#{taskid},'%')
                </when>
                <otherwise>
                   and st.taskid=#{taskid}
                </otherwise>
            </choose>
        </if>
        <if test="channelid!=null and channelid >=0">
            and st.channelid=#{channelid}
        </if>
        <if test="sp_name!=null and sp_name!=''">
            and sp.sp_name like CONCAT('%',#{sp_name},'%')
        </if>
        <if test="sp_saler!=null and sp_saler!=''">
            and sp.sp_saler =#{sp_saler}
        </if>
        <if test="createtime!=null and createtime!=''">
            and st.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d %H:%i:%s')
        </if>

        <if test="endtime!=null and endtime!=''">
            and st.create_time&lt;DATE_ADD(str_to_date(#{endtime},'%Y-%m-%d %H:%i:%s'),INTERVAL 5 SECOND)
        </if>
         <if test="chinese != null and  chinese != ''">
            and st.countrycode like concat('%',#{chinese},'%')
        </if>
        <if test="content!=null and content!=''">
            and st.res_content like concat('%',#{content},'%')
        </if>
        and st.taskid not in(
        select b.taskid
        from inter_arrive b
        where
        st.TASKID=b.TASKID and st.mdn=b.mdn and st.num=b.num
        <if test="mdn!=null and mdn!=''">
            and st.mdn=#{mdn}
        </if>

        <if test="sign !=null and sign !=''">
            and st.sign=#{sign}
        </if>
        <if test="sp_id!=null and sp_id>0">
            and st.sp_id=#{sp_id}
        </if>
        <if test="taskid!=null and taskid>0">
            <choose>
                <when test="taskid.toString().length()&lt;18">
                     and st.taskid like CONCAT(#{taskid},'%')
                </when>
                <otherwise>
                   and st.taskid=#{taskid}
                </otherwise>
            </choose>
        </if>
        <if test="channelid!=null and channelid >=0">
            and st.channelid=#{channelid}
        </if>
        <if test="sp_name!=null and sp_name!=''">
            and sp.sp_name like CONCAT('%',#{sp_name},'%')
        </if>
        <if test="sp_saler!=null and sp_saler!=''">
            and sp.sp_saler =#{sp_saler}
        </if>
        <if test="createtime!=null and createtime!=''">
            and st.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d %H:%i:%s')
        </if>

        <if test="endtime!=null and endtime!=''">
            and st.create_time&lt;DATE_ADD(str_to_date(#{endtime},'%Y-%m-%d %H:%i:%s'),INTERVAL 3 DAY)
        </if>
        <if test="chinese != null and  chinese != ''">
            and st.countrycode like concat('%',#{chinese},'%')
        </if>
        )
    </select>

    <select id="searchCountPageInterTaskDetailInfo" resultType="java.lang.Long">
  select count(1)
       <!--  st.arrive_time -->
        from inter_submit st
        LEFT JOIN sms_sp_info sp
        ON st.sp_id = sp.id
        LEFT JOIN sms_send_channel_info sc
        ON st.CHANNELID = sc.id
       <!--  LEFT JOIN receipt_code r
        ON st.stat_desc = r.stat_desc -->
        <where>
            <if test="mdn!=null and mdn!=''">
                and st.mdn=#{mdn}
            </if>
            <if test="sp_id!=null and sp_id>0">
                and st.sp_id=#{sp_id}
            </if>
            <if test="taskid!=null and taskid>0">
               <choose>
                     <when test="taskid.toString().length()&lt;18">
                         and st.taskid like CONCAT(#{taskid},'%')
                    </when>
                    <otherwise>
                       and st.taskid=#{taskid}
                    </otherwise>
                </choose>
            </if>
            <if test="channelid !=null and channelid>=0">
                and st.channelid=#{channelid}
            </if>
             <if test="sign!=null and sign!=''">
                and st.sign=#{sign}
            </if>
            <if test="sp_name!=null and sp_name!=''">
                and sp.sp_name like CONCAT('%',#{sp_name},'%')
            </if>
             <if test="sp_saler!=null and sp_saler!=''">
                and sp.sp_saler =#{sp_saler}
            </if>
            <if test='res_result=="0"'>
                and st.res_result= 0
            </if>
            <if test='res_result=="1"'>
                and st.res_result != 0
            </if>

            <if test="createtime!=null and createtime!=''">
                and st.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d %H:%i:%s')
            </if>

            <if test="endtime!=null and endtime!=''">
                and st.create_time&lt;DATE_ADD(str_to_date(#{endtime},'%Y-%m-%d %H:%i:%s'),INTERVAL 5 SECOND)
            </if>
            <if test="content!=null and content!=''">
                and res_content like concat('%',#{content},'%')
            </if>
            <if test="chinese != null and  chinese != ''">
                and st.countrycode like concat('%',#{chinese},'%')
            </if>
        </where>
        order by st.id desc
    </select>

    <select id="exportInterMoneyRecord" resultType="java.util.Map">
        SELECT
        <if test="groupBySpid == 'true'">
            sp.id spid,
            sp.sp_name,
        </if>
        <if test="groupByCountry == 'true'">
            iscs.country_code country,
        </if>
        <if test="groupByChannel == 'true'">
            iscs.channelid channelid,
            ssci.channel_name channel_name,
        </if>
        <if test="groupBySupplier == 'true'">
            iscs.supplier_name supplier_name,
        </if>
        <if test="groupByDate == 'true'">
            DATE(iscs.stat_time) stat_time,
        </if>
        <choose>
            <when test="groupByCountry == 'true'">
                sum(ifnull(isp.price, 0)*iscs.succ*sp.inter_price_rate* fr.floating_rate) interIncome,
                sum(ifnull(ss.cost, 0)*iscs.succ*sp.inter_price_rate * ss.ss_floating_rate) interCost,
                sum(iscs.succ) num,
                max(isp.price) price, -- 聚合后的单价（一个国家可能对应多个sp定价，取MAX）
                max(ss.cost) cost_price, -- 聚合后的成本单价
                max(sp.inter_price_rate) interPriceRate,
                max(isp.currency) income_currency,
                max(fr.floating_rate) income_rate,
                max(ss.currency) cost_currency,
                max(ss.ss_floating_rate) cost_rate
            </when>
            <otherwise>
                sum(ifnull(isp.price, 0)*iscs.succ*sp.inter_price_rate* fr.floating_rate) interIncome,
                sum(ifnull(ss.cost, 0)*iscs.succ*sp.inter_price_rate * ss.ss_floating_rate) interCost,
                sum(iscs.succ) num,
                null price,
                null cost_price,
                null interPriceRate,
                null income_currency,
                null income_rate,
                null cost_currency,
                null cost_rate
            </otherwise>
        </choose>
        FROM
        (
        SELECT
        <choose>
            <when test="queryType == 'arrive'">
                sum(ifnull(i.arrive_succ, 0)) succ,
            </when>
            <otherwise>
                sum(ifnull(i.submit_succ, 0)) succ,
            </otherwise>
        </choose>
        i.spid,
        i.country_code,
        i.channelid,
        cs.supplier_name,
        i.stat_time
        FROM
        inter_sp_country_summary i
        left join sms_send_channel_info ssci on i.channelid = ssci.id
        left join channel_supplier cs on ssci.supplier_id = cs.id
        <where>
            <if test="createtime!=null and createtime!=''">
                and i.stat_time &gt;= #{createtime}
            </if>
            <if test="createtime1!=null and createtime1!=''">
                and i.stat_time &lt; DATE_ADD(str_to_date(#{createtime1},'%Y-%m-%d %H:%i:%s'),INTERVAL 1 DAY)
            </if>
            <if test="country!=null and country!=''">
                and i.country_code=#{country}
            </if>
            <if test="spid!=null and spid!=''">
                and i.spid=#{spid}
            </if>
        </where>
        GROUP BY i.spid,i.country_code,i.channelid,cs.supplier_name,i.stat_time
        ) iscs
        inner join sms_sp_info sp on iscs.spid=sp.id and sp.status=1
        left join sms_send_channel_info ssci on iscs.channelid = ssci.id
        left join inter_sms_price isp on isp.gid=sp.inter_price_group and isp.country=iscs.country_code
        left join inter_sms_floating_rate fr ON IFNULL(isp.currency, '¥') = fr.currency
        left join (select sci.id, sp.country, sp.price cost, sp.currency, isfr.floating_rate ss_floating_rate from
        sms_send_channel_info sci
        inner join inter_sms_price sp on sci.inter_price_group = sp.gid
        INNER JOIN inter_sms_floating_rate isfr ON sp.currency = isfr.currency) ss on iscs.channelid = ss.id and
        ss.country=iscs.country_code
        <where>
            <if test="sp_type!=null and sp_type>0">
                and sp.sp_type =#{sp_type}
            </if>
            <if test="sp_name!=null and sp_name!=''">
                and sp.sp_name like concat('%',#{sp_name},'%')
            </if>
            <if test="spid!=null and spid!=''">
                and sp.id=#{spid}
            </if>
        </where>
        GROUP BY
        <trim suffixOverrides=",">
            <if test="groupBySpid == 'true'">
                sp.id, sp.sp_name,
            </if>
            <if test="groupByCountry == 'true'">
                iscs.country_code,
            </if>
            <if test="groupByChannel == 'true'">
                iscs.channelid, ssci.channel_name,
            </if>
            <if test="groupBySupplier == 'true'">
                iscs.supplier_name,
            </if>
            <if test="groupByDate == 'true'">
                DATE(iscs.stat_time),
            </if>
        </trim>
        <if test="orderType=='ASC'">
            <if test="col=='num'">
                order by num
            </if>
            <if test="col=='gross'">
                order by interIncome-interCost
            </if>
        </if>
        <if test="orderType=='DESC'">
            <if test="col=='num'">
                order by num DESC
            </if>
            <if test="col=='gross'">
                order by interIncome-interCost DESC
            </if>
        </if>
    </select>

    <select id="queryCountryPriceHis" parameterType="CountryPriceHis" resultType="CountryPriceHis">
        select id,gid,country,price_before,price_after,modifyName,modifytime,currency
        from inter_sms_price_his
        where gid = #{gid}
        ORDER BY modifytime DESC
    </select>

    <insert id="insertCountryPriceHis" useGeneratedKeys="true" keyProperty="id" parameterType="CountryPriceHis">
        insert into inter_sms_price_his
            (gid, country, price_before, price_after, modifyName, modifytime, currency) values
            (#{gid}, #{country}, #{price_before}, #{price_after}, #{modifyName}, now(), #{currency})
    </insert>
</mapper>