<?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.TaskInfoMapper">

    <resultMap type="TaskInfo" id="taskResultMap">
        <id column="id" property="task_id" />
        <result column="content" property="content" />
        <result column="createtime" property="createTime" />
        <result column="total" property="total" />
        <result column="allnumber" property="allnumber" />
        <result column="mobilenumber" property="mobilenumber" />
        <result column="unicomnumber" property="unicomnumber" />
        <result column="telecomnumer" property="telecomnumber" />
        <result column="succ" property="succ" />
        <result column="fail" property="fail" />
        <result column="arrive_total" property="arrive_total" />
        <result column="arrive_succ" property="arrive_succ" />
        <result column="arrive_fail" property="arrive_fail" />
        <result column="task_type" property="task_type" />
        <result column="status" property="status" />
        <result column="endtime" property="endTime" />
        <result column="send_type" property="send_type" />
        <result column="sp_id" property="sp_id" />
        <result column="unRecMsgnum" property="unRecMsgnum" />
        <result column="sp_name" property="sp_name" />
        <result column="time" property="time" />
        <result column="difference" property="difference" />
        <result column="stat_time" property="stat_time"/>
        <result column="descptions" property="descptions"/>
        <result column="task_name" property="taskName"/>
        <result column="ip" property="ip" />
        <result column="stat_time" property="stat_time" />
        <result column="saleprice" property="saleprice" />
        <result column="mobile_price" property="mobile_price" />
        <result column="unicom_price" property="unicom_price" />
        <result column="telecom_price" property="telecom_price" />
        <result column="full_name" property="fullName"/>
        <result column="eid" property="eid"/>
    </resultMap>

    <resultMap type="TaskDetailInfo" id="TaskDetailInfoResultMap">
        <id column="id" property="id" />
        <result column="taskid" property="taskid" />
        <result column="messageid" property="messageid" />
        <result column="channelid" property="channelid" />
        <result column="res_result" property="res_result" />
        <result column="res_desc" property="res_desc" />
        <result column="mdn" property="mdn" />
        <result column="sn" property="sn" />
        <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="source" property="source" />
 		<result column="num" property="num" />
 		<result column="extendnum" property="extendnum" />
 		<result column="resend_channelid" property="resend_channelid" />
    </resultMap>

    <resultMap type="ProvisionInfo" id="provisionInfoMap">
        <id column="id" property="sp_id" />
        <result column="sp_name" property="sp_name" />
        <result column="sp_saler" property="sp_saler" />
        <result column="full_name" property="customerName" />
        <result column="clientid" property="clientid" />
        <result column="provision_price" property="provisionPrice" />
        <result column="serviceType" property="serviceType" />
        <result column="saleprice" property="salePrice" />
        <result column="channelid" property="channelid" />
        <result column="complaintsNum" property="complaintsNum" />
        <result column="totalSuccNum" property="totalSuccNum" />
        <result column="totalProfit" property="totalProfit" />
        <result column="profit" property="profit" />
        <result column="totalComplaintsRate" property="totalComplaintsRate" />
        <result column="statTime" property="month" />
    </resultMap>


    <resultMap type="ReplyDetailInfo" id="ReplyDetailInfoResultMap">
        <id column="id" property="id" />
        <result column="sp_id" property="sp_id" />
        <result column="mobile" property="mobile" />
        <result column="callmdn" property="callmdn" />
        <result column="content" property="content" />
        <result column="reply_time" property="replyTime" />
        <result column="status" property="flag" />
        <result column="createtime" property="createtime" />
        <result column="subport" property="subport" />
        <result column="region" property="region" />
        <result column="res_content" property="res_content" />

    </resultMap>

    <resultMap type="TaskInfo" id="taskInfoMap">
        <id column="id" property="task_id" />
        <result column="content" property="content" />
        <result column="createtime" property="createTime" />
        <result column="total" property="total" />
        <result column="allnumber" property="allnumber" />
        <result column="mobilenumber" property="mobilenumber" />
        <result column="unicomnumber" property="unicomnumber" />
        <result column="telecomnumber" property="telecomnumber" />
        <result column="task_type" property="task_type" />
        <result column="endtime" property="endTime" />
        <result column="send_type" property="send_type" />
        <result column="sp_id" property="sp_id" />
        <result column="sp_audit_type" property="sp_audit_type" />
    </resultMap>


    <resultMap type="TaskInfo" id="spAccountList">
        <result column="sp_name" property="sp_name" />
        <result column="createtime" property="createTime" />
        <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" />
    </resultMap>

    <resultMap type="TaskInfo" id="SpCostResultMap">
        <id column="id" property="task_id" />
        <result column="sp_id" property="sp_id" />
        <result column="sp_name" property="sp_name" />
        <result column="createtime" property="createTime" />
        <result column="sp_saler" property="sp_saler" />
        <result column="costprice" property="costprice" />
        <result column="saleprice" property="saleprice" />
        <result column="margin" property="margin" />
    </resultMap>

	<resultMap type="TaskInfo" id="TaskQueueMap">
		<result column="sp_id" property="sp_id" />
		<result column="sp_name" property="sp_name" />
		<result column="content" property="content" />
		<result column="co" property="total"/>
	</resultMap>

	<select id="listPageReSendDetail" parameterType="TaskDetailInfo"
        resultMap="TaskDetailInfoResultMap">

        select st.id,
        st.taskid,
        st.sp_id,
        st.source,
        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.RESEND_CHANNELID,
        <!-- 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
        from sms_arrive_resend st
        LEFT JOIN sms_sp_info sp
        ON st.sp_id = sp.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="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>
        </where>
        order by st.id desc
    </select>

    <select id="exportTaskDetailByResendDeatil" parameterType="TaskDetailInfo"
            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
        from sms_arrive_resend 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="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="endId != null">
                and st.id &lt;  #{endId}
            </if>
        </where>
        order by st.id desc
        <if test="exportExcelSize != null ">
            limit #{exportExcelSize}
        </if>
    </select>

    <select id="exportTaskDetailByResendDeatilCount" parameterType="TaskDetailInfo"
            resultType="java.lang.Long">
        select count(st.id)
        from sms_arrive_resend 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="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>
        </where>
        order by st.id desc
    </select>

    <select id="listPageSpCost2" parameterType="TaskInfo" resultMap="SpCostResultMap">
        select
        sd.sp_id,
        s.sp_name,
        s.sp_saler,
        s.platform,
        IFNULL(sd.costprice,0) costprice,
        IFNULL(sd.saleprice,0) saleprice,
        (IFNULL(sd.saleprice,0)-IFNULL(sd.costprice,0)) margin,
        date_format(sd.createtime,'%Y-%m-%d') createtime
        from sms_sp_day_fee sd, sms_sp_info s
        where s.id = sd.sp_id
        <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_saler!=null and sp_saler!=''">
            and s.sp_saler like CONCAT('%',#{sp_saler},'%')
        </if>
        <if test="sp_id!=null and sp_id>0">
            and sd.sp_id=#{sp_id}
        </if>
        <if test="createTime!=null and createTime!=''">
            and sd.createtime&gt;=str_to_date(#{createTime},'%Y-%m-%d')
        </if>
        <if test="createTime1!=null and createTime1!=''">
            and
            sd.createtime&lt;=DATE_ADD(str_to_date(#{createTime1},'%Y-%m-%d'),INTERVAL 1 DAY)
        </if>
    </select>


    <select id="listPageMonthCost" parameterType="TaskInfo"
        resultMap="SpCostResultMap">
        select
        sd.sp_id,
        s.sp_name,
        s.sp_saler,
        s.platform,
        sum( IFNULL(sd.costprice,0)) costprice,
        sum( IFNULL(sd.saleprice,0)) saleprice,
        sum( (IFNULL(sd.saleprice,0)-IFNULL(sd.costprice,0))) margin,
        date_format(sd.createtime,'%Y-%m') createtime
        from sms_sp_day_fee sd, sms_sp_info s
        where s.id = sd.sp_id
        <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_saler!=null and sp_saler!=''">
            and s.sp_saler like CONCAT('%',#{sp_saler},'%')
        </if>
        <if test="sp_id!=null and sp_id>0">
            and sd.sp_id=#{sp_id}
        </if>
        <if test="createTime!=null and createTime!=''">
            and date_format(sd.createtime,'%Y-%m')=#{createTime}
        </if>
        group by sd.sp_id,s.sp_name, s.sp_saler,
        date_format(sd.createtime,'%Y-%m'),s.platform
    </select>


    <select id="exportMonthCost" parameterType="TaskInfo"
        resultType="Map">
        select
        sd.sp_id,
        s.sp_name,
        s.sp_saler,
        sum( IFNULL(sd.costprice,0)) costprice,
        sum( IFNULL(sd.saleprice,0)) saleprice,
        sum( (IFNULL(sd.saleprice,0)-IFNULL(sd.costprice,0))) margin,
        date_format(sd.createtime,'%Y-%m') createtime
        from sms_sp_day_fee sd, sms_sp_info s
        where s.id = sd.sp_id

        <if test="sp_name!=null and sp_name!=''">
            and s.sp_name like CONCAT('%',#{sp_name},'%')
        </if>
        <if test="sp_saler!=null and sp_saler!=''">
            and s.sp_saler =#{sp_saler}
        </if>
        <if test="sp_id!=null and sp_id>0">
            and sd.sp_id=#{sp_id}
        </if>
        <if test="createTime!=null and createTime!=''">
            and date_format(sd.createtime,'%Y-%m')=#{createTime}
        </if>
        group by sd.sp_id,s.sp_name, s.sp_saler,
        date_format(sd.createtime,'%Y-%m')
    </select>



    <select id="exportSpCost" parameterType="TaskInfo" resultType="Map">
        select
        sd.sp_id,
        s.sp_name,
        s.sp_saler,
        IFNULL(sd.costprice,0) costprice,
        IFNULL(sd.saleprice,0) saleprice,
        (IFNULL(sd.saleprice,0)-IFNULL(sd.costprice,0)) margin,
        date_format(sd.createtime,'%Y-%m-%d') createtime
        from sms_sp_day_fee sd, sms_sp_info s
        where s.id = sd.sp_id
        <if test="sp_name != null and sp_name != ''">
            and s.sp_name like CONCAT('%',#{sp_name},'%')
        </if>
        <if test="sp_saler!=null and sp_saler!=''">
            and s.sp_saler = #{sp_saler}
        </if>
        <if test="sp_id != null and sp_id > 0">
            and sd.sp_id= #{sp_id}
        </if>
        <if test="createTime!=null and createTime!=''">
            and sd.createtime &gt;= str_to_date(#{createTime},'%Y-%m-%d')
        </if>
        <if test="createTime1!=null and createTime1!=''">
            and
            sd.createtime &lt;= DATE_ADD(str_to_date(#{createTime1},'%Y-%m-%d'),INTERVAL 1 DAY)
        </if>
    </select>

    <select id="ExportAccount" parameterType="TaskInfo" resultType="Map">
        select * from ( select sp.id sp_id,
        sp.sp_name,
        date_format(tk.createtime, '%Y-%m-%d') time,
        sum(tk.allnumber) allnumber,
        sum(tk.succ) succ,
        sum(tk.fail) fail,
        sum(tk.arrive_succ) arrive_succ,
        sum(tk.arrive_fail) arrive_fail
        from sms_send_task tk, sms_sp_info sp
        where tk.sp_id = 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.sp_id=#{sp_id}
        </if>
        <if test="createTime!=null and createTime!=''">
            and tk.createtime&gt;= #{createTime}
        </if>

        <if test="createTime1!=null and createTime1!=''">
            and tk.createtime&lt;= #{createTime1}
        </if>
        group by sp.id,sp.sp_name,date_format(tk.createtime, '%Y-%m-%d')
        ) a limit 0,10000
    </select>

    <select id="listPageTaskInfo" parameterType="TaskInfo"
        resultMap="taskResultMap">
        select tk.id,
        tk.sp_id,
        sp.sp_name,
        tk.content,
        tk.createtime,
        tk.total,
        tk.allnumber,
        tk.unicomnumber,
        tk.mobilenumber,
        tk.telecomnumber,
        tk.succ,
        tk.fail,
        tk.arrive_succ,
        tk.arrive_fail,
        tk.task_type,
        tk.status,
        tk.endtime,
        tk.DESCPTION as descptions,
        (tk.allnumber-tk.arrive_succ-tk.arrive_fail) unRecMsgnum,
        tk.send_type, tk.task_name
        from sms_send_task tk, sms_sp_info sp
        where sp.id = tk.sp_id
        <if test="sp_name!=null and sp_name!=''">
            and sp.sp_name like CONCAT('%',#{sp_name},'%')
        </if>
        <if test="content!=null and content!=''">
            and tk.content like CONCAT('%',#{content},'%')
        </if>
        <if test="sp_id!=null and sp_id>0">
            and tk.sp_id=#{sp_id}
        </if>
        <if test="sp_saler!=null and sp_saler!=''">
            and sp.sp_saler =#{sp_saler}
        </if>
        <if test="task_id!=null and task_id>0">
            and tk.id=#{task_id}
        </if>
         <if test="send_type!=null and send_type!=''">
            and tk.send_type=#{send_type}
        </if>
         <if test="task_type!=null and task_type!=''">
            and tk.task_type=#{task_type}
        </if>
        <if test="sign!=null and sign!=''">
            and tk.sign=#{sign}
        </if>
        <if test="createTime!=null and createTime!=''">
            and tk.createtime&gt;=str_to_date(#{createTime},'%Y-%m-%d')
        </if>

        <if test="createTime1!=null and createTime1!=''">
            and
            tk.createtime&lt;=DATE_ADD(str_to_date(#{createTime1},'%Y-%m-%d'),INTERVAL 1 DAY)
        </if>
        <if test="taskName != null and taskName != ''">
            and tk.task_name like CONCAT('%',#{taskName},'%')
        </if>
        order by tk.id desc
    </select>

    <select id="listPageTaskInfoApi" parameterType="TaskInfo"
        resultMap="taskResultMap">
        select tk.id,
        tk.sp_id,
        sp.sp_name,
        tk.content,
        tk.createtime,
        tk.total,
        tk.allnumber,
        tk.unicomnumber,
        tk.mobilenumber,
        tk.telecomnumber,
        tk.INTERNATIONALNUMBER


        from sms_send_task_api tk, sms_sp_info sp
        where sp.id = tk.sp_id
        <if test="sp_name!=null and sp_name!=''">
            and sp.sp_name like CONCAT('%',#{sp_name},'%')
        </if>
        <if test="content!=null and content!=''">
            and tk.content like CONCAT('%',#{content},'%')
        </if>
        <if test="sp_id!=null and sp_id>0">
            and tk.sp_id=#{sp_id}
        </if>
        <if test="sp_saler!=null and sp_saler!=''">
            and sp.sp_saler =#{sp_saler}
        </if>
        <if test="task_id!=null and task_id>0">
            and tk.id=#{task_id}
        </if>

        <if test="sign!=null and sign!=''">
            and tk.sign=#{sign}
        </if>
        <if test="createTime!=null and createTime!=''">
            and tk.createtime&gt;=str_to_date(#{createTime},'%Y-%m-%d')
        </if>

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

    <select id="listPageHistoryTaskInfo" parameterType="TaskInfo"
            resultMap="taskResultMap">
        select tk.id,
        tk.sp_id,
        sp.sp_name,
        tk.content,
        tk.createtime,
        tk.total,
        tk.allnumber,
        tk.unicomnumber,
        tk.mobilenumber,
        tk.telecomnumber,
        tk.succ,
        tk.fail,
        tk.arrive_succ,
        tk.arrive_fail,
        tk.task_type,
        tk.status,
        tk.endtime,
        (tk.allnumber-tk.arrive_succ-tk.arrive_fail) unRecMsgnum,
        tk.send_type
        from sms_send_task_${history_dateStr} tk, sms_sp_info sp
        where sp.id = tk.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.sp_id=#{sp_id}
        </if>
        <if test="task_id!=null and task_id>0">
            and tk.id=#{task_id}
        </if>
        <if test="createTime!=null and createTime!=''">
            and tk.createtime&gt;=str_to_date(#{createTime},'%Y-%m-%d')
        </if>

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

    <select id="getTaskInfoById" parameterType="TaskInfo" resultMap="taskInfoMap">
        select tk.id,
        tk.sp_id,
        tk.content,
        tk.createid,
        tk.createtime,
        tk.total,
        tk.allnumber,
        tk.unicomnumber,
        tk.mobilenumber,
        tk.telecomnumber,
        tk.task_type,
        tk.status,
        tk.endtime,
        sp.sp_audit_type,
        tk.send_type
        from sms_send_task tk, sms_api_setting sp
        where sp.sp_id = tk.sp_id
        <if test="sp_id!=null and sp_id>0">
            and tk.sp_id=#{sp_id}
        </if>
        <if test="task_id!=null and task_id>0">
            and tk.id=#{task_id}
        </if>
    </select>

    <select id="listPagePlatformTaskTotal" parameterType="TaskInfo"
        resultMap="taskResultMap">
        select
        tk.pcid,
       tk.allnumber,
        tk.succ,
        tk.fail,
        stat_time createTime,
        ip
        from platform_client_summary tk
         where 1=1
        <if test="pcid !=null and pcid !=''">
            and tk.pcid like CONCAT('%',#{pcid},'%')
        </if>
        <if test="createTime!=null and createTime!=''">
            and tk.stat_time = #{createTime}
        </if>
        order by tk.succ desc
    </select>

    <select id="listPageSpTaskTotal" parameterType="TaskInfo"
        resultMap="taskResultMap">
        select sp.id sp_id,
        sp.sp_name,
        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(tk.allnumber-asa.total-tk.arrive_succ-tk.arrive_fail) unRecMsgnum, -->
        <if test="type_day != null and type_day == 'day'">
            tk.stat_time,
        </if>
        sum(tk.arrive_fail) arrive_fail,
        se.full_name
        from sms_sp_info sp left join  sms_sp_summary tk on tk.spid = sp.id
        left join sms_enterprise se on sp.eid = se.id

        <where>
        <if test="sp_name!=null and sp_name!=''">
            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="star_level!=null and star_level>0">
            and sp.star_level =#{star_level}
        </if>
        <if test="managerId != null and managerId != ''">
            and sp.sp_saler in (select ifnull(seller,'') from sale_manager sm where managerId=#{managerId}) and sp.sp_saler != ''
        </if>
            <if test="eid != null and eid != ''">
                and sp.eid = #{eid}
            </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>
        </where>
        group by sp.id, sp.sp_name
        <if test="type_day!=null and type_day == 'day'">
            ,tk.stat_time
        </if>
        <choose>
            <when test="sort != null and sort != '' and sort == 'up'">
                order by stat_time asc
            </when>
            <when test="sort != null and sort != '' and sort == 'down'">
                order by stat_time desc
            </when>
            <otherwise>
                order by sum(tk.allnumber) desc
            </otherwise>
        </choose>
    </select>

    <select id="listPageOfPdd" parameterType="TaskInfo"
            resultMap="taskResultMap">
        select sp.id sp_id,
        sp.sp_name,
        sum(tk.allnumber) allnumber,
        sum(tk.arrive_succ) arrive_succ,
        sum(tk.arrive_fail) arrive_fail
        from sms_sp_info sp left join  sms_sp_pdd_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="salerList!=null and salerList.size()>0">
            and sp.sp_saler in
            <foreach collection="salerList" index="index"  item="item" open="(" separator="," close=")">
                '${item}'
            </foreach>
        </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="listOfPdd" parameterType="TaskInfo"
            resultMap="taskResultMap">
        select sp.id sp_id,
        sp.sp_name,
        sum(tk.allnumber) allnumber,
        sum(tk.arrive_succ) arrive_succ,
        sum(tk.arrive_fail) arrive_fail
        from sms_sp_info sp left join  sms_sp_pdd_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="salerList!=null and salerList.size()>0">
            and sp.sp_saler in
            <foreach collection="salerList" index="index"  item="item" open="(" separator="," close=")">
                '${item}'
            </foreach>
        </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="listPageCmppTaskTotal" parameterType="TaskInfo"
        resultMap="taskResultMap">
        select sp.id sp_id,
        sp.sp_name,
        s.clientid,
        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_api_socket_sp s left join sms_sp_info sp ON  sp.id=s.spid
        left join  sms_sp_summary tk on tk.spid = s.spid


        where 1=1
     	<if test="clientid != null and clientid != ''">
                and s.clientid = #{clientid}
        </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 tk.spid=#{sp_id}
        </if>
        <if test="sp_saler!=null and sp_saler!=''">
            and sp.sp_saler =#{sp_saler}
        </if>
        <if test="salerList!=null and salerList.size()>0">
            and sp.sp_saler in
            <foreach collection="salerList" index="index"  item="item" open="(" separator="," close=")">
               '${item}'
            </foreach>
        </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,clientid
        order by sum(tk.allnumber) desc

    </select>

       <select id="exportSpTotalList" 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, -->
       <if test="type_day != null and type_day == 'day'">
           DATE_FORMAT(tk.stat_time,'%Y-%m-%d') stat_time,
       </if>
        sum(tk.arrive_fail) arrive_fail, se.full_name as eid
        from sms_sp_info sp left join sms_sp_summary tk on tk.spid = sp.id
           left join sms_enterprise se on se.id = sp.eid
        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_saler!= 'undefined'">
            and sp.sp_saler =#{sp_saler}
        </if>
       <if test="managerId != null and managerId != ''">
           and sp.sp_saler in (select ifnull(seller,'') from sale_manager where managerId = #{managerId}) and sp.sp_saler != ''
       </if>
        <if test="sp_type!=null and sp_type>0">
            and sp.sp_type =#{sp_type}
        </if>
        <if test="star_level!=null and star_level>0">
            and sp.star_level =#{star_level}
        </if>
           <if test="eid != null and eid != ''">
               and sp.eid = #{eid}
           </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
       <if test="type_day!=null and type_day == 'day'">
           ,tk.stat_time
       </if>
        order by sp.id

    </select>
    <select id="exportCmppTotalList" parameterType="TaskInfo"
        resultType="Map">
        select sp.id sp_id,
        sp.sp_name,
        s.clientid,
        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_api_socket_sp s left join  sms_sp_info sp on s.spid=sp.id left join sms_sp_summary tk on tk.spid = s.spid
        where 1=1
        <if test="clientid!=null and clientid!=''">
            and s.clientid =#{clientid}
        </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 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="exportPlatformTotalList" parameterType="TaskInfo"
        resultType="Map">
        select
        tk.pcid,
        tk.allnumber,
        tk.succ,
        tk.fail
        ,stat_time createTime
        from platform_client_summary tk
        where 1=1
        <if test="pcid !=null and pcid !=''">
            and tk.pcid like CONCAT('%',#{pcid},'%')
        </if>
        <if test="createTime!=null and createTime!=''">
            and tk.stat_time =#{createTime}
        </if>
        order by tk.succ  desc
    </select>
    <select id="listPageSpAccount" parameterType="TaskInfo"
        resultMap="taskResultMap">
        select sp.id sp_id,
        sp.sp_name,
        date_format(tk.createtime, '%Y-%m-%d') time,
        sum(tk.allnumber) allnumber,
        sum(tk.succ) succ,
        sum(tk.fail) fail,
        sum(tk.arrive_succ) arrive_succ,
        sum(tk.allnumber-tk.arrive_succ-tk.arrive_fail) unRecMsgnum,
        sum(tk.arrive_fail) arrive_fail
        from sms_send_task tk, sms_sp_info sp
        where tk.sp_id = 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.sp_id=#{sp_id}
        </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>

        group by sp.id, sp.sp_name,date_format(tk.createtime, '%Y-%m-%d')
    </select>



    <select id="listPageTaskDetailInfo" parameterType="TaskDetailInfo"
        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.SIZES,
        <!-- st.REPORT_RESULT result, -->
        <!-- IFNULL(r.receipt_desc,st.stat_desc) stat_desc, -->
        <!-- st.stat_desc, -->
        st.channelid,
        st.status,
        st.otype,
        st.res_content
       <!--  st.arrive_time -->
        from sms_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="province!=null and province!=''">
                	and st.province=#{province}
             </if>
			 <if test="mdn!=null and mdn!=''">
                 <choose>
	                <when test='mdn.toString().contains("_")'>
	                     and st.mdn like #{mdn}
	                </when>
	                <otherwise>
	                   and st.mdn=#{mdn}
	                </otherwise>
            	</choose>
            </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="salerList!=null and salerList.size()>0">
                and sp.sp_saler in
                <foreach collection="salerList" index="index"  item="item" open="(" separator="," close=")">
                   '${item}'
                </foreach>
            </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="timeType == 0">
                <if test="createtime!=null and createtime!=''">
                    and st.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d %H:%i:%s')
                    and st.taskid &gt;= CONCAT(DATE_FORMAT(#{createtime},'%y%m%d%H%i%s'), '000000')
                </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 1 DAY)
                    and st.taskid &lt; CONCAT(DATE_FORMAT(#{endtime},'%y%m%d%H%i%s'), '000000')
                </if>
            </if>
            <if test="timeType == 1">
                <if test="createtime!=null and createtime!=''">
                    and st.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d %H:%i:%s')
                    and st.send_time &gt;= #{createtime}
                </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 1 DAY)
                    and st.send_time &lt; #{endtime}
                </if>
            </if>
            <if test="otype!=null and otype!=''">
            	and st.otype=#{otype}
            </if>
            <if test="fixedTelephone!=null and fixedTelephone!=''">
                and st.CALLMDN like CONCAT(#{fixedTelephone},'%')
            </if>
            <if test="areaCode!=null and areaCode!=''">
                and st.CALLMDN like CONCAT(#{areaCode},'%')
            </if>
            <if test="content!=null and content!=''">
	        	and res_content like concat('%',#{content},'%')
	        </if>
            <if test="lsms != null and lsms == 1">
                and st.sizes = 1
            </if>
            <if test="lsms != null and lsms == 2">
                and st.sizes > 1
            </if>
            <if test="managerId != null and managerId != ''">
                and sc.business_manager in (select ifnull(business,0) from business_manager where managerId =  #{managerId}) and sc.business_manager != ''
            </if>
            <if test="businessManager != null and businessManager != ''">
                and sc.business_manager = #{businessManager}
            </if>
        </where>
        order by st.id desc
    </select>

     <select id="listPageTaskNoReportDetailInfo" parameterType="TaskDetailInfo"
        resultMap="TaskDetailInfoResultMap">
         SELECT  st.sid id, st.taskid, st.sp_id, sp.sp_name, st.mdn,
                 st.callmdn, st.send_time, st.CHANNELID, st.num, st.SIZES,st.otype, st.res_content
         FROM
                 sms_submit_noreport st,
                 sms_sp_info sp,
                (select CHANNEL_NAME,id from sms_send_channel_info union all select CHANNEL_NAME,id from mms_send_channel_info) as sc
         <where>
             st.SP_ID = sp.id
             and st.CHANNELID = sc.id
             <if test="province!=null and province!=''">
                and st.province=#{province}
             </if>
             <if test="mdn!=null and mdn!=''">
                 <choose>
                     <when test='mdn.toString().contains("_")'>
                         and st.mdn like #{mdn}
                     </when>
                     <otherwise>
                         and st.mdn=#{mdn}
                     </otherwise>
                 </choose>
             </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="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="salerList!=null and salerList.size()>0">
                 and sp.sp_saler in
                 <foreach collection="salerList" index="index"  item="item" open="(" separator="," close=")">
                    '${item}'
                 </foreach>
             </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="timeType == 0">
                 <if test="createtime!=null and createtime!=''">
                     and st.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d %H:%i:%s')
                     and st.taskid &gt;= CONCAT(DATE_FORMAT(#{createtime},'%y%m%d%H%i%s'), '000000')
                 </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 1 DAY)
                     and st.taskid &lt; CONCAT(DATE_FORMAT(#{endtime},'%y%m%d%H%i%s'), '000000')
                 </if>
             </if>
             <if test="timeType == 1">
                 <if test="createtime!=null and createtime!=''">
                     and st.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d %H:%i:%s')
                     and st.send_time &gt;= #{createtime}
                 </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 1 DAY)
                     and st.send_time &lt; #{endtime}
                 </if>
             </if>
             <if test="otype!=null and otype!=''">
                 and st.otype=#{otype}
             </if>
             <if test="content!=null and content!=''">
                 and st.res_content like concat('%',#{content},'%')
             </if>
             <if test="lsms != null and lsms == 1">
                 and st.sizes = 1
             </if>
             <if test="lsms != null and lsms == 2">
                 and st.sizes > 1
             </if>
             <if test="fixedTelephone!=null and fixedTelephone!=''">
                 and st.CALLMDN like CONCAT(#{fixedTelephone},'%')
             </if>
             <if test="areaCode!=null and areaCode!=''">
                 and st.CALLMDN like CONCAT(#{areaCode},'%')
             </if>
             <if test="managerId != null and managerId != ''">
                 and sc.business_manager in (select ifnull(business,0) from business_manager where managerId =  #{managerId}) and sc.business_manager != ''
             </if>
             <if test="businessManager != null and businessManager != ''">
                 and sc.business_manager = #{businessManager}
             </if>
         </where>
         order by st.TASKID desc
     </select>

        <select id="listPageTaskDetailInfoForStatDesc" parameterType="TaskDetailInfo"
        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.SIZES,
        st.otype,
        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
        from sms_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="province!=null and province!=''">
                	and st.province=#{province}
             </if>
            <if test="mdn!=null and mdn!=''">
                 <choose>
	                <when test='mdn.toString().contains("_")'>
	                     and st.mdn like #{mdn}
	                </when>
	                <otherwise>
	                   and st.mdn=#{mdn}
	                </otherwise>
            	</choose>
            </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="salerList!=null and salerList.size()>0">
                and sp.sp_saler in
                <foreach collection="salerList" index="index"  item="item" open="(" separator="," close=")">
                   '${item}'
                </foreach>
            </if>
            <if test='res_result=="2"'>
                and st.result= 0
            </if>
            <if test='res_result=="3"'>
                and st.result != 0
            </if>
            <if test="timeType == 0">
                <if test="createtime!=null and createtime!=''">
                    and st.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d %H:%i:%s')
                    and st.taskid &gt;= CONCAT(DATE_FORMAT(#{createtime},'%y%m%d%H%i%s'), '000000')
                </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)
                    and st.taskid &lt; CONCAT(DATE_FORMAT(#{endtime},'%y%m%d%H%i%s'), '000000')
                </if>
            </if>
            <if test="timeType == 1">
                <if test="createtime!=null and createtime!=''">
                    and st.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d %H:%i:%s')
                    and st.res_content &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)
                    and st.res_content &lt; str_to_date(#{endtime},'%Y-%m-%d %H:%i:%s')
                </if>
            </if>
            <if test="otype !=null and otype!=''">
            	and st.otype=#{otype}
            </if>
            <if test="lsms != null and lsms == 1">
                and st.sizes = 1
            </if>
            <if test="lsms != null and lsms == 2">
                and st.sizes > 1
            </if>
            <if test="fixedTelephone!=null and fixedTelephone!=''">
                and st.CALLMDN like CONCAT(#{fixedTelephone},'%')
            </if>
            <if test="areaCode!=null and areaCode!=''">
                and st.CALLMDN like CONCAT(#{areaCode},'%')
            </if>
            <if test="managerId != null and managerId != ''">
                and sc.business_manager in (select ifnull(business,0) from business_manager where managerId =  #{managerId}) and sc.business_manager != ''
            </if>
            <if test="businessManager != null and businessManager != ''">
                and sc.business_manager = #{businessManager}
            </if>
        </where>
        order by st.id desc
    </select>

    <select id="listPageSpReportFailDetailInfo" parameterType="TaskDetailInfo"
        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 -->
        DATE_FORMAT(str_to_date(st.arrive_time,'%Y%m%d%H%i%s'),'%Y-%m-%d %H:%i:%s') arrive_time
        from sms_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>
        	st.result!=0
            <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">
                and st.taskid=#{taskid}
            </if>
            <if test="channelid!=null and channelid!=''">
                and st.channelid=#{channelid}
            </if>
            <if test="stat_desc!=null and stat_desc!=''">
                and st.stat_desc=#{stat_desc}
            </if>
            <if test="createtime!=null and createtime!=''">
                and st.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d')
                and st.taskid&gt;CONCAT(date_format(str_to_date(#{createtime}, '%Y-%m-%d' ) , '%y%m%d'),'000000000000')
            </if>

            <if test="endtime!=null and endtime!=''">
                and st.create_time&lt;DATE_ADD(str_to_date(#{endtime},'%Y-%m-%d'),INTERVAL 1 DAY)
                and st.taskid&lt;CONCAT(date_format(DATE_ADD(str_to_date(#{endtime},'%Y-%m-%d'),INTERVAL 1 DAY), '%y%m%d'),'000000000000')
            </if>
        </where>
        order by st.id desc
    </select>

        <select id="listPageSpSubmitFailDetailInfo" parameterType="TaskDetailInfo"
        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.status
        <!-- st.arrive_time -->
        from sms_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>
        	st.res_result!=0
            <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">
                and st.taskid=#{taskid}
            </if>
            <if test="channelid!=null and channelid!=''">
                and st.channelid=#{channelid}
            </if>
            <if test="sign!=null and sign!=''">
                and st.sign=#{sign}
            </if>
            <if test="createtime!=null and createtime!=''">
                and st.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d')
            </if>

            <if test="endtime!=null and endtime!=''">
                and st.create_time&lt;DATE_ADD(str_to_date(#{endtime},'%Y-%m-%d'),INTERVAL 1 DAY)
            </if>
        </where>
        order by st.id desc
    </select>

    <select id="getTaskDetailFromArrive" parameterType="TaskDetailInfo"
        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 sms_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="getHisTaskDetailFromArrive" parameterType="TaskDetailInfo"
        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 sms_arrive_${history_dateStr} 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="getTaskDetailFromSubmit" parameterType="TaskDetailInfo"
        resultMap="TaskDetailInfoResultMap">
 		select
 		st.id,
		st.res_desc,
        st.send_time,
        st.res_content
        from sms_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>
            <if test="otype!=null and otype!=''">
            	and st.otype=#{otype}
            </if>
        limit 1
    </select>

     <select id="getTaskSumFromSubmit" parameterType="TaskDetailInfo"
        resultMap="TaskDetailInfoResultMap">
 		select
 		taskid,res_result,count(*) num
        from sms_submit st
        where taskid=#{taskid}
         <if test="createtime!=null and createtime!=''">
                and st.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d')
            </if>

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

		group by taskid,res_result
    </select>

      <select id="getTaskSumFromArrive" parameterType="TaskDetailInfo"
        resultMap="TaskDetailInfoResultMap">
 		select
 		taskid,result res_result,count(*) num
        from sms_arrive st
        where taskid=#{taskid}
       <if test="createtime!=null and createtime!=''">
                and st.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d')
            </if>

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

		group by taskid,result
    </select>


    <select id="isTableExist" parameterType="String" resultType="int">
        SELECT COUNT(1) FROM information_schema.tables WHERE table_schema='zx_sms' AND table_name = #{tableName}
    </select>
    <select id="listPageHistoryTaskDetailInfo" parameterType="TaskDetailInfo"
            resultMap="TaskDetailInfoResultMap">

        select st.id,
        st.taskid,
        st.sp_id,
        sc.CHANNEL_NAME as pa_dec,
        st.channelid,
        sp.sp_name,
        st.mdn,
        st.callmdn,
        st.send_time,
        st.res_desc,
        st.num,
        <!-- st.REPORT_RESULT result, -->
        <!-- /*st.stat_desc,*/ -->
        r.receipt_desc stat_desc,
        st.status,
        st.arrive_time
        from sms_submit_${history_dateStr} 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!=''">
                <choose>
                    <when test='mdn.toString().contains("_")'>
                        and st.mdn like #{mdn}
                    </when>
                    <otherwise>
                        and st.mdn=#{mdn}
                    </otherwise>
                </choose>
            </if>

            <if test="sp_id!=null and sp_id>0">
                and st.sp_id=#{sp_id}
            </if>
            <if test="taskid!=null and taskid>0">
                and st.taskid=#{taskid}
            </if>
            <if test="channelid!=null and channelid!=''">
                and st.channelid=#{channelid}
            </if>
            <if test="stat_desc!=null and stat_desc!=''">
                and st.stat_desc=#{stat_desc}
            </if>
            <if test="createtime!=null and createtime!=''">
                and st.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d')
            </if>

            <if test="endtime!=null and endtime!=''">
                and st.create_time&lt;=DATE_ADD(str_to_date(#{endtime},'%Y-%m-%d'),INTERVAL 1 DAY)
            </if>
        </where>
        order by st.id desc
    </select>

    	<select id="ExportTaskDetail" parameterType="TaskDetailInfo"
		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.report_result result, -->
		<!-- st.stat_desc, -->
		st.status,
		<!-- st.arrive_time, -->
		st.res_content
        from sms_submit
		st, sms_sp_info sp
		where st.sp_id = sp.id

		<if test="mdn!=null and mdn!=''">
            <choose>
                <when test='mdn.toString().contains("_")'>
                    and st.mdn like #{mdn}
                </when>
                <otherwise>
                    and st.mdn=#{mdn}
                </otherwise>
            </choose>
		</if>
		<if test="otype!=null and otype!=''">
			and st.otype=#{otype}
		</if>
		<if test="sp_name!=null and sp_name!=''">
			and sp.sp_name like CONCAT('%',#{sp_name},'%')
		</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="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="sign !=null and sign !=''">
            and st.sign=#{sign}
        </if>
            <if test="province != null and province != ''">
                and st.province=#{province}
            </if>
            <if test="content!=null and content!=''">
                AND st.RES_CONTENT LIKE concat('%',#{content},'%')
            </if>
            <if test="timeType == 0">
                <if test="createtime!=null and createtime!=''">
                    and st.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d %H:%i:%s')
                    and st.taskid &gt;= CONCAT(DATE_FORMAT(#{createtime},'%y%m%d%H%i%s'), '000000')
                </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 1 DAY)
                    and st.taskid &lt; CONCAT(DATE_FORMAT(#{endtime},'%y%m%d%H%i%s'), '000000')
                </if>
            </if>
            <if test="timeType == 1">
                <if test="createtime!=null and createtime!=''">
                    and st.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d %H:%i:%s')
                    and st.send_time &gt;= #{createtime}
                </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 1 DAY)
                    and st.send_time &lt; #{endtime}
                </if>
            </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="ExportTaskInfo" parameterType="TaskInfo"
        resultType="Map">
        select tk.id,
        tk.sp_id,
        sp.sp_name,
        tk.content,
        tk.createtime,
        tk.total,
        tk.allnumber,
        tk.unicomnumber,
        tk.mobilenumber,
        tk.telecomnumber,
        tk.succ,
        tk.fail,
        tk.arrive_succ,
        tk.arrive_fail,
        tk.task_type,
        tk.status,
        tk.endtime,
        (tk.allnumber-tk.arrive_succ-tk.arrive_fail) unRecMsgnum,
        tk.send_type, tk.task_name as taskName
        from sms_send_task tk, sms_sp_info sp
        where sp.id = tk.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.sp_id=#{sp_id}
        </if>
        <if test="task_id!=null and task_id>0">
            and tk.id=#{task_id}
        </if>
         <if test="send_type!=null and send_type!=''">
            and tk.send_type=#{send_type}
        </if>
         <if test="task_type!=null and task_type!=''">
            and tk.task_type=#{task_type}
        </if>
        <if test="sign!=null and sign!=''">
            and tk.sign=#{sign}
        </if>
        <if test="createTime!=null and createTime!=''">
            and tk.createtime&gt;=str_to_date(#{createTime},'%Y-%m-%d')
        </if>

        <if test="createTime1!=null and createTime1!=''">
            and
            tk.createtime&lt;=DATE_ADD(str_to_date(#{createTime1},'%Y-%m-%d'),INTERVAL 1 DAY)
        </if>
         <if test="endId != null">
                and tk.id &lt;  #{endId}
        </if>
        order by tk.id desc

        <if test="exportExcelSize != null ">
            limit #{exportExcelSize}
        </if>
    </select>

    <select id="ExportTaskInfoApi" parameterType="TaskInfo"
        resultType="Map">
        select tk.id,
        tk.sp_id,
        sp.sp_name,
        tk.content,
        tk.createtime,
        tk.total,
        tk.allnumber,
        tk.unicomnumber,
        tk.mobilenumber,
        tk.telecomnumber

        from sms_send_task_api tk, sms_sp_info sp
        where sp.id = tk.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.sp_id=#{sp_id}
        </if>
        <if test="task_id!=null and task_id>0">
            and tk.id=#{task_id}
        </if>

        <if test="sign!=null and sign!=''">
            and tk.sign=#{sign}
        </if>
        <if test="createTime!=null and createTime!=''">
            and tk.createtime&gt;=str_to_date(#{createTime},'%Y-%m-%d')
        </if>

        <if test="createTime1!=null and createTime1!=''">
            and
            tk.createtime&lt;=DATE_ADD(str_to_date(#{createTime1},'%Y-%m-%d'),INTERVAL 1 DAY)
        </if>
         <if test="endId != null">
                and tk.id &lt;  #{endId}
        </if>
        order by tk.id desc

        <if test="exportExcelSize != null ">
            limit #{exportExcelSize}
        </if>
    </select>

       <select id="ExportTaskInfoCount" parameterType="TaskInfo"
        resultType="Long">
        select count(1)

        from sms_send_task tk, sms_sp_info sp
        where sp.id = tk.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.sp_id=#{sp_id}
        </if>
        <if test="task_id!=null and task_id>0">
            and tk.id=#{task_id}
        </if>
         <if test="send_type!=null and send_type!=''">
            and tk.send_type=#{send_type}
        </if>
         <if test="task_type!=null and task_type!=''">
            and tk.task_type=#{task_type}
        </if>
        <if test="sign!=null and sign!=''">
            and tk.sign=#{sign}
        </if>
        <if test="createTime!=null and createTime!=''">
            and tk.createtime&gt;=str_to_date(#{createTime},'%Y-%m-%d')
        </if>

        <if test="createTime1!=null and createTime1!=''">
            and
            tk.createtime&lt;=DATE_ADD(str_to_date(#{createTime1},'%Y-%m-%d'),INTERVAL 1 DAY)
        </if>
        order by tk.id desc

    </select>

    <select id="ExportTaskInfoApiCount" parameterType="TaskInfo"
        resultType="Long">
        select count(1)

        from sms_send_task_api tk, sms_sp_info sp
        where sp.id = tk.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.sp_id=#{sp_id}
        </if>
        <if test="task_id!=null and task_id>0">
            and tk.id=#{task_id}
        </if>

        <if test="sign!=null and sign!=''">
            and tk.sign=#{sign}
        </if>
        <if test="createTime!=null and createTime!=''">
            and tk.createtime&gt;=str_to_date(#{createTime},'%Y-%m-%d')
        </if>

        <if test="createTime1!=null and createTime1!=''">
            and
            tk.createtime&lt;=DATE_ADD(str_to_date(#{createTime1},'%Y-%m-%d'),INTERVAL 1 DAY)
        </if>
        order by tk.id desc

    </select>
	<select id="ExportTaskNoReportDetail" parameterType="TaskDetailInfo"
		resultType="Map">
		 select
        a.id,a.taskid,a.sp_id,a.pa_dec,a.sp_name,a.mdn,a.callmdn,a.send_time,a.res_desc,a.CHANNELID,a.num,a.res_content


        from (select st.sid id,
        st.taskid,
        st.sp_id,
        sc.CHANNEL_NAME as pa_dec,
        sp.sp_name,
        st.mdn,
        st.callmdn,
        st.send_time,
        (case when st.RES_RESULT=0 then '提交成功' else '提交失败' end) res_desc,
        st.CHANNELID,
        st.num,
		st.res_content

        from sms_submit_noreport st, sms_sp_info sp, (select CHANNEL_NAME,id from sms_send_channel_info union all select CHANNEL_NAME,id from mms_send_channel_info) as sc
        where st.sp_id = sp.id
        and st.CHANNELID = sc.id

        <if test="sp_id!=null and sp_id>0">
            and st.sp_id=#{sp_id}
        </if>
        <if test="mdn != null and mdn != ''">
            <choose>
                <when test='mdn.toString().contains("_")'>
                    and st.mdn like #{mdn}
                </when>
                <otherwise>
                    and st.mdn=#{mdn}
                </otherwise>
            </choose>
        </if>
        <if test="otype!=null and otype!=''">
        	and st.otype=#{otype}
        </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="province != null and province != ''">
                and st.province=#{province}
            </if>
        <if test="content!=null and content!=''">
            AND st.RES_CONTENT LIKE concat('%',#{content},'%')
        </if>
        <if test="timeType == 0">
            <if test="createtime!=null and createtime!=''">
                and st.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d %H:%i:%s')
                and st.taskid &gt;= CONCAT(DATE_FORMAT(#{createtime},'%y%m%d%H%i%s'), '000000')
            </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 1 DAY)
                and st.taskid &lt; CONCAT(DATE_FORMAT(#{endtime},'%y%m%d%H%i%s'), '000000')
            </if>
        </if>
        <if test="timeType == 1">
            <if test="createtime!=null and createtime!=''">
                and st.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d %H:%i:%s')
                and st.send_time &gt;= #{createtime}
            </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 1 DAY)
                and st.send_time &lt; #{endtime}
            </if>
        </if>
        <if test="endId != null">
                and st.sid &lt;  #{endId}
        </if>
        order by st.sid desc
        ) a

        <if test="exportExcelSize != null ">
            limit #{exportExcelSize}
        </if>
	</select>

	<select id="ExportTaskDetailByArriveAll" parameterType="TaskDetailInfo"
		resultType="Map">
			select su.RES_CONTENT,su.SIGN,su.TASKID,su.MDN,su.NUM,su.SEND_TIME,su.STAT_DESC,su.ARRIVE_TIME,su.result,su.callmdn,su.RES_DESC,su.id,su.sp_id from (
			select a1.RES_CONTENT,a1.SIGN,a1.TASKID,a1.MDN,a1.NUM,a1.SEND_TIME,b1.stat_desc,b1.ARRIVE_TIME,b1.result,a1.callmdn,a1.RES_DESC,a1.id,a1.sp_id from
			(select a.RES_CONTENT,a.SIGN,a.TASKID,a.MDN,a.NUM,a.SEND_TIME,a.callmdn,a.RES_DESC,a.id,a.sp_id from sms_submit a
			<where>
				<if test="sp_id!=null and sp_id>0">
					and a.sp_id=#{sp_id}
				</if>
				<if test='res_result=="0"'>
	                and a.result= 0
	            </if>
	            <if test='res_result=="1"'>
	                and a.result != 0
	            </if>
				<if test="createtime!=null and createtime!=''">
					and CREATE_TIME >= #{createtime}
				</if>
				<if test="endtime!=null and endtime!=''">
				 	and  CREATE_TIME &lt; DATE_ADD(str_to_date(#{endtime},'%Y-%m-%d %H:%i:%s'),INTERVAL 4 DAY)
				 	and taskid &lt; CONCAT(DATE_FORMAT(date_add(#{endtime},INTERVAL 1 DAY),'%y%m%d'),'000000000000')
				</if>
				<if test="taskid!=null and taskid>0">
					and taskid=#{taskid}
				</if>
				 <if test="channelid!=null and channelid >=0">
		            and channelid=#{channelid}
		        </if>
		        <if test="sign !=null and sign !=''">
		            and sign=#{sign}
		        </if>
		        <if test="mdn!=null and mdn!=''">
					and mdn=#{mdn}
				</if>
				<if test="otype!=null and otype!=''">
					and otype=#{otype}
				</if>
			</where>
			 ) a1,
			(select b.taskid,b.mdn,b.num,b.STAT_DESC,b.ARRIVE_TIME,if(b.result=0,'到达成功','到达失败') result from sms_arrive b
			<where>
				<if test="sp_id!=null and sp_id>0">
					and sp_id=#{sp_id}
				</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 CREATE_TIME >= #{createtime}
				</if>
				<if test="endtime!=null and endtime!=''">
				 	and  CREATE_TIME &lt; DATE_ADD(str_to_date(#{endtime},'%Y-%m-%d %H:%i:%s'),INTERVAL 4 DAY)
				 	and taskid &lt; CONCAT(DATE_FORMAT(date_add(#{endtime},INTERVAL 1 DAY),'%y%m%d'),'000000000000')
				</if>
				<if test="taskid!=null and taskid>0">
					and taskid=#{taskid}
				</if>
				 <if test="channelid!=null and channelid >=0">
		            and channelid=#{channelid}
		        </if>
		        <if test="stat_desc!=null and stat_desc!=''">
		            and stat_desc=#{stat_desc}
		        </if>
		        <if test="sign !=null and sign !=''">
		            and sign=#{sign}
		        </if>
		        <if test="mdn!=null and mdn!=''">
					and mdn=#{mdn}
				</if>
				<if test="otype!=null and otype!=''">
					and otype=#{otype}
				</if>
			</where>
			) b1 where a1.TASKID=b1.TASKID and a1.mdn=b1.mdn and a1.num=b1.num

			union all

			select a.RES_CONTENT,a.SIGN,a.TASKID,a.MDN,a.NUM,a.SEND_TIME,'未收回执' stat_desc,'' ARRIVE_TIME,'' result,a.callmdn,a.RES_DESC,a.id,a.sp_id  from sms_submit a
			<where>
				<if test="sp_id!=null and sp_id>0">
					and a.sp_id=#{sp_id}
				</if>
				<if test='res_result=="0"'>
	                and b.res_result= 0
	            </if>
	            <if test='res_result=="1"'>
	                and b.res_result != 0
	            </if>
				<if test="createtime!=null and createtime!=''">
					and CREATE_TIME >= #{createtime}
				</if>
				<if test="endtime!=null and endtime!=''">
				 	and  CREATE_TIME &lt; DATE_ADD(str_to_date(#{endtime},'%Y-%m-%d %H:%i:%s'),INTERVAL 4 DAY)
				 	and taskid &lt; CONCAT(DATE_FORMAT(date_add(#{endtime},INTERVAL 1 DAY),'%y%m%d'),'000000000000')
				</if>
				<if test="taskid!=null and taskid>0">
					and taskid=#{taskid}
				</if>
				 <if test="channelid!=null and channelid >=0">
		            and channelid=#{channelid}
		        </if>
		        <if test="sign !=null and sign !=''">
		            and sign=#{sign}
		        </if>
		        <if test="mdn!=null and mdn!=''">
					and mdn=#{mdn}
				</if>
				<if test="otype!=null and otype!=''">
					and otype=#{otype}
				</if>
				and a.taskid not in
					(select b.taskid from sms_arrive b
						<where>
							<if test="sp_id!=null and sp_id>0">
								and b.sp_id=#{sp_id}
							</if>
							<if test='res_result=="2"'>
				                and b.result= 0
				            </if>
				            <if test='res_result=="3"'>
				                and b.result != 0
				            </if>
							<if test="endtime!=null and endtime!=''">
							 	and  CREATE_TIME &lt; DATE_ADD(str_to_date(#{endtime},'%Y-%m-%d %H:%i:%s'),INTERVAL 4 DAY)
							 	and taskid &lt; CONCAT(DATE_FORMAT(date_add(#{endtime},INTERVAL 1 DAY),'%y%m%d'),'000000000000')
							</if>
							<if test="taskid!=null and taskid>0">
								and taskid=#{taskid}
							</if>
							 <if test="channelid!=null and channelid >=0">
					            and channelid=#{channelid}
					        </if>
					        <if test="stat_desc!=null and stat_desc!=''">
					            and stat_desc=#{stat_desc}
					        </if>
					        <if test="sign !=null and sign !=''">
					            and sign=#{sign}
					        </if>
					        <if test="mdn!=null and mdn!=''">
								and mdn=#{mdn}
							</if>
							<if test="otype!=null and otype!=''">
								and otype=#{otype}
							</if>
						</where>
					and a.TASKID=b.TASKID and a.mdn=b.mdn and a.num=b.num)
			</where>

			) su,sms_sp_info sp
			<where>
				su.sp_id=sp.id
				<if test="sp_name!=null and sp_name!=''">
					and sp.sp_name like CONCAT('%',#{sp_name},'%')
				</if>
				<if test="endId != null">
	                and su.id &lt;  #{endId}
	            </if>
			</where>
			ORDER BY su.id DESC
			limit #{exportExcelSize}
		</select>

		<select id="ExportTaskDetailByArrive" parameterType="TaskDetailInfo"
			resultType="Map">
			select su.RES_CONTENT,su.SIGN,su.TASKID,su.MDN,su.NUM,su.SEND_TIME,su.STAT_DESC,su.ARRIVE_TIME,su.result,su.callmdn,su.RES_DESC from (
			select a1.RES_CONTENT,a1.SIGN,a1.TASKID,a1.MDN,a1.NUM,a1.SEND_TIME,b1.stat_desc,b1.ARRIVE_TIME,b1.result,a1.callmdn,a1.RES_DESC,a1.sp_id from
			(select a.RES_CONTENT,a.SIGN,a.TASKID,a.MDN,a.NUM,a.SEND_TIME,a.callmdn,a.RES_DESC,a.sp_id from sms_submit a
			<where>
				<if test="sp_id!=null and sp_id>0">
					and a.sp_id=#{sp_id}
				</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="createtime!=null and createtime!=''">
					and CREATE_TIME >= #{createtime}
				</if>
				<if test="endtime!=null and endtime!=''">
				 	and  CREATE_TIME &lt; DATE_ADD(str_to_date(#{endtime},'%Y-%m-%d %H:%i:%s'),INTERVAL 4 DAY)
				 	and taskid &lt; CONCAT(DATE_FORMAT(date_add(#{endtime},INTERVAL 1 DAY),'%y%m%d'),'000000000000')
				</if>
				<if test="taskid!=null and taskid>0">
					and taskid=#{taskid}
				</if>
				 <if test="channelid!=null and channelid >=0">
		            and channelid=#{channelid}
		        </if>
		        <if test="sign !=null and sign !=''">
		            and sign=#{sign}
		        </if>
		        <if test="mdn!=null and mdn!=''">
					and mdn=#{mdn}
				</if>
				<if test="otype!=null and otype!=''">
					and otype=#{otype}
				</if>
			</where>
			 ) a1,
			(select b.taskid,b.mdn,b.num,b.STAT_DESC,b.ARRIVE_TIME,if(b.result=0,'到达成功','到达失败') result,b.id from sms_arrive b
			<where>
				<if test="sp_id!=null and sp_id>0">
					and sp_id=#{sp_id}
				</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 CREATE_TIME >= #{createtime}
				</if>
				<if test="endtime!=null and endtime!=''">
				 	and  CREATE_TIME &lt; DATE_ADD(str_to_date(#{endtime},'%Y-%m-%d %H:%i:%s'),INTERVAL 4 DAY)
				 	and taskid &lt; CONCAT(DATE_FORMAT(date_add(#{endtime},INTERVAL 1 DAY),'%y%m%d'),'000000000000')
				</if>
				<if test="taskid!=null and taskid>0">
					and taskid=#{taskid}
				</if>
				 <if test="channelid!=null and channelid >=0">
		            and channelid=#{channelid}
		        </if>
		        <if test="stat_desc!=null and stat_desc!=''">
		            and stat_desc=#{stat_desc}
		        </if>
		        <if test="sign !=null and sign !=''">
		            and sign=#{sign}
		        </if>
		        <if test="mdn!=null and mdn!=''">
					and mdn=#{mdn}
				</if>
				<if test="otype!=null and otype!=''">
					and otype=#{otype}
				</if>
				<if test="endId != null">
	                and b.id &lt; #{endId}
	            </if>
	            ORDER BY b.id desc
				limit #{exportExcelSize}
			</where>
			) b1 where a1.TASKID=b1.TASKID and a1.mdn=b1.mdn and a1.num=b1.num
			) su,sms_sp_info sp
			<where>
				su.sp_id=sp.id
				<if test="sp_name!=null and sp_name!=''">
					and sp.sp_name like CONCAT('%',#{sp_name},'%')
				</if>
			</where>


		</select>

		<select id="ExportTaskDetailByArriveDesc" parameterType="TaskDetailInfo" resultType="Map">
			select b.taskid,b.mdn,b.num,b.STAT_DESC,b.ARRIVE_TIME,if(b.result=0,'到达成功','到达失败') result from sms_arrive b,sms_sp_info sp
			<where>
				sp.id=b.sp_id
				<if test="sp_id!=null and sp_id>0">
					and b.sp_id=#{sp_id}
				</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 >= #{createtime}
				</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 4 DAY)
				 	and b.taskid &lt; CONCAT(DATE_FORMAT(date_add(#{endtime},INTERVAL 1 DAY),'%y%m%d'),'000000000000')
				</if>
				<if test="taskid!=null and taskid>0">
					and b.taskid=#{taskid}
				</if>
				 <if test="channelid!=null and channelid >=0">
		            and b.channelid=#{channelid}
		        </if>
		        <if test="stat_desc!=null and stat_desc!=''">
		            and b.stat_desc=#{stat_desc}
		        </if>
		        <if test="sign !=null and sign !=''">
		            and b.sign=#{sign}
		        </if>
		        <if test="mdn!=null and mdn!=''">
					and b.mdn=#{mdn}
				</if>
				<if test="otype!=null and otype!=''">
					and b.otype=#{otype}
				</if>
				<if test="sp_name!=null and sp_name!=''">
					and sp.sp_name like CONCAT('%',#{sp_name},'%')
				</if>
				<if test="endId != null">
	                and b.id &lt;  #{endId}
	            </if>
			</where>
			ORDER BY b.id DESC
			limit #{exportExcelSize}
		</select>

		<select id="ExportTaskDetailBySubmitDesc" parameterType="TaskDetailInfo"
		resultType="Map">
			select b.*,sp.sp_name (select a.RES_CONTENT,a.SIGN,a.TASKID,a.MDN,a.NUM,a.SEND_TIME,a.callmdn,a.RES_DESC from sms_submit a
			<where>
				1=1
				<if test="sp_id!=null and sp_id>0">
					and a.sp_id=#{sp_id}
				</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="createtime!=null and createtime!=''">
					and a.CREATE_TIME >= #{createtime}
				</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 4 DAY)
				 	and a.taskid &lt; CONCAT(DATE_FORMAT(date_add(#{endtime},INTERVAL 1 DAY),'%y%m%d'),'000000000000')
				</if>
				<if test="taskid!=null and taskid>0">
					and a.taskid=#{taskid}
				</if>
				 <if test="channelid!=null and channelid >=0">
		            and a.channelid=#{channelid}
		        </if>
		        <if test="sign !=null and sign !=''">
		            and a.sign=#{sign}
		        </if>
		        <if test="mdn!=null and mdn!=''">
					and a.mdn=#{mdn}
				</if>
				<if test="otype!=null and otype!=''">
					and a.otype=#{otype}
				</if>
				<if test="endId != null">
	                and a.id &lt;  #{endId}
	            </if>
			</where>
			ORDER BY a.id DESC
			limit #{exportExcelSize}
			 ) b,sms_sp_info sp
			where sp.id=b.SP_ID
			<if test="sp_name!=null and sp_name!=''">
				and sp.sp_name like CONCAT('%',#{sp_name},'%')
			</if>
            ORDER BY a.id DESC
		</select>

	<select id="ExportTaskDetailByStatDesc" parameterType="TaskDetailInfo"
		resultType="Map">

		select a.*,sp.sp_name from
   		(select st.id,
		st.taskid,
		st.sp_id,
		st.mdn,
		st.callmdn,
		st.num,
		st.result result,
		st.stat_desc,
		st.status,
		st.arrive_time
		<!-- DATE_FORMAT(str_to_date(st.arrive_time,'%Y%m%d%H%i%s'),'%Y-%m-%d %H:%i:%s') arrive_time -->
		from sms_arrive
		st
		where 1=1
		<if test="mdn!=null and mdn!=''">
            <choose>
                <when test='mdn.toString().contains("_")'>
                    and st.mdn like #{mdn}
                </when>
                <otherwise>
                    and st.mdn=#{mdn}
                </otherwise>
            </choose>
		</if>
		<if test="otype!=null and otype!=''">
			and st.otype=#{otype}
		</if>
            <if test='res_result=="2"'>
                and st.result= 0
            </if>
            <if test='res_result=="3"'>
                and st.result != 0
            </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="province!=null and province!=''">
            and st.province=#{province}
        </if>

         <if test="sign !=null and sign !=''">
            and st.sign=#{sign}
        </if>
        <if test="timeType == 0">
            <if test="createtime!=null and createtime!=''">
                and st.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d %H:%i:%s')
                and st.taskid &gt;= CONCAT(DATE_FORMAT(#{createtime},'%y%m%d%H%i%s'), '000000')
            </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)
                and st.taskid &lt; CONCAT(DATE_FORMAT(#{endtime},'%y%m%d%H%i%s'), '000000')
            </if>
        </if>
        <if test="timeType == 1">
            <if test="createtime!=null and createtime!=''">
                and st.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d %H:%i:%s')
                and st.res_content &gt;= #{createtime}
            </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)
                and st.res_content &lt; #{endtime}
            </if>
        </if>
            <if test="endId != null">
                and st.id &lt;  #{endId}
            </if>
            ORDER BY st.id DESC
        <if test="exportExcelSize != null ">
            limit #{exportExcelSize}
        </if>
        ) a,sms_sp_info sp
		where sp.id=a.SP_ID
		<if test="sp_name!=null and sp_name!=''">
			and sp.sp_name like CONCAT('%',#{sp_name},'%')
		</if>
        ORDER BY a.id DESC
	</select>

    <select id="getTaskDetailById"
        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.otype,
        st.province mdnProvice,
        st.messageid msgid,
        st.res_desc,
        st.stat_desc extendnum
        from sms_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}
        <if test="createtime!=null and createtime!=''">
            and st.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d')
        </if>
         limit 1
    </select>

    <select id="getTaskDetailByData" resultMap="TaskDetailInfoResultMap">

    </select>


    <select id="getTaskDetailArriveById"
            resultMap="TaskDetailInfoResultMap">
        select st.id,
        st.taskid,
        st.sp_id,
        sc.CHANNEL_NAME as pa_dec,
        sp.sp_name,
        st.mdn,
        st.res_content as send_time,
        st.callmdn,
        st.num,
        st.otype,
        st.province mdnProvice,
        st.messageid msgid
        from sms_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
        st.id=#{id}
        <if test="createtime!=null and createtime!=''">
            and st.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d')
        </if>
        limit 1
    </select>

    <select id="getPushTask" resultType="TaskDetailInfo">
    	select ip,push_time from sms_sp_pushreport_record where taskid=#{taskid} and spid=#{sp_id} and mdn=#{mdn} limit 1
    </select>
    <select id="getPushResult" resultType="String">
    	select result from sms_sp_pushreport_resp where taskid=#{taskid} and spid=#{sp_id} and mdn=#{mdn} limit 1
    </select>



    <select id="getHisTaskDetailById" parameterType="TaskDetailInfo"
        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.otype,
        st.province mdnProvice,
        st.messageid msgid,
        st.res_desc
        from sms_submit_${history_dateStr} 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="getMmsTaskDetailById"
        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.otype,
        st.res_desc
        from sms_submit st
        left join  sms_sp_info sp on st.sp_id = sp.id
        left join  mms_send_channel_info sc on st.CHANNELID = sc.id
        where
         st.id=#{id}
        <if test="createtime!=null and createtime!=''">
            and st.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d')
        </if>
    </select>

    <select id="getTaskInfoByComplaint" parameterType="cn.roadm.bo.ComplaintPhoneInfo" resultMap="TaskDetailInfoResultMap">
        select mdn, sn, sp_id, taskid from sms_submit
        where mdn = #{truePhone} AND taskid = #{taskId} AND sp_id = #{spId} AND channelid = #{channelId} AND NUM = 0
    </select>

    <select id="getTaskInfoByMdnAndTaskId" resultMap="TaskDetailInfoResultMap">
        select id, TASKID, MESSAGEID, MDN, RES_RESULT, RES_DESC, CALLMDN, RES_CONTENT, SP_ID,
               SEND_TIME, CREATE_TIME, CHANNELID, STATUS, NUM, SIZES, REPORT_RESULT,
               ARRIVE_TIME, STAT_DESC, UPDATE_TIME, SN, SIGN, OTYPE, PROVINCE, UID, PRICE
            from sms_submit
        where mdn = #{mdn} and taskid = #{taskId} and NUM = 0
    </select>

    <select id="listPageReplyDetailInfo" parameterType="ReplyDetailInfo"
        resultMap="ReplyDetailInfoResultMap">
        select rd.id,
        rd.sp_id,
        rd.callmdn,
        rd.mobile,
        rd.content,
        str_to_date(rd.reply_time,'%Y%m%d%H%i%S') reply_time,
        rd.createtime,
        rd.channelid,
        sc.channel_name,
        rd.status,
        rd.subport,
        rd.TASK_ID as taskId,
        rd.reason,
        rd.region,
        rd.res_content
        from sms_reply_record rd
        left join sms_send_channel_info sc on sc.id = rd.channelid
        left join sms_sp_info sp on rd.sp_id = sp.id
        <where>
            rd.IS_DEL = 0
        	<if test="callmdn!=null and callmdn!=''">
        		and rd.callmdn=#{callmdn}
        	</if>
            <if test="taskId != null and taskId != ''">
                and rd.TASK_ID = #{taskId}
            </if>
            <if test="sp_id!=null and sp_id>=0">
                and rd.sp_id=#{sp_id}
            </if>

			<if test="sp_saler!=null and sp_saler!=''">
                and sp.sp_saler=#{sp_saler}
            </if>
            <if test="salerList!=null and salerList.size()>0">
                and sp.sp_saler in
                <foreach collection="salerList" index="index" item="item" open="(" separator="," close=")">
                   '${item}'
                </foreach>
            </if>
			<if test="status!=null ">
                and rd.status=#{status}
            </if>
            <if test="channelid !=null and channelid != '' and channelid != '-1'">
                and rd.channelid=#{channelid}
            </if>
            <if test="mobile!=null and mobile!=''">
                and rd.mobile=#{mobile}
            </if>

            <if test="content!=null and content!=''">
                and rd.content like CONCAT('%',#{content},'%')
            </if>

            <if test="res_content!=null and res_content!=''">
                and rd.res_content like CONCAT('%',#{res_content},'%')
            </if>

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

            <if test="endtime!=null and endtime!=''">
                and rd.createtime&lt;=str_to_date(#{endtime},'%Y-%m-%d %H:%i:%s')
            </if>
            <if test="region!=null and region!=''">
                and rd.region like CONCAT(#{region},'%')
            </if>
        </where>
        order by rd.createtime desc

    </select>

    <update id="updateByids">
        update sms_reply_record s
        set
        s.status = #{status},
        s.reason = null,
        s.TASK_ID = #{taskId}
        where s.id in
        <foreach collection="ids" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
    </update>

    <select id="getCostTotalByMonth" parameterType="TaskInfo"
        resultType="double">
        select IFNULL(sum(sd.costprice),0) costtotal
        from sms_sp_day_fee sd, sms_sp_info s
        where s.id = sd.sp_id and date_format(sd.createtime, '%Y-%m')=#{createTime}
    </select>


    <select id="getSaleTotalByMonth" parameterType="TaskInfo"
        resultType="double">
        select IFNULL(sum(sd.saleprice),0) saletotal
        from sms_sp_day_fee sd, sms_sp_info s
        where s.id = sd.sp_id and date_format(sd.createtime, '%Y-%m')=#{createTime}
    </select>

    <select id="getMarginTotalByMonth" parameterType="TaskInfo"
        resultType="double">
        select sum( (IFNULL(saleprice,0)-IFNULL(costprice,0))) margintotal
        from sms_sp_day_fee sd, sms_sp_info s
        where s.id = sd.sp_id and date_format(sd.createtime, '%Y-%m')=#{createTime}
    </select>

    <select id="getTaskById" parameterType="TaskInfo" resultType="int">
        select count(1) from sms_send_audit_task ak, sms_sp_info s where s.id= ak.sp_id
        AND ak.user_audit_status = 0 and ak.status=1
    </select>

   <update id="updateTaskContent" parameterType="TaskInfo">
        update
        sms_send_task set
        content=#{content,jdbcType=VARCHAR}
         <if test="allnumber!=null and allnumber>0">
                        ,allnumber=#{allnumber}
                </if>
                <if test="unicomnumber!=null and unicomnumber>0">
                        ,unicomnumber=#{unicomnumber}
                </if>
                 <if test="mobilenumber!=null and mobilenumber>0">
            ,mobilenumber=#{mobilenumber}
        </if>
        <if test="telecomnumber!=null and telecomnumber>0">
            , telecomnumber=#{telecomnumber}
        </if>
        where
        id=#{task_id}
    </update>

      <update id="updateApiCronTask" parameterType="Map">
        update
        sms_api_crontab_task set
        ltcontent=#{ltcontent,jdbcType=VARCHAR},
        dxcontent=#{dxcontent,jdbcType=VARCHAR}
        where
        task_id=#{taskId}
    </update>

    <select id="getApiCronTask" parameterType="TaskInfo" resultType="ApiCronTask">
    SELECT a.unicomMdns,a.mobileMdns, a.telcomMdns,a.sn,a.msgFmt
	from sms_api_crontab_task a  WHERE a.task_id = #{task_id} limit 1

    </select>

    <select id="listPageSpProvinceTaskTotal"
		parameterType="TaskInfo" resultMap="taskResultMap">
		select sp.id sp_id,
		sp.sp_name,
		tk.province,
		vspp.sp_all_submit,
		sum(tk.submit_succ) succ,
		sum(IFNULL(tk.submit_fail,0)) fail,
		sum(tk.arrive_succ) arrive_succ,
		sum(IFNULL(tk.submit_succ,0))+sum(IFNULL(tk.submit_fail,0))-sum(IFNULL(tk.arrive_succ,0))-sum(IFNULL(tk.arrive_fail,0)) unRecMsgnum,
<!-- sum(IFNULL(tk.submit_succ+tk.submit_fail-tk.arrive_succ-tk.arrive_fail,0)) unRecMsgnum, -->
		sum(tk.arrive_fail) arrive_fail
		from sms_sp_province_summary tk, sms_sp_info sp,
		(
		select sum(spp.submit_succ) sp_all_submit,spp.spid from
		sms_sp_province_summary spp, sms_sp_info spinfo
		where spp.spid = spinfo.id
		<if test="sp_name!=null and sp_name!=''">
			and spinfo.sp_name like CONCAT('%',#{sp_name},'%')
		</if>
		<if test="sp_id!=null and sp_id>0">
			and spp.spid=#{sp_id}
		</if>
		<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>
		 group by spp.spid
		 ) vspp
		where tk.spid = sp.id and tk.spid = vspp.spid


		<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="province!=null and province!=''">
			and tk.province =#{province}
		</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,tk.province
		order by succ desc

	</select>


	<select id="exportSpProvinceTotalList" parameterType="TaskInfo"
		resultType="Map">
		select sp.id sp_id,
		tk.province,
		CONCAT(Round(sum(tk.submit_succ)/vspp.sp_all_submit*100,2),'%') sp_province_percent,
		CONCAT(Round(sum(tk.arrive_succ)/sum(tk.submit_succ)*100,2),'%') sp_succ_percent,
		sp.sp_name,
		sum(IFNULL(tk.submit_succ,0))+sum(IFNULL(tk.submit_fail,0))-sum(IFNULL(tk.arrive_succ,0))-sum(IFNULL(tk.arrive_fail,0)) unRecMsgnum,
		sum(tk.submit_succ) succ,
		sum(IFNULL(tk.submit_fail,0)) fail,
		sum(tk.arrive_succ) arrive_succ,
		sum(tk.arrive_fail) arrive_fail
		<if test="ismon==1">,DATE_FORMAT(tk.stat_time, '%Y-%m-%d') stat_time</if>
		from sms_sp_province_summary tk, sms_sp_info sp,
		(
		select sum(spp.submit_succ) sp_all_submit,spp.spid
		<if test="ismon==1">,spp.stat_time</if> from
		sms_sp_province_summary spp, sms_sp_info spinfo
		where spp.spid = spinfo.id
		<if test="sp_name!=null and sp_name!=''">
			and spinfo.sp_name like CONCAT('%',#{sp_name},'%')
		</if>
		<if test="sp_id!=null and sp_id>0">
			and spp.spid=#{sp_id}
		</if>
		<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>
		 group by spp.spid
		 <if test="ismon==1">
		 	,spp.stat_time
		 </if>
		) vspp
		where tk.spid = sp.id
			and tk.spid = vspp.spid
		<if test="ismon==1">
			and tk.stat_time=vspp.stat_time
		</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 tk.spid=#{sp_id}
		</if>
		<if test="sp_saler!=null and sp_saler!=''">
			and sp.sp_saler =#{sp_saler}
		</if>
		<if test="province!=null and province!='' ">
			and tk.province =#{province}
		</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,tk.province
		<if test="ismon==1">,tk.stat_time</if>
		order by sp.id,succ desc
	</select>

	<select id="listChannelTotalList"
        resultType="Map">
        select a.id channelid,a.channel_name channelName ,is_support_international from sms_send_channel_info a order by a.id
    </select>

	<select id="listPageSpChannelTaskTotal"
		parameterType="TaskInfo" resultMap="taskResultMap">
		select sp.id sp_id,
		sp.sp_name,
		tk.channelid,
		vspp.sp_all_submit,
		sum(tk.submit_succ) succ,
		sum(IFNULL(tk.submit_fail,0)) fail,
		sum(tk.arrive_succ) arrive_succ,
<!-- sum(IFNULL(tk.submit_succ+tk.submit_fail-tk.arrive_succ-tk.arrive_fail,0)) unRecMsgnum, -->
sum(IFNULL(tk.submit_succ,0))+sum(IFNULL(tk.submit_fail,0))-sum(IFNULL(tk.arrive_succ,0))-sum(IFNULL(tk.arrive_fail,0)) unRecMsgnum,
		sum(tk.arrive_fail) arrive_fail
		from sms_sp_province_summary tk, sms_sp_info sp,
		(

		select sum(spp.submit_succ) sp_all_submit,spp.spid from
		sms_sp_province_summary spp, sms_sp_info spinfo
		where spp.spid = spinfo.id
		<if test="sp_name!=null and sp_name!=''">
			and spinfo.sp_name like CONCAT('%',#{sp_name},'%')
		</if>
		<if test="sp_id!=null and sp_id>0">
			and spp.spid=#{sp_id}
		</if>
		<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>
		 group by spp.spid

		) vspp,sms_send_channel_info ssci
		where tk.spid = sp.id and tk.spid = vspp.spid
		and tk.channelid = ssci.id


		<if test="sp_name!=null and sp_name!=''">
			and sp.sp_name like CONCAT('%',#{sp_name},'%')
		</if>
		<if test="channel_name!=null and channel_name!=''">
			and ssci.channel_name like CONCAT('%',#{channel_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="channelid!=null and channelid!=-1">
			and tk.channelid =#{channelid}
		</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,tk.channelid
		order by succ desc

	</select>

		<select id="exportSpChannelTotalList" parameterType="TaskInfo"
		resultType="Map">
		select sp.id sp_id,
		(select a.channel_name from sms_send_channel_info a where a.id = tk.channelid) channel_name,
		CONCAT(Round(sum(tk.submit_succ)/vspp.sp_all_submit*100,2),'%') sp_channel_percent,
		CONCAT(Round(sum(tk.arrive_succ)/sum(tk.submit_succ)*100,2),'%') sp_succ_percent,
		sum(IFNULL(tk.submit_succ,0))+sum(IFNULL(tk.submit_fail,0))-sum(IFNULL(tk.arrive_succ,0))-sum(IFNULL(tk.arrive_fail,0)) unRecMsgnum,
		sp.sp_name,
		sum(tk.submit_succ) succ,
		sum(IFNULL(tk.submit_fail,0)) fail,
		sum(tk.arrive_succ) arrive_succ,
		sum(tk.arrive_fail) arrive_fail,
		tk.channelid
		<if test="ismon==1">,DATE_FORMAT(tk.stat_time, '%Y-%m-%d') stat_time</if>
		from sms_sp_province_summary tk, sms_sp_info sp,
		(

		select sum(spp.submit_succ) sp_all_submit,spp.spid
		<if test="ismon==1">,spp.stat_time </if>from
		sms_sp_province_summary spp, sms_sp_info spinfo
		where spp.spid = spinfo.id
		<if test="sp_name!=null and sp_name!=''">
			and spinfo.sp_name like CONCAT('%',#{sp_name},'%')
		</if>
		<if test="sp_id!=null and sp_id>0">
			and spp.spid=#{sp_id}
		</if>
		<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>
		 group by spp.spid
		 <if test="ismon==1">
		 	,spp.stat_time
		 </if>

		) vspp,sms_send_channel_info ssci
		where tk.spid = sp.id
			and tk.spid = vspp.spid and tk.channelid = ssci.id
			<if test="ismon==1">
				and vspp.stat_time=tk.stat_time
			</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 tk.spid=#{sp_id}
		</if>
		<if test="channel_name!=null and channel_name!=''">
			and ssci.channel_name like CONCAT('%',#{channel_name},'%')
		</if>
		<if test="sp_saler!=null and sp_saler!=''">
			and sp.sp_saler =#{sp_saler}
		</if>
		<if test="channelid!=null and channelid!=-1 ">
			and tk.channelid =#{channelid}
		</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,tk.channelid
		<if test="ismon==1">
			,tk.stat_time
		</if>
		order by sp.id,succ desc
	</select>

   <!--fuction:企业发送统计(运营商) and 企业发送统计(运营商) 导出    developer : 李相  BEGIN -->
    <select id="listPageCarrierTotalList" parameterType="TaskInfo" resultMap="taskResultMap">
        select sp.id sp_id,
        sp.sp_name,
        tk.otype,
        vspp.sp_all_submit,
        sum(tk.submit_succ) succ,
        sum(IFNULL(tk.submit_fail,0)) fail,
        sum(tk.arrive_succ) arrive_succ,
      <!--   sum(IFNULL(tk.submit_succ+tk.submit_fail-tk.arrive_succ-tk.arrive_fail,0)) unRecMsgnum, -->
        sum(IFNULL(tk.submit_succ,0))+sum(IFNULL(tk.submit_fail,0))-sum(IFNULL(tk.arrive_succ,0))-sum(IFNULL(tk.arrive_fail,0)) unRecMsgnum,
        sum(tk.arrive_fail) arrive_fail
        from sms_sp_province_summary tk, sms_sp_info sp,

        (
		select sum(spp.submit_succ) sp_all_submit,spp.spid from
		sms_sp_province_summary spp, sms_sp_info spinfo
		where spp.spid = spinfo.id
		<if test="sp_name!=null and sp_name!=''">
			and spinfo.sp_name like CONCAT('%',#{sp_name},'%')
		</if>
		<if test="sp_saler!=null and sp_saler!=''">
            and spinfo.sp_saler =#{sp_saler}
        </if>
		<if test="sp_id!=null and sp_id>0">
			and spp.spid=#{sp_id}
		</if>
		<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>
		 group by spp.spid

		) vspp

        where tk.spid = sp.id
			and tk.spid = vspp.spid
        <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="otype!=null and otype>0 ">
            and tk.otype =#{otype}
        </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, tk.otype
        order by succ desc
    </select>


    <select id="exportCarrierTotalList" parameterType="TaskInfo" resultType="Map">
        select sp.id sp_id,
        sp.sp_name,
        tk.otype,
        CONCAT(Round(sum(tk.submit_succ)/vspp.sp_all_submit*100,2),'%') sp_otype_percent,
		CONCAT(Round(sum(tk.arrive_succ)/sum(tk.submit_succ)*100,2),'%') sp_succ_percent,
        sum(tk.submit_succ) succ,
        sum(IFNULL(tk.submit_succ,0))+sum(IFNULL(tk.submit_fail,0))-sum(IFNULL(tk.arrive_succ,0))-sum(IFNULL(tk.arrive_fail,0)) unRecMsgnum,
        sum(IFNULL(tk.submit_fail,0)) fail,
        sum(tk.arrive_succ) arrive_succ,
        sum(tk.arrive_fail) arrive_fail
        <if test="ismon==1">,DATE_FORMAT(tk.stat_time, '%Y-%m-%d') stat_time</if>
        from sms_sp_province_summary tk, sms_sp_info sp,

         (

		select sum(spp.submit_succ) sp_all_submit,spp.spid
		<if test="ismon==1">,spp.stat_time</if> from
		sms_sp_province_summary spp, sms_sp_info spinfo
		where spp.spid = spinfo.id
		<if test="sp_name!=null and sp_name!=''">
			and spinfo.sp_name like CONCAT('%',#{sp_name},'%')
		</if>
		<if test="sp_id!=null and sp_id>0">
			and spp.spid=#{sp_id}
		</if>
		<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>
		 group by spp.spid
		 <if test="ismon==1">,spp.stat_time</if>

		) vspp

        where tk.spid = sp.id
			and tk.spid = vspp.spid
		<if test="ismon==1">
		 	and vspp.stat_time=tk.stat_time
		 </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 tk.spid=#{sp_id}
        </if>
		<if test="sp_saler!=null and sp_saler!=''">
            and sp.sp_saler =#{sp_saler}
        </if>
        <if test=" otype != null and otype>0">
            and tk.otype=#{otype}
        </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, tk.otype
        <if test="ismon==1">,tk.stat_time</if>
        order by sp.id,succ desc
    </select>

        <select id="listPageSysPcoTaskTotal"
		parameterType="TaskInfo" resultMap="taskResultMap">
		select
		<if test="sp_name!=null and sp_name!=''">
			sp.sp_name,
		</if>
		<if test="sp_id!=null and sp_id>0">
			sp.id sp_id,
		</if>

		tk.province,
		 <if test="type_otype!=null">
        	tk.otype,
        </if>
        <if test="type_channel!=null">
        	tk.channelid,
        </if>
		vspp.sp_all_submit,
		sum(tk.submit_succ) succ,
		sum(IFNULL(tk.submit_fail,0)) fail,
		sum(tk.arrive_succ) arrive_succ,

		sum(tk.arrive_fail) arrive_fail
		from sms_sp_province_summary tk, sms_sp_info sp,

		(select sum(spp.submit_succ) sp_all_submit,spp.province from
		sms_sp_province_summary spp left join sms_sp_info spi
		on  spp.spid = spi.id
		where 1=1
		<if test="sp_name!=null and sp_name!=''">
			and spi.sp_name like CONCAT('%',#{sp_name},'%')
		</if>
		<if test="sp_id!=null and sp_id>0">
			and spp.spid=#{sp_id}
		</if>
		<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>

		) vspp

		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="star_level!=null and star_level>0">
            and sp.star_level =#{star_level}
        </if>
		<if test="province!=null and province!=''">
			and tk.province =#{province}
		</if>
 		<if test="type_channel!=null and channelid!=null and channelid>-1">
                and tk.channelid=#{channelid}
            </if>
        <if test="type_otype!=null and otype!=null and otype>0 ">
            and tk.otype =#{otype}
        </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

		<if test="sp_name!=null and sp_name!=''">
			sp.sp_name,
		</if>
		<if test="sp_id!=null and sp_id>0">
			sp.id,
		</if>

        <if test="type_otype!=null">
        	tk.otype,
        </if>
        <if test="type_channel!=null">
        	tk.channelid,
        </if>
        tk.province
		order by sum(tk.submit_succ) desc

	</select>


	<select id="exportSysPcoTotalList" parameterType="TaskInfo"
		resultType="Map">
		select
		<if test="sp_name!=null and sp_name!=''">
			sp.sp_name,
		</if>
		<if test="sp_id!=null and sp_id>0">
			sp.id sp_id,
		</if>
		 <if test="type_otype!=null">
        	(case when tk.otype = '1' then "联通"
        when tk.otype = '2' then "移动"
        else "电信" end) otype_name,
        </if>
        <if test="type_channel!=null">
        	(select a.channel_name from sms_send_channel_info a where a.id = tk.channelid) channel_name,
        </if>
		tk.province,
		CONCAT(Round(sum(tk.submit_succ)/vspp.sp_all_submit*100,2),'%') sp_province_percent,
		CONCAT(Round(sum(tk.arrive_succ)/sum(tk.submit_succ)*100,2),'%') sp_succ_percent,
		sum(tk.submit_succ) succ,
		sum(IFNULL(tk.submit_fail,0)) fail,
		sum(tk.arrive_succ) arrive_succ,
		sum(tk.arrive_fail) arrive_fail
		from sms_sp_province_summary tk, sms_sp_info sp,

		(select sum(spp.submit_succ) sp_all_submit,spp.province from
		sms_sp_province_summary spp left join sms_sp_info spi
		on  spp.spid = spi.id
		where 1=1
		<if test="sp_name!=null and sp_name!=''">
			and spi.sp_name like CONCAT('%',#{sp_name},'%')
		</if>
		<if test="sp_id!=null and sp_id>0">
			and spp.spid=#{sp_id}
		</if>
		<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>

		) vspp

		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="star_level!=null and star_level>0">
			and sp.star_level =#{star_level}
		</if>
		<if test="province!=null and province!='' ">
			and tk.province =#{province}
		</if>
		<if test="type_channel!=null and type_channel!='' and channelid!=null and channelid>-1">
                and tk.channelid=#{channelid}
            </if>
        <if test="type_otype!=null and type_otype!='' and otype!=null and otype>0 ">
            and tk.otype =#{otype}
        </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

		<if test="sp_name!=null and sp_name!=''">
			sp.sp_name,
		</if>
		<if test="sp_id!=null and sp_id>0">
			sp.id,
		</if>

        <if test="type_otype!=null and type_otype!=''">
        	tk.otype,
        </if>
        <if test="type_channel!=null and type_channel!=''">
        	tk.channelid,
        </if>
        tk.province
		order by sum(tk.submit_succ) desc
	</select>




		<select id="listTaskSpDetailInfo" parameterType="TaskDetailInfo"
        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.status,
        st.channelid
        <!-- st.arrive_time -->
        from sms_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="sp_id!=null and sp_id>0">
                and st.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 st.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d')
            </if>

            <if test="endtime!=null and endtime!=''">
                and st.create_time&lt;DATE_ADD(str_to_date(#{endtime},'%Y-%m-%d'),INTERVAL 1 DAY)
            </if>
        </where>
        order by st.id desc
        limit #{page.currentResult},#{page.showCount}
    </select>

	<select id="listTaskSpDetailInfoCount" parameterType="TaskDetailInfo"
        resultType="int">

        select IFNULL(sum(al.allnumber),0) allnumber from (select
        IFNULL(sum(st.allnumber),0) allnumber
        from sms_sp_summary st
        <where>

            <if test="sp_id!=null and sp_id>0">
                and st.spid=#{sp_id}
            </if>
            <if test="createtime!=null and createtime!=''">
                and st.stat_time&gt;=str_to_date(#{createtime},'%Y-%m-%d')
            </if>

            <if test="endtime!=null and endtime!=''">
                and st.stat_time&lt;DATE_ADD(str_to_date(#{endtime},'%Y-%m-%d'),INTERVAL 1 DAY)
            </if>
        </where>
        union
        select
        IFNULL(sum(mst.allnumber),0) allnumber
        from mms_sp_summary mst
        <where>

            <if test="sp_id!=null and sp_id>0">
                and mst.spid=#{sp_id}
            </if>
            <if test="createtime!=null and createtime!=''">
                and mst.stat_time&gt;=str_to_date(#{createtime},'%Y-%m-%d')
            </if>

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

     <select id="listPageFailureReturn"
		parameterType="TaskInfo" resultMap="taskResultMap">
		select
		tk.id,
		tk.spid sp_id,
		sp.sp_name,
		tk.allnumber,
		tk.return_time  createTime
		from sms_failure_return_record tk, sms_sp_info sp

		where tk.spid = sp.id
 		<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 tk.spid=#{sp_id}
		</if>
		<if test="createTime!=null and createTime!=''">
			and tk.return_time&gt;=str_to_date(#{createTime},'%Y-%m-%d')
		</if>
		<if test="createTime1!=null and createTime1!=''">
			and
			tk.return_time&lt;DATE_ADD(str_to_date(#{createTime1},'%Y-%m-%d'),INTERVAL
			1 DAY)
		</if>
		order by tk.return_time desc
	</select>

	<update id="updateReplyDetailInfoById" parameterType="ReplyDetailInfo">
        update
        sms_reply_record set
        status=#{status}

        where
        id=#{id}
    </update>
    <insert id="reInsertReplyDetailInfo"    parameterType="ReplyDetailInfo">
    	insert into sms_reply_record(CALLMDN,MOBILE,CONTENT,REPLY_TIME,CREATETIME,SP_ID,STATUS,SUBPORT,IS_DEL,CHANNELID,task_id,region,RES_CONTENT,SN)
	    select CALLMDN,MOBILE,CONTENT,REPLY_TIME,CREATETIME,SP_ID,0,SUBPORT,IS_DEL,CHANNELID,task_id,region,RES_CONTENT,SN from sms_reply_record where id=#{id}
	</insert>
	<delete id="deleteReplyDetailInfoById" parameterType="ReplyDetailInfo">
        delete from sms_reply_record where id=#{id}
    </delete>

    <delete id="deleteReplyDetailInfoBySearch" parameterType="ReplyDetailInfo">
        delete from sms_reply_record
        where 1=1 and status= 2
        <if test="mobile!=null and mobile !=''">
			and mobile=#{mobile}
		</if>
		<if test="content!=null and content !=''">
			and content=#{content}
		</if>
		<if test="callmdn!=null and callmdn!=''">
        	and callmdn=#{callmdn}
        </if>
        <if test="channelid!=null and channelid >=0">
            and channelid=#{channelid}
        </if>
		<if test="sp_id!=null and sp_id >=0">
			and sp_id=#{sp_id}
		</if>
        <if test="createtime!=null and createtime!=''">
                and createtime&gt;=str_to_date(#{createtime},'%Y-%m-%d')
        </if>

        <if test="endtime!=null and endtime!=''">
                and createtime&lt;=DATE_ADD(str_to_date(#{endtime},'%Y-%m-%d'),INTERVAL 1 DAY)
        </if>
    </delete>
   <insert id="reInsertReplyDetailInfoBySearch"   useGeneratedKeys="true" keyProperty="id" parameterType="ReplyDetailInfo">
    	insert into sms_reply_record(CALLMDN,MOBILE,CONTENT,REPLY_TIME,CREATETIME,SP_ID,STATUS,SUBPORT,IS_DEL,CHANNELID,task_id)
	    select CALLMDN,MOBILE,CONTENT,REPLY_TIME,CREATETIME,ifnull(#{newSpid},sp_id) SP_ID,0,SUBPORT,IS_DEL,CHANNELID,task_id from sms_reply_record
	     where 1=1
        <if test="mobile!=null and mobile !=''">
			and mobile=#{mobile}
		</if>
		<if test="content!=null and content !=''">
			and content=#{content}
		</if>
		 <if test="callmdn!=null and callmdn!=''">
        	and callmdn=#{callmdn}
        </if>
		<if test="sp_id!=null and sp_id >=0">
			and sp_id=#{sp_id}
		</if>
       <if test="channelid!=null and channelid >=0">
           and channelid=#{channelid}
       </if>
        <if test="createtime!=null and createtime!=''">
           and createtime&gt;=str_to_date(#{createtime},'%Y-%m-%d %H:%i:%s')
        </if>

        <if test="endtime!=null and endtime!=''">
            and createtime&lt;=str_to_date(#{endtime},'%Y-%m-%d %H:%i:%s')
        </if>
	</insert>
    <update id="updateReplyDetailInfoBySearch" parameterType="ReplyDetailInfo">
        update
        sms_reply_record set
        status=#{status}

        where 1=1
        <if test="callmdn!=null and callmdn!=''">
        	and callmdn=#{callmdn}
        </if>
        <if test="mobile!=null and mobile !=''">
			and mobile=#{mobile}
		</if>
		<if test="content!=null and content !=''">
			and content=#{content}
		</if>
        <if test="channelid!=null and channelid >=0">
            and channelid=#{channelid}
        </if>
		<if test="sp_id!=null and sp_id >=0">
			and sp_id=#{sp_id}
		</if>
        <if test="createtime!=null and createtime!=''">
                and createtime&gt;=str_to_date(#{createtime},'%Y-%m-%d')
        </if>

        <if test="endtime!=null and endtime!=''">
                and createtime&lt;=DATE_ADD(str_to_date(#{endtime},'%Y-%m-%d'),INTERVAL 1 DAY)
        </if>
    </update>

 <select id="listPlatformTaskTotalCount" parameterType="TaskInfo"
        resultMap="taskResultMap">
        select

        sum(IFNULL(tk.allnumber,0)) allnumber,
        sum(IFNULL(tk.succ,0)) succ,
        sum(IFNULL(tk.fail,0)) fail
        from platform_client_summary tk
        where 1=1

         <if test="pcid !=null and pcid !=''">
            and tk.pcid like CONCAT('%',#{pcid},'%')
        </if>

        <if test="createTime!=null and createTime!=''">
            and tk.stat_time =#{createTime}
        </if>

    </select>

    <select id="listSpTaskTotalCount" 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 sms_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="star_level!=null and star_level>0">
            and sp.star_level =#{star_level}
        </if>
        <if test="eid != null and eid != ''">
            and sp.eid = #{eid}
        </if>
        <if test="managerId != null and managerId != ''">
            and sp.sp_saler in (select ifnull(seller,'') from sale_manager sm where managerId=#{managerId}) and sp.sp_saler != ''
        </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="listCmppTaskTotalCount" 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 sms_sp_summary tk, sms_sp_info sp,sms_api_socket_sp s
        where tk.spid = sp.id  and tk.id=s.spid and sp.id=s.spid

         <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="listSpPcoTaskTotal"
		parameterType="TaskInfo" resultMap="taskResultMap">
		select
		sum(IFNULL(tk.submit_succ,0)) succ,
		sum(IFNULL(tk.submit_fail,0)) fail,
		sum(IFNULL(tk.arrive_succ,0)) arrive_succ,
		sum(IFNULL(tk.arrive_fail,0)) arrive_fail,
		sum(IFNULL(tk.submit_succ,0))+sum(IFNULL(tk.submit_fail,0))-sum(IFNULL(tk.arrive_succ,0))-sum(IFNULL(tk.arrive_fail,0)) unRecMsgnum
		<!-- sum(IFNULL(tk.submit_succ+tk.submit_fail-tk.arrive_succ-tk.arrive_fail,0)) unRecMsgnum -->
		from sms_sp_province_summary tk, sms_sp_info sp,sms_send_channel_info ssci

		where tk.spid = sp.id  and tk.channelid = ssci.id
		<if test="sp_name!=null and sp_name!=''">
			and sp.sp_name like CONCAT('%',#{sp_name},'%')
		</if>
        <if test="sp_type!=null and sp_type>0">
            and sp.sp_type =#{sp_type}
        </if>
        <if test="star_level!=null and star_level>0">
            and sp.star_level =#{star_level}
        </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="queryType == 'channel' and channelid !=null and channelid >= 0">
			and ssci.id =#{channelid}
		</if>
		<if test="queryType == 'operator' and otype!=null and otype>0 ">
            and tk.otype =#{otype}
        </if>
        <if test="queryType == 'province' and province!=null and province!=''">
			and tk.province =#{province}
		</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="searchPageTaskDetailInfoForStatDesc" parameterType="TaskDetailInfo"
        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.channelid,
        st.SIZES,
        st.otype,
        <!-- st.arrive_time -->
        DATE_FORMAT(str_to_date(st.arrive_time,'%Y%m%d%H%i%s'),'%Y-%m-%d %H:%i:%s') arrive_time
        from sms_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!=''">
                 <choose>
	                <when test='mdn.toString().contains("_")'>
	                     and st.mdn like #{mdn}
	                </when>
	                <otherwise>
	                   and st.mdn=#{mdn}
	                </otherwise>
            	</choose>
         </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="managerId != null and managerId != ''">
                and sc.business_manager in (select ifnull(business,0) from business_manager where managerId =  #{managerId}) and sc.business_manager != ''
            </if>
            <if test="businessManager != null and businessManager != ''">
                and sc.business_manager = #{businessManager}
            </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_saler!='undefined'">
                and sp.sp_saler =#{sp_saler}
            </if>
            <if test="salerList!=null and salerList.size()>0">
                and sp.sp_saler in
                <foreach collection="salerList" index="index"  item="item" open="(" separator="," close=")">
                   '${item}'
                </foreach>
            </if>
            <if test='res_result=="2"'>
                and st.result= 0
            </if>
            <if test='res_result=="3"'>
                and st.result != 0
            </if>
            <if test="timeType == 0">
                    <if test="createtime!=null and createtime!=''">
                        and st.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d %H:%i:%s')
                        and st.taskid &gt;= CONCAT(DATE_FORMAT(#{createtime},'%y%m%d%H%i%s'), '000000')
                    </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 1 DAY)
                        and st.taskid &lt; CONCAT(DATE_FORMAT(#{endtime},'%y%m%d%H%i%s'), '000000')
                    </if>
                </if>
                <if test="timeType == 1">
                    <if test="createtime!=null and createtime!=''">
                        and st.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d %H:%i:%s')
                        and st.res_content &gt;= #{createtime}
                    </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 1 DAY)
                        and st.res_content &lt; #{endtime}
                    </if>
                </if>
            <if test="otype!=null and otype!=''">
            	and st.otype=#{otype}
            </if>
            <if test="lsms != null and lsms == 1">
                and st.sizes = 1
            </if>
            <if test="lsms != null and lsms == 2">
                and st.sizes > 1
            </if>
            <if test="province !=null and province !=''">
                and st.province=#{province}
            </if>
            <if test="fixedTelephone!=null and fixedTelephone!=''">
                and st.CALLMDN like CONCAT(#{fixedTelephone},'%')
            </if>
            <if test="areaCode!=null and areaCode!=''">
                and st.CALLMDN like CONCAT(#{areaCode},'%')
            </if>
        </where>
        order by st.id desc
    </select>

    <select id="taskDetailInfoForStatDescCount" parameterType="TaskDetailInfo" resultType="java.lang.Long">
        select count(st.id)
        from sms_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!=''">
                <choose>
                    <when test='mdn.toString().contains("_")'>
                        and st.mdn like #{mdn}
                    </when>
                    <otherwise>
                        and st.mdn=#{mdn}
                    </otherwise>
                </choose>
            </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="managerId != null and managerId != ''">
                and sc.business_manager in (select ifnull(business,0) from business_manager where managerId =  #{managerId}) and sc.business_manager != ''
            </if>
            <if test="businessManager != null and businessManager != ''">
                and sc.business_manager = #{businessManager}
            </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_saler!='undefined'">
                and sp.sp_saler =#{sp_saler}
            </if>
            <if test="salerList!=null and salerList.size()>0">
                and sp.sp_saler in
                <foreach collection="salerList" index="index"  item="item" open="(" separator="," close=")">
                    '${item}'
                </foreach>
            </if>
            <if test='res_result=="2"'>
                and st.result= 0
            </if>
            <if test='res_result=="3"'>
                and st.result != 0
            </if>
            <if test="timeType == 0">
                <if test="createtime!=null and createtime!=''">
                    and st.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d %H:%i:%s')
                    and st.taskid &gt;= CONCAT(DATE_FORMAT(#{createtime},'%y%m%d%H%i%s'), '000000')
                </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)
                    and st.taskid &lt; CONCAT(DATE_FORMAT(#{endtime},'%y%m%d%H%i%s'), '000000')
                </if>
            </if>
            <if test="timeType == 1">
                <if test="createtime!=null and createtime!=''">
                    and st.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d %H:%i:%s')
                    and st.res_content &gt;= #{createtime}
                </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)
                    and st.res_content &lt; #{endtime}
                </if>
            </if>
            <if test="otype!=null and otype!=''">
                and st.otype=#{otype}
            </if>
            <if test="lsms != null and lsms == 1">
                and st.sizes = 1
            </if>
            <if test="lsms != null and lsms == 2">
                and st.sizes > 1
            </if>
            <if test="province !=null and province !=''">
                and st.province=#{province}
            </if>
            <if test="fixedTelephone!=null and fixedTelephone!=''">
                and st.CALLMDN like CONCAT(#{fixedTelephone},'%')
            </if>
            <if test="areaCode!=null and areaCode!=''">
                and st.CALLMDN like CONCAT(#{areaCode},'%')
            </if>
        </where>
    </select>

    <select id="searchPageTaskDetailInfo" parameterType="TaskDetailInfo"
        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.SIZES,
        st.channelid,
        <!-- st.REPORT_RESULT result, -->
        <!-- IFNULL(r.receipt_desc,st.stat_desc) stat_desc, --> <!-- st.stat_desc, -->
        st.status,
        st.otype,
        st.res_content
        <!-- st.arrive_time -->
        from sms_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!=''">
                 <choose>
	                <when test='mdn.toString().contains("_")'>
	                     and st.mdn like #{mdn}
	                </when>
	                <otherwise>
	                   and st.mdn=#{mdn}
	                </otherwise>
            	</choose>
         	</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_saler!='undefined'">
                and sp.sp_saler =#{sp_saler}
            </if>
            <if test="salerList!=null and salerList.size()>0">
                and sp.sp_saler in
                <foreach collection="salerList" index="index"  item="item" open="(" separator="," close=")">
                   '${item}'
                </foreach>
            </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="timeType == 0">
                 <if test="createtime!=null and createtime!=''">
                    and st.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d %H:%i:%s')
                    and st.taskid &gt;= CONCAT(DATE_FORMAT(#{createtime},'%y%m%d%H%i%s'), '000000')
                </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 1 DAY)
                    and st.taskid &lt; CONCAT(DATE_FORMAT(#{endtime},'%y%m%d%H%i%s'), '000000')
                </if>
            </if>
            <if test="timeType == 1">
                <if test="createtime!=null and createtime!=''">
                    and st.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d %H:%i:%s')
                    and st.send_time &gt;= #{createtime}
                </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 1 DAY)
                    and st.send_time &lt; #{endtime}
                </if>
            </if>
            <if test="otype!=null and otype!=''">
            	and st.otype=#{otype}
            </if>
            <if test="content!=null and content!=''">
	        	and st.res_content like concat('%',#{content},'%')
	        </if>
            <if test="lsms != null and lsms == 1">
                and st.sizes = 1
            </if>
            <if test="lsms != null and lsms == 2">
                and st.sizes > 1
            </if>
            <if test="province !=null and province !=''">
                	and st.province=#{province}
            </if>
            <if test="fixedTelephone!=null and fixedTelephone!=''">
                and st.CALLMDN like CONCAT(#{fixedTelephone},'%')
            </if>
            <if test="areaCode!=null and areaCode!=''">
                and st.CALLMDN like CONCAT(#{areaCode},'%')
            </if>
            <if test="managerId != null and managerId != ''">
                and sc.business_manager in (select ifnull(business,0) from business_manager where managerId =  #{managerId}) and sc.business_manager != ''
            </if>
            <if test="businessManager != null and businessManager != ''">
                and sc.business_manager = #{businessManager}
            </if>
        </where>
        order by st.id desc
    </select>

    <select id="taskDetailInfoCount" parameterType="TaskDetailInfo" resultType="java.lang.Long">

        select count(st.id)
        from sms_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!=''">
                <choose>
                    <when test='mdn.toString().contains("_")'>
                        and st.mdn like #{mdn}
                    </when>
                    <otherwise>
                        and st.mdn=#{mdn}
                    </otherwise>
                </choose>
            </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_saler!='undefined'">
                and sp.sp_saler =#{sp_saler}
            </if>
            <if test="salerList!=null and salerList.size()>0">
                and sp.sp_saler in
                <foreach collection="salerList" index="index"  item="item" open="(" separator="," close=")">
                    '${item}'
                </foreach>
            </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="timeType == 0">
                <if test="createtime!=null and createtime!=''">
                    and st.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d %H:%i:%s')
                    and st.taskid &gt;= CONCAT(DATE_FORMAT(#{createtime},'%y%m%d%H%i%s'), '000000')
                </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 1 DAY)
                    and st.taskid &lt; CONCAT(DATE_FORMAT(#{endtime},'%y%m%d%H%i%s'), '000000')
                </if>
            </if>
            <if test="timeType == 1">
                <if test="createtime!=null and createtime!=''">
                    and st.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d %H:%i:%s')
                    and st.send_time &gt;= #{createtime}
                </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 1 DAY)
                    and st.send_time &lt; #{endtime}
                </if>
            </if>
            <if test="otype!=null and otype!=''">
                and st.otype=#{otype}
            </if>
            <if test="content!=null and content!=''">
                and st.res_content like concat('%',#{content},'%')
            </if>
            <if test="lsms != null and lsms == 1">
                and st.sizes = 1
            </if>
            <if test="lsms != null and lsms == 2">
                and st.sizes > 1
            </if>
            <if test="province !=null and province !=''">
                and st.province=#{province}
            </if>
            <if test="fixedTelephone!=null and fixedTelephone!=''">
                and st.CALLMDN like CONCAT(#{fixedTelephone},'%')
            </if>
            <if test="areaCode!=null and areaCode!=''">
                and st.CALLMDN like CONCAT(#{areaCode},'%')
            </if>
            <if test="managerId != null and managerId != ''">
                and sc.business_manager in (select ifnull(business,0) from business_manager where managerId =  #{managerId}) and sc.business_manager != ''
            </if>
            <if test="businessManager != null and businessManager != ''">
                and sc.business_manager = #{businessManager}
            </if>
        </where>
    </select>

          <select id="searchPageTaskNoReportDetailInfo" parameterType="TaskDetailInfo"
        resultMap="TaskDetailInfoResultMap">
              SELECT
              st.sid id,
              st.taskid,
              st.sp_id,
              sp.sp_name,
              st.mdn,
              st.callmdn,
              st.send_time,
              st.CHANNELID,
              st.num,
              st.SIZES,
              st.otype,
              st.res_content
              FROM
              sms_submit_noreport st,
              sms_sp_info sp,
              (select CHANNEL_NAME,id from sms_send_channel_info union all select CHANNEL_NAME,id from mms_send_channel_info) as sc
              <where>
                  st.SP_ID = sp.id
                  and st.CHANNELID = sc.id
                  <if test="mdn!=null and mdn!=''">
                      <choose>
                          <when test='mdn.toString().contains("_")'>
                              and st.mdn like #{mdn}
                          </when>
                          <otherwise>
                              and st.mdn=#{mdn}
                          </otherwise>
                      </choose>
                  </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="managerId != null and managerId != ''">
                      and c.business_manager in (select ifnull(business,0) from business_manager where managerId =  #{managerId}) and sc.business_manager != ''
                  </if>
                  <if test="businessManager != null and businessManager != ''">
                      and sc.business_manager = #{businessManager}
                  </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_saler!='undefined'">
                      and sp.sp_saler =#{sp_saler}
                  </if>
                  <if test="salerList!=null and salerList.size()>0">
                      and sp.sp_saler in
                      <foreach collection="salerList" index="index"  item="item" open="(" separator="," close=")">
                         '${item}'
                      </foreach>
                  </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="timeType == 0">
                    <if test="createtime!=null and createtime!=''">
                        and st.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d %H:%i:%s')
                        and st.taskid &gt;= CONCAT(DATE_FORMAT(#{createtime},'%y%m%d%H%i%s'), '000000')
                    </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 1 DAY)
                        and st.taskid &lt; CONCAT(DATE_FORMAT(#{endtime},'%y%m%d%H%i%s'), '000000')
                    </if>
                </if>
                <if test="timeType == 1">
                    <if test="createtime!=null and createtime!=''">
                        and st.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d %H:%i:%s')
                        and st.send_time &gt;= #{createtime}
                    </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 1 DAY)
                        and st.send_time &lt; #{endtime}
                    </if>
                </if>
                  <if test="otype!=null and otype!=''">
                      and st.otype=#{otype}
                  </if>
                  <if test="content!=null and content!=''">
                      and st.res_content like concat('%',#{content},'%')
                  </if>
                  <if test="lsms != null and lsms == 1">
                      and st.sizes = 1
                  </if>
                  <if test="lsms != null and lsms == 2">
                      and st.sizes > 1
                  </if>
                  <if test="province !=null and province !=''">
                	and st.province=#{province}
                </if>
                  <if test="fixedTelephone!=null and fixedTelephone!=''">
                      and st.CALLMDN like CONCAT(#{fixedTelephone},'%')
                  </if>
                  <if test="areaCode!=null and areaCode!=''">
                      and st.CALLMDN like CONCAT(#{areaCode},'%')
                  </if>
              </where>
              order by st.TASKID desc
    </select>

    <select id="taskNoReportDetailInfoCount" parameterType="TaskDetailInfo" resultType="java.lang.Long">
        SELECT count(st.sid) FROM
        sms_submit_noreport st,
        sms_sp_info sp,
        (select CHANNEL_NAME,id from sms_send_channel_info union all select CHANNEL_NAME,id from mms_send_channel_info) as sc
        <where>
            st.SP_ID = sp.id
            and st.CHANNELID = sc.id
            <if test="mdn!=null and mdn!=''">
                <choose>
                    <when test='mdn.toString().contains("_")'>
                        and st.mdn like #{mdn}
                    </when>
                    <otherwise>
                        and st.mdn=#{mdn}
                    </otherwise>
                </choose>
            </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="managerId != null and managerId != ''">
                and sc.business_manager in (select ifnull(business,0) from business_manager where managerId =  #{managerId}) and sc.business_manager != ''
            </if>
            <if test="businessManager != null and businessManager != ''">
                and sc.business_manager = #{businessManager}
            </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_saler!='undefined'">
                and sp.sp_saler =#{sp_saler}
            </if>
            <if test="salerList!=null and salerList.size()>0">
                and sp.sp_saler in
                <foreach collection="salerList" index="index"  item="item" open="(" separator="," close=")">
                    '${item}'
                </foreach>
            </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="timeType == 0">
                <if test="createtime!=null and createtime!=''">
                    and st.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d %H:%i:%s')
                    and st.taskid &gt;= CONCAT(DATE_FORMAT(#{createtime},'%y%m%d%H%i%s'), '000000')
                </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 1 DAY)
                    and st.taskid &lt; CONCAT(DATE_FORMAT(#{endtime},'%y%m%d%H%i%s'), '000000')
                </if>
            </if>
            <if test="timeType == 1">
                <if test="createtime!=null and createtime!=''">
                    and st.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d %H:%i:%s')
                    and st.send_time &gt;= #{createtime}
                </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 1 DAY)
                    and st.send_time &lt; #{endtime}
                </if>
            </if>
            <if test="otype!=null and otype!=''">
                and st.otype=#{otype}
            </if>
            <if test="content!=null and content!=''">
                and st.res_content like concat('%',#{content},'%')
            </if>
            <if test="lsms != null and lsms == 1">
                and st.sizes = 1
            </if>
            <if test="lsms != null and lsms == 2">
                and st.sizes > 1
            </if>
            <if test="province !=null and province !=''">
                and st.province=#{province}
            </if>
            <if test="fixedTelephone!=null and fixedTelephone!=''">
                and st.CALLMDN like CONCAT(#{fixedTelephone},'%')
            </if>
            <if test="areaCode!=null and areaCode!=''">
                and st.CALLMDN like CONCAT(#{areaCode},'%')
            </if>
        </where>
    </select>

     <select id="getCrontabTaskById" parameterType="String"
        resultMap="taskResultMap">
 		select
 			taskid,book_time,book_type,status
        from sms_crontab_send st
        where taskid=#{taskid}
		limit 1
    </select>

    <select id="listPageSpMmsTaskTotal" 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(IFNULL(tk.arrive_succ,0) + IFNULL(tk.arrive_fail,0)) arrive_total,
        sum(tk.arrive_succ) arrive_succ,
        <!-- sum(tk.allnumber-tk.arrive_succ-tk.arrive_fail) unRecMsgnum, -->
        asa.total,
        sum(tk.arrive_fail) arrive_fail
        from sms_sp_info sp left join  mms_sp_summary tk on tk.spid = sp.id

		left join (select a.sp_id,sum(a.total) total  from sms_send_audit_task a
        where a.status = 1 and a.send_type in('200','20000')
        <if test="createTime!=null and createTime!=''">
            and a.createtime&gt;=str_to_date(#{createTime},'%Y-%m-%d')
        </if>
        <if test="createTime1!=null and createTime1!=''">
            and
            a.createtime&lt;DATE_ADD(str_to_date(#{createTime1},'%Y-%m-%d'),INTERVAL 1 DAY)
        </if>
        group by a.sp_id) asa on tk.spid = asa.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="listSpMmsTaskTotalCount" 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) + IFNULL(tk.arrive_fail,0)) arrive_total,
        sum(IFNULL(tk.arrive_succ,0)) arrive_succ,
        <!-- sum(IFNULL(tk.allnumber-tk.arrive_succ-tk.arrive_fail,0)) unRecMsgnum, -->
        sum(IFNULL(tk.succ,0))+sum(IFNULL(tk.fail,0))-sum(IFNULL(tk.arrive_succ,0))-sum(IFNULL(tk.arrive_fail,0)) unRecMsgnum,
        sum(IFNULL(tk.arrive_fail,0)) arrive_fail
        from mms_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="exportSpMmsTotalList" 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(IFNULL(tk.arrive_succ,0) + IFNULL(tk.arrive_fail,0)) arrive_total,
        sum(tk.arrive_succ) arrive_succ,
        <!-- sum(tk.allnumber-tk.arrive_succ-tk.arrive_fail) unRecMsgnum, -->
        sum(tk.succ)+sum(IFNULL(tk.fail,0))-sum(IFNULL(tk.arrive_succ,0))-sum(IFNULL(tk.arrive_fail,0)) unRecMsgnum,
        asa.total,
        sum(tk.arrive_fail) arrive_fail

        from sms_sp_info sp left join mms_sp_summary tk on tk.spid = sp.id

		left join (select a.sp_id,sum(a.total) total  from sms_send_audit_task a
        where a.status = 1 and a.send_type in('200','20000')
        <if test="createTime!=null and createTime!=''">
            and a.createtime&gt;=str_to_date(#{createTime},'%Y-%m-%d')
        </if>
        <if test="createTime1!=null and createTime1!=''">
            and
            a.createtime&lt;DATE_ADD(str_to_date(#{createTime1},'%Y-%m-%d'),INTERVAL 1 DAY)
        </if>
        group by a.sp_id) asa on tk.spid = asa.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="listPageSpProvinceMmsTaskTotal"
		parameterType="TaskInfo" resultMap="taskResultMap">
		select sp.id sp_id,
		sp.sp_name,
		tk.province,
		vspp.sp_all_submit,
        <if test="ismon==1">
            tk.stat_time,
        </if>
		sum(tk.submit_succ) succ,
		sum(IFNULL(tk.submit_fail,0)) fail,
		sum(tk.arrive_succ) arrive_succ,
		<!-- sum(IFNULL(tk.submit_succ+tk.submit_fail-tk.arrive_succ-tk.arrive_fail,0)) unRecMsgnum, -->
		sum(IFNULL(tk.submit_succ,0))+sum(IFNULL(tk.submit_fail,0))-sum(IFNULL(tk.arrive_succ,0))-sum(IFNULL(tk.arrive_fail,0)) unRecMsgnum,
		sum(tk.arrive_fail) arrive_fail
		from mms_sp_province_summary tk, sms_sp_info sp,
		(
		select sum(spp.submit_succ) sp_all_submit,spp.spid from
		mms_sp_province_summary spp, sms_sp_info spinfo
		where spp.spid = spinfo.id
		<if test="sp_name!=null and sp_name!=''">
			and spinfo.sp_name like CONCAT('%',#{sp_name},'%')
		</if>
		<if test="sp_id!=null and sp_id>0">
			and spp.spid=#{sp_id}
		</if>

		<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>
		 group by spp.spid
		 ) vspp
		where tk.spid = sp.id and tk.spid = vspp.spid


		<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="province!=null and province!=''">
			and tk.province =#{province}
		</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,tk.province
        <if test="ismon==1">
            ,tk.stat_time
        </if>
		order by
        <choose>
            <when test="ismon == 1 and sort != null and sort != '' and sort == 'up'">
                tk.stat_time asc
            </when>
            <when test="ismon == 1 and sort != null and sort != '' and sort == 'down'">
                tk.stat_time desc
            </when>
            <otherwise>
                sp.id,succ desc
            </otherwise>
        </choose>
	</select>


	<select id="listPageSpTemMmsTaskTotal"
		parameterType="TaskInfo" resultMap="taskResultMap">
		select sp.id sp_id,
		sp.sp_name,
		tk.content,
		vspp.sp_all_submit,
        <if test="ismon==1">
            tk.stat_time,
        </if>
		sum(tk.submit_succ) succ,
		sum(IFNULL(tk.submit_fail,0)) fail,
		sum(tk.arrive_succ) arrive_succ,
		<!-- sum(IFNULL(tk.submit_succ+tk.submit_fail-tk.arrive_succ-tk.arrive_fail,0)) unRecMsgnum, -->
		sum(IFNULL(tk.submit_succ,0))+sum(IFNULL(tk.submit_fail,0))-sum(IFNULL(tk.arrive_succ,0))-sum(IFNULL(tk.arrive_fail,0)) unRecMsgnum,
		sum(tk.arrive_fail) arrive_fail
		from mms_sp_tem_summary tk, sms_sp_info sp,
		(
		select sum(spp.submit_succ) sp_all_submit,spp.spid from
		mms_sp_tem_summary spp, sms_sp_info spinfo
		where spp.spid = spinfo.id
		<if test="sp_name!=null and sp_name!=''">
			and spinfo.sp_name like CONCAT('%',#{sp_name},'%')
		</if>
		<if test="sp_id!=null and sp_id>0">
			and spp.spid=#{sp_id}
		</if>
		<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>
		 group by spp.spid
		 ) vspp
		where tk.spid = sp.id and tk.spid = vspp.spid


		<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="content!=null and content!=''">
			and tk.content =#{content}
		</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,tk.content
        <if test="ismon==1">
            ,tk.stat_time
        </if>
		order by
        <choose>
            <when test="ismon == 1 and sort != null and sort != '' and sort == 'up'">
                tk.stat_time asc
            </when>
            <when test="ismon == 1 and sort != null and sort != '' and sort == 'down'">
                tk.stat_time desc
            </when>
            <otherwise>
                sp.id,succ desc
            </otherwise>
        </choose>

	</select>

    <select id="listPageCarrierMmsTotalList" parameterType="TaskInfo" resultMap="taskResultMap">
        select sp.id sp_id,
        sp.sp_name,
        tk.otype,
        vspp.sp_all_submit,
        <if test="ismon==1">
            tk.stat_time,
        </if>
        sum(tk.submit_succ) succ,
        sum(IFNULL(tk.submit_fail,0)) fail,
        sum(tk.arrive_succ) arrive_succ,
        sum(IFNULL(tk.submit_succ,0))+sum(IFNULL(tk.submit_fail,0))-sum(IFNULL(tk.arrive_succ,0))-sum(IFNULL(tk.arrive_fail,0)) unRecMsgnum,
       <!--  sum(IFNULL(tk.submit_succ+tk.submit_fail-tk.arrive_succ-tk.arrive_fail,0)) unRecMsgnum, -->
        sum(tk.arrive_fail) arrive_fail
        from mms_sp_province_summary tk, sms_sp_info sp,

        (
		select sum(spp.submit_succ) sp_all_submit,spp.spid from
		mms_sp_province_summary spp, sms_sp_info spinfo
		where spp.spid = spinfo.id
		<if test="sp_name!=null and sp_name!=''">
			and spinfo.sp_name like CONCAT('%',#{sp_name},'%')
		</if>
		<if test="sp_id!=null and sp_id>0">
			and spp.spid=#{sp_id}
		</if>
		<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>
		 group by spp.spid

		) vspp

        where tk.spid = sp.id
			and tk.spid = vspp.spid
        <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="otype!=null and otype>0 ">
            and tk.otype =#{otype}
        </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, tk.otype
        <if test="ismon==1">
            ,tk.stat_time
        </if>
        order by
        <choose>
            <when test="ismon == 1 and sort != null and sort != '' and sort == 'up'">
                tk.stat_time asc
            </when>
            <when test="ismon == 1 and sort != null and sort != '' and sort == 'down'">
                tk.stat_time desc
            </when>
            <otherwise>
                sp.id,succ desc
            </otherwise>
        </choose>
    </select>

    <select id="listPageSpIdMmsTaskTotal"
            parameterType="TaskInfo" resultMap="taskResultMap">
        select sp.id sp_id,
        sp.sp_name,
        vspp.sp_all_submit,
        <if test="ismon==1">
            tk.stat_time,
        </if>
        sum(tk.submit_succ) succ,
        sum(IFNULL(tk.submit_fail,0)) fail,
        sum(tk.arrive_succ) arrive_succ,
        <!-- sum(IFNULL(tk.submit_succ+tk.submit_fail-tk.arrive_succ-tk.arrive_fail,0)) unRecMsgnum, -->
        sum(IFNULL(tk.submit_succ,0))+sum(IFNULL(tk.submit_fail,0))-sum(IFNULL(tk.arrive_succ,0))-sum(IFNULL(tk.arrive_fail,0)) unRecMsgnum,
        sum(tk.arrive_fail) arrive_fail
        from mms_sp_province_summary tk, sms_sp_info sp,
        (

        select sum(spp.submit_succ) sp_all_submit,spp.spid from
        mms_sp_province_summary spp, sms_sp_info spinfo
        where spp.spid = spinfo.id
        <if test="sp_name!=null and sp_name!=''">
            and spinfo.sp_name like CONCAT('%',#{sp_name},'%')
        </if>
        <if test="sp_id!=null and sp_id>0">
            and spp.spid=#{sp_id}
        </if>
        <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>
        group by spp.spid

        ) vspp
        where tk.spid = sp.id and tk.spid = vspp.spid


        <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="channelid!=null and channelid!=-1">
            and tk.channelid =#{channelid}
        </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
        <if test="ismon==1">
            ,tk.stat_time
        </if>
        order by
        <choose>
            <when test="ismon == 1 and sort != null and sort != '' and sort == 'up'">
                tk.stat_time asc
            </when>
            <when test="ismon == 1 and sort != null and sort != '' and sort == 'down'">
                tk.stat_time desc
            </when>
            <otherwise>
                sp.id,succ desc
            </otherwise>
        </choose>

    </select>

	<select id="listPageSpChannelMmsTaskTotal"
		parameterType="TaskInfo" resultMap="taskResultMap">
		select sp.id sp_id,
		sp.sp_name,
		tk.channelid,
		vspp.sp_all_submit,
        <if test="ismon==1">
            tk.stat_time,
        </if>
		sum(tk.submit_succ) succ,
		sum(IFNULL(tk.submit_fail,0)) fail,
		sum(tk.arrive_succ) arrive_succ,
		<!-- sum(IFNULL(tk.submit_succ+tk.submit_fail-tk.arrive_succ-tk.arrive_fail,0)) unRecMsgnum, -->
		sum(IFNULL(tk.submit_succ,0))+sum(IFNULL(tk.submit_fail,0))-sum(IFNULL(tk.arrive_succ,0))-sum(IFNULL(tk.arrive_fail,0)) unRecMsgnum,
		sum(tk.arrive_fail) arrive_fail
		from mms_sp_province_summary tk, sms_sp_info sp, mms_send_channel_info msci,
		(

		select sum(spp.submit_succ) sp_all_submit,spp.spid from
		mms_sp_province_summary spp, sms_sp_info spinfo
		where spp.spid = spinfo.id
		<if test="sp_name!=null and sp_name!=''">
			and spinfo.sp_name like CONCAT('%',#{sp_name},'%')
		</if>
		<if test="sp_id!=null and sp_id>0">
			and spp.spid=#{sp_id}
		</if>
		<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>
		 group by spp.spid

		) vspp
		where tk.spid = sp.id and tk.spid = vspp.spid and tk.channelid = msci.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="channel_name!=null and channel_name !=''">
            and msci.CHANNEL_NAME like CONCAT('%', #{channel_name}, '%')
        </if>
 		<if test="sp_saler!=null and sp_saler!=''">
            and sp.sp_saler =#{sp_saler}
        </if>
		<if test="channelid!=null and channelid!=-1">
			and tk.channelid =#{channelid}
		</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,tk.channelid
        <if test="ismon==1">
            ,tk.stat_time
        </if>
		order by
       <choose>
            <when test="ismon == 1 and sort != null and sort != '' and sort == 'up'">
                tk.stat_time asc
            </when>
            <when test="ismon == 1 and sort != null and sort != '' and sort == 'down'">
                tk.stat_time desc
            </when>
            <otherwise>
                sp.id,succ desc
            </otherwise>
        </choose>

	</select>

	<select id="listMmsChannelTotalList"
        resultType="Map">
        select a.id channelid,a.channel_name channelName from mms_send_channel_info a order by a.id
    </select>

    <select id="listSmsChannelTotalList"
            resultType="Map">
        select a.id channelid,a.channel_name channelName from sms_send_channel_info a order by a.id
    </select>

    <select id="selectChatbotConfig" resultType="Map">
        SELECT chatbot ,`sign`,csptoken FROM
        (SELECT a.chatbotId AS chatbot,a.`sign` AS `sign`,FROM_BASE64(b.csp_token) AS csptoken
        FROM (select * from `csp_chatbot` where status = 30
        <if test="agentIds!=null and agentIds!=''">
             and agent_id in(${agentIds})
        </if>
        )  a LEFT JOIN `csp_chatbot_send_info` b ON a.chatbotid = b.chatbot_id) c
        WHERE c.chatbot NOT IN (SELECT chatbot FROM `sms_channel_sign_chatbot` where channelid = #{channelId} and chatbot is not NULL)
    </select>

    <select id="selectGkChatbotConfig" resultType="Map">
        SELECT chatbot ,`sign`,csptoken FROM
        (SELECT a.chatbotId AS chatbot,a.`sign` AS `sign`,FROM_BASE64(b.devToken) AS csptoken
        FROM (select * from `csp_chatbot` where status = 30
        <if test="agentIds!=null and agentIds!=''">
            and agent_id in(${agentIds})
        </if>
        )  a LEFT JOIN `csp_chatbot_info` b ON a.chatbotid = b.chatbotId) c
        WHERE c.csptoken is not null and c.chatbot NOT IN (SELECT chatbot FROM `sms_channel_sign_chatbot` where channelid = #{channelId} and chatbot is not NULL)
    </select>

    <select id="selectTelecomUnicomChatbotConfig" resultType="Map">
        select chatbotId as chatbot,sign,appId,appKey from `csp_chatbot`
        where status = 30
        <if test="agentIds!=null and agentIds!=''">
            and agent_id in(${agentIds})
        </if>
        and chatbotId NOT IN (SELECT chatbot FROM `sms_channel_sign_telecom_unicom_chatbot` where channelid = 616 and chatbot is not NULL)
    </select>

    <select id="selectMmsChatbotConfig" resultType="Map">
        SELECT chatbot ,`sign`,csptoken FROM
        (SELECT a.chatbotId AS chatbot,a.`sign` AS `sign`,FROM_BASE64(b.csp_token) AS csptoken
        FROM (select * from `csp_chatbot` where status = 30
        <if test="agentIds!=null and agentIds!=''">
            and agent_id in(${agentIds})
        </if>
        )  a LEFT JOIN `csp_chatbot_send_info` b ON a.chatbotid = b.chatbot_id) c
        WHERE c.chatbot NOT IN (SELECT chatbot FROM `mms_channel_sign_chatbot` where channelid = #{channelId} and chatbot is not NULL)
    </select>

    <insert id="batchUpdateChatbotConfig" parameterType="java.util.List">
        INSERT INTO `sms_channel_sign_chatbot`(`channelid`,`sign`,`chatbot`,`csptoken`,`createtime`) VALUES
        <foreach collection="param" item="item" separator=",">
            (#{channelId},concat("【",#{item.sign},"】"),#{item.chatbot},#{item.csptoken},now())
        </foreach>
    </insert>

    <insert id="batchUpdateTelecomUnicomChatbotConfig" parameterType="java.util.List">
        INSERT INTO `sms_channel_sign_telecom_unicom_chatbot`(`channelid`,`sign`,`chatbot`,`appId`,`appKey`,`createtime`) VALUES
        <foreach collection="param" item="item" separator=",">
            (#{channelId},concat("【",#{item.sign},"】"),#{item.chatbot},#{item.appId},#{item.appKey},now())
        </foreach>
    </insert>

    <insert id="batchUpdateMmsChatbotConfig" parameterType="java.util.List">
        INSERT INTO `mms_channel_sign_chatbot`(`channelid`,`sign`,`chatbot`,`csptoken`,`createtime`) VALUES
        <foreach collection="param" item="item" separator=",">
            (#{channelId},concat("【",#{item.sign},"】"),#{item.chatbot},#{item.csptoken},now())
        </foreach>
    </insert>

    <update id="changeMmsChatbotSignStatus" parameterType="cn.roadm.bo.ChannelSignChatbot">
        update mms_channel_sign_chatbot set status = #{status} where chatbot = #{chatbot} and channelid = #{channelid}
    </update>

    <update id="changeSmsChatbotSignStatus" parameterType="cn.roadm.bo.ChannelSignChatbot">
        update sms_channel_sign_chatbot set status = #{status} where chatbot = #{chatbot} and channelid = #{channelid}
    </update>

    <update id="changeSmsTelecomChatbotSignStatus" parameterType="cn.roadm.bo.ChannelSignChatbot">
        update sms_channel_sign_telecom_unicom_chatbot set status = #{status} where chatbot = #{chatbot} and channelid = #{channelid}
    </update>

    <update id="changeMmsTelecomChatbotSignStatus" parameterType="cn.roadm.bo.ChannelSignChatbot">
        update mms_channel_sign_telecom_unicom_chatbot set status = #{status} where chatbot = #{chatbot} and channelid = #{channelid}
    </update>

    <select id="selectAgentIdFromSms" resultType="string">
        select a.id as agentIds from csp_agent a ,
        (select JSON_UNQUOTE(channelTemplatevar->'$.cpsId') as cspId
        from http_channel_template_config where channelid=#{channelId}) b,
        (select mobile_prefix from sms_send_channel_info where id = #{channelId}) c
        where a.csp_code = b.cspId and  a.service_code like CONCAT('%',c.mobile_prefix, '%')
    </select>

    <select id="selectAgentIdFromMms" resultType="string">
        select a.id as agentIds from csp_agent a ,
        (select JSON_UNQUOTE(channelTemplatevar->'$.cpsId') as cspId
        from mms_http_channel_template_config where channelid=#{channelId}) b,
        (select mobile_prefix from mms_send_channel_info where id = #{channelId}) c
        where a.csp_code = b.cspId and  a.service_code like CONCAT('%',c.mobile_prefix, '%')
    </select>

    <select id="selectSmsChannelMobilePrefix" resultType="string">
        select mobile_prefix from sms_send_channel_info where id = #{channelId}
    </select>

    <select id="selectMmsChannelMobilePrefix" resultType="string">
        select mobile_prefix from mms_send_channel_info where id = #{channelId}
    </select>

    <select id="getAllRemoteId"
        resultType="Map">
        select tr.channelid,tr.remote_templateid,tl.name from template_remote tr,template_local tl where tr.local_template=tl.id and tr.status=2  order by tr.id
    </select>

 	<select id="listSpPcoMmsTaskTotal"
		parameterType="TaskInfo" resultMap="taskResultMap">
		select
		sum(IFNULL(tk.submit_succ,0)) succ,
		sum(IFNULL(tk.submit_fail,0)) fail,
		sum(IFNULL(tk.arrive_succ,0)) arrive_succ,
		sum(IFNULL(tk.arrive_fail,0)) arrive_fail,
		sum(IFNULL(tk.submit_succ,0))+sum(IFNULL(tk.submit_fail,0))-sum(IFNULL(tk.arrive_succ,0))-sum(IFNULL(tk.arrive_fail,0)) unRecMsgnum
		<!-- sum(IFNULL(tk.submit_succ+tk.submit_fail-tk.arrive_succ-tk.arrive_fail,0)) unRecMsgnum -->
		from mms_sp_province_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="queryType == 'channel' and channelid!=null and channelid!=-1">
			and tk.channelid =#{channelid}
		</if>
		<if test="queryType == 'operator' and otype!=null and otype>0 ">
            and tk.otype =#{otype}
        </if>
        <if test="queryType == 'province' and province!=null and province!=''">
			and tk.province =#{province}
		</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="listSpTemMmsTaskTotal"
		parameterType="TaskInfo" resultMap="taskResultMap">
		select
		sum(IFNULL(tk.submit_succ,0)) succ,
		sum(IFNULL(tk.submit_fail,0)) fail,
		sum(IFNULL(tk.arrive_succ,0)) arrive_succ,
		sum(IFNULL(tk.arrive_fail,0)) arrive_fail,
		sum(IFNULL(tk.submit_succ,0))+sum(IFNULL(tk.submit_fail,0))-sum(IFNULL(tk.arrive_succ,0))-sum(IFNULL(tk.arrive_fail,0)) unRecMsgnum
		<!-- sum(IFNULL(tk.submit_succ+tk.submit_fail-tk.arrive_succ-tk.arrive_fail,0)) unRecMsgnum -->
		from mms_sp_tem_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="content!=null and content!=''">
			and tk.content =#{content}
		</if>
        <if test="sign != null and sign != ''">
            and tk.sign like CONCAT('%',#{sign},'%')
        </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="exportSpChannelMmsTotalList" parameterType="TaskInfo"
		resultType="Map">
		select sp.id sp_id,
		(select a.channel_name from mms_send_channel_info a where a.id = tk.channelid) channel_name,
		CONCAT(Round(sum(tk.submit_succ)/vspp.sp_all_submit*100,2),'%') sp_channel_percent,
        CONCAT(Round(sum(IFNULL(tk.arrive_succ,0))/(sum(IFNULL(tk.submit_succ,0))+sum(IFNULL(tk.submit_fail,0)))*100,2),'%') sp_succ_percent,
		sum(IFNULL(tk.submit_succ,0))+sum(IFNULL(tk.submit_fail,0))-sum(IFNULL(tk.arrive_succ,0))-sum(IFNULL(tk.arrive_fail,0)) unRecMsgnum,
		sp.sp_name,
        <if test="ismon==1">
            date_format(tk.stat_time, '%Y-%m-%d') statTime,
        </if>
		sum(tk.submit_succ) succ,
		sum(IFNULL(tk.submit_fail,0)) fail,
		sum(tk.arrive_succ) arrive_succ,
		sum(tk.arrive_fail) arrive_fail
		from mms_sp_province_summary tk, sms_sp_info sp,
		(

		select sum(spp.submit_succ) sp_all_submit,spp.spid from
		mms_sp_province_summary spp, sms_sp_info spinfo
		where spp.spid = spinfo.id
		<if test="sp_name!=null and sp_name!=''">
			and spinfo.sp_name like CONCAT('%',#{sp_name},'%')
		</if>
		<if test="sp_id!=null and sp_id>0">
			and spp.spid=#{sp_id}
		</if>
		<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>
		 group by spp.spid

		) vspp
		where tk.spid = sp.id
			and tk.spid = vspp.spid
		<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="channelid!=null and channelid!=-1 ">
			and tk.channelid =#{channelid}
		</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,tk.channelid
        <if test="ismon==1">
            ,tk.stat_time
        </if>
		order by sp.id,succ desc
	</select>

<select id="exportCarrierMmsTotalList" parameterType="TaskInfo" resultType="Map">
        select sp.id sp_id,
        sp.sp_name,
        tk.otype,
        <if test="ismon==1">
            date_format(tk.stat_time, '%Y-%m-%d') statTime,
        </if>
        CONCAT(Round(sum(tk.submit_succ)/vspp.sp_all_submit*100,2),'%') sp_otype_percent,
		CONCAT(Round(sum(IFNULL(tk.arrive_succ,0))/(sum(IFNULL(tk.submit_succ,0))+sum(IFNULL(tk.submit_fail,0)))*100,2),'%') sp_succ_percent,
		sum(IFNULL(tk.submit_succ,0))+sum(IFNULL(tk.submit_fail,0))-sum(IFNULL(tk.arrive_succ,0))-sum(IFNULL(tk.arrive_fail,0)) unRecMsgnum,
        sum(tk.submit_succ) succ,
        sum(IFNULL(tk.submit_fail,0)) fail,
        sum(tk.arrive_succ) arrive_succ,
        sum(tk.arrive_fail) arrive_fail
        from mms_sp_province_summary tk, sms_sp_info sp,

         (

		select sum(spp.submit_succ) sp_all_submit,spp.spid from
		mms_sp_province_summary spp, sms_sp_info spinfo
		where spp.spid = spinfo.id
		<if test="sp_name!=null and sp_name!=''">
			and spinfo.sp_name like CONCAT('%',#{sp_name},'%')
		</if>
		<if test="sp_id!=null and sp_id>0">
			and spp.spid=#{sp_id}
		</if>
		<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>
		 group by spp.spid

		) vspp

        where tk.spid = sp.id
			and tk.spid = vspp.spid
        <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=" otype != null and otype>0">
            and tk.otype=#{otype}
        </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, tk.otype
        <if test="ismon==1">
            ,tk.stat_time
        </if>
        order by sp.id,succ desc
    </select>

    <select id="exportSpidMmsTotalList" parameterType="TaskInfo" resultType="Map">
        select sp.id sp_id,
        sp.sp_name,
        <if test="ismon==1">
            date_format(tk.stat_time, '%Y-%m-%d') statTime,
        </if>
        CONCAT(Round(sum(tk.submit_succ)/vspp.sp_all_submit*100,2),'%') sp_otype_percent,
        CONCAT(Round(sum(IFNULL(tk.arrive_succ,0))/(sum(IFNULL(tk.submit_succ,0))+sum(IFNULL(tk.submit_fail,0)))*100,2),'%') sp_succ_percent,
        sum(IFNULL(tk.submit_succ,0))+sum(IFNULL(tk.submit_fail,0))-sum(IFNULL(tk.arrive_succ,0))-sum(IFNULL(tk.arrive_fail,0)) unRecMsgnum,
        sum(tk.submit_succ) succ,
        sum(IFNULL(tk.submit_fail,0)) fail,
        sum(tk.arrive_succ) arrive_succ,
        sum(tk.arrive_fail) arrive_fail
        from mms_sp_province_summary tk, sms_sp_info sp,

        (

        select sum(spp.submit_succ) sp_all_submit,spp.spid from
        mms_sp_province_summary spp, sms_sp_info spinfo
        where spp.spid = spinfo.id
        <if test="sp_name!=null and sp_name!=''">
            and spinfo.sp_name like CONCAT('%',#{sp_name},'%')
        </if>
        <if test="sp_id!=null and sp_id>0">
            and spp.spid=#{sp_id}
        </if>
        <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>
        group by spp.spid

        ) vspp

        where tk.spid = sp.id
        and tk.spid = vspp.spid
        <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=" otype != null and otype>0">
            and tk.otype=#{otype}
        </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
        <if test="ismon==1">
            ,tk.stat_time
        </if>
        order by sp.id,succ desc
    </select>

 	<select id="exportSpProvinceMmsTotalList" parameterType="TaskInfo"
		resultType="Map">
		select sp.id sp_id,
		tk.province,
		CONCAT(Round(sum(tk.submit_succ)/vspp.sp_all_submit*100,2),'%') sp_province_percent,
        CONCAT(Round(sum(IFNULL(tk.arrive_succ,0))/(sum(IFNULL(tk.submit_succ,0))+sum(IFNULL(tk.submit_fail,0)))*100,2),'%') sp_succ_percent,
		sum(IFNULL(tk.submit_succ,0))+sum(IFNULL(tk.submit_fail,0))-sum(IFNULL(tk.arrive_succ,0))-sum(IFNULL(tk.arrive_fail,0)) unRecMsgnum,
		sp.sp_name,
        <if test="ismon==1">
            date_format(tk.stat_time, '%Y-%m-%d') statTime,
        </if>
		sum(tk.submit_succ) succ,
		sum(IFNULL(tk.submit_fail,0)) fail,
		sum(tk.arrive_succ) arrive_succ,
		sum(tk.arrive_fail) arrive_fail
		from mms_sp_province_summary tk, sms_sp_info sp,
		(
		select sum(spp.submit_succ) sp_all_submit,spp.spid from
		mms_sp_province_summary spp, sms_sp_info spinfo
		where spp.spid = spinfo.id
		<if test="sp_name!=null and sp_name!=''">
			and spinfo.sp_name like CONCAT('%',#{sp_name},'%')
		</if>
		<if test="sp_id!=null and sp_id>0">
			and spp.spid=#{sp_id}
		</if>
		<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>
		 group by spp.spid
		) vspp
		where tk.spid = sp.id
			and tk.spid = vspp.spid
		<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="province!=null and province!='' ">
			and tk.province =#{province}
		</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,tk.province
        <if test="ismon==1">
            ,tk.stat_time
        </if>
		order by sp.id,succ desc
	</select>

 <update id="updateReplySpId" parameterType="ReplyDetailInfo">
        update
        sms_reply_record set
        sp_id=#{sp_id}
        where
        id=#{id}
    </update>

   <update id="updateBookSend" parameterType="map" >
		update
		SMS_CRONTAB_SEND set
		status=2
		where taskid=#{id} and status!=2
	</update>

	<update id="updateTaskFail" parameterType="map" >
		update sms_send_task
		set
		status=2,descption='取消任务'
		where id=#{id} and status!=2
	</update>
	<select id="getTaskInfoAllnumberById" parameterType="TaskInfo" resultMap="taskResultMap">
        select tk.id,
        tk.sp_id,
        tk.content,
		tk.createid,
        tk.createtime,
        tk.total,
        tk.allnumber,
        tk.unicomnumber,
        tk.mobilenumber,
        tk.telecomnumber,
        tk.task_type,
        tk.status,
        tk.endtime,
        tk.send_type,
        sp.return_fee_type,
        tk.FAIL
        from sms_send_task tk , sms_sp_info sp
        where sp.id=tk.sp_id and  tk.id=#{task_id} limit 1
    </select>


 <select id="listPageSpTaskTotalCurrent" parameterType="TaskInfo"
        resultMap="taskResultMap">
        select sp.id sp_id,
        sp.sp_name,
        sum(tk.current_send) current_send,
        sum(tk.current_commit) current_commit,
        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, -->
        asa.wait_audit+scs.crontab total,
        sum(tk.arrive_fail) arrive_fail
        from sms_sp_info sp left join  sms_sp_summary tk on tk.spid = sp.id

        left join (select a.sp_id,sum(a.allnumber) wait_audit  from sms_send_audit_task a
        where a.status = 1 and a.send_type in('1000','10000')
        <if test="createTime!=null and createTime!=''">
            and a.createtime&gt;=str_to_date(#{createTime},'%Y-%m-%d')
        </if>
        <if test="createTime1!=null and createTime1!=''">
            and
            a.createtime&lt;DATE_ADD(str_to_date(#{createTime1},'%Y-%m-%d'),INTERVAL 1 DAY)
        </if>
        group by a.sp_id) asa on tk.spid = asa.sp_id

        left join (select b.sp_id,sum(b.total) crontab  from sms_crontab_send b
        where b.status in (0,1)
        <if test="createTime!=null and createTime!=''">
            and b.createtime&gt;=str_to_date(#{createTime},'%Y-%m-%d')
        </if>
        <if test="createTime1!=null and createTime1!=''">
            and
            b.createtime&lt;DATE_ADD(str_to_date(#{createTime1},'%Y-%m-%d'),INTERVAL 1 DAY)
        </if>
        group by b.sp_id) scs on tk.spid = scs.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="exportSpTotalListCurrent" parameterType="TaskInfo"
        resultType="Map">
        select sp.id sp_id,
        sp.sp_name,
        sum(tk.current_send) current_send,
        sum(tk.current_commit) current_commit,
        sum(tk.allnumber) allnumber,
        sum(tk.succ) succ,
        sum(IFNULL(tk.fail,0)) fail,
        sum(tk.arrive_succ) arrive_succ,

        sum(tk.current_send)-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 sms_sp_summary tk on tk.spid = sp.id

        left join (select a.sp_id,sum(a.allnumber) wait_audit  from sms_send_audit_task a
        where a.status = 1 and a.send_type in('1000','10000')
        <if test="createTime!=null and createTime!=''">
            and a.createtime&gt;=str_to_date(#{createTime},'%Y-%m-%d')
        </if>
        <if test="createTime1!=null and createTime1!=''">
            and
            a.createtime&lt;DATE_ADD(str_to_date(#{createTime1},'%Y-%m-%d'),INTERVAL 1 DAY)
        </if>
        group by a.sp_id) asa on tk.spid = asa.sp_id

        left join (select b.sp_id,sum(b.total) crontab  from sms_crontab_send b
        where b.status in (0,1)
        <if test="createTime!=null and createTime!=''">
            and b.createtime&gt;=str_to_date(#{createTime},'%Y-%m-%d')
        </if>
        <if test="createTime1!=null and createTime1!=''">
            and
            b.createtime&lt;DATE_ADD(str_to_date(#{createTime1},'%Y-%m-%d'),INTERVAL 1 DAY)
        </if>
        group by b.sp_id) scs on tk.spid = scs.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="listSpTaskTotalCountCurrent" parameterType="TaskInfo"
        resultMap="taskResultMap">
        select
        sum(IFNULL(tk.current_send,0)) current_send,
        sum(IFNULL(tk.current_commit,0)) current_commit,
        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.current_send,0))-sum(IFNULL(tk.arrive_succ,0))-sum(IFNULL(tk.arrive_fail,0)) unRecMsgnum,
        sum(IFNULL(tk.arrive_fail,0)) arrive_fail
        from sms_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="ExportReplyDetailInfoCount" parameterType="ReplyDetailInfo" resultType="long">
        select count(rd.id) count
        from sms_reply_record rd
        left join sms_sp_info sp on rd.sp_id = sp.id
        <where>
            rd.IS_DEL = 0
            <if test="sp_id!=null and sp_id>=0">
                and rd.sp_id=#{sp_id}
            </if>
            <if test="callmdn!=null and callmdn!=''">
                and rd.callmdn=#{callmdn}
            </if>
            <if test="sp_saler!=null and sp_saler!=''">
                and sp.sp_saler=#{sp_saler}
            </if>
            <if test="mobile!=null and mobile!=''">
                and rd.mobile=#{mobile}
            </if>
            <if test="channelid !='' and channelid >=0">
                and rd.channelid=#{channelid}
            </if>
            <if test="content!=null and content!=''">
                and rd.content like CONCAT('%',#{content},'%')
            </if>
            <if test="taskId!=null and taskId>0">
                and rd.task_id=#{taskId}
            </if>
            <if test="createtime!=null and createtime!=''">
                and rd.createtime&gt;=str_to_date(#{createtime},'%Y-%m-%d %H:%i:%s')
            </if>

            <if test="endtime!=null and endtime!=''">
                and rd.createtime&lt;=str_to_date(#{endtime},'%Y-%m-%d %H:%i:%s')
            </if>
        </where>
        order by rd.createtime desc
    </select>

    <select id="ExportReplyDetailInfo" parameterType="ReplyDetailInfo" resultType="Map">
         select rd.id,
        rd.sp_id,
        sp.sp_name,
        rd.callmdn,
        rd.mobile,
        rd.content,
        str_to_date(rd.reply_time,'%Y%m%d%H%i%S') reply_time,
       rd.TASK_ID,
       rd.SUBPORT,
        rd.createtime,
        case when  rd.status =1 then '已处理'
        	when  rd.status =0 then '未处理'
            when  rd.status =2 then '推送失败'
        end status
        <!-- rd.status -->
        from sms_reply_record rd
        left join sms_sp_info sp on rd.sp_id = sp.id
        <where>
        	rd.IS_DEL = 0
            <if test="sp_id!=null and sp_id>=0">
                and rd.sp_id=#{sp_id}
            </if>
            <if test="callmdn!=null and callmdn!=''">
        		and rd.callmdn=#{callmdn}
        	</if>
			<if test="sp_saler!=null and sp_saler!=''">
                and sp.sp_saler=#{sp_saler}
            </if>
            <if test="mobile!=null and mobile!=''">
                and rd.mobile=#{mobile}
            </if>
             <if test="channelid !='' and channelid >=0">
                and rd.channelid=#{channelid}
            </if>
            <if test="content!=null and content!=''">
                and rd.content like CONCAT('%',#{content},'%')
            </if>
            <if test="taskId!=null and taskId>0">
                and rd.task_id=#{taskId}
            </if>
            <if test="createtime!=null and createtime!=''">
                and rd.createtime&gt;=str_to_date(#{createtime},'%Y-%m-%d')
            </if>

            <if test="endtime!=null and endtime!=''">
                and rd.createtime&lt;=DATE_ADD(str_to_date(#{endtime},'%Y-%m-%d'),INTERVAL 1 DAY)
            </if>
            <if test="endId != null">
                and rd.id &lt;  #{endId}
            </if>
        </where>
        order by rd.id desc
        <if test="exportExcelSize != null ">
            limit #{exportExcelSize}
        </if>
    </select>


    <select id="listPageReReportTask" parameterType="ReReportTask"
        resultType="ReReportTask">
        select st.id,
        st.taskid,
        st.sp_id,
        st.mdn,
        st.starttime,
        st.endtime,
        st.stat_desc,
        st.status,
        st.res_content,
        st.sign,
        st.source,
        st.allnumber,
        st.createtime,
        st.result,
        st.time_type
        from sms_rereport_task st
        <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="source!=null and source!=''">
                and st.source=#{source}
            </if>
            <if test="result!=null and result>-1">
                and st.result=#{result}
            </if>
            <if test="sp_id!=null and sp_id>0">
                and st.sp_id=#{sp_id}
            </if>
            <if test="taskid!=null and taskid>0">
                and st.taskid=#{taskid}
            </if>
            <if test="res_content!=null and res_content!=''">
                and st.res_content like CONCAT('%',#{res_content},'%')
            </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="starttime!=null and starttime!=''">
                and st.createtime&gt;=str_to_date(#{starttime},'%Y-%m-%d %H:%i:%s')
            </if>

            <if test="endtime!=null and endtime!=''">
                and st.createtime&lt;DATE_ADD(str_to_date(#{endtime},'%Y-%m-%d %H:%i:%s'),INTERVAL 5 SECOND)
            </if> -->
        </where>
        order by st.id desc
    </select>
    <update id="cancelRerortTask">
    	update sms_rereport_task set status=4 where id=#{id}
    </update>
  <select id="getReReportTaskNum" parameterType="ReReportTask"
        resultType="ReReportTask">
        select
        count(1) allnumber
        from sms_arrive st
        <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="source!=null and source!=''">
                and st.source=#{source}
            </if>
            <if test="sp_id!=null and sp_id>0">
                and st.sp_id=#{sp_id}
            </if>
            <if test="taskid!=null and taskid>0">
                and st.taskid=#{taskid}
            </if>
            <if test="res_content!=null and res_content!=''">
                and st.res_content like CONCAT('%',#{res_content},'%')
            </if>
             <if test="sign!=null and sign!=''">
                and st.sign=#{sign}
            </if>
            <if test="stat_desc!=null and stat_desc!=''">
                and st.stat_desc=#{stat_desc}
            </if>
            <if test="result!=null and result>-1">
                and st.result=#{result}
            </if>
            <choose>
                <when test="time_type!=null and time_type == 1">
                    and st.taskid >= #{starttimeTask} and st.create_time&gt;=str_to_date(#{starttime},'%Y-%m-%d %H:%i:%s')
                </when>
                <otherwise>
                    <if test="starttime!=null and starttime!=''">
                        and st.create_time&gt;=str_to_date(#{starttime},'%Y-%m-%d %H:%i:%s')
                    </if>
                </otherwise>
            </choose>
            <choose>
                <when test="time_type!=null and time_type == 1">
                    and st.taskid &lt; #{endtimeTask} and st.create_time&lt;DATE_ADD(str_to_date(#{endtime},'%Y-%m-%d %H:%i:%s'),INTERVAL 4 DAY)
                </when>
                <otherwise>
                    <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>
                </otherwise>
            </choose>

        </where>

    </select>

    <insert id="insertReReportTask"  useGeneratedKeys="true" keyProperty="id" parameterType="ReReportTask">
        insert into sms_rereport_task
        (sp_id,taskid,MDN,res_content,starttime,endtime,stat_desc,sign,source,allnumber,createtime,status,result,time_type) values
        (#{sp_id},#{taskid},#{mdn},#{res_content,jdbcType=VARCHAR},#{starttime,jdbcType=VARCHAR},#{endtime,jdbcType=VARCHAR}
        ,#{stat_desc,jdbcType=VARCHAR},#{sign,jdbcType=VARCHAR},#{source,jdbcType=VARCHAR},#{allnumber},sysdate(),#{status},#{result},#{time_type})
    </insert>

	<update id="updateReReportTask" parameterType="map" >
		update sms_rereport_task
		set
		status=1
		where id=#{id} and status=0
	</update>

	<select id="ExportTaskDetailByStatDescCount" parameterType="TaskDetailInfo"
		resultType="Long">
   		select count(a.id) from
		(select id,sp_id from sms_arrive
		st
		where 1=1
		<if test="mdn!=null and mdn!=''">
            <choose>
                <when test='mdn.toString().contains("_")'>
                    and st.mdn like #{mdn}
                </when>
                <otherwise>
                    and st.mdn=#{mdn}
                </otherwise>
            </choose>
		</if>
            <if test='res_result=="2"'>
                and st.result= 0
            </if>
            <if test='res_result=="3"'>
                and st.result != 0
            </if>
		<if test="sp_id!=null and sp_id>0">
			and st.sp_id=#{sp_id}
		</if>
        <if test="province!=null and province!=''">
            and st.province=#{province}
        </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="sign !=null and sign !=''">
            and st.sign=#{sign}
        </if>
        <if test="timeType == 0">
            <if test="createtime!=null and createtime!=''">
                and st.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d %H:%i:%s')
                and st.taskid &gt;= CONCAT(DATE_FORMAT(#{createtime},'%y%m%d%H%i%s'), '000000')
            </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 1 DAY)
                and st.taskid &lt; CONCAT(DATE_FORMAT(#{endtime},'%y%m%d%H%i%s'), '000000')
            </if>
        </if>
        <if test="timeType == 1">
            <if test="createtime!=null and createtime!=''">
                and st.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d %H:%i:%s')
                and st.send_time &gt;= #{createtime}
            </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 1 DAY)
                and st.send_time &lt; #{endtime}
            </if>
        </if>

            ) a, sms_sp_info sp
            where sp.id=a.SP_ID
            <if test="sp_name!=null and sp_name!=''">
			and sp.sp_name like CONCAT('%',#{sp_name},'%')
		</if>
	</select>

	<select id="ExportTaskDetailByAllCount" parameterType="TaskDetailInfo"
		resultType="Long">
   		select count(a.id) from
		(select id,sp_id from sms_submit
		st
		where 1=1
		<if test="mdn!=null and mdn!=''">
            <choose>
                <when test='mdn.toString().contains("_")'>
                    and st.mdn like #{mdn}
                </when>
                <otherwise>
                    and st.mdn=#{mdn}
                </otherwise>
            </choose>
		</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="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="province!=null and province!=''">
            and st.province=#{province}
        </if>
        <if test="content!=null and content!=''">
            AND st.RES_CONTENT LIKE concat('%',#{content},'%')
        </if>
        <if test="sign !=null and sign !=''">
            and st.sign=#{sign}
        </if>
        <if test="timeType == 0">
            <if test="createtime!=null and createtime!=''">
                and st.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d %H:%i:%s')
                and st.taskid &gt;= CONCAT(DATE_FORMAT(#{createtime},'%y%m%d%H%i%s'), '000000')
            </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 1 DAY)
                and st.taskid &lt; CONCAT(DATE_FORMAT(#{endtime},'%y%m%d%H%i%s'), '000000')
            </if>
        </if>
        <if test="timeType == 1">
            <if test="createtime!=null and createtime!=''">
                and st.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d %H:%i:%s')
                and st.send_time &gt;= #{createtime}
            </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 1 DAY)
                and st.send_time &lt; #{endtime}
            </if>
        </if>

            ) a, sms_sp_info sp
            where sp.id=a.SP_ID
            <if test="sp_name!=null and sp_name!=''">
			and sp.sp_name like CONCAT('%',#{sp_name},'%')
		</if>
	</select>

	<select id="ExportTaskNoReportDetailCount" parameterType="TaskDetailInfo"
		resultType="Long">
		 select
        count(1)

        from (select st.sid id,
        st.taskid,
        st.sp_id,
        sc.CHANNEL_NAME as pa_dec,
        sp.sp_name,
        st.mdn,
        st.callmdn,
        st.send_time,
        st.CHANNELID
        from sms_submit_noreport st, sms_sp_info sp, sms_send_channel_info sc
        where st.sp_id = sp.id
        and st.CHANNELID = sc.id

        <if test="sp_id!=null and sp_id>0">
            and st.sp_id=#{sp_id}
        </if>
        <if test="mdn != null and mdn != ''">
            <choose>
                <when test='mdn.toString().contains("_")'>
                    and st.mdn like #{mdn}
                </when>
                <otherwise>
                    and st.mdn=#{mdn}
                </otherwise>
            </choose>
        </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="province!=null and province!=''">
            and st.province=#{province}
        </if>
        <if test="sign !=null and sign !=''">
                and st.sign=#{sign}
        </if>
        <if test="content!=null and content!=''">
            AND st.RES_CONTENT LIKE concat('%',#{content},'%')
        </if>
        <if test="timeType == 0">
            <if test="createtime!=null and createtime!=''">
                and st.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d %H:%i:%s')
                and st.taskid &gt;= CONCAT(DATE_FORMAT(#{createtime},'%y%m%d%H%i%s'), '000000')
            </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 1 DAY)
                and st.taskid &lt; CONCAT(DATE_FORMAT(#{endtime},'%y%m%d%H%i%s'), '000000')
            </if>
        </if>
        <if test="timeType == 1">
            <if test="createtime!=null and createtime!=''">
                and st.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d %H:%i:%s')
                and st.send_time &gt;= #{createtime}
            </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 1 DAY)
                and st.send_time &lt; #{endtime}
            </if>
        </if>
        order by st.sid desc
        ) a
	</select>
	<select id="ExportTaskNoReportCount" parameterType="TaskDetailInfo"
		resultType="Long">
		select count(1)
		from sms_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="sp_name!=null and sp_name!=''">
			and sp.sp_name like CONCAT('%',#{sp_name},'%')
		</if>
            <if test='res_result=="2"'>
                and st.result= 0
            </if>
            <if test='res_result=="3"'>
                and st.result != 0
            </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="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>
            ORDER BY st.id DESC
	</select>
    <update id="setUtf8mb4" parameterType="string">
		set names utf8mb4
	</update>

	<delete id="deleteAuditTask" parameterType="map">
	 	delete from sms_send_audit_task where id=#{id} and status=1
	</delete>


    <select id="listPageSpMonthTaskTotal" parameterType="TaskInfo"
        resultMap="taskResultMap">
        select sp.id sp_id,
        tk.stat_time createTime,
        sp.sp_name,
        tk.allnumber,
        tk.succ,
        tk.fail,
        tk.arrive_succ,
        <!-- sum(tk.allnumber-asa.total-tk.arrive_succ-tk.arrive_fail) unRecMsgnum, -->
        tk.arrive_fail

        from sms_sp_info sp left join  sms_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  DATE_FORMAT(tk.stat_time,'%Y-%m')=#{createTime}
            <!-- and tk.stat_time =str_to_date(#{createTime},'%Y-%m') -->
        </if>


        order by sp.id

    </select>

   <select id="exportSpMonthTotalList" parameterType="TaskInfo"
        resultType="Map">
        select sp.id sp_id,
        DATE_FORMAT(tk.stat_time,'%Y-%m-%d') createTime,
        sp.sp_name,
        tk.allnumber,
        tk.succ,
        tk.fail,
        tk.arrive_succ,
        tk.succ+IFNULL(tk.fail,0)-IFNULL(tk.arrive_succ,0)-IFNULL(tk.arrive_fail,0) unRecMsgnum,
        tk.arrive_fail
        from sms_sp_info sp left join sms_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 DATE_FORMAT(tk.stat_time,'%Y-%m')=#{createTime}
        </if>

        order by sp.id
    </select>

    <select id="listSpMonthTaskTotalCount" 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.succ,0))+sum(IFNULL(tk.fail,0))-sum(IFNULL(tk.arrive_succ,0))-sum(IFNULL(tk.arrive_fail,0)) unRecMsgnum,
        sum(IFNULL(tk.arrive_fail,0)) arrive_fail
        from sms_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 DATE_FORMAT(tk.stat_time,'%Y-%m')=#{createTime}
        </if>

    </select>

    <select id="listPageSpSignTaskTotal" parameterType="TaskInfo"
        resultMap="taskResultMap">
        select sp.id sp_id,
        sp.sp_name,
       tk.sign,
        sum(tk.submit_succ) succ,
        sum(IFNULL(tk.submit_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  sms_sp_sign_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="sign!=null and sign!=''">
            and tk.sign =#{sign}
        </if>
         <if test="channelid !=null and channelid>=0">
            and tk.channelid =#{channelid}
        </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,tk.sign
        order by sum(tk.submit_succ) desc

    </select>

    <select id="listSpSignTaskTotalCount" parameterType="TaskInfo"
        resultMap="taskResultMap">
        select

        sum(IFNULL(tk.submit_succ,0)) succ,
        sum(IFNULL(tk.submit_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.submit_succ,0))+sum(IFNULL(tk.submit_fail,0))-sum(IFNULL(tk.arrive_succ,0))-sum(IFNULL(tk.arrive_fail,0)) unRecMsgnum,
        sum(IFNULL(tk.arrive_fail,0)) arrive_fail
        from sms_sp_sign_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="sign!=null and sign!=''">
            and tk.sign =#{sign}
        </if>
        <if test="sp_type!=null and sp_type>0">
            and sp.sp_type =#{sp_type}
        </if>
        <if test="channelid !=null and channelid >=0">
            and tk.channelid =#{channelid}
        </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="exportSpSignTotalList" parameterType="TaskInfo"
        resultType="Map">


         select sp.id sp_id,
        sp.sp_name,
       tk.sign,
        sum(tk.submit_succ) succ,
        sum(IFNULL(tk.submit_fail,0)) fail,
        sum(tk.arrive_succ) arrive_succ,
        <!-- sum(tk.allnumber-asa.total-tk.arrive_succ-tk.arrive_fail) unRecMsgnum, -->

       sum(IFNULL(tk.submit_succ,0))+sum(IFNULL(tk.submit_fail,0))-sum(IFNULL(tk.arrive_succ,0))-sum(IFNULL(tk.arrive_fail,0)) unRecMsgnum,
        sum(tk.arrive_fail) arrive_fail
        from sms_sp_info sp left join  sms_sp_sign_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="sign!=null and sign!=''">
            and tk.sign =#{sign}
        </if>
        <if test="channelid !=null and channelid !=''">
            and tk.channelid =#{channelid}
        </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,tk.sign
        order by sum(tk.submit_succ) desc


    </select>


     <select id="waitAuditCount" parameterType="TaskInfo"
        resultType="Integer">

        select sum(a.allnumber) wait_audit  from sms_send_audit_task a
        where a.status = 1
        and a.send_type in('1000','10000')
        and a.sp_id=#{sp_id}
        <if test="createTime!=null and createTime!=''">
            and a.createtime&gt;=str_to_date(#{createTime},'%Y-%m-%d')
        </if>
        <if test="createTime1!=null and createTime1!=''">
            and
            a.createtime&lt;DATE_ADD(str_to_date(#{createTime1},'%Y-%m-%d'),INTERVAL 1 DAY)
        </if>

    </select>

     <select id="waitApiAuditCount" parameterType="TaskInfo"
        resultType="Integer">

       select sum(api.allnumber) wait_audit  from sms_api_audit_task api
        where api.status = 1
        and api.send_type in('1000','10000')
        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="crontabCount" parameterType="TaskInfo"
        resultType="Integer">

       select sum(st.allnumber) crontab  from sms_crontab_send b
       left join sms_send_task st on st.id = b.taskid
        where b.status =0 and b.sp_id=#{sp_id} and st.status in (0,1)
        <if test="createTime!=null and createTime!=''">
            and b.createtime&gt;=str_to_date(#{createTime},'%Y-%m-%d')
            and st.createtime &gt;= str_to_date( #{createTime}, '%Y-%m-%d' )
        </if>
        <if test="createTime1!=null and createTime1!=''">
            and
            b.createtime&lt;DATE_ADD(str_to_date(#{createTime1},'%Y-%m-%d'),INTERVAL 1 DAY)
            and st.createtime &lt; DATE_ADD(str_to_date( #{createTime1}, '%Y-%m-%d' ),INTERVAL 1 DAY)
        </if>

     </select>

     <select id="crontabApiCount" parameterType="TaskInfo"
        resultType="Integer">

       select sum(b.allnumber) crontab  from sms_api_crontab_task b
        where b.sp_id=#{sp_id} and b.status = 2
        <if test="createTime!=null and createTime!=''">
            and b.createtime&gt;=str_to_date(#{createTime},'%Y-%m-%d')
        </if>
        <if test="createTime1!=null and createTime1!=''">
            and
            b.createtime&lt;DATE_ADD(str_to_date(#{createTime1},'%Y-%m-%d'),INTERVAL 1 DAY)
        </if>

     </select>


     <select id="listPageSpReportTotal" parameterType="TaskInfo"
        resultMap="taskResultMap">
        select pk.*,sum(su.arrive_succ) arrive_succ,sum(su.arrive_succ)-pk.pushnum difference from (select sp.id sp_id,
        sp.sp_name,
        sum(tk.succnum) succnum,
        sum(tk.failnum) failnum,
        sum(tk.respsucc) respsucc,
        sum(tk.respfail) respfail,


        sum(IFNULL(tk.succnum,0))+sum(IFNULL(tk.failnum,0)) pushnum,
        sum(IFNULL(tk.respsucc,0))+sum(IFNULL(tk.respfail,0)) respnum


        from sms_sp_info sp left join  sms_sp_pushreport_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) pk left join sms_sp_summary su on su.spid=pk.sp_id
        where 1=1
         <if test="sp_id!=null and sp_id>0">
            and su.spid=#{sp_id}
        </if>
        <if test="createTime!=null and createTime!=''">
            and su.stat_time&gt;=str_to_date(#{createTime},'%Y-%m-%d')
        </if>
        <if test="createTime1!=null and createTime1!=''">
            and
            su.stat_time&lt;DATE_ADD(str_to_date(#{createTime1},'%Y-%m-%d'),INTERVAL 1 DAY)
        </if>
		group by pk.sp_id,pk.sp_name order by pk.sp_id

    </select>

   <select id="listSpReportTotalCount" parameterType="TaskInfo"
        resultMap="taskResultMap">
        select
        <!-- sum(IFNULL(tk.pushnum,0)) allnumber,
        sum(IFNULL(tk.respnum,0)) succ -->
        sum(tk.succnum) succnum,
        sum(tk.failnum) failnum,
        sum(tk.respsucc) respsucc,
        sum(tk.respfail) respfail,


        sum(IFNULL(tk.succnum,0))+sum(IFNULL(tk.failnum,0)) pushnum,
        sum(IFNULL(tk.respsucc,0))+sum(IFNULL(tk.respfail,0)) respnum

        from sms_sp_pushreport_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="exportSpReportTotalList" parameterType="TaskInfo"
        resultType="Map">
        select sp.id sp_id,
        sp.sp_name,
        <!-- sum(tk.pushnum) allnumber,
        sum(tk.respnum) succ -->

        sum(tk.succnum) succnum,
        sum(tk.failnum) failnum,
        sum(tk.respsucc) respsucc,
        sum(tk.respfail) respfail,


        sum(IFNULL(tk.succnum,0))+sum(IFNULL(tk.failnum,0)) pushnum,
        sum(IFNULL(tk.respsucc,0))+sum(IFNULL(tk.respfail,0)) respnum
        from sms_sp_info sp left join sms_sp_pushreport_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="listPagePushReplyDetailInfo" parameterType="ReplyDetailInfo"
        resultMap="ReplyDetailInfoResultMap">
        select
        rd.id,
        rd.spid sp_id,
        rd.callmdn,
        rd.mdn mobile,
        rd.content,
        rd.msgId,
        rd.ip,
        rd.push_time

        from sms_sp_pushreply_record rd

        left join sms_sp_info sp on rd.spid = sp.id
        <where>
            <if test="sp_id!=null and sp_id>0">
                rd.spid=#{sp_id}
            </if>

			<if test="sp_saler!=null and sp_saler!=''">
                and sp.sp_saler=#{sp_saler}
            </if>
            <if test="mobile!=null and mobile!=''">
                and rd.mdn=#{mobile}
            </if>

            <if test="content!=null and content!=''">
                and rd.content like CONCAT('%',#{content},'%')
            </if>

            <if test="createtime!=null and createtime!=''">
                and rd.push_time&gt;=str_to_date(#{createtime},'%Y-%m-%d')
            </if>

            <if test="endtime!=null and endtime!=''">
                and rd.push_time&lt;=DATE_ADD(str_to_date(#{endtime},'%Y-%m-%d'),INTERVAL 1 DAY)
            </if>
        </where>
        order by rd.push_time desc

    </select>


   <select id="listPagePushReportDetailInfo" parameterType="TaskDetailInfo"
        resultMap="TaskDetailInfoResultMap">
        select

        rd.spid sp_id,
        rd.callmdn,
        rd.mdn,
        rd.arrive_time,
        rd.push_time,
        c.resp_time,
        rd.ip,
        rd.duration,
        rd.stat_desc,
        rd.msgId,
        rd.result,
        rd.taskid,
        rd.type,
        rd.inside

        from sms_sp_pushreport_record rd

        left join sms_sp_info sp on rd.spid = sp.id

        left join sms_sp_pushreport_resp c on c.taskid = rd.taskid  and c.mdn =rd.mdn and c.msgid = rd.msgid
        <where>
            <if test="sp_id!=null and sp_id>0">
                rd.spid=#{sp_id}
            </if>

			<if test="sp_saler!=null and sp_saler!=''">
                and sp.sp_saler=#{sp_saler}
            </if>
            <if test="mdn!=null and mdn!=''">
                and rd.mdn=#{mdn}
            </if>
            <if test="taskid!=null and taskid!=''">
                and rd.taskid=#{taskid}
            </if>
            <if test="type !=null and type !=''">
                and rd.type =#{type}
            </if>
           <!--  <if test="content!=null and content!=''">
                and rd.content like CONCAT('%',#{content},'%')
            </if> -->

            <if test="createtime!=null and createtime!=''">
                and rd.push_time&gt;=str_to_date(#{createtime},'%Y-%m-%d')
            </if>

            <if test="endtime!=null and endtime!=''">
                and rd.push_time&lt;=DATE_ADD(str_to_date(#{endtime},'%Y-%m-%d'),INTERVAL 1 DAY)
            </if>
        </where>
        order by rd.push_time desc

    </select>


  <select id="listPageTaskQueue" parameterType="TaskInfo" resultMap="TaskQueueMap">
		select a.*,ss.sp_name from (select content,count(1) co,sp_id,otype from sms_api_audit_task
		<where>
			status=1
	    <if test="sp_id!=null and sp_id!=''">
			and sp_id=#{sp_id}
		</if>
		<if test="content!=null and content!=''">
			and content like CONCAT('%',#{content},'%')
		</if>
		<if test="otype>0">
			and otype=#{otype}
		</if>
		</where>
		 GROUP BY content,sp_id,otype) a ,sms_sp_info ss
		where ss.id=a.sp_id
          <if test="sp_saler!=null and sp_saler!=''">
              and ss.sp_saler = #{sp_saler}
          </if>
          <if test="salerList!=null and salerList.size()>0">
              and ss.sp_saler in
              <foreach collection="salerList" index="index"  item="item" open="(" separator="," close=")">
                  '${item}'
              </foreach>
          </if>
		ORDER BY a.co desc

	</select>

	  <select id="getTaskQueueByContent" parameterType="TaskInfo" resultMap="TaskQueueMap">
		select a.*,ss.sp_name from (select content,count(1) co,sp_id,otype from sms_api_audit_task
		<where>
			 sp_id=#{sp_id} and content=#{content}
			 <if test="otype>0">
			 	and otype=#{otype}
			 </if>
		</where>
		 GROUP BY content,sp_id,otype
		 <if test="otype>0">
		 	,otype
		 </if>
		 ) a ,sms_sp_info ss
		where ss.id=a.sp_id
		ORDER BY a.co desc

	</select>

	<insert id="insertSmsModify">
		insert into sms_audit_content_modify(src_content,allnumber,mobile_content,unicom_content,
		telcom_content,content_type,modify_type,createtime,`status`,spids,username,otype,template_content,remark,source_type,limitsize) values(#{src_content},#{allnumber},#{mobile_content},
		#{unicom_content},#{telcom_content},#{content_type},#{modify_type},now(),#{status},#{spids},#{username},#{otype},#{template_content},#{remark},#{sourceType},#{limitsize})
	</insert>

	<select id="historyListPageTaskInfo" parameterType="TaskInfo"
        resultMap="taskResultMap">
        select tk.id,
        tk.sp_id,
        sp.sp_name,
        tk.content,
        tk.createtime,
        tk.total,
        tk.allnumber,
        tk.unicomnumber,
        tk.mobilenumber,
        tk.telecomnumber,
        tk.succ,
        tk.fail,
        tk.arrive_succ,
        tk.arrive_fail,
        tk.task_type,
        tk.status,
        tk.endtime,
        (tk.allnumber-tk.arrive_succ-tk.arrive_fail) unRecMsgnum,
        tk.send_type
        from sms_send_task_${history_dateStr} tk, sms_sp_info sp
        where sp.id = tk.sp_id
        <if test="sp_name!=null and sp_name!=''">
            and sp.sp_name like CONCAT('%',#{sp_name},'%')
        </if>
        <if test="content!=null and content!=''">
            and tk.content like CONCAT('%',#{content},'%')
        </if>
        <if test="sp_id!=null and sp_id>0">
            and tk.sp_id=#{sp_id}
        </if>
        <if test="sp_saler!=null and sp_saler!=''">
            and sp.sp_saler =#{sp_saler}
        </if>
        <if test="task_id!=null and task_id>0">
            and tk.id=#{task_id}
        </if>
         <if test="send_type!=null and send_type!=''">
            and tk.send_type=#{send_type}
        </if>
         <if test="task_type!=null and task_type!=''">
            and tk.task_type=#{task_type}
        </if>
        <if test="sign!=null and sign!=''">
            and tk.sign=#{sign}
        </if>
        <if test="createTime!=null and createTime!=''">
            and tk.createtime&gt;=str_to_date(#{createTime},'%Y-%m-%d')
        </if>

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

    <select id="getTaskInfoHistoryById" parameterType="TaskInfo" resultMap="taskInfoMap">
        select tk.id,
        tk.sp_id,
        tk.content,
        tk.createid,
        tk.createtime,
        tk.total,
        tk.allnumber,
        tk.unicomnumber,
        tk.mobilenumber,
        tk.telecomnumber,
        tk.task_type,
        tk.status,
        tk.endtime,
        sp.sp_audit_type,
        tk.send_type
        from sms_send_task_${history_dateStr} tk, sms_api_setting sp
        where sp.sp_id = tk.sp_id
        <if test="sp_id!=null and sp_id>0">
            and tk.sp_id=#{sp_id}
        </if>
        <if test="task_id!=null and task_id>0">
            and tk.id=#{task_id}
        </if>
    </select>

    <select id="listPageTaskHistoryDetailInfoForStatDesc" parameterType="TaskDetailInfo"
        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
        from sms_arrive_${history_dateStr} 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!=''">
                <choose>
                    <when test='mdn.toString().contains("_")'>
                        and st.mdn like #{mdn}
                    </when>
                    <otherwise>
                        and st.mdn=#{mdn}
                    </otherwise>
                </choose>
            </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>
        </where>
        order by st.id desc
    </select>

    <select id="getTaskDetailHistoryFromArrive" parameterType="TaskDetailInfo"
        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 sms_arrive_${history_dateStr} 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="getTaskDetailHistoryFromSubmit" parameterType="TaskDetailInfo"
        resultMap="TaskDetailInfoResultMap">
 		select
 		st.id,
		st.res_desc,
        st.send_time,
        st.res_content
        from sms_submit_${history_dateStr} 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="getHistoryTaskSumFromSubmit" parameterType="TaskDetailInfo"
        resultMap="TaskDetailInfoResultMap">
 		select
 		taskid,res_result,count(*) num
        from sms_submit_${history_dateStr} st
        where taskid=#{taskid}
         <if test="createtime!=null and createtime!=''">
                and st.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d')
            </if>

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

		group by taskid,res_result
    </select>

    <select id="getHistoryTaskSumFromArrive" parameterType="TaskDetailInfo"
        resultMap="TaskDetailInfoResultMap">
 		select
 		taskid,result res_result,count(*) num
        from sms_arrive_${history_dateStr} st
        where taskid=#{taskid}
       <if test="createtime!=null and createtime!=''">
                and st.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d')
            </if>

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

		group by taskid,result
    </select>

	<select id="listPageSysPcoTaskTotal1"
		parameterType="TaskInfo" resultMap="taskResultMap">
        select
        <if test="(type_sp!=null and type_sp!='') or (sp_name!=null and sp_name!='')">
            t.sp_name,
        </if>
        <if test="(type_sp!=null and type_sp!='') or (sp_id!=null and sp_id>0)">
            t.sp_id, t.eid,
        </if>
        <if test="type_channel!=null and type_channel!=''">
            t.channelid,
        </if>
        <if test="type_otype!=null and type_otype!=''">
            t.otype,
        </if>
        <if test="type_province!=null and type_province!=''">
            t.province,
        </if>
        <if test="type_day!=null and type_day!=''">
            t.stat_time,
        </if>
        t.succ, t.fail, t.arrive_succ, t.arrive_fail
        <if test="(type_sp!=null and type_sp!='') or (sp_id!=null and sp_id>0)">
            ,s.clientid
        </if>
        from (
		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, sp.eid,
		</if>
		<if test="type_channel!=null and type_channel!=''">
        	spp.channelid,
        </if>
        <if test="type_otype!=null and type_otype!=''">
			spp.otype,
        </if>
        <if test="type_province!=null and type_province!=''">
        	spp.province,
        </if>
         <if test="type_day!=null and type_day!=''">
         	spp.stat_time,
         </if>
		sum( IFNULL(spp.submit_succ, 0 ) ) succ,
		sum( IFNULL( spp.submit_fail, 0 ) ) fail,
		sum( spp.arrive_succ ) arrive_succ,
		sum( spp.arrive_fail ) arrive_fail
		FROM
			sms_sp_province_summary spp
        <if test="type_channel!=null and type_channel!='' and channel_name!=null and channel_name != ''">
            left join sms_send_channel_info sc on spp.channelid=sc.id
        </if>
        ,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="type_province!=null and type_province!='' and province!=null and province!=''">
                and spp.province=#{province}
         </if>
          <if test="type_otype!=null and type_otype!='' and otype!=null and otype >0">
                and spp.otype=#{otype}
         </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="eid != null and eid != ''">
            and sp.eid=#{eid}
        </if>
		<if test="sp_saler!=null and sp_saler!=''">
            and sp.sp_saler like CONCAT('%', #{sp_saler}, '%')
        </if>
        <if test="sp_type!=null and sp_type!=''">
            and sp.sp_type = #{sp_type}
        </if>
        <if test="star_level!=null and star_level>0">
            and sp.star_level =#{star_level}
        </if>
        <if test="salerList!=null and salerList.size()>0">
            and sp.sp_saler in
            <foreach collection="salerList" index="index"  item="item" open="(" separator="," close=")">
               '${item}'
            </foreach>
        </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>
		<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_otype!=null and type_otype!=''">
	        	spp.otype,
	        </if>
	        <if test="type_province!=null and type_province!=''">
	        	spp.province,
	        </if>
	        <if test="type_day!=null and type_day!=''">
	        	spp.stat_time,
	        </if>
		</trim>
        order by
        <choose>
            <when test="sort != null and sort != '' and sort == 'up'">
                stat_time asc
            </when>
            <when test="sort != null and sort != '' and sort == 'down'">
                stat_time desc
            </when>
            <otherwise>
                sum(spp.submit_succ) desc
            </otherwise>
        </choose>
        ) t
        <if test="(type_sp!=null and type_sp!='') or (sp_id!=null and sp_id>0)">
            left join sms_api_socket_sp s on t.sp_id = s.spid
        </if>
        <where>
            <if test="succ!=null and succ!=''">
                and t.succ &gt; #{succ}
            </if>
        </where>
        <if test="col != null and col != '' and col=='succ'">
            order by  t.succ ${orderType}
        </if>
        <if test="col != null and col != '' and col=='arriveSucc'">
            order by  t.arrive_succ ${orderType}
        </if>
	</select>

	<select id="exportSysPcoTotalList1" parameterType="TaskInfo"
		resultType="Map">
        select
        <if test="(type_sp!=null and type_sp!='') or (sp_name!=null and sp_name!='')">
            t.sp_name,
        </if>
        <if test="(type_sp!=null and type_sp!='') or (sp_id!=null and sp_id>0)">
            t.sp_id, t.eid,
        </if>
        <if test="type_channel!=null and type_channel!=''">
            t.channelid,
            t.channel_name,
        </if>
        <if test="type_otype!=null and type_otype!=''">
            t.otype_name,
        </if>
        <if test="type_province!=null and type_province!=''">
            t.province,
        </if>
        <if test="type_day!=null and type_day!=''">
            t.stat_time,
        </if>
        <if test="(type_sp!=null and type_sp!='') or (sp_id!=null and sp_id>0)">
             s.clientid,
        </if>
        t.succ, t.fail, t.arrive_succ, t.arrive_fail
        from (
		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, sp.eid,
		</if>
		<if test="type_channel!=null and type_channel!=''">
        	sc.channel_name,
        	sc.id channelid,
        </if>
        <if test="type_otype!=null and type_otype!=''">
		(case when spp.otype = '1' then "联通"
        when spp.otype = '2' then "移动"
        else "电信" end) otype_name,
        </if>
        <if test="type_province!=null and type_province!=''">
        	spp.province,
        </if>
         <if test="type_day!=null and type_day!=''">
         	date_format(spp.stat_time,'%Y-%m-%d') stat_time,
         </if>
        CONCAT(Round(sum(spp.arrive_succ)/sum(spp.submit_succ)*100,2),'%') sp_succ_percent,
		sum( IFNULL(spp.submit_succ,0) ) succ,
		sum( IFNULL( spp.submit_fail,0 ) ) fail,
		sum( IFNULL(spp.arrive_succ,0) ) arrive_succ,
		sum( IFNULL(spp.arrive_fail,0) ) arrive_fail
		FROM
			sms_sp_province_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="type_province!=null and type_province!='' and province!=null and province!=''">
                and spp.province=#{province}
         </if>
          <if test="type_otype!=null and type_otype!='' and otype!=null and otype >0">
                and spp.otype=#{otype}
         </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="eid != null and eid != ''">
            and sp.eid = #{eid}
        </if>
		<if test="sp_saler!=null and sp_saler!=''">
            and sp.sp_saler like CONCAT('%', #{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!=''">
            and sp.sp_type = #{sp_type}
        </if>
        <if test="star_level!=null and star_level>0">
            and sp.star_level =#{star_level}
        </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_otype!=null and type_otype!=''">
	        	spp.otype,
	        </if>
	        <if test="type_province!=null and type_province!=''">
	        	spp.province,
	        </if>
	        <if test="type_day!=null and type_day!=''">
	        	spp.stat_time,
	        </if>
		</trim>

		order by sum(spp.submit_succ) desc
        ) t
        <if test="(type_sp!=null and type_sp!='') or (sp_id!=null and sp_id>0)">
            left join sms_api_socket_sp s on t.sp_id = s.spid
        </if>
        <where>
            <if test="succ!=null and succ!=''">
                and t.succ &gt; #{succ}
            </if>
        </where>
	</select>

	<select id="getSysPcoTaskTotal"
		parameterType="TaskInfo" resultType="TaskInfo">
        select
        CONCAT(Round(sum(arrive_succ)/sum(succ)*100,2),'%') sp_succ_percent,
        sum( IFNULL(succ,0) ) succ,
        sum( IFNULL( fail, 0 ) ) fail,
        sum( IFNULL(arrive_succ,0) ) arrive_succ,
        sum( IFNULL(arrive_fail,0) ) arrive_fail
        from (
		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, sp.eid,
        </if>
        <if test="type_channel!=null and type_channel!=''">
            spp.channelid,
        </if>
        <if test="type_otype!=null and type_otype!=''">
            spp.otype,
        </if>
        <if test="type_province!=null and type_province!=''">
            spp.province,
        </if>
        <if test="type_day!=null and type_day!=''">
            spp.stat_time,
        </if>
        sum( IFNULL(spp.submit_succ, 0 ) ) succ,
        sum( IFNULL( spp.submit_fail, 0 ) ) fail,
        sum( spp.arrive_succ ) arrive_succ,
        sum( spp.arrive_fail ) arrive_fail
		FROM
			sms_sp_province_summary spp
        <if test="type_channel!=null and type_channel!='' and channel_name!=null and channel_name !=''">
            left join sms_send_channel_info sc on spp.channelid=sc.id
        </if>
        ,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="eid != null and eid != ''">
            and sp.eid = #{eid}
        </if>
		<if test="sp_saler!=null and sp_saler!=''">
            and sp.sp_saler like CONCAT('%', #{sp_saler}, '%')
        </if>
        <if test="salerList!=null and salerList.size()>0">
            and sp.sp_saler in
            <foreach collection="salerList" index="index"  item="item" open="(" separator="," close=")">
               '${item}'
            </foreach>
        </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_saler!=null and sp_saler!=''">
            and sp.sp_saler like CONCAT('%', #{sp_saler}, '%')
        </if>
        <if test="sp_type!=null and sp_type!=''">
            and sp.sp_type = #{sp_type}
        </if>
        <if test="star_level!=null and star_level>0">
            and sp.star_level =#{star_level}
        </if>
		<if test="type_province!=null and type_province!='' and province!=null and province!=''">
                and spp.province=#{province}
         </if>
          <if test="type_otype!=null and type_otype!='' and otype!=null and otype >0">
                and spp.otype=#{otype}
         </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>
        <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_otype!=null and type_otype!=''">
                spp.otype,
            </if>
            <if test="type_province!=null and type_province!=''">
                spp.province,
            </if>
            <if test="type_day!=null and type_day!=''">
                spp.stat_time,
            </if>
        </trim>
        ) t
        <where>
            <if test="succ!=null and succ!=''">
                and t.succ &gt; #{succ}
            </if>
        </where>
	</select>

	<select id="listPageNoreportTask" resultType="cn.roadm.bo.NoreportTask">
		select id,sp_id,DATE_FORMAT(createtime, '%Y-%m-%d %H:%i:%s') createtime,
		DATE_FORMAT(endtime, '%Y-%m-%d %H:%i:%s') endtime,taskid,content,phones,
		num,DATE_FORMAT(starttime, '%Y-%m-%d %H:%i:%s') starttime,status,res_result,sign,timeout,channelid,province,otype from noreport_task
		<where>
			<if test="sp_id!=null and sp_id>0">
				and sp_id=#{sp_id}
			</if>
			<if test="starttime!=null and starttime!=''">
				and createtime &gt;= #{starttime}
			</if>
			<if test="endtime!=null and endtime!=''">
				and createtime &lt;= #{endtime}
			</if>
			<if test="status!=null and status!=''">
				and status=#{status}
			</if>
			<if test="sign!=null and sign!=''">
				and ss.sign=#{sign}
			</if>
			<if test="province!=null and province!=''">
				and province=#{province}
			</if>
			<if test="otype!=null and otype!=''">
				and otype=#{otype}
			</if>
		</where>
		order by id desc
	</select>

    <!-- <if test="starttime!=null and starttime!=''">
				and ssn.send_time &gt; #{starttime}
			</if>
			<if test="endtime!=null and endtime!=''">
				and ssn.send_time &lt; #{endtime}
			</if>
			<if test="starttime!=null and starttime!=''">
				and ssn.create_time &gt; #{starttime}
			</if>
			<if test="endtime!=null and endtime!=''">
				and ssn.create_time &lt; #{endtime}
			</if> -->
	<select id="getNpreportCount" resultType="int">
		select count(1) from sms_submit_noreport ssn
		<where>
			<if test="sp_id!=null and sp_id>0">
				and ssn.sp_id=#{sp_id}
			</if>
            <if test="starttime != null and starttime != ''">
                and ssn.send_time &gt;= str_to_date(#{starttime},'%Y-%m-%d %H:%i:%s')
                and ssn.create_time &gt;= str_to_date(substring(#{starttime}, 1, 10),'%Y-%m-%d')
            </if>
			<if test="endtime != null and endtime != ''">
                and ssn.send_time &lt; DATE_ADD(str_to_date(#{endtime},'%Y-%m-%d %H:%i:%s'), INTERVAL 5 SECOND)
                and ssn.create_time &lt; DATE_ADD(str_to_date(substring(#{endtime}, 1, 10),'%Y-%m-%d'), interval 1 day)
            </if>
			<if test="content!=null and content!=''">
				and ssn.res_content like concat('%',#{content},'%')
			</if>
			<if test="phones!=null and phones!=''">
				and ssn.mdn=#{phones}
			</if>
			<if test="taskid!=null and taskid!=''">
				and ssn.taskid=#{taskid}
			</if>
			<if test="sign!=null and sign!=''">
				and ssn.sign=#{sign}
			</if>
			<if test="timeout==1">
				and ssn.messageid=1
			</if>
			<if test="channelid!=null and channelid!=''">
				and ssn.channelid=#{channelid}
			</if>
            <if test="province!=null and province!=''">
                and ssn.province=#{province}
            </if>
            <if test="otype!=null and otype!=''">
                and ssn.otype=#{otype}
            </if>

		</where>
	</select>

	<insert id="insertNoreportTask" parameterType="cn.roadm.bo.NoreportTask">
		insert into noreport_task(sp_id,createtime,
		<if test="endtime!=null and endtime!=''">
			endtime,
		</if>
		taskid,content,phones,num,
		<if test="starttime!=null and starttime!=''">
			starttime,
		</if>
		<if test="sign!=null and sign!=''">
			sign,
		</if>
		<if test="channelid!=null and channelid!=''">
			channelid,
		</if>
		<if test="province!=null and province!=''">
			province,
		</if>
		<if test="otype!=null and otype!=''">
			otype,
		</if>
		timeout,status,res_result)
		values(#{sp_id},now(),
		<if test="endtime!=null and endtime!=''">
			#{endtime},
		</if>
		#{taskid},#{content},#{phones},#{num},
		<if test="starttime!=null and starttime!=''">
			#{starttime},
		</if>
		<if test="sign!=null and sign!=''">
			#{sign},
		</if>
		<if test="channelid!=null and channelid!=''">
			#{channelid},
		</if>
		<if test="province!=null and province!=''">
			#{province},
		</if>
		<if test="otype!=null and otype!=''">
			#{otype},
		</if>
		#{timeout},0,#{res_result})
	</insert>

	<update id="updatetNoreportTask">
		update noreport_task set status=#{status} where id=#{id}
	</update>

	<select id="listPageSpMonChannelTaskTotal"
		parameterType="TaskInfo" resultMap="taskResultMap">
		select sp.id sp_id,
		sp.sp_name,
		tk.channelid,
		tk.stat_time,
		vspp.sp_all_submit,
		sum(tk.submit_succ) succ,
		sum(IFNULL(tk.submit_fail,0)) fail,
		sum(tk.arrive_succ) arrive_succ,
<!-- sum(IFNULL(tk.submit_succ+tk.submit_fail-tk.arrive_succ-tk.arrive_fail,0)) unRecMsgnum, -->
sum(IFNULL(tk.submit_succ,0))+sum(IFNULL(tk.submit_fail,0))-sum(IFNULL(tk.arrive_succ,0))-sum(IFNULL(tk.arrive_fail,0)) unRecMsgnum,
		sum(tk.arrive_fail) arrive_fail
		from sms_sp_province_summary tk, sms_sp_info sp,
		(

		select sum(spp.submit_succ) sp_all_submit,spp.spid,spp.stat_time from
		sms_sp_province_summary spp, sms_sp_info spinfo
		where spp.spid = spinfo.id
		<if test="sp_name!=null and sp_name!=''">
			and spinfo.sp_name like CONCAT('%',#{sp_name},'%')
		</if>
		<if test="sp_id!=null and sp_id>0">
			and spp.spid=#{sp_id}
		</if>
		<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>
		 group by spp.spid,spp.stat_time

		) vspp,sms_send_channel_info ssci
		where tk.spid = sp.id and tk.spid = vspp.spid
		and tk.channelid = ssci.id and tk.stat_time=vspp.stat_time


		<if test="sp_name!=null and sp_name!=''">
			and sp.sp_name like CONCAT('%',#{sp_name},'%')
		</if>
		<if test="channel_name!=null and channel_name!=''">
			and ssci.channel_name like CONCAT('%',#{channel_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="channelid!=null and channelid!=-1">
			and tk.channelid =#{channelid}
		</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,tk.channelid,tk.stat_time
        order by
        <choose>
            <when test="sort != null and sort != '' and sort == 'up'">
                tk.stat_time asc
            </when>
            <when test="sort != null and sort != '' and sort == 'down'">
                tk.stat_time desc
            </when>
            <otherwise>
                succ desc
            </otherwise>
        </choose>
	</select>


	 <!--fuction:企业月发送统计(运营商) and 企业发送统计(运营商) 导出    developer : 李相  BEGIN -->
    <select id="listPageCarrierMonTotalList" parameterType="TaskInfo" resultMap="taskResultMap">
        select sp.id sp_id,
        sp.sp_name,
        tk.otype,
        tk.stat_time,
        vspp.sp_all_submit,
        sum(tk.submit_succ) succ,
        sum(IFNULL(tk.submit_fail,0)) fail,
        sum(tk.arrive_succ) arrive_succ,
      <!--   sum(IFNULL(tk.submit_succ+tk.submit_fail-tk.arrive_succ-tk.arrive_fail,0)) unRecMsgnum, -->
        sum(IFNULL(tk.submit_succ,0))+sum(IFNULL(tk.submit_fail,0))-sum(IFNULL(tk.arrive_succ,0))-sum(IFNULL(tk.arrive_fail,0)) unRecMsgnum,
        sum(tk.arrive_fail) arrive_fail
        from sms_sp_province_summary tk, sms_sp_info sp,

        (
		select sum(spp.submit_succ) sp_all_submit,spp.spid,spp.stat_time from
		sms_sp_province_summary spp, sms_sp_info spinfo
		where spp.spid = spinfo.id
		<if test="sp_name!=null and sp_name!=''">
			and spinfo.sp_name like CONCAT('%',#{sp_name},'%')
		</if>
		<if test="sp_saler!=null and sp_saler!=''">
            and spinfo.sp_saler =#{sp_saler}
        </if>
		<if test="sp_id!=null and sp_id>0">
			and spp.spid=#{sp_id}
		</if>
		<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>
		 group by spp.spid,spp.stat_time

		) vspp

        where tk.spid = sp.id
			and tk.spid = vspp.spid and vspp.stat_time=tk.stat_time
        <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="otype!=null and otype>0 ">
            and tk.otype =#{otype}
        </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, tk.otype,tk.stat_time
        order by
        <choose>
            <when test="sort != null and sort != '' and sort == 'up'">
                tk.stat_time asc
            </when>
            <when test="sort != null and sort != '' and sort == 'down'">
                tk.stat_time desc
            </when>
            <otherwise>
                succ desc
            </otherwise>
        </choose>
    </select>

      <select id="listPageSpMonProvinceTaskTotal"
		parameterType="TaskInfo" resultMap="taskResultMap">
		select sp.id sp_id,
		sp.sp_name,
		tk.province,
		tk.stat_time,
		vspp.sp_all_submit,
		sum(tk.submit_succ) succ,
		sum(IFNULL(tk.submit_fail,0)) fail,
		sum(tk.arrive_succ) arrive_succ,
		sum(IFNULL(tk.submit_succ,0))+sum(IFNULL(tk.submit_fail,0))-sum(IFNULL(tk.arrive_succ,0))-sum(IFNULL(tk.arrive_fail,0)) unRecMsgnum,
<!-- sum(IFNULL(tk.submit_succ+tk.submit_fail-tk.arrive_succ-tk.arrive_fail,0)) unRecMsgnum, -->
		sum(tk.arrive_fail) arrive_fail
		from sms_sp_province_summary tk, sms_sp_info sp,
		(
		select sum(spp.submit_succ) sp_all_submit,spp.spid,spp.stat_time from
		sms_sp_province_summary spp, sms_sp_info spinfo
		where spp.spid = spinfo.id
		<if test="sp_name!=null and sp_name!=''">
			and spinfo.sp_name like CONCAT('%',#{sp_name},'%')
		</if>
		<if test="sp_id!=null and sp_id>0">
			and spp.spid=#{sp_id}
		</if>
		<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>
		 group by spp.spid,spp.stat_time
		 ) vspp
		where tk.spid = sp.id and tk.spid = vspp.spid and vspp.stat_time=tk.stat_time


		<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="province!=null and province!=''">
			and tk.province =#{province}
		</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,tk.province,tk.stat_time
        order by
        <choose>
            <when test="sort != null and sort != '' and sort == 'up'">
                tk.stat_time asc
            </when>
            <when test="sort != null and sort != '' and sort == 'down'">
                tk.stat_time desc
            </when>
            <otherwise>
                succ desc
            </otherwise>
        </choose>
	</select>


	<select id="exportSpMonChannelTotalList" parameterType="TaskInfo"
		resultType="Map">
		select sp.id sp_id,
		(select a.channel_name from sms_send_channel_info a where a.id = tk.channelid) channel_name,
		CONCAT(Round(sum(tk.submit_succ)/vspp.sp_all_submit*100,2),'%') sp_channel_percent,
		CONCAT(Round(sum(tk.arrive_succ)/sum(tk.submit_succ)*100,2),'%') sp_succ_percent,
		sum(IFNULL(tk.submit_succ,0))+sum(IFNULL(tk.submit_fail,0))-sum(IFNULL(tk.arrive_succ,0))-sum(IFNULL(tk.arrive_fail,0)) unRecMsgnum,
		sp.sp_name,
		sum(tk.submit_succ) succ,
		sum(IFNULL(tk.submit_fail,0)) fail,
		sum(tk.arrive_succ) arrive_succ,
		sum(tk.arrive_fail) arrive_fail
		from sms_sp_province_summary tk, sms_sp_info sp,
		(

		select sum(spp.submit_succ) sp_all_submit,spp.spid from
		sms_sp_province_summary spp, sms_sp_info spinfo
		where spp.spid = spinfo.id
		<if test="sp_name!=null and sp_name!=''">
			and spinfo.sp_name like CONCAT('%',#{sp_name},'%')
		</if>
		<if test="sp_id!=null and sp_id>0">
			and spp.spid=#{sp_id}
		</if>
		<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>
		 group by spp.spid,spp.stat_time

		) vspp,sms_send_channel_info ssci
		where tk.spid = sp.id
			and tk.spid = vspp.spid and tk.channelid = ssci.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="channel_name!=null and channel_name!=''">
			and ssci.channel_name like CONCAT('%',#{channel_name},'%')
		</if>
		<if test="sp_saler!=null and sp_saler!=''">
			and sp.sp_saler =#{sp_saler}
		</if>
		<if test="channelid!=null and channelid!=-1 ">
			and tk.channelid =#{channelid}
		</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,tk.channelid
		order by sp.id,succ desc
	</select>

	<select id="listPageSmsModify" resultType="cn.roadm.bo.SmsAuditContentModify">
		select id,src_content,allnumber,mobile_content,unicom_content,telcom_content,content_type,
		modify_type,DATE_FORMAT(createtime, '%Y-%m-%d %H:%i:%s') createtime,status,DATE_FORMAT(donetime, '%Y-%m-%d %H:%i:%s') donetime,
		donenum,spids,username,remark,otype,template_content from sms_audit_content_modify
		<where>
			<if test="spids!=null and spids!=''">
				and spids like concat('%',#{spids},'%')
			</if>
			<if test="src_content!=null and src_content!=''">
				and src_content like concat('%',#{src_content},'%')
			</if>
			<if test="status!=null and status!=''">
				and status=#{status}
			</if>
			<if test="otype>0">
				and otype=#{otype}
			</if>
			<if test="content_type!=null and content_type!='' and content_type>-1">
				content_type=#{content_type}
			</if>
			<if test="createtime!=null and createtime!=''">
            	and createtime&gt;=str_to_date(#{createtime},'%Y-%m-%d')
	        </if>
	        <if test="createtime1!=null and createtime1!=''">
	            and createtime&lt;DATE_ADD(str_to_date(#{createtime1},'%Y-%m-%d'),INTERVAL 1 DAY)
	        </if>
	        <if test="sourceType != null and sourceType != ''">
                and source_type = #{sourceType}
            </if>
		</where>
		order by createtime desc
	</select>

	<update id="updateSmsModifyStatus">
		update sms_audit_content_modify set status=#{status} where id=#{id}
	</update>
	<select id="listPageNoreportConfig" resultType="cn.roadm.bo.NoreportSpConfig">
		select nsc.id,DATE_FORMAT(nsc.createtime, '%Y-%m-%d %H:%i:%s') createtime,nsc.scan_time,nsc.delayTime,
		nsc.sign,nsc.channelid,nsc.percentage,nsc.isWithinTime,sp.id sp_id,sp.sp_name,nsc.isMobile,nsc.isUnicom,
		nsc.isTelecom,nsc.isOpen,nsc.mdnLib,nsc.whiteMdn,nsc.whiteCity
		from sms_sp_info sp left join noreport_sp_config nsc on sp.id=nsc.sp_id
		 <where>
		 	sp.status=1
		 	<if test="sp_id!=null and sp_id!=''">
		 		and sp.id=#{sp_id}
		 	</if>
		 	<if test="sp_name!=null and sp_name!=''">
		 		and sp.sp_name like concat('%',#{sp_name},'%')
		 	</if>
		 	<if test="isOpen != null and isOpen!=''">
		 		and nsc.isOpen=#{isOpen}
		 	</if>
            <if test="channelIds != null and channelIds != ''">
                and nsc.channelid like CONCAT('%',#{channelIds}, '%')
            </if>
            <if test="signs != null and signs != ''">
                and nsc.sign like CONCAT('%', #{signs}, '%')
            </if>
		 </where>
	</select>
	<select id="listPageNoreportInternationalConfig" resultType="cn.roadm.bo.NoreportInternationalSpConfig">
		select nsc.id,DATE_FORMAT(nsc.createtime, '%Y-%m-%d %H:%i:%s') createtime,nsc.scan_time,
		nsc.channelid,nsc.percentage,nsc.isWithinTime,sp.id sp_id,sp.sp_name,nsc.isMobile,nsc.isUnicom,
		nsc.isTelecom,nsc.isOpen
		from sms_sp_info sp left join noreport_international_sp_config nsc on sp.id=nsc.sp_id
		 <where>
		 	sp.status=1
		 	<if test="sp_id!=null and sp_id!=''">
		 		and sp.id=#{sp_id}
		 	</if>
		 	<if test="sp_name!=null and sp_name!=''">
		 		and sp.sp_name like concat('%',#{sp_name},'%')
		 	</if>
		 	<if test="isOpen != null and isOpen!=''">
		 		and nsc.isOpen=#{isOpen}
		 	</if>
            <if test="channelIds != null and channelIds != ''">
                and nsc.channelid like CONCAT('%',#{channelIds}, '%')
            </if>
		 </where>
	</select>

    <insert id="insertNoreportConfig">
        insert into noreport_sp_config(sp_id,createtime,sign,channelid,percentage,isWithinTime,scan_time,
                                       isMobile,isUnicom,isTelecom,delayTime,isOpen,mdnLib,whiteMdn,whiteCity,
                                       oneday,threeday,nday,ntimes,long_sms_time,longSmsEnable, nullMdnLib,report_status)
        values(#{sp_id},now(),#{sign},#{channelid},#{percentage},#{isWithinTime},#{scan_time},
               #{isMobile},#{isUnicom},#{isTelecom},#{delayTime},#{isOpen},#{mdnLib},#{whiteMdn},#{whiteCity},
               #{oneday},#{threeday},#{nday},#{ntimes},#{long_sms_time},#{longSmsEnable}, #{nullMdnLib},#{report_status})
    </insert>
    <update id="updateNoreportConfig">
        update noreport_sp_config set sp_id=#{sp_id},sign=#{sign},
                                      channelid=#{channelid},percentage=#{percentage},isWithinTime=#{isWithinTime},scan_time=#{scan_time},
                                      isMobile=#{isMobile},isUnicom=#{isUnicom},isTelecom=#{isTelecom},delayTime=#{delayTime},
                                      isOpen=#{isOpen},mdnLib=#{mdnLib},whiteMdn=#{whiteMdn},whiteCity=#{whiteCity},oneday=#{oneday},
                                      threeday=#{threeday},nday=#{nday},ntimes=#{ntimes},long_sms_time=#{long_sms_time},longSmsEnable=#{longSmsEnable},
        nullMdnLib=#{nullMdnLib},report_status = #{report_status} where id=#{id}
    </update>

    <insert id="insertNoreportInternationalConfig">
        insert into noreport_international_sp_config(sp_id,createtime,channelid,percentage,isWithinTime,scan_time,
                                       isMobile,isUnicom,isTelecom,isOpen,
                                       long_sms_time,longSmsEnable,report_status)
        values(#{sp_id},now(),#{channelid},#{percentage},#{isWithinTime},#{scan_time},
               #{isMobile},#{isUnicom},#{isTelecom},#{isOpen},
               #{long_sms_time},#{longSmsEnable},#{report_status})
    </insert>
    <update id="updateNoreportInternationalConfig">
        update noreport_international_sp_config set sp_id=#{sp_id},channelid=#{channelid},percentage=#{percentage},
                                      isWithinTime=#{isWithinTime},scan_time=#{scan_time},isMobile=#{isMobile},
                                      isUnicom=#{isUnicom},isTelecom=#{isTelecom},isOpen=#{isOpen},
                                      long_sms_time=#{long_sms_time},longSmsEnable=#{longSmsEnable},
                                      report_status = #{report_status} where id=#{id}
    </update>
	<select id="getNoreportConfigById" resultType="cn.roadm.bo.NoreportSpConfig">
		select nsc.id,DATE_FORMAT(nsc.createtime, '%Y-%m-%d %H:%i:%s') createtime,nsc.scan_time,nsc.delayTime,
		nsc.sign,nsc.channelid,nsc.percentage,nsc.isWithinTime,sp.id sp_id,sp.sp_name,nsc.isMobile,nsc.isUnicom,
		nsc.isTelecom,nsc.isOpen,nsc.mdnLib,nsc.whiteMdn,nsc.whiteCity,nsc.oneday,nsc.threeday,nsc.nday,nsc.ntimes,nsc.long_sms_time,
        ifnull(nsc.longSmsEnable, 0) as longSmsEnable, nullMdnLib,report_status
		from sms_sp_info sp left join noreport_sp_config nsc on sp.id=nsc.sp_id where sp.id=#{sp_id} and sp.status=1
	</select>
	<select id="getNoreportInternationalConfigById" resultType="cn.roadm.bo.NoreportInternationalSpConfig">
		select nsc.id,DATE_FORMAT(nsc.createtime, '%Y-%m-%d %H:%i:%s') createtime,nsc.scan_time,
		nsc.channelid,nsc.percentage,nsc.isWithinTime,sp.id sp_id,sp.sp_name,nsc.isMobile,nsc.isUnicom,
		nsc.isTelecom,nsc.isOpen,nsc.long_sms_time,ifnull(nsc.longSmsEnable, 0) as longSmsEnable,report_status
		from sms_sp_info sp left join noreport_international_sp_config nsc on sp.id=nsc.sp_id where sp.id=#{sp_id} and sp.status=1
	</select>

	<select id="listPageNoreportRecord" parameterType="TaskDetailInfo"
        resultMap="TaskDetailInfoResultMap">


        select nr.id,
        nr.taskid,
        nr.sp_id,
        sc.CHANNEL_NAME as pa_dec,
        sp.sp_name,
        nr.mdn,
        nr.callmdn,
        nr.send_time,
        nr.channelid,
        nr.res_content,
        nr.create_time,
        nr.status
        from noreport_record nr
        LEFT JOIN sms_sp_info sp
        ON nr.sp_id = sp.id
        LEFT JOIN sms_send_channel_info sc
        ON nr.CHANNELID = sc.id

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

            <if test="sp_id!=null and sp_id>0">
                and nr.sp_id=#{sp_id}
            </if>
            <if test="taskid!=null and taskid>0">
                and nr.taskid=#{taskid}
            </if>
            <if test="channelid!=null and channelid!=''">
                and nr.channelid=#{channelid}
            </if>
             <if test="sign!=null and sign!=''">
                and nr.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="createtime!=null and createtime!=''">
                and nr.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d %H:%i:%s')
            </if>

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

    <update id="updateNoreport">
    	update noreport_record set status =#{status} where id=#{id}
    </update>

   <select id="listPagePriceRecord" resultType="cn.roadm.bo.PriceRecord">
		SELECT
   			sp.id spid,
			sp.sp_name,
			sp.sp_type,
			sp.commission_price,
			sp.noProfit,
			sum( pr.income ) income,
			sum( pr.cost ) cost,
			sum(pr.un_income) un_income,
			sum(pr.un_cost) un_cost,
			ifnull( sum( pr.succ ), 0 ) num,
			sum(pr.unkonw) unknown,
			pr.province
			<if test="queryType=='spchannel'">
				,pr.channelid
			</if>
			<if test="ismon==1">
				,pr.stat_time
				<if test="queryType=='sp'">
					,pr.sprice
				</if>
				<if test="queryType=='spchannel'">
					,pr.sprice,pr.cprice
				</if>
			</if>
		FROM
			(
			SELECT
				sg.*,
				ifnull( spp.price, 0 )* sg.succ income,
				ifnull( spp.price, 0 )* sg.unkonw un_income,
				scp.price cprice,
				spp.price sprice,
				ifnull( scp.price, 0 )* sg.succ cost,
				ifnull( scp.price, 0 )* sg.unkonw un_cost,
				scp.province
			FROM
				(
				SELECT
					sum(
					ifnull( sps.arrive_succ, 0 )) succ,
					sum(ifnull( sps.submit_succ, 0 )) +
					sum(ifnull( sps.submit_fail, 0 )) -
					sum(ifnull( sps.arrive_fail, 0 )) -
					sum(ifnull( sps.arrive_succ, 0 )) unkonw,
					sps.spid,
					sps.channelid,
					sps.stat_time,
					sps.province pro
				FROM
					sms_sp_province_summary sps
				<where>
					<if test="createtime!=null and createtime!=''">
						and sps.stat_time &gt;= #{createtime}
					</if>
					<if test="createtime1!=null and createtime1!=''">
						and sps.stat_time &lt; DATE_ADD(str_to_date(#{createtime1},'%Y-%m-%d %H:%i:%s'),INTERVAL 1 DAY)
					</if>
					<if test="channelid!=null and channelid!=''">
						and sps.channelid=#{channelid}
					</if>
				</where>
				GROUP BY
					sps.spid,
					sps.channelid,
					sps.stat_time,
					sps.province
				having sum(ifnull( sps.arrive_succ, 0 ))+sum(ifnull( sps.submit_succ, 0 )) +
					sum(ifnull( sps.submit_fail, 0 )) -
					sum(ifnull( sps.arrive_fail, 0 )) -
					sum(ifnull( sps.arrive_succ, 0 )) &gt;= 0
				) sg left join sms_sp_price spp on
				spp.spid = sg.spid and sg.stat_time =spp.createtime
				left join sms_channel_price scp on
				scp.channelid = sg.channelid and sg.stat_time = scp.createtime
				where scp.province is null
				UNION ALL
				SELECT
				sg.*,
				ifnull( spp.provinceNetPrice, 0 )* sg.succ income,
				ifnull( spp.provinceNetPrice, 0 )* sg.unkonw un_income,
				scp.provinceNetPrice cprice,
				spp.provinceNetPrice sprice,
				ifnull( scp.provinceNetPrice, 0 )* sg.succ cost,
				ifnull( scp.provinceNetPrice, 0 )* sg.unkonw un_cost,
				scp.province
			FROM
				(
				SELECT
					sum(
					ifnull( sps.arrive_succ, 0 )) succ,
					sum(ifnull( sps.submit_succ, 0 )) +
					sum(ifnull( sps.submit_fail, 0 )) -
					sum(ifnull( sps.arrive_fail, 0 )) -
					sum(ifnull( sps.arrive_succ, 0 )) unkonw,
					sps.spid,
					sps.channelid,
					sps.stat_time,
					sps.province pro
				FROM
					sms_sp_province_summary sps
				<where>
					<if test="createtime!=null and createtime!=''">
						and sps.stat_time &gt;= #{createtime}
					</if>
					<if test="createtime1!=null and createtime1!=''">
						and sps.stat_time &lt; DATE_ADD(str_to_date(#{createtime1},'%Y-%m-%d %H:%i:%s'),INTERVAL 1 DAY)
					</if>
					<if test="channelid!=null and channelid!=''">
						and sps.channelid=#{channelid}
					</if>
				</where>
				GROUP BY
					sps.spid,
					sps.channelid,
					sps.stat_time,
					sps.province
				having sum(ifnull( sps.arrive_succ, 0 ))+sum(ifnull( sps.submit_succ, 0 )) +
					sum(ifnull( sps.submit_fail, 0 )) -
					sum(ifnull( sps.arrive_fail, 0 )) -
					sum(ifnull( sps.arrive_succ, 0 )) &gt;= 0
				) sg left join sms_sp_price spp on
				spp.spid = sg.spid and sg.stat_time =spp.createtime
				left join sms_channel_price scp on
				scp.channelid = sg.channelid and sg.stat_time = scp.createtime
				where scp.province is not null
		) pr inner join sms_sp_info sp on pr.spid=sp.id
			<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
		sp.id,sp.sp_name,sp.commission_price,sp.sp_type,pr.province
		<if test="queryType=='spchannel'">
			,pr.channelid
		</if>
		<if test="ismon==1">
			,pr.stat_time
			<if test="queryType=='sp'">
				,pr.sprice
			</if>
			<if test="queryType=='spchannel'">
				,pr.sprice,pr.cprice
			</if>
		</if>
		order by sum( pr.succ ) desc
   </select>



    <select id="listPagePriceChannel" resultType="cn.roadm.bo.PriceRecord">
   		SELECT
   			sc.id channelid,
			sc.channel_name,
			sum( pr.income ) income,
			sum( pr.cost ) cost,
			sum(pr.un_income) un_income,
			sum(pr.un_cost) un_cost,
			ifnull( sum( pr.succ ), 0 ) num,
			sum(pr.unkonw) unknown,
			pr.province
			<if test="ismon==1">
				,pr.stat_time,pr.cprice
			</if>

		FROM
			(
			SELECT
				sg.*,
				if(sp.noProfit>0,ifnull( scp.price, 0 )* sg.succ,ifnull( spp.price, 0 )* sg.succ) income,
				if(sp.noProfit>0,ifnull( scp.price, 0 )* sg.unkonw,ifnull( spp.price, 0 )* sg.unkonw) un_income,
				scp.price cprice,
				spp.price sprice,
				ifnull( scp.price, 0 )* sg.succ cost,
				ifnull( scp.price, 0 )* sg.unkonw un_cost,
				scp.province
			FROM
				(
				SELECT
					sum(
					ifnull( sps.arrive_succ, 0 )) succ,
					sum(ifnull( sps.submit_succ, 0 )) +
					sum(ifnull( sps.submit_fail, 0 )) -
					sum(ifnull( sps.arrive_fail, 0 )) -
					sum(ifnull( sps.arrive_succ, 0 )) unkonw,
					sps.spid,
					sps.channelid,
					sps.stat_time,
					sps.province pro
				FROM
					sms_sp_province_summary sps
				<where>
					<if test="createtime!=null and createtime!=''">
						and sps.stat_time &gt;= #{createtime}
					</if>
					<if test="createtime1!=null and createtime1!=''">
						and sps.stat_time &lt; DATE_ADD(str_to_date(#{createtime1},'%Y-%m-%d %H:%i:%s'),INTERVAL 1 DAY)
					</if>
					<if test="channelid!=null and channelid!=''">
						and sps.channelid=#{channelid}
					</if>
				</where>
				GROUP BY
					sps.spid,
					sps.channelid,
					sps.stat_time,
					sps.province
				having sum(ifnull( sps.arrive_succ, 0 ))+sum(ifnull( sps.submit_succ, 0 )) +
					sum(ifnull( sps.submit_fail, 0 )) -
					sum(ifnull( sps.arrive_fail, 0 )) -
					sum(ifnull( sps.arrive_succ, 0 )) &gt;= 0

				) sg left join sms_sp_price spp on
				spp.spid = sg.spid and sg.stat_time =spp.createtime
				left join sms_channel_price scp on
				scp.channelid = sg.channelid and sg.stat_time = scp.createtime
				left join sms_sp_info sp on sg.spid=sp.id
				where scp.province is null
				UNION ALL
				SELECT
				sg.*,
				if(sp.noProfit>0,ifnull( scp.provinceNetPrice, 0 )* sg.succ,ifnull( spp.provinceNetPrice, 0 )* sg.succ) income,
				if(sp.noProfit>0,ifnull( scp.provinceNetPrice, 0 )* sg.unkonw,ifnull( spp.provinceNetPrice, 0 )* sg.unkonw) un_income,
				scp.price provinceNetPrice,
				spp.price provinceNetPrice,
				ifnull( scp.provinceNetPrice, 0 )* sg.succ cost,
				ifnull( scp.provinceNetPrice, 0 )* sg.unkonw un_cost,
				scp.province
			FROM
				(
				SELECT
					sum(
					ifnull( sps.arrive_succ, 0 )) succ,
					sum(ifnull( sps.submit_succ, 0 )) +
					sum(ifnull( sps.submit_fail, 0 )) -
					sum(ifnull( sps.arrive_fail, 0 )) -
					sum(ifnull( sps.arrive_succ, 0 )) unkonw,
					sps.spid,
					sps.channelid,
					sps.stat_time,
					sps.province pro
				FROM
					sms_sp_province_summary sps
				<where>
					<if test="createtime!=null and createtime!=''">
						and sps.stat_time &gt;= #{createtime}
					</if>
					<if test="createtime1!=null and createtime1!=''">
						and sps.stat_time &lt; DATE_ADD(str_to_date(#{createtime1},'%Y-%m-%d %H:%i:%s'),INTERVAL 1 DAY)
					</if>
					<if test="channelid!=null and channelid!=''">
						and sps.channelid=#{channelid}
					</if>
				</where>
				GROUP BY
					sps.spid,
					sps.channelid,
					sps.stat_time,
					sps.province
				having sum(ifnull( sps.arrive_succ, 0 ))+sum(ifnull( sps.submit_succ, 0 )) +
					sum(ifnull( sps.submit_fail, 0 )) -
					sum(ifnull( sps.arrive_fail, 0 )) -
					sum(ifnull( sps.arrive_succ, 0 )) &gt;= 0

				) sg left join sms_sp_price spp on
				spp.spid = sg.spid and sg.stat_time =spp.createtime
				left join sms_channel_price scp on
				scp.channelid = sg.channelid and sg.stat_time = scp.createtime
				left join sms_sp_info sp on sg.spid=sp.id
				where scp.province is not null
		) pr inner join sms_send_channel_info sc on pr.channelid=sc.id
			<where>
				<if test="channelid!=null and channelid!=''">
					and sc.id=#{channelid}
				</if>
			</where>
		GROUP BY
		sc.id,sc.channel_name,pr.province
		<if test="ismon==1">
			,pr.stat_time,pr.cprice
		</if>
		order by sum( pr.succ ) desc
   </select>
   <select id="listPageTaskDetailByContent"  parameterType="TaskDetailInfo" 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.channelid,
			a1.`STATUS`,
			a1.res_content,
            a1.otype,
			b1.result,
			b1.stat_desc,
			b1.arrive_time,
            b1.SIZES,
            b1.NUM
		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.otype,
				a.`STATUS`,
                a.SIZES
			FROM
				sms_submit a
			<where>
				<if test="content!=null and content!=''">
					AND a.RES_CONTENT LIKE concat('%',#{content},'%')
				</if>
				<if test="mdn!=null and mdn!=''">
                    <choose>
                        <when test='mdn.toString().contains("_")'>
                            and a.mdn like #{mdn}
                        </when>
                        <otherwise>
                            and a.mdn=#{mdn}
                        </otherwise>
                    </choose>
	            </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="timeType == 0">
                    <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%H%i%s'), '000000')
                    </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 1 DAY)
                        and a.taskid &lt; CONCAT(DATE_FORMAT(#{endtime},'%y%m%d%H%i%s'), '000000')
                    </if>
                </if>
                <if test="timeType == 1">
                    <if test="createtime!=null and createtime!=''">
                        and a.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d %H:%i:%s')
                        and a.send_time &gt;= #{createtime}
                    </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 1 DAY)
                        and a.send_time &lt; #{endtime}
                    </if>
                </if>
	            <if test="otype !=null and otype!=''">
	            	and a.otype=#{otype}
	            </if>
                <if test="lsms != null and lsms == 1">
                    and a.sizes = 1
                </if>
                <if test="lsms != null and lsms == 2">
                    and a.sizes > 1
                </if>
                <if test="province!=null and province!=''">
                	and a.province=#{province}
                </if>
                <if test="fixedTelephone!=null and fixedTelephone!=''">
                    and a.CALLMDN like CONCAT(#{fixedTelephone},'%')
                </if>
                <if test="areaCode!=null and areaCode!=''">
                    and a.CALLMDN like CONCAT(#{areaCode},'%')
                </if>
			</where>
			) a1,
			(
			SELECT
				b.SP_ID,
				b.taskid,
				b.mdn,
				b.num,
				b.STAT_DESC,
				b.CHANNELID,
				b.RESULT result,
				b.arrive_time,
                b.SIZES

			FROM
				sms_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="timeType == 0">
                    <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%H%i%s'), '000000')
                    </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 3 DAY)
                        and b.taskid &lt; CONCAT(DATE_FORMAT(#{endtime},'%y%m%d%H%i%s'), '000000')
                    </if>
                </if>
                <if test="timeType == 1">
                    <if test="createtime!=null and createtime!=''">
                        and b.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d %H:%i:%s')
                        and b.res_content &gt;= str_to_date(#{createtime},'%Y-%m-%d %H:%i:%s')
                    </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 3 DAY)
                        and b.res_content &lt; str_to_date(#{endtime},'%Y-%m-%d %H:%i:%s')
                    </if>
                </if>
	            <if test="otype !=null and otype!=''">
	            	and b.otype=#{otype}
	            </if>
                <if test="lsms != null and lsms == 1">
                    and b.sizes = 1
                </if>
                <if test="lsms != null and lsms == 2">
                    and b.sizes > 1
                </if>
			</where>
			) b1,sms_sp_info sp,(select CHANNEL_NAME,id from sms_send_channel_info union all select CHANNEL_NAME,id from mms_send_channel_info) as 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>
            <if test="sp_saler!=null and sp_saler!='' and sp_saler!='undefined'">
                and sp.sp_saler =#{sp_saler}
            </if>
            <if test="salerList!=null and salerList.size()>0">
                and sp.sp_saler in
                <foreach collection="salerList"  index="index"  item="item" open="(" separator="," close=")">
                   '${item}'
                </foreach>
            </if>
            <if test="managerId != null and managerId != ''">
                and sc.business_manager in (select ifnull(business,0) from business_manager where managerId =  #{managerId}) and sc.business_manager != ''
            </if>
            <if test="businessManager != null and businessManager != ''">
                and sc.business_manager = #{businessManager}
            </if>
   </select>


   <select id="getPriceRecord" resultType="cn.roadm.bo.PriceRecord">
		SELECT
   			sp.id spid,
			sp.sp_name,
			sp.sp_type,
			sp.commission_price,
			sp.noProfit,
			sum( pr.income ) income,
			sum( pr.cost ) cost,
			sum(pr.un_income) un_income,
			sum(pr.un_cost) un_cost,
			ifnull( sum( pr.succ ), 0 ) num,
			sum(pr.unkonw) unknown,
			pr.province
			<if test="queryType=='spchannel'">
				,pr.channelid
			</if>
			<if test="ismon==1">
				,pr.stat_time
				<if test="queryType=='sp'">
					,pr.sprice
				</if>
				<if test="queryType=='spchannel'">
					,pr.sprice,pr.cprice
				</if>
			</if>
		FROM
			(
			SELECT
				sg.*,
				ifnull( spp.price, 0 )* sg.succ income,
				ifnull( spp.price, 0 )* sg.unkonw un_income,
				scp.price cprice,
				spp.price sprice,
				ifnull( scp.price, 0 )* sg.succ cost,
				ifnull( scp.price, 0 )* sg.unkonw un_cost,
				scp.province
			FROM
				(
				SELECT
					sum(
					ifnull( sps.arrive_succ, 0 )) succ,
					sum(ifnull( sps.submit_succ, 0 )) +
					sum(ifnull( sps.submit_fail, 0 )) -
					sum(ifnull( sps.arrive_fail, 0 )) -
					sum(ifnull( sps.arrive_succ, 0 )) unkonw,
					sps.spid,
					sps.channelid,
					sps.stat_time,
					sps.province pro
				FROM
					sms_sp_province_summary sps
				<where>
					<if test="createtime!=null and createtime!=''">
						and sps.stat_time &gt;= #{createtime}
					</if>
					<if test="createtime1!=null and createtime1!=''">
						and sps.stat_time &lt; DATE_ADD(str_to_date(#{createtime1},'%Y-%m-%d %H:%i:%s'),INTERVAL 1 DAY)
					</if>
					<if test="channelid!=null and channelid!=''">
						and sps.channelid=#{channelid}
					</if>
				</where>
				GROUP BY
					sps.spid,
					sps.channelid,
					sps.stat_time,
					sps.province
				having sum(ifnull( sps.arrive_succ, 0 ))+sum(ifnull( sps.submit_succ, 0 )) +
					sum(ifnull( sps.submit_fail, 0 )) -
					sum(ifnull( sps.arrive_fail, 0 )) -
					sum(ifnull( sps.arrive_succ, 0 )) &gt;= 0
				) sg left join sms_sp_price spp on
				spp.spid = sg.spid and sg.stat_time =spp.createtime
				left join sms_channel_price scp on
				scp.channelid = sg.channelid and sg.stat_time = scp.createtime
				where scp.province is null
				UNION ALL
				SELECT
				sg.*,
				ifnull( spp.provinceNetPrice, 0 )* sg.succ income,
				ifnull( spp.provinceNetPrice, 0 )* sg.unkonw un_income,
				scp.provinceNetPrice cprice,
				spp.provinceNetPrice sprice,
				ifnull( scp.provinceNetPrice, 0 )* sg.succ cost,
				ifnull( scp.provinceNetPrice, 0 )* sg.unkonw un_cost,
				scp.province
			FROM
				(
				SELECT
					sum(
					ifnull( sps.arrive_succ, 0 )) succ,
					sum(ifnull( sps.submit_succ, 0 )) +
					sum(ifnull( sps.submit_fail, 0 )) -
					sum(ifnull( sps.arrive_fail, 0 )) -
					sum(ifnull( sps.arrive_succ, 0 )) unkonw,
					sps.spid,
					sps.channelid,
					sps.stat_time,
					sps.province pro
				FROM
					sms_sp_province_summary sps
				<where>
					<if test="createtime!=null and createtime!=''">
						and sps.stat_time &gt;= #{createtime}
					</if>
					<if test="createtime1!=null and createtime1!=''">
						and sps.stat_time &lt; DATE_ADD(str_to_date(#{createtime1},'%Y-%m-%d %H:%i:%s'),INTERVAL 1 DAY)
					</if>
					<if test="channelid!=null and channelid!=''">
						and sps.channelid=#{channelid}
					</if>
				</where>
				GROUP BY
					sps.spid,
					sps.channelid,
					sps.stat_time,
					sps.province
				having sum(ifnull( sps.arrive_succ, 0 ))+sum(ifnull( sps.submit_succ, 0 )) +
					sum(ifnull( sps.submit_fail, 0 )) -
					sum(ifnull( sps.arrive_fail, 0 )) -
					sum(ifnull( sps.arrive_succ, 0 )) &gt;= 0
				) sg left join sms_sp_price spp on
				spp.spid = sg.spid and sg.stat_time =spp.createtime
				left join sms_channel_price scp on
				scp.channelid = sg.channelid and sg.stat_time = scp.createtime
				where scp.province is not null
		) pr inner join sms_sp_info sp on pr.spid=sp.id
			<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
		sp.id,sp.sp_name,sp.commission_price,sp.sp_type,pr.province
		<if test="queryType=='spchannel'">
			,pr.channelid
		</if>
		<if test="ismon==1">
			,pr.stat_time
			<if test="queryType=='sp'">
				,pr.sprice
			</if>
			<if test="queryType=='spchannel'">
				,pr.sprice,pr.cprice
			</if>
		</if>
   </select>

   <select id="getPriceChannel" resultType="cn.roadm.bo.PriceRecord">
   		SELECT
   			sc.id channelid,
			sc.channel_name,
			sum( pr.income ) income,
			sum( pr.cost ) cost,
			sum(pr.un_income) un_income,
			sum(pr.un_cost) un_cost,
			ifnull( sum( pr.succ ), 0 ) num,
			sum(pr.unkonw) unknown,
			pr.province
			<if test="ismon==1">
				,pr.stat_time,pr.cprice
			</if>

		FROM
			(
			SELECT
				sg.*,
				if(sp.noProfit>0,ifnull( scp.price, 0 )* sg.succ,ifnull( spp.price, 0 )* sg.succ) income,
				if(sp.noProfit>0,ifnull( scp.price, 0 )* sg.unkonw,ifnull( spp.price, 0 )* sg.unkonw) un_income,
				scp.price cprice,
				spp.price sprice,
				ifnull( scp.price, 0 )* sg.succ cost,
				ifnull( scp.price, 0 )* sg.unkonw un_cost,
				scp.province
			FROM
				(
				SELECT
					sum(
					ifnull( sps.arrive_succ, 0 )) succ,
					sum(ifnull( sps.submit_succ, 0 )) +
					sum(ifnull( sps.submit_fail, 0 )) -
					sum(ifnull( sps.arrive_fail, 0 )) -
					sum(ifnull( sps.arrive_succ, 0 )) unkonw,
					sps.spid,
					sps.channelid,
					sps.stat_time,
					sps.province pro
				FROM
					sms_sp_province_summary sps
				<where>
					<if test="createtime!=null and createtime!=''">
						and sps.stat_time &gt;= #{createtime}
					</if>
					<if test="createtime1!=null and createtime1!=''">
						and sps.stat_time &lt; DATE_ADD(str_to_date(#{createtime1},'%Y-%m-%d %H:%i:%s'),INTERVAL 1 DAY)
					</if>
					<if test="channelid!=null and channelid!=''">
						and sps.channelid=#{channelid}
					</if>
				</where>
				GROUP BY
					sps.spid,
					sps.channelid,
					sps.stat_time,
					sps.province
				having sum(ifnull( sps.arrive_succ, 0 ))+sum(ifnull( sps.submit_succ, 0 )) +
					sum(ifnull( sps.submit_fail, 0 )) -
					sum(ifnull( sps.arrive_fail, 0 )) -
					sum(ifnull( sps.arrive_succ, 0 )) &gt;= 0

				) sg left join sms_sp_price spp on
				spp.spid = sg.spid and sg.stat_time =spp.createtime
				left join sms_channel_price scp on
				scp.channelid = sg.channelid and sg.stat_time = scp.createtime
				left join sms_sp_info sp on sg.spid=sp.id
				where scp.province is null
				UNION ALL
				SELECT
				sg.*,
				if(sp.noProfit>0,ifnull( scp.provinceNetPrice, 0 )* sg.succ,ifnull( spp.provinceNetPrice, 0 )* sg.succ) income,
				if(sp.noProfit>0,ifnull( scp.provinceNetPrice, 0 )* sg.unkonw,ifnull( spp.provinceNetPrice, 0 )* sg.unkonw) un_income,
				scp.price provinceNetPrice,
				spp.price provinceNetPrice,
				ifnull( scp.provinceNetPrice, 0 )* sg.succ cost,
				ifnull( scp.provinceNetPrice, 0 )* sg.unkonw un_cost,
				scp.province
			FROM
				(
				SELECT
					sum(
					ifnull( sps.arrive_succ, 0 )) succ,
					sum(ifnull( sps.submit_succ, 0 )) +
					sum(ifnull( sps.submit_fail, 0 )) -
					sum(ifnull( sps.arrive_fail, 0 )) -
					sum(ifnull( sps.arrive_succ, 0 )) unkonw,
					sps.spid,
					sps.channelid,
					sps.stat_time,
					sps.province pro
				FROM
					sms_sp_province_summary sps
				<where>
					<if test="createtime!=null and createtime!=''">
						and sps.stat_time &gt;= #{createtime}
					</if>
					<if test="createtime1!=null and createtime1!=''">
						and sps.stat_time &lt; DATE_ADD(str_to_date(#{createtime1},'%Y-%m-%d %H:%i:%s'),INTERVAL 1 DAY)
					</if>
					<if test="channelid!=null and channelid!=''">
						and sps.channelid=#{channelid}
					</if>
				</where>
				GROUP BY
					sps.spid,
					sps.channelid,
					sps.stat_time,
					sps.province
				having sum(ifnull( sps.arrive_succ, 0 ))+sum(ifnull( sps.submit_succ, 0 )) +
					sum(ifnull( sps.submit_fail, 0 )) -
					sum(ifnull( sps.arrive_fail, 0 )) -
					sum(ifnull( sps.arrive_succ, 0 )) &gt;= 0

				) sg left join sms_sp_price spp on
				spp.spid = sg.spid and sg.stat_time =spp.createtime
				left join sms_channel_price scp on
				scp.channelid = sg.channelid and sg.stat_time = scp.createtime
				left join sms_sp_info sp on sg.spid=sp.id
				where scp.province is not null
		) pr inner join sms_send_channel_info sc on pr.channelid=sc.id
			<where>
				<if test="channelid!=null and channelid!=''">
					and sc.id=#{channelid}
				</if>
			</where>
		GROUP BY
		sc.id,sc.channel_name,pr.province
		<if test="ismon==1">
			,pr.stat_time,pr.cprice
		</if>
   </select>

   <select id="searchPageTaskDetailByContent"  parameterType="TaskDetailInfo" 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 ,
            a1.otype,
            b1.result,
            b1.STAT_DESC stat_desc,
			b1.arrive_time
		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.otype,
                a.SIZES
			FROM
				sms_submit a
			<where>
				<if test="content!=null and content!=''">
					AND a.RES_CONTENT LIKE concat('%',#{content},'%')
				</if>
				<if test="mdn!=null and mdn!=''">
					<choose>
		                <when test="mdn.toString().length()&lt;11">
		                   and a.mdn like CONCAT('%',#{mdn},'%')
		                </when>
		                <otherwise>
		                   and a.mdn=#{mdn}
		                </otherwise>
	            	</choose>
	            </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="timeType == 0">
                    <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%H%i%s'), '000000')
                    </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 1 DAY)
                        and a.taskid &lt; CONCAT(DATE_FORMAT(#{endtime},'%y%m%d%H%i%s'), '000000')
                    </if>
                </if>
                <if test="timeType == 1">
                    <if test="createtime!=null and createtime!=''">
                        and a.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d %H:%i:%s')
                        and a.send_time &gt;= #{createtime}
                    </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 1 DAY)
                        and a.send_time &lt; #{endtime}
                    </if>
                </if>
	            <if test="otype !=null and otype!=''">
	            	and a.otype=#{otype}
	            </if>
                <if test="lsms != null and lsms == 1">
                    and a.sizes = 1
                </if>
                <if test="lsms != null and lsms == 2">
                    and a.sizes > 1
                </if>
                <if test="province !=null and province !=''">
                	and a.province=#{province}
                </if>
                <if test="fixedTelephone!=null and fixedTelephone!=''">
                    and a.CALLMDN like CONCAT(#{fixedTelephone},'%')
                </if>
                <if test="areaCode!=null and areaCode!=''">
                    and a.CALLMDN like CONCAT(#{areaCode},'%')
                </if>
			</where>
			) a1,
			(
			SELECT
				b.SP_ID,
				b.taskid,
				b.mdn,
				b.num,
				b.STAT_DESC,
				b.CHANNELID,
				b.RESULT result,
				b.arrive_time,
                b.SIZES
			FROM
				sms_arrive b
			<where>
				<if test="stat_desc!=null and stat_desc!=''">
	                and b.stat_desc=#{stat_desc}
	            </if>
	            <if test="mdn!=null and mdn!=''">
	                <choose>
		                <when test="mdn.toString().length()&lt;11">
		                   and b.mdn like CONCAT('%',#{mdn},'%')
		                </when>
		                <otherwise>
		                   and b.mdn=#{mdn}
		                </otherwise>
	            	</choose>
	            </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="timeType == 0">
                    <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%H%i%s'), '000000')
                    </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 1 DAY)
                        and b.taskid &lt; CONCAT(DATE_FORMAT(#{endtime},'%y%m%d%H%i%s'), '000000')
                    </if>
                </if>
                <if test="timeType == 1">
                    <if test="createtime!=null and createtime!=''">
                        and b.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d %H:%i:%s')
                        and b.res_content &gt;= #{createtime}
                    </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 1 DAY)
                        and b.res_content &lt; #{endtime}
                    </if>
                </if>
	            <if test="otype !=null and otype!=''">
	            	and b.otype=#{otype}
	            </if>
                <if test="lsms != null and lsms == 1">
                    and b.sizes = 1
                </if>
                <if test="lsms != null and lsms == 2">
                    and b.sizes > 1
                </if>
			</where>
			) b1,sms_sp_info sp, (select CHANNEL_NAME,id from sms_send_channel_info union all select CHANNEL_NAME,id from mms_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>
            <if test="sp_saler!=null and sp_saler!='' and sp_saler!='undefined'">
                and sp.sp_saler =#{sp_saler}
            </if>
            <if test="salerList!=null and salerList.size()>0">
                and sp.sp_saler in
                <foreach collection="salerList" index="index" item="item" open="(" separator="," close=")">
                   '${item}'
                </foreach>
            </if>
            <if test="managerId != null and managerId != ''">
                and sc.business_manager in (select ifnull(business,0) from business_manager where managerId =  #{managerId}) and sc.business_manager != ''
            </if>
            <if test="businessManager != null and businessManager != ''">
                and sc.business_manager = #{businessManager}
            </if>
        </where>
   </select>

    <select id="taskDetailByContentCount" parameterType="TaskDetailInfo" resultType="java.lang.Long">
        SELECT count(a1.id) 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.otype,
        a.SIZES
        FROM
        sms_submit a
        <where>
            <if test="content!=null and content!=''">
                AND a.RES_CONTENT LIKE concat('%',#{content},'%')
            </if>
            <if test="mdn!=null and mdn!=''">
                <choose>
                    <when test="mdn.toString().length()&lt;11">
                        and a.mdn like CONCAT('%',#{mdn},'%')
                    </when>
                    <otherwise>
                        and a.mdn=#{mdn}
                    </otherwise>
                </choose>
            </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="timeType == 0">
                <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%H%i%s'), '000000')
                </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 1 DAY)
                    and a.taskid &lt; CONCAT(DATE_FORMAT(#{endtime},'%y%m%d%H%i%s'), '000000')
                </if>
            </if>
            <if test="timeType == 1">
                <if test="createtime!=null and createtime!=''">
                    and a.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d %H:%i:%s')
                    and a.send_time &gt;= #{createtime}
                </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 1 DAY)
                    and a.send_time &lt; #{endtime}
                </if>
            </if>
            <if test="otype !=null and otype!=''">
                and a.otype=#{otype}
            </if>
            <if test="lsms != null and lsms == 1">
                and a.sizes = 1
            </if>
            <if test="lsms != null and lsms == 2">
                and a.sizes > 1
            </if>
            <if test="province !=null and province !=''">
                and a.province=#{province}
            </if>
            <if test="fixedTelephone!=null and fixedTelephone!=''">
                and a.CALLMDN like CONCAT(#{fixedTelephone},'%')
            </if>
            <if test="areaCode!=null and areaCode!=''">
                and a.CALLMDN like CONCAT(#{areaCode},'%')
            </if>
        </where>
        ) a1,
        (
        SELECT
        b.SP_ID,
        b.taskid,
        b.mdn,
        b.num,
        b.STAT_DESC,
        b.CHANNELID,
        b.RESULT result,
        b.arrive_time,
        b.SIZES
        FROM
        sms_arrive b
        <where>
            <if test="stat_desc!=null and stat_desc!=''">
                and b.stat_desc=#{stat_desc}
            </if>
            <if test="mdn!=null and mdn!=''">
                <choose>
                    <when test="mdn.toString().length()&lt;11">
                        and b.mdn like CONCAT('%',#{mdn},'%')
                    </when>
                    <otherwise>
                        and b.mdn=#{mdn}
                    </otherwise>
                </choose>
            </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="timeType == 0">
                <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%H%i%s'), '000000')
                </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 3 DAY)
                    and b.taskid &lt; CONCAT(DATE_FORMAT(#{endtime},'%y%m%d%H%i%s'), '000000')
                </if>
            </if>
            <if test="timeType == 1">
                <if test="createtime!=null and createtime!=''">
                    and b.create_time&gt;=str_to_date(#{createtime},'%Y-%m-%d %H:%i:%s')
                    and b.res_content &gt;= #{createtime}
                </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 3 DAY)
                    and b.res_content &lt; #{endtime}
                </if>
            </if>
            <if test="otype !=null and otype!=''">
                and b.otype=#{otype}
            </if>
            <if test="lsms != null and lsms == 1">
                and b.sizes = 1
            </if>
            <if test="lsms != null and lsms == 2">
                and b.sizes > 1
            </if>
        </where>
        ) b1,sms_sp_info sp,(select CHANNEL_NAME,id from sms_send_channel_info union all select CHANNEL_NAME,id from mms_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>
            <if test="sp_saler!=null and sp_saler!='' and sp_saler!='undefined'">
                and sp.sp_saler =#{sp_saler}
            </if>
            <if test="salerList!=null and salerList.size()>0">
                and sp.sp_saler in
                <foreach collection="salerList" index="index" item="item" open="(" separator="," close=")">
                   '${item}'
                </foreach>
            </if>
            <if test="managerId != null and managerId != ''">
                and sc.business_manager in (select ifnull(business,0) from business_manager where managerId =  #{managerId}) and sc.business_manager != ''
            </if>
            <if test="businessManager != null and businessManager != ''">
                and sc.business_manager = #{businessManager}
            </if>
        </where>
   </select>

    <select id="queryExportSpTaskInfoCount" resultType="integer">
        select count(1)  from sms_send_task tk, sms_sp_info sp where sp.id = tk.sp_id
        <if test="spName != null and spName != ''">
            and sp.sp_name like CONCAT('%',#{spName},'%')
        </if>
        <if test="content != null and content != ''">
            and tk.content like CONCAT('%',#{content},'%')
        </if>
        <if test="spId != null and spId > 0">
            and tk.sp_id=#{spId}
        </if>
        <if test="saleName != null and saleName != ''">
            and sp.sp_saler =#{saleName}
        </if>
        <if test="taskId != null and taskId > 0">
            and tk.id=#{taskId}
        </if>
        <if test="sendType != null and sendType != ''">
            and tk.send_type=#{sendType}
        </if>
        <if test="taskType != null and taskType != ''">
            and tk.task_type=#{taskType}
        </if>
        <if test="startTime != null and startTime != ''">
            and tk.createtime&gt;=str_to_date(#{startTime},'%Y-%m-%d')
        </if>
        <if test="endTime != null and endTIme != ''">
            and tk.createtime&lt;=DATE_ADD(str_to_date(#{endTIme},'%Y-%m-%d'),INTERVAL 1 DAY)
        </if>
    </select>
    <select id="queryExportSpTaskInfo" resultType="map">
        select tk.id, tk.sp_id, sp.sp_name, tk.content, tk.createtime, tk.total, tk.allnumber, tk.unicomnumber, tk.mobilenumber,
        tk.telecomnumber, tk.succ, tk.fail, tk.arrive_succ,  tk.arrive_fail, tk.task_type, tk.status, tk.endtime,  (tk.allnumber-tk.arrive_succ-tk.arrive_fail) unRecMsgNum,
        tk.send_type  from sms_send_task tk, sms_sp_info sp where sp.id = tk.sp_id
        <if test="spName != null and spName != ''">
            and sp.sp_name like CONCAT('%',#{spName},'%')
        </if>
        <if test="content != null and content != ''">
            and tk.content like CONCAT('%',#{content},'%')
        </if>
        <if test="spId != null and spId > 0">
            and tk.sp_id=#{spId}
        </if>
        <if test="saleName != null and saleName != ''">
            and sp.sp_saler =#{saleName}
        </if>
        <if test="taskId != null and taskId > 0">
            and tk.id=#{taskId}
        </if>
        <if test="sendType != null and sendType != ''">
            and tk.send_type=#{sendType}
        </if>
        <if test="taskType != null and taskType != ''">
            and tk.task_type=#{taskType}
        </if>
        <if test="startTime != null and startTime != ''">
            and tk.createtime&gt;=str_to_date(#{startTime},'%Y-%m-%d')
        </if>
        <if test="endTime != null and endTIme != ''">
            and
            tk.createtime&lt;=DATE_ADD(str_to_date(#{endTIme},'%Y-%m-%d'),INTERVAL 1 DAY)
        </if>
        <if test="endId != null">
            and tk.id &lt;  #{endId}
        </if>
        order by tk.id desc

        <if test="exportExcelSize != null ">
            limit #{exportExcelSize}
        </if>
    </select>
    <select id="queryExportSpTaskApiInfoCount" resultType="integer">
        select count(1) where sp.id = tk.sp_id
        <if test="spName != null and spName != ''">
            and sp.sp_name like CONCAT('%', #{spName} ,'%')
        </if>
        <if test="spId != null and spId > 0">
            and tk.sp_id = #{spId}
        </if>
        <if test="saleName != null and saleName != ''">
            and sp.sp_saler = #{saleName}
        </if>
        <if test="taskId != null and taskId > 0">
            and tk.id = #{taskId}
        </if>
        <if test="startTime != null and startTime != ''">
            and tk.createtime&gt;=str_to_date(#{startTime},'%Y-%m-%d')
        </if>

        <if test="endTime != null and endTime != ''">
            and tk.createtime&lt;=DATE_ADD(str_to_date(#{endTime},'%Y-%m-%d'),INTERVAL 1 DAY)
        </if>
        order by tk.id desc
    </select>
    <select id="queryExportSpInfoApi" resultType="map">
        select tk.id, tk.sp_id,  sp.sp_name, tk.content, tk.createtime, tk.total, tk.allnumber, tk.unicomnumber, tk.mobilenumber,
        tk.telecomnumber, tk.INTERNATIONALNUMBER from sms_send_task_api tk, sms_sp_info sp
        where sp.id = tk.sp_id
        <if test="spName != null and spName != ''">
            and sp.sp_name like CONCAT('%', #{spName} ,'%')
        </if>
        <if test="spId != null and spId > 0">
            and tk.sp_id = #{spId}
        </if>
        <if test="saleName != null and saleName != ''">
            and sp.sp_saler = #{saleName}
        </if>
        <if test="taskId != null and taskId > 0">
            and tk.id = #{taskId}
        </if>
        <if test="startTime != null and startTime != ''">
            and tk.createtime&gt;=str_to_date(#{startTime},'%Y-%m-%d')
        </if>

        <if test="endTime != null and endTime != ''">
            and tk.createtime&lt;=DATE_ADD(str_to_date(#{endTime},'%Y-%m-%d'),INTERVAL 1 DAY)
        </if>
        <if test="endId != null">
            and tk.id &lt;  #{endId}
        </if>
        order by tk.id desc

        <if test="exportExcelSize != null ">
            limit #{exportExcelSize}
        </if>
    </select>
    <select id="listPageGetBlackNum" resultType="cn.roadm.bo.BlackPhoneSummary">
    	select bps.spid,bps.black_num,DATE_FORMAT(bps.stat_time, '%Y-%m-%d %H:%i:%s') stat_time,bps.black_type_id,bpt.blacklist_group_name from black_phone_summary bps,sms_black_phone_type bpt
    	<where>
    		bps.black_type_id=bpt.id
    		<if test="spid!=null and spid!=''">
    			and spid=#{spid}
    		</if>
    		<if test="createtime!=null and createtime!=''">
    			and stat_time &gt;= #{createtime}
    		</if>
    		<if test="createtime1!=null and createtime1!=''">
    			and stat_time &lt; date_add(#{createtime1},INTERVAL 1 DAY)
    		</if>
    		<if test="black_type_id!=null and black_type_id!=''">
    			and black_type_id=#{black_type_id}
    		</if>
    	</where>
        order by stat_time
    </select>

    <select id="getBlackNumCount" resultType="long">
    	select ifnull(sum(bps.black_num),0) from black_phone_summary bps,sms_black_phone_type bpt
    	<where>
    		bps.black_type_id=bpt.id
    		<if test="spid!=null and spid!=''">
    			and spid=#{spid}
    		</if>
    		<if test="createtime!=null and createtime!=''">
    			and stat_time &gt;= #{createtime}
    		</if>
    		<if test="createtime1!=null and createtime1!=''">
    			and stat_time &lt;date_add(#{createtime1},INTERVAL 1 DAY)
    		</if>
    		<if test="black_type_id!=null and black_type_id!=''">
    			and black_type_id=#{black_type_id}
    		</if>
    	</where>
    </select>


    <select id="getBlackNumCost" resultType="int">
    	SELECT ifnull(sum(black_count),0) from (select ifnull(sum(bps.black_num*bpt.price),0) black_count from black_phone_summary bps,sms_black_phone_type bpt,sms_sp_info sp
    	<where>
    		bps.black_type_id=bpt.id and bps.spid=sp.id and bpt.type=3
    		<if test="spid!=null and spid!=''">
	    		and bps.spid=#{spid}
    		</if>
    		<if test="createtime!=null and createtime!=''">
    			and bps.stat_time &gt;= #{createtime}
    		</if>
    		<if test="createtime1!=null and createtime1!=''">
    			and bps.stat_time &lt;date_add(#{createtime1},INTERVAL 1 DAY)
    		</if>
    		<if test="black_type_id!=null and black_type_id!=''">
    			and bps.black_type_id=#{black_type_id}
    		</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="sp_type!=null and sp_type>0">
				AND sp.sp_type =#{sp_type}
			</if>
            <if test="fullName!=null and fullName!=''">
					AND sp.eid = (select id from sms_enterprise where full_name=#{fullName} AND state = 0 )
            </if>
    		group by bps.spid) a
    	</where>
    </select>

    <select id="getAllRemoteBlackType" resultType="cn.roadm.bo.BlackPhoneType">
    	select id,blacklist_group_name from sms_black_phone_type where type=3
    </select>

    <select id="getAllAimRemoteIdInfoType" resultType="cn.roadm.bo.AimCheckApiSummary">
        select k.remote_id,k.local_id,a.name as local_name,a.spid as sp_id from kp_template_remote k left join aim_template_local a
        on k.local_id = a.id where k.local_id!='-1' and k.audit=1 and k.state = 0 and a.spid is not null
    </select>

    <select id="listPageGetAimCheckApiNum" resultType="cn.roadm.bo.AimCheckApiSummary">
        select ac.sp_id,ac.remote_id,ac.req_count,ac.succ_count,DATE_FORMAT(ac.time, '%Y-%m-%d %H:%i:%s') time,t.local_name,t.local_id from aim_check_api_summary ac
        left join (select k.remote_id,k.local_id,a.name as local_name,a.spid as sp_id from kp_template_remote k left join aim_template_local a
        on k.local_id = a.id where k.local_id!='-1' and k.audit=1) t on ac.sp_id = t.sp_id and ac.remote_id = t.remote_id
        where 1=1
        <if test="sp_id!=null and sp_id!=''">
            and ac.sp_id=#{sp_id}
        </if>
        <if test="createtime!=null and createtime!=''">
            and ac.time &gt;= #{createtime}
        </if>
        <if test="createtime1!=null and createtime1!=''">
            and ac.time &lt; date_add(#{createtime1},INTERVAL 1 DAY)
        </if>
        <if test="remote_id!=null and remote_id!=''">
            and ac.remote_id=#{remote_id}
        </if>
        order by ac.time desc

    </select>

    <select id="getAimCheckApiNumCount" resultType="cn.roadm.bo.AimCheckApiSummary">
        select ifnull(sum(req_count),0) as req_sum,ifnull(sum(succ_count),0) as succ_sum from aim_check_api_summary
        where 1=1
        <if test="sp_id!=null and sp_id!=''">
            and sp_id=#{sp_id}
        </if>
        <if test="createtime!=null and createtime!=''">
            and time &gt;= #{createtime}
        </if>
        <if test="createtime1!=null and createtime1!=''">
            and time &lt; date_add(#{createtime1},INTERVAL 1 DAY)
        </if>
        <if test="remote_id!=null and remote_id!=''">
            and remote_id=#{remote_id}
        </if>
    </select>

    <select id="queryRecentlyTaskContent" parameterType="TaskInfo" resultType="TaskInfo">
    </select>

    <select id="getSysTotalCityData" parameterType="TaskInfo" resultType="TaskInfo">
        SELECT
            CONCAT( Round( sum( spc.arrive_succ ) / sum( spc.submit_succ ) * 100, 2 ), '%' ) sp_succ_percent,
            sum( spc.submit_succ ) succ,
            sum( IFNULL( spc.submit_fail, 0 ) ) fail,
            sum( spc.arrive_succ ) arrive_succ,
            sum( spc.arrive_fail ) arrive_fail
        FROM
            `sms_sp_city_summary` spc,
            sms_sp_info sp
        <where>
            spc.spid = sp.id
            <if test="createTime!=null and createTime!=''">
                and spc.stat_time&gt;=str_to_date(#{createTime},'%Y-%m-%d')
            </if>
            <if test="createTime1!=null and createTime1!=''">
                and
                spc.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 spc.spid=#{sp_id}
            </if>
            <if test="type_channel!=null and type_channel!='' and channelid!=null and channelid >=0">
                and spc.channelid=#{channelid}
            </if>
        </where>
    </select>

    <select id="listPageSysPcoTaskCityTotal" parameterType="TaskInfo" resultType="TaskInfo">
        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_channel!=null and type_channel!=''">
            spc.channelid,
        </if>
        <if test="type_day!=null and type_day!=''">
            spc.stat_time,
        </if>
        sum( spc.submit_succ ) succ,
        sum( IFNULL( spc.submit_fail, 0 ) ) fail,
        sum( spc.arrive_succ ) arrive_succ,
        sum( spc.arrive_fail ) arrive_fail ,
        spc.city city_name
        FROM
            sms_sp_city_summary spc,sms_sp_info sp
        WHERE
        spc.spid=sp.id
        <if test="createTime!=null and createTime!=''">
            and spc.stat_time &gt;= str_to_date(#{createTime},'%Y-%m-%d')
        </if>
        <if test="createTime1!=null and createTime1!=''">
            and spc.stat_time &lt; DATE_ADD(str_to_date(#{createTime1},'%Y-%m-%d'),INTERVAL 1 DAY)
        </if>
        <if test="type_channel!=null and type_channel!='' and channelid!=null and channelid >=0">
            and spc.channelid=#{channelid}
        </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 spc.spid=#{sp_id}
        </if>
        <if test="city_name != null and city_name != ''">
            and spc.city = #{city_name}
        </if>
        <trim prefix="group by" suffixOverrides=",">
            spc.city,
            <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!=''">
                spc.channelid,
            </if>
            <if test="type_day!=null and type_day!=''">
                spc.stat_time,
            </if>
        </trim>
        order by sum(spc.submit_succ) desc
    </select>

    <select id="exportSysPcoTaskCityTotal" parameterType="TaskInfo" resultType="map">
        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_day!=null and type_day!=''">
            DATE_FORMAT(spc.stat_time,'%Y-%m-%d') STAT_TIME,
        </if>
        CONCAT( Round( sum( spc.arrive_succ ) / sum( spc.submit_succ ) * 100, 2 ), '%' ) SP_SUCC_PERCENT,
        sum( spc.submit_succ ) SUCC,
        sum( IFNULL( spc.submit_fail, 0 ) ) FAIL,
        sum( spc.arrive_succ ) ARRIVE_SUCC,
        sum( spc.arrive_fail ) ARRIVE_FAIL ,
        spc.city CITY_NAME
        FROM
        sms_sp_city_summary spc,sms_sp_info sp,sms_send_channel_info sc
        WHERE
        spc.spid=sp.id and spc.channelid = sc.id
        <if test="createTime!=null and createTime!=''">
            and spc.stat_time &gt;= str_to_date(#{createTime},'%Y-%m-%d')
        </if>
        <if test="createTime1!=null and createTime1!=''">
            and spc.stat_time &lt; DATE_ADD(str_to_date(#{createTime1},'%Y-%m-%d'),INTERVAL 1 DAY)
        </if>
        <if test="type_channel!=null and type_channel!='' and channelid!=null and channelid >=0">
            and spc.channelid=#{channelid}
        </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 spc.spid=#{sp_id}
        </if>
        <if test="city_name != null and city_name != ''">
            and spc.city = #{city_name}
        </if>
        <trim prefix="group by" suffixOverrides=",">
            spc.city,
            <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!=''">
                spc.channelid,
            </if>
            <if test="type_day!=null and type_day!=''">
                spc.stat_time,
            </if>
        </trim>
        order by sum(spc.submit_succ) desc
    </select>

    <insert id="addReplayRecord">
        insert into sms_reply_record(callmdn,mobile,content,reply_time,createtime,sp_id,status,channelid,SUBPORT) values
        <foreach collection="mdnList" item="item" index="index" separator=",">
            (#{replayData.replayCallMdn}, #{item.mdn}, #{item.content}, #{replayData.replayDateTime}, #{replayData.replayTime}, #{replayData.replaySpId},
            0, #{replayData.replayChannelId}, #{replayData.replayExtendNum})
        </foreach>
    </insert>

    <insert id="addSubmitReplayRecord">
        insert into sms_submit(callmdn,mdn,res_content,SEND_TIME,create_time,sp_id,status,channelid,num,sizes,taskid,MESSAGEID,RES_RESULT,RES_DESC,SIGN,OTYPE) values
        <foreach collection="list" item="item" index="index" separator="," >
            (#{item.replayCallMdn},#{item.mdn}, #{item.sendContent}, #{item.createTime}, #{item.time}, #{item.replaySpId},
            0, #{item.replayChannelId}, 0, 1, #{item.taskId}, 1, 0, '发送成功', #{item.sign}, #{item.otype})
        </foreach>
    </insert>

    <insert id="addArriveReplayRecord">
        insert into sms_arrive(callmdn,mdn,ARRIVE_TIME,create_time,sp_id,status,channelid,num,sizes,taskid,MESSAGEID,RESULT,STAT_DESC,SIGN,OTYPE) values
        <foreach collection="list" item="item" index="index" separator=",">
            (#{item.replayCallMdn}, #{item.mdn}, #{item.createTime}, #{item.time}, #{item.replaySpId},
            0, #{item.replayChannelId}, 0, 1, #{item.taskId}, 1, 0, 'DELIVRD', #{item.sign}, #{item.otype})
        </foreach>
    </insert>

    <update id="deleteReplayOne">
        update sms_reply_record set IS_DEL = 1 where ID = #{id}
    </update>

    <update id="updateTaskBookTime">
        update sms_crontab_send set BOOK_TIME = #{bookTime} where TASKID = #{id}
    </update>

    <update id="updateTaskBookTimeAndTaskId">
        update sms_crontab_send set BOOK_TIME = #{bookTime},TASKID = #{taskId} where TASKID = #{id}
    </update>

    <update id="rebackBookTaskAndTaskId">
        update sms_send_task set ID = #{taskId} where ID = #{id}
    </update>

    <update id="rebackBookTask">
        update sms_crontab_send set STATUS = 0 where TASKID = #{taskId}
    </update>

    <update id="rebackBookTask1">
        update sms_send_task set status = 0, DESCPTION = null where ID = #{taskId}
    </update>
     <select id="listPagePriceRecordNew" resultType="cn.roadm.bo.PriceRecord">
     select list.*
         <if test="queryType=='spchannel'">
             ,sas.clientid,c.loginname,spif.sp_saler
         </if>
         from(
     <if test="nettype &lt;= 0 ">
     	 SELECT
			sp.id spid,
			sp.sp_name,
            sp.eid as full_name,
			sp.sp_type,
			sp.commission_price,
			sp.noProfit,
			sum( pr.unkonw ) unknown,
			sum( pr.income ) income,
			sum( pr.cost ) cost,
			sum( pr.un_income ) un_income,
			sum( pr.un_cost ) un_cost,
			ifnull( sum( pr.succ ), 0 ) num,
			sum(ifnull( pr.fail, 0 )) fail,
			'全国' as province,
			0 as nettype,
			pr.otype
			<if test="queryType=='spchannel'">
				,pr.channelid
			</if>
            <choose>
                <when test="ismon==1">
                    ,DATE_FORMAT(pr.stat_time,'%Y-%m-%d') as stateTime
                    <if test="queryType=='sp'">
                        ,pr.sp_price sprice
                    </if>
                    <if test="queryType=='spchannel'">
                        ,pr.sp_price sprice,
                        pr.channel_price cprice
                    </if>
                </when>
                <when test="ismon==2">
                    , DATE_FORMAT(pr.stat_time,'%Y-%m') as stateTime
                    <if test="queryType=='sp'">
                        ,pr.sp_price sprice
                    </if>
                    <if test="queryType=='spchannel'">
                        ,pr.sp_price sprice,
                        pr.channel_price cprice
                    </if>
                </when>
            </choose>
		FROM
			(
			SELECT
				prs.* ,
					ifnull( prs.sp_price, 0 )* prs.succ income,
					ifnull( prs.sp_price, 0 )* prs.unkonw un_income,
					ifnull( prs.channel_price, 0 )* prs.succ cost,
					ifnull( prs.channel_price, 0 )* prs.unkonw un_cost

			FROM
				(
				SELECT
					sum(
					ifnull( sps.arrive_succ, 0 )) succ,
					sum(
					ifnull( sps.arrive_fail, 0 )) fail,
					sum(
						ifnull( sps.submit_succ, 0 )) + sum(
						ifnull( sps.submit_fail, 0 )) - sum(
						ifnull( sps.arrive_fail, 0 )) - sum(
						ifnull( sps.arrive_succ, 0 )) unkonw,
					sps.spid,
					sps.channelid,
					sps.stat_time,
					sps.sp_price,
					sps.channel_price,
					sps.otype
				FROM
					sms_sp_province_summary sps
				<where>
				     ifnull(sps.nettype,0)=0
						<if test="createtime!=null and createtime!=''">
							and sps.stat_time &gt;= #{createtime}
						</if>
						<if test="createtime1!=null and createtime1!=''">
							and sps.stat_time &lt; DATE_ADD(str_to_date(#{createtime1},'%Y-%m-%d %H:%i:%s'),INTERVAL 1 DAY)
						</if>
						<if test="channelid!=null and channelid!=''">
							and sps.channelid=#{channelid}
						</if>
						<if test="spid!=null and spid!=''">
							and sps.spid=#{spid}
						</if>
						<if test="otype!=null and otype>0">
							and sps.otype=#{otype}
						</if>
				</where>
				GROUP BY
					sps.spid,
					sps.channelid,
					sps.stat_time,
					sps.sp_price,
					sps.channel_price,
					sps.otype
					 ) as prs
			) pr inner join sms_sp_info sp ON pr.spid = sp.id
			<where>
				<if test="sp_type!=null and sp_type>0">
					AND sp.sp_type =#{sp_type}
				</if>
                <if test="star_level!=null and star_level>0">
                    and sp.star_level =#{star_level}
                </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>
                <if test="sp_saler!=null and sp_saler!=''">
                    and sp.sp_saler like CONCAT('%', #{sp_saler}, '%')
                </if>
                <if test="salerList!=null and salerList.size()>0">
                    and sp.sp_saler in
                    <foreach collection="salerList" index="index"  item="item" open="(" separator="," close=")">
                        '${item}'
                    </foreach>
                </if>
                <if test="full_name != null and full_name != ''">
                    and sp.eid = #{full_name}
                </if>
			</where>
			GROUP BY
			sp.id,
			sp.sp_name,
			sp.commission_price,
			sp.sp_type,
			sp.noProfit,
			pr.otype
			<if test="queryType=='spchannel'">
			,pr.channelid
			</if>
             <choose>
                 <when test="ismon==1">
                    ,stateTime
                    <if test="queryType=='sp'">
                        ,pr.sp_price
                    </if>
                    <if test="queryType=='spchannel'">
                        ,pr.sp_price,pr.channel_price
                    </if>
			    </when>
                <when test="ismon==2">
                    ,stateTime
                    <if test="queryType=='sp'">
                        ,pr.sp_price
                    </if>
                    <if test="queryType=='spchannel'">
                        ,pr.sp_price,pr.channel_price
                    </if>
                </when>
             </choose>
			</if>
		<if test="nettype &lt; 0 and otype &lt; 1">
			union all
		</if>
		<if test="nettype != 0 and otype &lt; 1">
			SELECT
				sp.id spid,
				sp.sp_name,
                sp.eid as full_name,
				sp.sp_type,
				sp.commission_price,
				sp.noProfit,
				sum( pr.unkonw ) unknown,
				sum( pr.income ) income,
				sum( pr.cost ) cost,
				sum( pr.un_income ) un_income,
				sum( pr.un_cost ) un_cost,
				ifnull( sum( pr.succ ), 0 ) num,
				sum(ifnull( pr.fail, 0 )) fail,
				pr.province,
				1 as nettype,
				0 otype
				<if test="queryType=='spchannel'">
					,pr.channelid
				</if>
                <choose>
                    <when test="ismon==1">
                        ,DATE_FORMAT(pr.stat_time,'%Y-%m-%d') as stateTime
                        <if test="queryType=='sp'">
                            ,pr.sp_price sprice
                        </if>
                        <if test="queryType=='spchannel'">
                            ,pr.sp_price sprice,
                            pr.channel_price cprice
                        </if>
                    </when>
                    <when test="ismon==2">
                        , DATE_FORMAT(pr.stat_time,'%Y-%m') as stateTime
                        <if test="queryType=='sp'">
                            ,pr.sp_price sprice
                        </if>
                        <if test="queryType=='spchannel'">
                            ,pr.sp_price sprice,
                            pr.channel_price cprice
                        </if>
                    </when>
                </choose>
			FROM
				(
				SELECT
					prs.* ,
						ifnull( prs.sp_price, 0 )* prs.succ income,
						ifnull( prs.sp_price, 0 )* prs.unkonw un_income,
						ifnull( prs.channel_price, 0 )* prs.succ cost,
						ifnull( prs.channel_price, 0 )* prs.unkonw un_cost

				FROM
					(
					SELECT
						sum(
						ifnull( sps.arrive_succ, 0 )) succ,
						sum(
						ifnull( sps.arrive_fail, 0 )) fail,
						sum(
							ifnull( sps.submit_succ, 0 )) + sum(
							ifnull( sps.submit_fail, 0 )) - sum(
							ifnull( sps.arrive_fail, 0 )) - sum(
							ifnull( sps.arrive_succ, 0 )) unkonw,
						sps.spid,
						sps.channelid,
						sps.stat_time,
						sps.sp_price,
						sps.channel_price,
						sps.province
					FROM
						sms_sp_province_summary sps
					<where>
					     ifnull(sps.nettype,0)=1
							<if test="createtime!=null and createtime!=''">
								and sps.stat_time &gt;= #{createtime}
							</if>
							<if test="createtime1!=null and createtime1!=''">
								and sps.stat_time &lt; DATE_ADD(str_to_date(#{createtime1},'%Y-%m-%d %H:%i:%s'),INTERVAL 1 DAY)
							</if>
							<if test="channelid!=null and channelid!=''">
								and sps.channelid=#{channelid}
							</if>
							<if test="spid!=null and spid!=''">
								and sps.spid=#{spid}
							</if>
					</where>
					GROUP BY
						sps.spid,
						sps.channelid,
						sps.stat_time,
						sps.sp_price,
						sps.province,
						sps.channel_price
						 ) as prs
				) pr inner join sms_sp_info sp ON pr.spid = sp.id
				<where>
					<if test="sp_type!=null and sp_type>0">
						AND sp.sp_type =#{sp_type}
					</if>
                    <if test="star_level!=null and star_level>0">
                        and sp.star_level =#{star_level}
                    </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>
                    <if test="sp_saler!=null and sp_saler!=''">
                        and sp.sp_saler like CONCAT('%', #{sp_saler}, '%')
                    </if>
                    <if test="salerList!=null and salerList.size()>0">
                        and sp.sp_saler in
                        <foreach collection="salerList" index="index"  item="item" open="(" separator="," close=")">
                            '${item}'
                        </foreach>
                    </if>
                    <if test="full_name != null and full_name != ''">
                        and sp.eid = #{full_name}
                    </if>
				</where>
				GROUP BY
				sp.id,
				sp.sp_name,
				sp.commission_price,
				sp.sp_type,
				sp.noProfit,
				pr.province
				<if test="queryType=='spchannel'">
				,pr.channelid
				</if>
                <choose>
                    <when test="ismon==1">
					,stateTime
					<if test="queryType=='sp'">
						,pr.sp_price
					</if>
					<if test="queryType=='spchannel'">
						,pr.sp_price,pr.channel_price
					</if>
				</when>
                <when test="ismon==2">
					,stateTime
					<if test="queryType=='sp'">
						,pr.sp_price
					</if>
					<if test="queryType=='spchannel'">
						,pr.sp_price,pr.channel_price
					</if>
				</when>
                </choose>
			</if>) list
         <if test="queryType=='spchannel'">
             left join sms_api_socket_sp sas on sas.spid = list.spid
             left join sms_sp_info spif on spif.id = list.spid
             left join (SELECT channelid,loginname FROM
             (SELECT id AS channelid,loginname FROM sms_carrier_channel_info
             UNION ALL
             SELECT channelid,
             CASE
             WHEN channeltemplatevar->'$.appId' IS NOT NULL THEN JSON_UNQUOTE(channeltemplatevar->'$.appId')
             WHEN channeltemplatevar->'$.appid' IS NOT NULL THEN JSON_UNQUOTE(channeltemplatevar->'$.appid')
             WHEN channeltemplatevar->'$.LoginName' IS NOT NULL THEN JSON_UNQUOTE(channeltemplatevar->'$.LoginName')
             WHEN channeltemplatevar->'$.uname' IS NOT NULL THEN JSON_UNQUOTE(channeltemplatevar->'$.uname')
             WHEN channeltemplatevar->'$.accessKeyId' IS NOT NULL THEN JSON_UNQUOTE(channeltemplatevar->'$.accessKeyId')
             WHEN channeltemplatevar->'$.accessKey' IS NOT NULL THEN JSON_UNQUOTE(channeltemplatevar->'$.accessKey')
             WHEN channeltemplatevar->'$.username' IS NOT NULL THEN JSON_UNQUOTE(channeltemplatevar->'$.username')
             WHEN channeltemplatevar->'$.AccountId' IS NOT NULL THEN JSON_UNQUOTE(channeltemplatevar->'$.AccountId')
             WHEN channeltemplatevar->'$.Account' IS NOT NULL THEN JSON_UNQUOTE(channeltemplatevar->'$.Account')
             WHEN channeltemplatevar->'$.account' IS NOT NULL THEN JSON_UNQUOTE(channeltemplatevar->'$.account')
             WHEN channeltemplatevar->'$.AppKey' IS NOT NULL THEN JSON_UNQUOTE(channeltemplatevar->'$.AppKey')
             WHEN channeltemplatevar->'$.api_key' IS NOT NULL THEN JSON_UNQUOTE(channeltemplatevar->'$.api_key')
             WHEN channeltemplatevar->'$.apiKey' IS NOT NULL THEN JSON_UNQUOTE(channeltemplatevar->'$.apiKey')
             WHEN channeltemplatevar->'$.X_APP_ID' IS NOT NULL THEN JSON_UNQUOTE(channeltemplatevar->'$.X_APP_ID')
             END  AS loginname FROM http_channel_template_config) b
             ) c ON c.channelid = list.channelid
         </if>
			<if test="orderType=='ASC'">
				<if test="col=='num'">
					order by num
				</if>
				<if test="col=='gross'">
					order by noProfit asc,income-cost asc
				</if>
				<if test="col=='time'">
					order by stateTime
				</if>
			</if>
			<if test="orderType=='DESC'">
				<if test="col=='num'">
					order by num DESC
				</if>
				<if test="col=='gross'">
					order by noProfit asc,income-cost DESC
				</if>
				<if test="col=='time'">
					order by stateTime DESC
				</if>
			</if>

     </select>


     <select id="listPagePriceRecordHz" resultType="cn.roadm.bo.PriceRecord">
     select spid,
			sp_name,
			sp_type,
			noProfit,
			sum( income ) income,
			sum( cost ) cost,
			ifnull( sum( num ), 0 ) num,
            ifnull( sum( unkonw ), 0 ) unknow,
            ifnull(sum(oldPrice) - sum(newPrice),0) adjustPrice,
			sum(ifnull( fail, 0 )) fail
	 from(
     	 SELECT
			sp.id spid,
			sp.sp_name,
			sp.sp_type,
			sp.noProfit,
             sa.saleprice * 10000 * count( pr.sp_price ) newPrice,
             sum( pr.sp_price ) oldPrice,
			sum( pr.income ) income,
			sum( pr.cost ) cost,
			case
			    when sp.return_fee_type = 3
			        then ifnull( sum( pr.succ ), 0 ) + ifnull( sum( pr.unkonw ), 0 )
			    else ifnull( sum( pr.succ ), 0 )
			end num,
            ifnull( sum( pr.unkonw ), 0 ) unkonw,
			sum(ifnull( pr.fail, 0 )) fail
		FROM
			(
			SELECT
				prs.* ,
					ifnull( prs.sp_price, 0 )* prs.succ income,
					ifnull( prs.sp_price, 0 )* prs.unkonw un_income,
					ifnull( prs.channel_price, 0 )* prs.succ cost,
					ifnull( prs.channel_price, 0 )* prs.unkonw un_cost

			FROM
				(
				SELECT
					sum(
					ifnull( sps.arrive_succ, 0 )) succ,
					sum(
					ifnull( sps.arrive_fail, 0 )) fail,
					sum(
						ifnull( sps.submit_succ, 0 )) + sum(
						ifnull( sps.submit_fail, 0 )) - sum(
						ifnull( sps.arrive_fail, 0 )) - sum(
						ifnull( sps.arrive_succ, 0 )) unkonw,
					sps.spid,
					sps.channelid,
					sps.stat_time,
					sps.sp_price,
					sps.channel_price
				FROM
					sms_sp_province_summary sps
				<where>
				     ifnull(sps.nettype,0)=0
						<if test="createtime!=null and createtime!=''">
							and sps.stat_time &gt;= #{createtime}
						</if>
						<if test="createtime1!=null and createtime1!=''">
							and sps.stat_time &lt; DATE_ADD(str_to_date(#{createtime1},'%Y-%m-%d %H:%i:%s'),INTERVAL 1 DAY)
						</if>
						<if test="channelid!=null and channelid!=''">
							and sps.channelid=#{channelid}
						</if>
						<if test="spid!=null and spid!=''">
							and sps.spid=#{spid}
						</if>
				</where>
				GROUP BY
					sps.spid,
					sps.channelid,
					sps.stat_time,
					sps.sp_price,
					sps.channel_price
					 ) as prs
			) pr inner join sms_sp_info sp ON pr.spid = sp.id
                left join sms_api_setting sa on sp.id=sa.sp_id
			<where>
				<if test="sp_type!=null and sp_type>0">
					AND sp.sp_type =#{sp_type}
				</if>
                <if test="star_level!=null and star_level>0">
                    and sp.star_level =#{star_level}
                </if>
                 <if test="payType != null">
                    and sp.is_api_billing = #{payType}
                </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>
                <if test="sp_saler!=null and sp_saler!=''">
                    and sp.sp_saler like CONCAT('%', #{sp_saler}, '%')
                </if>
                <if test="salerList!=null and salerList.size()>0">
                    and sp.sp_saler in
                    <foreach collection="salerList" index="index"  item="item" open="(" separator="," close=")">
                        '${item}'
                    </foreach>
                </if>
			</where>
			GROUP BY
			sp.id,
			sp.sp_name,
			sp.commission_price,
			sp.sp_type,
			sp.noProfit
			<if test="queryType=='spchannel'">
			,pr.channelid
			</if>
			<if test="ismon==1">
				,pr.stat_time
				<if test="queryType=='sp'">
					,pr.sp_price
				</if>
				<if test="queryType=='spchannel'">
					,pr.sp_price,pr.channel_price
				</if>
			</if>
		union all
		SELECT
			sp.id spid,
			sp.sp_name,
			sp.sp_type,
			sp.noProfit,
             sa.saleprice * 10000 * count( pr.sp_price ) newPrice,
             sum( pr.sp_price ) oldPrice,
			sum( pr.income ) income,
			sum( pr.cost ) cost,
			case
			    when sp.return_fee_type = 3
			        then ifnull( sum( pr.succ ), 0 ) + ifnull( sum( pr.unkonw ), 0 )
			    else ifnull( sum( pr.succ ), 0 )
			end num,
			ifnull( sum( pr.unkonw ), 0 ) unkonw,
			sum(ifnull( pr.fail, 0 )) fail
		FROM
			(
			SELECT
				prs.* ,
					ifnull( prs.sp_price, 0 )* prs.succ income,
					ifnull( prs.sp_price, 0 )* prs.unkonw un_income,
					ifnull( prs.channel_price, 0 )* prs.succ cost,
					ifnull( prs.channel_price, 0 )* prs.unkonw un_cost

			FROM
				(
				SELECT
					sum(
					ifnull( sps.arrive_succ, 0 )) succ,
					sum(
					ifnull( sps.arrive_fail, 0 )) fail,
					sum(
						ifnull( sps.submit_succ, 0 )) + sum(
						ifnull( sps.submit_fail, 0 )) - sum(
						ifnull( sps.arrive_fail, 0 )) - sum(
						ifnull( sps.arrive_succ, 0 )) unkonw,
					sps.spid,
					sps.channelid,
					sps.stat_time,
					sps.sp_price,
					sps.channel_price,
					sps.province
				FROM
					sms_sp_province_summary sps
				<where>
				     ifnull(sps.nettype,0)=1
						<if test="createtime!=null and createtime!=''">
							and sps.stat_time &gt;= #{createtime}
						</if>
						<if test="createtime1!=null and createtime1!=''">
							and sps.stat_time &lt; DATE_ADD(str_to_date(#{createtime1},'%Y-%m-%d %H:%i:%s'),INTERVAL 1 DAY)
						</if>
						<if test="channelid!=null and channelid!=''">
							and sps.channelid=#{channelid}
						</if>
						<if test="spid!=null and spid!=''">
							and sps.spid=#{spid}
						</if>
				</where>
				GROUP BY
					sps.spid,
					sps.channelid,
					sps.stat_time,
					sps.sp_price,
					sps.province,
					sps.channel_price
					 ) as prs
			) pr inner join sms_sp_info sp ON pr.spid = sp.id
            left join sms_api_setting sa on sp.id=sa.sp_id
			<where>
				<if test="sp_type!=null and sp_type>0">
					AND sp.sp_type =#{sp_type}
				</if>
                <if test="star_level!=null and star_level>0">
                    and sp.star_level =#{star_level}
                </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>
                 <if test="payType != null">
                    and sp.is_api_billing = #{payType}
                </if>
                <if test="sp_saler!=null and sp_saler!=''">
                    and sp.sp_saler like CONCAT('%', #{sp_saler}, '%')
                </if>
                <if test="salerList!=null and salerList.size()>0">
                    and sp.sp_saler in
                    <foreach collection="salerList" index="index"  item="item" open="(" separator="," close=")">
                        '${item}'
                    </foreach>
                </if>
			</where>
			GROUP BY
			sp.id,
			sp.sp_name,
			sp.commission_price,
			sp.sp_type,
			sp.noProfit,
			pr.province
			<if test="queryType=='spchannel'">
			,pr.channelid
			</if>
			<if test="ismon==1">
				,pr.stat_time
				<if test="queryType=='sp'">
					,pr.sp_price
				</if>
				<if test="queryType=='spchannel'">
					,pr.sp_price,pr.channel_price
				</if>
			</if>) list
			<where>
                <if test="adjustPrice!=null and adjustPrice==0">
                    (oldPrice - newPrice) &lt;&gt; 0
                </if>
                <if test="adjustPrice!=null and adjustPrice==1">
                    (oldPrice - newPrice) = 0
                </if>
            </where>
			GROUP BY
			spid,
			sp_name,
			sp_type,
			noProfit
			<if test="orderType=='ASC'">
				<if test="col=='num'">
					order by sum(num)
				</if>
				<if test="col=='gross'">
					order by noProfit asc,sum(income)-sum(cost)
				</if>
				<if test="col=='time'">
					order by stat_time
				</if>
			</if>
			<if test="orderType=='DESC'">
				<if test="col=='num'">
					order by sum(num) DESC
				</if>
				<if test="col=='gross'">
					order by noProfit asc,sum(income)-sum(cost) DESC
				</if>
				<if test="col=='time'">
					order by stat_time DESC
				</if>
			</if>

     </select>

     <select id="listPageMmsPriceRecordHz" resultType="cn.roadm.bo.PriceRecord">
     select spid,
			sp_name,
			sp_type,
			noProfit,
			sum( income ) income,
			sum( cost ) cost,
			ifnull( sum( num ), 0 ) num,
            ifnull(sum(oldPrice) - sum(newPrice),0) adjustPrice,
			sum(ifnull( fail, 0 )) fail
	 from(
     	 SELECT
			sp.id spid,
			sp.sp_name,
			sp.sp_type,
			sp.noProfit,
             sa.saleprice * 10000 * count( pr.sp_price ) newPrice,
             sum( pr.sp_price ) oldPrice,
			sum( pr.income ) income,
			sum( pr.cost ) cost,
			ifnull( sum( pr.succ ), 0 ) num,
			ifnull( sum( pr.unkonw ), 0 ) unkonw,
			sum(ifnull( pr.fail, 0 )) fail
		FROM
			(
			SELECT
				prs.* ,
					ifnull( prs.sp_price, 0 )* prs.succ income,
					ifnull( prs.sp_price, 0 )* prs.unkonw un_income,
					ifnull( prs.channel_price, 0 )* prs.succ cost,
					ifnull( prs.channel_price, 0 )* prs.unkonw un_cost

			FROM
				(
				SELECT
					sum(
					ifnull( sps.arrive_succ, 0 )) succ,
					sum(
					ifnull( sps.arrive_fail, 0 )) fail,
					sum(
						ifnull( sps.submit_succ, 0 )) + sum(
						ifnull( sps.submit_fail, 0 )) - sum(
						ifnull( sps.arrive_fail, 0 )) - sum(
						ifnull( sps.arrive_succ, 0 )) unkonw,
					sps.spid,
					sps.channelid,
					sps.stat_time,
					sps.sp_price,
					sps.channel_price
				FROM
					mms_sp_province_summary sps
				<where>
				     ifnull(sps.nettype,0)=0
						<if test="createtime!=null and createtime!=''">
							and sps.stat_time &gt;= #{createtime}
						</if>
						<if test="createtime1!=null and createtime1!=''">
							and sps.stat_time &lt; DATE_ADD(str_to_date(#{createtime1},'%Y-%m-%d %H:%i:%s'),INTERVAL 1 DAY)
						</if>
						<if test="channelid!=null and channelid!=''">
							and sps.channelid=#{channelid}
						</if>
						<if test="spid!=null and spid!=''">
							and sps.spid=#{spid}
						</if>
				</where>
				GROUP BY
					sps.spid,
					sps.channelid,
					sps.stat_time,
					sps.sp_price,
					sps.channel_price
					 ) as prs
			) pr inner join sms_sp_info sp ON pr.spid = sp.id
                left join sms_api_setting sa on sp.id=sa.sp_id
			<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>
                <if test="sp_saler!=null and sp_saler!=''">
                    and sp.sp_saler like CONCAT('%', #{sp_saler}, '%')
                </if>
                <if test="salerList!=null and salerList.size()>0">
                    and sp.sp_saler in
                    <foreach collection="salerList" index="index"  item="item" open="(" separator="," close=")">
                        '${item}'
                    </foreach>
                </if>
			</where>
			GROUP BY
			sp.id,
			sp.sp_name,
			sp.commission_price,
			sp.sp_type,
			sp.noProfit
			<if test="queryType=='spchannel'">
			,pr.channelid
			</if>
			<if test="ismon==1">
				,pr.stat_time
				<if test="queryType=='sp'">
					,pr.sp_price
				</if>
				<if test="queryType=='spchannel'">
					,pr.sp_price,pr.channel_price
				</if>
			</if>
		union all
		SELECT
			sp.id spid,
			sp.sp_name,
			sp.sp_type,
			sp.noProfit,
             sa.saleprice * 10000 * count( pr.sp_price ) newPrice,
             sum( pr.sp_price ) oldPrice,
			sum( pr.income ) income,
			sum( pr.cost ) cost,
			case
			    when sp.return_fee_type = 3
			        then ifnull( sum( pr.succ ), 0 ) + ifnull( sum( pr.unkonw ), 0 )
			    else ifnull( sum( pr.succ ), 0 )
			end num,
			ifnull( sum( pr.unkonw ), 0 ) unkonw,
			sum(ifnull( pr.fail, 0 )) fail
		FROM
			(
			SELECT
				prs.* ,
					ifnull( prs.sp_price, 0 )* prs.succ income,
					ifnull( prs.sp_price, 0 )* prs.unkonw un_income,
					ifnull( prs.channel_price, 0 )* prs.succ cost,
					ifnull( prs.channel_price, 0 )* prs.unkonw un_cost

			FROM
				(
				SELECT
					sum(
					ifnull( sps.arrive_succ, 0 )) succ,
					sum(
					ifnull( sps.arrive_fail, 0 )) fail,
					sum(
						ifnull( sps.submit_succ, 0 )) + sum(
						ifnull( sps.submit_fail, 0 )) - sum(
						ifnull( sps.arrive_fail, 0 )) - sum(
						ifnull( sps.arrive_succ, 0 )) unkonw,
					sps.spid,
					sps.channelid,
					sps.stat_time,
					sps.sp_price,
					sps.channel_price,
					sps.province
				FROM
					mms_sp_province_summary sps
				<where>
				     ifnull(sps.nettype,0)=1
						<if test="createtime!=null and createtime!=''">
							and sps.stat_time &gt;= #{createtime}
						</if>
						<if test="createtime1!=null and createtime1!=''">
							and sps.stat_time &lt; DATE_ADD(str_to_date(#{createtime1},'%Y-%m-%d %H:%i:%s'),INTERVAL 1 DAY)
						</if>
						<if test="channelid!=null and channelid!=''">
							and sps.channelid=#{channelid}
						</if>
						<if test="spid!=null and spid!=''">
							and sps.spid=#{spid}
						</if>
				</where>
				GROUP BY
					sps.spid,
					sps.channelid,
					sps.stat_time,
					sps.sp_price,
					sps.province,
					sps.channel_price
					 ) as prs
			) pr inner join sms_sp_info sp ON pr.spid = sp.id
            left join sms_api_setting sa on sp.id=sa.sp_id
			<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>
                <if test="sp_saler!=null and sp_saler!=''">
                    and sp.sp_saler like CONCAT('%', #{sp_saler}, '%')
                </if>
                <if test="salerList!=null and salerList.size()>0">
                    and sp.sp_saler in
                    <foreach collection="salerList" index="index"  item="item" open="(" separator="," close=")">
                        '${item}'
                    </foreach>
                </if>
			</where>
			GROUP BY
			sp.id,
			sp.sp_name,
			sp.commission_price,
			sp.sp_type,
			sp.noProfit,
			pr.province
			<if test="queryType=='spchannel'">
			,pr.channelid
			</if>
			<if test="ismon==1">
				,pr.stat_time
				<if test="queryType=='sp'">
					,pr.sp_price
				</if>
				<if test="queryType=='spchannel'">
					,pr.sp_price,pr.channel_price
				</if>
			</if>) list
			<where>
                <if test="adjustPrice!=null and adjustPrice==0">
                    (oldPrice - newPrice) &lt;&gt; 0
                </if>
                <if test="adjustPrice!=null and adjustPrice==1">
                    (oldPrice - newPrice) = 0
                </if>
            </where>
			GROUP BY
			spid,
			sp_name,
			sp_type,
			noProfit
			<if test="orderType=='ASC'">
				<if test="col=='num'">
					order by sum(num)
				</if>
				<if test="col=='gross'">
					order by noProfit asc,sum(income)-sum(cost)
				</if>
				<if test="col=='time'">
					order by stat_time
				</if>
			</if>
			<if test="orderType=='DESC'">
				<if test="col=='num'">
					order by sum(num) DESC
				</if>
				<if test="col=='gross'">
					order by noProfit asc,sum(income)-sum(cost) DESC
				</if>
				<if test="col=='time'">
					order by stat_time DESC
				</if>
			</if>

     </select>

     <select id="listPagePriceChannelNew" resultType="cn.roadm.bo.PriceRecord">
     select * from (
     <if test="nettype &lt;= 0 ">
     	 SELECT
			pr.channelid,
			sc.channel_name,
			sum( pr.unkonw ) unknown,
			sum( pr.income ) income,
			sum( pr.cost ) cost,
			sum( pr.un_income ) un_income,
			sum( pr.un_cost ) un_cost,
			ifnull( sum( pr.succ ), 0 ) num,
			sum(ifnull( pr.fail, 0 )) fail,
			'全国'  as province,
			0 nettype,
			pr.otype
            <choose>
                <when test="ismon==1">
				    ,DATE_FORMAT(pr.stat_time,'%Y-%m-%d') as stateTime,pr.channel_price cprice
			    </when>
                <when test="ismon==2">
                    ,DATE_FORMAT(pr.stat_time,'%Y-%m') as stateTime,pr.channel_price cprice
                </when>
            </choose>
		FROM
			(
			SELECT
				prs.* ,
					ifnull( prs.sp_price, 0 )* prs.succ income,
					ifnull( prs.sp_price, 0 )* prs.unkonw un_income,
					ifnull( prs.channel_price, 0 )* prs.succ cost,
					ifnull( prs.channel_price, 0 )* prs.unkonw un_cost

			FROM
				(
				SELECT
					sum(
					ifnull( sps.arrive_succ, 0 )) succ,
					sum(
					ifnull( sps.arrive_fail, 0 )) fail,
					sum(
						ifnull( sps.submit_succ, 0 )) + sum(
						ifnull( sps.submit_fail, 0 )) - sum(
						ifnull( sps.arrive_fail, 0 )) - sum(
						ifnull( sps.arrive_succ, 0 )) unkonw,
					sps.spid,
					sps.channelid,
					sps.stat_time,
					sps.sp_price,
					sps.channel_price,
					sps.otype
				FROM
					sms_sp_province_summary sps
				<where>
					ifnull(sps.nettype,0)=0
						<if test="createtime!=null and createtime!=''">
							and sps.stat_time &gt;= #{createtime}
						</if>
						<if test="createtime1!=null and createtime1!=''">
							and sps.stat_time &lt; DATE_ADD(str_to_date(#{createtime1},'%Y-%m-%d %H:%i:%s'),INTERVAL 1 DAY)
						</if>
						<if test="channelid!=null and channelid!=''">
							and sps.channelid=#{channelid}
						</if>
						<if test="otype!=null and otype>0">
							and sps.otype=#{otype}
						</if>
				</where>
				GROUP BY
					sps.spid,
					sps.channelid,
					sps.stat_time,
					sps.sp_price,
					sps.channel_price,
					sps.otype
					) as prs
			) pr left join sms_send_channel_info sc on pr.channelid=sc.id
			<where>
				<if test="channelid!=null and channelid!=''">
					and sc.id=#{channelid}
				</if>
                 <if test="channelMatchName != null and channelMatchName != ''">
                    and sc.channel_name like concat('%',#{channelMatchName},'%')
                </if>
                <if test="managerId != null and managerId != ''">
                    and sc.business_manager in (select ifnull(business,0) from business_manager where managerId =  #{managerId}) and sc.business_manager != ''
                </if>
                <if test="businessManager != null and businessManager != ''">
                    and sc.business_manager = #{businessManager}
                </if>
			</where>
			GROUP BY
			pr.channelid,
			sc.channel_name,
			pr.otype
            <choose>
                <when test="ismon==1">
				    ,stateTime,pr.channel_price
			    </when>
                <when test="ismon==2">
                    ,stateTime,pr.channel_price
                </when>
            </choose>
			</if>
		<if test="nettype &lt; 0 and otype &lt; 1">
			union all
		</if>
		<if test="nettype != 0 and otype &lt; 1">
		SELECT
			pr.channelid,
			sc.channel_name,
			sum( pr.unkonw ) unknown,
			sum( pr.income ) income,
			sum( pr.cost ) cost,
			sum( pr.un_income ) un_income,
			sum( pr.un_cost ) un_cost,
			ifnull( sum( pr.succ ), 0 ) num,
			sum(ifnull( pr.fail, 0 )) fail,
			pr.province,
			1 nettype,
			0 otype
            <choose>
                <when test="ismon==1">
				    ,DATE_FORMAT(pr.stat_time,'%Y-%m-%d') as stateTime,pr.channel_price cprice
			    </when>
                <when test="ismon==2">
				    ,DATE_FORMAT(pr.stat_time,'%Y-%m') as stateTime,pr.channel_price cprice
			    </when>
            </choose>
		FROM
			(
			SELECT
				prs.* ,
					ifnull( prs.sp_price, 0 )* prs.succ income,
					ifnull( prs.sp_price, 0 )* prs.unkonw un_income,
					ifnull( prs.channel_price, 0 )* prs.succ cost,
					ifnull( prs.channel_price, 0 )* prs.unkonw un_cost

			FROM
				(
				SELECT
					sum(
					ifnull( sps.arrive_succ, 0 )) succ,
					sum(
					ifnull( sps.arrive_fail, 0 )) fail,
					sum(
						ifnull( sps.submit_succ, 0 )) + sum(
						ifnull( sps.submit_fail, 0 )) - sum(
						ifnull( sps.arrive_fail, 0 )) - sum(
						ifnull( sps.arrive_succ, 0 )) unkonw,
					sps.spid,
					sps.channelid,
					sps.stat_time,
					sps.sp_price,
					sps.province,
					sps.channel_price
				FROM
					sms_sp_province_summary sps
				<where>
					ifnull(sps.nettype,0)=1
						<if test="createtime!=null and createtime!=''">
							and sps.stat_time &gt;= #{createtime}
						</if>
						<if test="createtime1!=null and createtime1!=''">
							and sps.stat_time &lt; DATE_ADD(str_to_date(#{createtime1},'%Y-%m-%d %H:%i:%s'),INTERVAL 1 DAY)
						</if>
						<if test="channelid!=null and channelid!=''">
							and sps.channelid=#{channelid}
						</if>
				</where>
				GROUP BY
					sps.spid,
					sps.channelid,
					sps.stat_time,
					sps.sp_price,
					sps.province,
					sps.channel_price
					) as prs
			) pr left join sms_send_channel_info sc on pr.channelid=sc.id
			<where>
				<if test="channelid!=null and channelid!=''">
					and sc.id=#{channelid}
				</if>
                 <if test="channelMatchName != null and channelMatchName != ''">
                    and sc.channel_name like concat('%',#{channelMatchName},'%')
                </if>
                <if test="managerId != null and managerId != ''">
                    and sc.business_manager in (select ifnull(business,0) from business_manager where managerId =  #{managerId}) and sc.business_manager != ''
                </if>
                <if test="businessManager != null and businessManager != ''">
                    and sc.business_manager = #{businessManager}
                </if>
			</where>
			GROUP BY
			pr.channelid,
			sc.channel_name,
			pr.province
            <choose>
                <when test="ismon==1">
				    ,stateTime,pr.channel_price
			    </when>
                <when test="ismon==2">
				    ,stateTime,pr.channel_price
			    </when>
            </choose>
			</if>) list
			<if test="orderType=='ASC'">
				<if test="col=='num'">
					order by num
				</if>
				<if test="col=='gross'">
					order by income-cost
				</if>
				<if test="col=='time'">
					order by stat_time
				</if>
			</if>
			<if test="orderType=='DESC'">
				<if test="col=='num'">
					order by num DESC
				</if>
				<if test="col=='gross'">
					order by income-cost DESC
				</if>
				<if test="col=='time'">
					order by stat_time DESC
				</if>
			</if>
     </select>

     <select id="getPriceRecordNew" resultType="cn.roadm.bo.PriceRecord">
         select list.*,
         oldPrice - newPrice adjustPrice,
         <if test="queryType=='spchannel'">
             c.loginname,chan.supplier_name, chan.cooperate_company, chan.business_manager as businessManager,
         </if>
         spif.sp_saler,ent.full_name,sas.clientid,spif.is_api_billing
         from(
         <if test="nettype &lt;= 0 ">
             SELECT
             sp.id spid,
             sp.sp_name,
             sp.eid as full_name,
             sp.sp_type,
             sp.commission_price,
             sp.noProfit,
             sa.saleprice * 10000 * count( pr.sp_price ) newPrice,
             sum( pr.sp_price ) oldPrice,
             sum( pr.unkonw ) unknown,
             sum( pr.income ) income,
             sum( pr.cost ) cost,
             sum( pr.un_income ) un_income,
             sum( pr.un_cost ) un_cost,
             ifnull( sum( pr.succ ), 0 ) num,
             sum(ifnull( pr.fail, 0 )) fail,
             '全国' as province,
             0 as nettype,
             pr.otype
             <if test="queryType=='spchannel'">
                 ,pr.channelid
             </if>
             <choose>
                  <when test="ismon==1">
                     ,DATE_FORMAT(pr.stat_time,'%Y-%m-%d') as stateTime
                     <if test="queryType=='sp'">
                         ,pr.sp_price sprice
                     </if>
                     <if test="queryType=='spchannel'">
                         ,pr.sp_price sprice,
                         pr.channel_price cprice
                     </if>
                 </when>
                 <when test="ismon==2">
                     ,DATE_FORMAT(pr.stat_time,'%Y-%m') as stateTime
                     <if test="queryType=='sp'">
                         ,pr.sp_price sprice
                     </if>
                     <if test="queryType=='spchannel'">
                         ,pr.sp_price sprice,
                         pr.channel_price cprice
                     </if>
                 </when>
             </choose>
             FROM
             (
             SELECT
             prs.* ,
             ifnull( prs.sp_price, 0 )* prs.succ income,
             ifnull( prs.sp_price, 0 )* prs.unkonw un_income,
             ifnull( prs.channel_price, 0 )* prs.succ cost,
             ifnull( prs.channel_price, 0 )* prs.unkonw un_cost

             FROM
             (
             SELECT
             sum(
             ifnull( sps.arrive_succ, 0 )) succ,
             sum(
             ifnull( sps.arrive_fail, 0 )) fail,
             sum(
             ifnull( sps.submit_succ, 0 )) + sum(
             ifnull( sps.submit_fail, 0 )) - sum(
             ifnull( sps.arrive_fail, 0 )) - sum(
             ifnull( sps.arrive_succ, 0 )) unkonw,
             sps.spid,
             sps.channelid,
             sps.stat_time,
             sps.sp_price,
             sps.channel_price,
             sps.otype
             FROM
             sms_sp_province_summary sps
             <where>
                 ifnull(sps.nettype,0)=0
                 <if test="createtime!=null and createtime!=''">
                     and sps.stat_time &gt;= #{createtime}
                 </if>
                 <if test="createtime1!=null and createtime1!=''">
                     and sps.stat_time &lt; DATE_ADD(str_to_date(#{createtime1},'%Y-%m-%d %H:%i:%s'),INTERVAL 1 DAY)
                 </if>
                 <if test="channelid!=null and channelid!=''">
                     and sps.channelid=#{channelid}
                 </if>
                 <if test="spid!=null and spid!=''">
                     and sps.spid=#{spid}
                 </if>
                 <if test="otype!=null and otype>0">
                     and sps.otype=#{otype}
                 </if>
             </where>
             GROUP BY
             sps.spid,
             sps.channelid,
             sps.stat_time,
             sps.sp_price,
             sps.channel_price,
             sps.otype
             ) as prs
             ) pr inner join sms_sp_info sp ON pr.spid = sp.id
             left join sms_api_setting sa on sp.id=sa.sp_id
             <where>
                 <if test="sp_type!=null and sp_type>0">
                     AND sp.sp_type =#{sp_type}
                 </if>
                 <if test="star_level!=null and star_level>0">
                     and sp.star_level =#{star_level}
                 </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>
                 <if test="sp_saler!=null and sp_saler!=''">
                     and sp.sp_saler like CONCAT('%', #{sp_saler}, '%')
                 </if>
                 <if test="salerList!=null and salerList.size()>0">
                     and sp.sp_saler in
                     <foreach collection="salerList" index="index" item="item" open="(" separator="," close=")">
                         '${item}'
                     </foreach>
                 </if>
                 <if test="full_name != null and full_name != ''">
                     and sp.eid = #{full_name}
                 </if>
             </where>
             GROUP BY
             sp.id,
             sp.sp_name,
             sp.commission_price,
             sp.sp_type,
             sp.noProfit,
             pr.otype
             <if test="queryType=='spchannel'">
                 ,pr.channelid
             </if>
             <choose>
                 <when test="ismon==1">
                     ,stateTime
                     <if test="queryType=='sp'">
                         ,pr.sp_price
                     </if>
                     <if test="queryType=='spchannel'">
                         ,pr.sp_price,pr.channel_price
                     </if>
                 </when>
                  <when test="ismon==2">
                     ,stateTime
                     <if test="queryType=='sp'">
                         ,pr.sp_price
                     </if>
                     <if test="queryType=='spchannel'">
                         ,pr.sp_price,pr.channel_price
                     </if>
                 </when>
             </choose>
         </if>
         <if test="nettype &lt; 0  and otype &lt; 1">
             union all
         </if>
         <if test="nettype != 0  and otype &lt; 1">
             SELECT
             sp.id spid,
             sp.sp_name,
             sp.eid as full_name,
             sp.sp_type,
             sp.commission_price,
             sp.noProfit,
             sa.saleprice * 10000 * count( pr.sp_price ) newPrice,
             sum( pr.sp_price ) oldPrice,
             sum( pr.unkonw ) unknown,
             sum( pr.income ) income,
             sum( pr.cost ) cost,
             sum( pr.un_income ) un_income,
             sum( pr.un_cost ) un_cost,
             ifnull( sum( pr.succ ), 0 ) num,
             sum(ifnull( pr.fail, 0 )) fail,
             pr.province,
             1 as nettype,
             0 otype
             <if test="queryType=='spchannel'">
                 ,pr.channelid
             </if>
             <choose>
                 <when test="ismon==1">
                     ,DATE_FORMAT(pr.stat_time,'%Y-%m-%d') as stateTime
                     <if test="queryType=='sp'">
                         ,pr.sp_price sprice
                     </if>
                     <if test="queryType=='spchannel'">
                         ,pr.sp_price sprice,
                         pr.channel_price cprice
                     </if>
                </when>
                 <when test="ismon==2">
                     ,DATE_FORMAT(pr.stat_time,'%Y-%m') as stateTime
                     <if test="queryType=='sp'">
                         ,pr.sp_price sprice
                     </if>
                     <if test="queryType=='spchannel'">
                         ,pr.sp_price sprice,
                         pr.channel_price cprice
                     </if>
                </when>
             </choose>
             FROM
             (
             SELECT
             prs.* ,
             ifnull( prs.sp_price, 0 )* prs.succ income,
             ifnull( prs.sp_price, 0 )* prs.unkonw un_income,
             ifnull( prs.channel_price, 0 )* prs.succ cost,
             ifnull( prs.channel_price, 0 )* prs.unkonw un_cost

             FROM
             (
             SELECT
             sum(
             ifnull( sps.arrive_succ, 0 )) succ,
             sum(
             ifnull( sps.arrive_fail, 0 )) fail,
             sum(
             ifnull( sps.submit_succ, 0 )) + sum(
             ifnull( sps.submit_fail, 0 )) - sum(
             ifnull( sps.arrive_fail, 0 )) - sum(
             ifnull( sps.arrive_succ, 0 )) unkonw,
             sps.spid,
             sps.channelid,
             sps.stat_time,
             sps.sp_price,
             sps.channel_price,
             sps.province
             FROM
             sms_sp_province_summary sps
             <where>
                 ifnull(sps.nettype,0)=1
                 <if test="createtime!=null and createtime!=''">
                     and sps.stat_time &gt;= #{createtime}
                 </if>
                 <if test="createtime1!=null and createtime1!=''">
                     and sps.stat_time &lt; DATE_ADD(str_to_date(#{createtime1},'%Y-%m-%d %H:%i:%s'),INTERVAL 1 DAY)
                 </if>
                 <if test="channelid!=null and channelid!=''">
                     and sps.channelid=#{channelid}
                 </if>
                 <if test="spid!=null and spid!=''">
                     and sps.spid=#{spid}
                 </if>
             </where>
             GROUP BY
             sps.spid,
             sps.channelid,
             sps.stat_time,
             sps.sp_price,
             sps.province,
             sps.channel_price
             ) as prs
             ) pr inner join sms_sp_info sp ON pr.spid = sp.id
             left join sms_api_setting sa on sp.id=sa.sp_id
             <where>
                 <if test="sp_type!=null and sp_type>0">
                     AND sp.sp_type =#{sp_type}
                 </if>
                 <if test="star_level!=null and star_level>0">
                     and sp.star_level =#{star_level}
                 </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>
                 <if test="sp_saler!=null and sp_saler!=''">
                     and sp.sp_saler like CONCAT('%', #{sp_saler}, '%')
                 </if>
                 <if test="salerList!=null and salerList.size()>0">
                     and sp.sp_saler in
                     <foreach collection="salerList" index="index" item="item" open="(" separator="," close=")">
                         '${item}'
                     </foreach>
                 </if>
                 <if test="full_name != null and full_name != ''">
                     and sp.eid = #{full_name}
                 </if>
             </where>
             GROUP BY
             sp.id,
             sp.sp_name,
             sp.commission_price,
             sp.sp_type,
             sp.noProfit,
             pr.province
             <if test="queryType=='spchannel'">
                 ,pr.channelid
             </if>
             <choose>
                 <when test="ismon==1">
                     ,stateTime
                     <if test="queryType=='sp'">
                         ,pr.sp_price
                     </if>
                     <if test="queryType=='spchannel'">
                         ,pr.sp_price,pr.channel_price
                     </if>
                </when>
                 <when test="ismon==2">
                     ,stateTime
                     <if test="queryType=='sp'">
                         ,pr.sp_price
                     </if>
                     <if test="queryType=='spchannel'">
                         ,pr.sp_price,pr.channel_price
                     </if>
                </when>
             </choose>
         </if>
         ) list left join sms_api_socket_sp sas on sas.spid = list.spid
         left join sms_sp_info spif on spif.id = list.spid left join sms_enterprise ent on ent.id = spif.eid
         <if test="queryType=='spchannel'">
             left join (SELECT channelid,loginname FROM
             (SELECT id AS channelid,loginname FROM sms_carrier_channel_info
             UNION ALL
             SELECT channelid,
             CASE
             WHEN channeltemplatevar->'$.appId' IS NOT NULL THEN JSON_UNQUOTE(channeltemplatevar->'$.appId')
             WHEN channeltemplatevar->'$.appid' IS NOT NULL THEN JSON_UNQUOTE(channeltemplatevar->'$.appid')
             WHEN channeltemplatevar->'$.LoginName' IS NOT NULL THEN JSON_UNQUOTE(channeltemplatevar->'$.LoginName')
             WHEN channeltemplatevar->'$.uname' IS NOT NULL THEN JSON_UNQUOTE(channeltemplatevar->'$.uname')
             WHEN channeltemplatevar->'$.accessKeyId' IS NOT NULL THEN JSON_UNQUOTE(channeltemplatevar->'$.accessKeyId')
             WHEN channeltemplatevar->'$.accessKey' IS NOT NULL THEN JSON_UNQUOTE(channeltemplatevar->'$.accessKey')
             WHEN channeltemplatevar->'$.username' IS NOT NULL THEN JSON_UNQUOTE(channeltemplatevar->'$.username')
             WHEN channeltemplatevar->'$.AccountId' IS NOT NULL THEN JSON_UNQUOTE(channeltemplatevar->'$.AccountId')
             WHEN channeltemplatevar->'$.Account' IS NOT NULL THEN JSON_UNQUOTE(channeltemplatevar->'$.Account')
             WHEN channeltemplatevar->'$.account' IS NOT NULL THEN JSON_UNQUOTE(channeltemplatevar->'$.account')
             WHEN channeltemplatevar->'$.AppKey' IS NOT NULL THEN JSON_UNQUOTE(channeltemplatevar->'$.AppKey')
             WHEN channeltemplatevar->'$.api_key' IS NOT NULL THEN JSON_UNQUOTE(channeltemplatevar->'$.api_key')
             WHEN channeltemplatevar->'$.apiKey' IS NOT NULL THEN JSON_UNQUOTE(channeltemplatevar->'$.apiKey')
             WHEN channeltemplatevar->'$.X_APP_ID' IS NOT NULL THEN JSON_UNQUOTE(channeltemplatevar->'$.X_APP_ID')
             END  AS loginname FROM http_channel_template_config) b
             ) c ON c.channelid = list.channelid
            left join (select a.id,a.business_manager,b.supplier_name, a.cooperate_company from sms_send_channel_info a left join channel_supplier b on a.supplier_id = b.id) chan on chan.id = list.channelid
         </if>
         <where>
             <if test="adjustPrice!=null and adjustPrice==0">
                 (oldPrice - newPrice) &lt;&gt; 0
             </if>
             <if test="adjustPrice!=null and adjustPrice==1">
                 (oldPrice - newPrice) = 0
             </if>
         </where>
     </select>

     <select id="getPriceRecordNewCount" resultType="cn.roadm.bo.PriceRecord">
     	select spid,
			sp_name,
			sp_type,
			noProfit,
            ifnull((sum(oldPrice) - sum(newPrice)),0) adjustPrice,
			sum( income ) income,
			sum( cost ) cost,
			ifnull( sum( num ), 0 ) num,
            ifnull( sum( unkonw ), 0 ) unknow,
			sum(ifnull( fail, 0 )) fail
	 from(
     	 SELECT
			sp.id spid,
			sp.sp_name,
			sp.sp_type,
			sp.noProfit,
            sa.saleprice * 10000 * count( pr.sp_price ) newPrice,
            sum( pr.sp_price ) oldPrice,
			sum( pr.income ) income,
			sum( pr.cost ) cost,
            case
                when sp.return_fee_type = 3
                    then ifnull( sum( pr.succ ), 0 ) + ifnull( sum( pr.unkonw ), 0 )
                else ifnull( sum( pr.succ ), 0 )
            end num,
            ifnull( sum( pr.unkonw ), 0 ) unkonw,
			sum(ifnull( pr.fail, 0 )) fail
		FROM
			(
			SELECT
				prs.* ,
					ifnull( prs.sp_price, 0 )* prs.succ income,
					ifnull( prs.sp_price, 0 )* prs.unkonw un_income,
					ifnull( prs.channel_price, 0 )* prs.succ cost,
					ifnull( prs.channel_price, 0 )* prs.unkonw un_cost

			FROM
				(
				SELECT
					sum(
					ifnull( sps.arrive_succ, 0 )) succ,
					sum(
					ifnull( sps.arrive_fail, 0 )) fail,
					sum(
						ifnull( sps.submit_succ, 0 )) + sum(
						ifnull( sps.submit_fail, 0 )) - sum(
						ifnull( sps.arrive_fail, 0 )) - sum(
						ifnull( sps.arrive_succ, 0 )) unkonw,
					sps.spid,
					sps.channelid,
					sps.stat_time,
					sps.sp_price,
					sps.channel_price
				FROM
					sms_sp_province_summary sps
				<where>
				     ifnull(sps.nettype,0)=0
						<if test="createtime!=null and createtime!=''">
							and sps.stat_time &gt;= #{createtime}
						</if>
						<if test="createtime1!=null and createtime1!=''">
							and sps.stat_time &lt; DATE_ADD(str_to_date(#{createtime1},'%Y-%m-%d %H:%i:%s'),INTERVAL 1 DAY)
						</if>
						<if test="channelid!=null and channelid!=''">
							and sps.channelid=#{channelid}
						</if>
						<if test="spid!=null and spid!=''">
							and sps.spid=#{spid}
						</if>
				</where>
				GROUP BY
					sps.spid,
					sps.channelid,
					sps.stat_time,
					sps.sp_price,
					sps.channel_price
					 ) as prs
			) pr inner join sms_sp_info sp ON pr.spid = sp.id
            left join sms_api_setting sa on sp.id=sa.sp_id
			<where>
				<if test="sp_type!=null and sp_type>0">
					AND sp.sp_type =#{sp_type}
				</if>
                <if test="star_level!=null and star_level>0">
                    and sp.star_level =#{star_level}
                </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>
                <if test="payType != null">
                    and sp.is_api_billing = #{payType}
                </if>
                <if test="sp_saler!=null and sp_saler!=''">
                    and sp.sp_saler like CONCAT('%', #{sp_saler}, '%')
                </if>
                <if test="salerList!=null and salerList.size()>0">
                    and sp.sp_saler in
                    <foreach collection="salerList" index="index"  item="item" open="(" separator="," close=")">
                        '${item}'
                    </foreach>
                </if>
			</where>
			GROUP BY
			sp.id,
			sp.sp_name,
			sp.commission_price,
			sp.sp_type,
			sp.noProfit
			<if test="queryType=='spchannel'">
			,pr.channelid
			</if>
			<if test="ismon==1">
				,pr.stat_time
				<if test="queryType=='sp'">
					,pr.sp_price
				</if>
				<if test="queryType=='spchannel'">
					,pr.sp_price,pr.channel_price
				</if>
			</if>
		union all
		SELECT
			sp.id spid,
			sp.sp_name,
			sp.sp_type,
			sp.noProfit,
            sa.saleprice * 10000 * count( pr.sp_price ) newPrice,
            sum( pr.sp_price ) oldPrice,
			sum( pr.income ) income,
			sum( pr.cost ) cost,
            case
                 when sp.return_fee_type = 3
                    then ifnull( sum( pr.succ ), 0 ) + ifnull( sum( pr.unkonw ), 0 )
                else ifnull( sum( pr.succ ), 0 )
            end num,
            ifnull( sum( pr.unkonw ), 0 ) unkonw,
			sum(ifnull( pr.fail, 0 )) fail
		FROM
			(
			SELECT
				prs.* ,
					ifnull( prs.sp_price, 0 )* prs.succ income,
					ifnull( prs.sp_price, 0 )* prs.unkonw un_income,
					ifnull( prs.channel_price, 0 )* prs.succ cost,
					ifnull( prs.channel_price, 0 )* prs.unkonw un_cost

			FROM
				(
				SELECT
					sum(
					ifnull( sps.arrive_succ, 0 )) succ,
					sum(
					ifnull( sps.arrive_fail, 0 )) fail,
					sum(
						ifnull( sps.submit_succ, 0 )) + sum(
						ifnull( sps.submit_fail, 0 )) - sum(
						ifnull( sps.arrive_fail, 0 )) - sum(
						ifnull( sps.arrive_succ, 0 )) unkonw,
					sps.spid,
					sps.channelid,
					sps.stat_time,
					sps.sp_price,
					sps.channel_price,
					sps.province
				FROM
					sms_sp_province_summary sps
				<where>
				     ifnull(sps.nettype,0)=1
						<if test="createtime!=null and createtime!=''">
							and sps.stat_time &gt;= #{createtime}
						</if>
						<if test="createtime1!=null and createtime1!=''">
							and sps.stat_time &lt; DATE_ADD(str_to_date(#{createtime1},'%Y-%m-%d %H:%i:%s'),INTERVAL 1 DAY)
						</if>
						<if test="channelid!=null and channelid!=''">
							and sps.channelid=#{channelid}
						</if>
						<if test="spid!=null and spid!=''">
							and sps.spid=#{spid}
						</if>
				</where>
				GROUP BY
					sps.spid,
					sps.channelid,
					sps.stat_time,
					sps.sp_price,
					sps.province,
					sps.channel_price
					 ) as prs
			) pr inner join sms_sp_info sp ON pr.spid = sp.id
            left join sms_api_setting sa on sp.id=sa.sp_id
			<where>
				<if test="sp_type!=null and sp_type>0">
					AND sp.sp_type =#{sp_type}
				</if>
                <if test="star_level!=null and star_level>0">
                    and sp.star_level =#{star_level}
                </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>
                 <if test="payType != null">
                    and sp.is_api_billing = #{payType}
                </if>
                <if test="sp_saler!=null and sp_saler!=''">
                    and sp.sp_saler like CONCAT('%', #{sp_saler}, '%')
                </if>
                <if test="salerList!=null and salerList.size()>0">
                    and sp.sp_saler in
                    <foreach collection="salerList" index="index"  item="item" open="(" separator="," close=")">
                        '${item}'
                    </foreach>
                </if>
			</where>
			GROUP BY
			sp.id,
			sp.sp_name,
			sp.commission_price,
			sp.sp_type,
			sp.noProfit,
			pr.province
			<if test="queryType=='spchannel'">
			,pr.channelid
			</if>
			<if test="ismon==1">
				,pr.stat_time
				<if test="queryType=='sp'">
					,pr.sp_price
				</if>
				<if test="queryType=='spchannel'">
					,pr.sp_price,pr.channel_price
				</if>
			</if>) list
             <where>
                 <if test="adjustPrice!=null and adjustPrice==0">
                     (oldPrice - newPrice) &lt;&gt; 0
                 </if>
                 <if test="adjustPrice!=null and adjustPrice==1">
                     (oldPrice - newPrice) = 0
                 </if>
             </where>
			GROUP BY
			spid,
			sp_name,
			sp_type,
			noProfit
			<if test="orderType=='ASC'">
				<if test="col=='num'">
					order by sum(num)
				</if>
				<if test="col=='gross'">
					order by noProfit asc,sum(income)-sum(cost)
				</if>
				<if test="col=='time'">
					order by stat_time
				</if>
			</if>
			<if test="orderType=='DESC'">
				<if test="col=='num'">
					order by sum(num) DESC
				</if>
				<if test="col=='gross'">
					order by noProfit asc,sum(income)-sum(cost) DESC
				</if>
				<if test="col=='time'">
					order by stat_time DESC
				</if>
			</if>
     </select>


     <select id="getPriceChannelNew" resultType="cn.roadm.bo.PriceRecord">
     	<if test="nettype &lt;= 0">
     	 SELECT
			sc.id channelid,
			sc.channel_name,
			sum( pr.unkonw ) unknown,
			sum( pr.income ) income,
			sum( pr.cost ) cost,
			sum( pr.un_income ) un_income,
			sum( pr.un_cost ) un_cost,
			ifnull( sum( pr.succ ), 0 ) num,
			sum(ifnull( pr.fail, 0 )) fail,
			'全国'  as province,
			0 nettype,
			pr.otype
            <choose>
                <when test="ismon==1">
				    ,DATE_FORMAT(pr.stat_time,'%Y-%m-%d') as stateTime,pr.channel_price cprice
                </when>
                <when test="ismon==2">
                    ,DATE_FORMAT(pr.stat_time,'%Y-%m') as stateTime, pr.channel_price cprice
                </when>
            </choose>
		FROM
			(
			SELECT
				prs.* ,
					ifnull( prs.sp_price, 0 )* prs.succ income,
					ifnull( prs.sp_price, 0 )* prs.unkonw un_income,
					ifnull( prs.channel_price, 0 )* prs.succ cost,
					ifnull( prs.channel_price, 0 )* prs.unkonw un_cost

			FROM
				(
				SELECT
					sum(
					ifnull( sps.arrive_succ, 0 )) succ,
					sum(
					ifnull( sps.arrive_fail, 0 )) fail,
					sum(
						ifnull( sps.submit_succ, 0 )) + sum(
						ifnull( sps.submit_fail, 0 )) - sum(
						ifnull( sps.arrive_fail, 0 )) - sum(
						ifnull( sps.arrive_succ, 0 )) unkonw,
					sps.spid,
					sps.channelid,
					sps.stat_time,
					sps.sp_price,
					sps.channel_price,
					sps.otype
				FROM
					sms_sp_province_summary sps
				<where>
					ifnull(sps.nettype,0)=0
						<if test="createtime!=null and createtime!=''">
							and sps.stat_time &gt;= #{createtime}
						</if>
						<if test="createtime1!=null and createtime1!=''">
							and sps.stat_time &lt; DATE_ADD(str_to_date(#{createtime1},'%Y-%m-%d %H:%i:%s'),INTERVAL 1 DAY)
						</if>
						<if test="channelid!=null and channelid!=''">
							and sps.channelid=#{channelid}
						</if>
						<if test="otype!=null and otype>0">
							and otype=#{otype}
						</if>
				</where>
				GROUP BY
					sps.spid,
					sps.channelid,
					sps.stat_time,
					sps.sp_price,
					sps.channel_price,
					sps.otype
					) as prs
			) pr left join sms_send_channel_info sc on pr.channelid=sc.id
			<where>
				<if test="channelid!=null and channelid!=''">
					and sc.id=#{channelid}
				</if>
                <if test="channelMatchName != null and channelMatchName != ''">
                    and sc.channel_name like concat('%',#{channelMatchName},'%')
                </if>
                <if test="managerId != null and managerId != ''">
                    and sc.business_manager in (select ifnull(business,0) from business_manager where managerId =  #{managerId}) and sc.business_manager != ''
                </if>
                <if test="businessManager != null and businessManager != ''">
                    and sc.business_manager = #{businessManager}
                </if>
			</where>
			GROUP BY
			sc.id,
			sc.channel_name,
			pr.otype
            <choose>
                <when test="ismon==1">
                   ,stateTime,pr.channel_price
                </when>
                <when test="ismon==2">
                    ,stateTime,pr.channel_price
                </when>
            </choose>
			</if>
		<if test="nettype &lt; 0  and otype &lt; 1">
			union all
		</if>
		<if test="nettype != 0  and otype &lt; 1">
		SELECT
			sc.id channelid,
			sc.channel_name,
			sum( pr.unkonw ) unknown,
			sum( pr.income ) income,
			sum( pr.cost ) cost,
			sum( pr.un_income ) un_income,
			sum( pr.un_cost ) un_cost,
			ifnull( sum( pr.succ ), 0 ) num,
			sum(ifnull( pr.fail, 0 )) fail,
			pr.province,
			1 nettype,
			0 otype
            <choose>
                <when test="ismon==1">
				    ,DATE_FORMAT(pr.stat_time,'%Y-%m-%d') as stateTime,pr.channel_price cprice
			    </when>
                <when test="ismon==2">
                    ,DATE_FORMAT(pr.stat_time,'%Y-%m') as stateTime,pr.channel_price cprice
                </when>
            </choose>
		FROM
			(
			SELECT
				prs.* ,
					ifnull( prs.sp_price, 0 )* prs.succ income,
					ifnull( prs.sp_price, 0 )* prs.unkonw un_income,
					ifnull( prs.channel_price, 0 )* prs.succ cost,
					ifnull( prs.channel_price, 0 )* prs.unkonw un_cost

			FROM
				(
				SELECT
					sum(
					ifnull( sps.arrive_succ, 0 )) succ,
					sum(
					ifnull( sps.arrive_fail, 0 )) fail,
					sum(
						ifnull( sps.submit_succ, 0 )) + sum(
						ifnull( sps.submit_fail, 0 )) - sum(
						ifnull( sps.arrive_fail, 0 )) - sum(
						ifnull( sps.arrive_succ, 0 )) unkonw,
					sps.spid,
					sps.channelid,
					sps.stat_time,
					sps.sp_price,
					sps.province,
					sps.channel_price
				FROM
					sms_sp_province_summary sps
				<where>
					ifnull(sps.nettype,0)=1
						<if test="createtime!=null and createtime!=''">
							and sps.stat_time &gt;= #{createtime}
						</if>
						<if test="createtime1!=null and createtime1!=''">
							and sps.stat_time &lt; DATE_ADD(str_to_date(#{createtime1},'%Y-%m-%d %H:%i:%s'),INTERVAL 1 DAY)
						</if>
						<if test="channelid!=null and channelid!=''">
							and sps.channelid=#{channelid}
						</if>
				</where>
				GROUP BY
					sps.spid,
					sps.channelid,
					sps.stat_time,
					sps.sp_price,
					sps.province,
					sps.channel_price
					) as prs
			) pr left join sms_send_channel_info sc on pr.channelid=sc.id
			<where>
				<if test="channelid!=null and channelid!=''">
					and sc.id=#{channelid}
				</if>
                <if test="channelMatchName != null and channelMatchName != ''">
                    and sc.channel_name like concat('%',#{channelMatchName},'%')
                </if>
                <if test="managerId != null and managerId != ''">
                    and sc.business_manager in (select ifnull(business,0) from business_manager where managerId =  #{managerId}) and sc.business_manager != ''
                </if>
                <if test="businessManager != null and businessManager != ''">
                    and sc.business_manager = #{businessManager}
                </if>
			</where>
			GROUP BY
			sc.id,
			sc.channel_name,
			pr.province
            <choose>
                <when test="ismon==1">
				    ,stateTime,pr.channel_price
			    </when>
                <when test="ismon==2">
				    ,stateTime,pr.channel_price
			    </when>
            </choose>
			</if>
     </select>

     <insert id="insertTemplate" useGeneratedKeys="true" keyProperty="id" parameterType="ChannelTemplate" >
    	insert into sms_template_local(content,createtime,title,`desc`,example) values(#{content},now(),#{title},#{desc},#{example})
    </insert>

    <update id="updateTemplate" parameterType="ChannelTemplate">
    	update sms_template_local set content=#{content},title=#{title},`desc`=#{desc},example=#{example} where id=#{id}
    </update>

    <select id="getSmsTemplateById" resultType="ChannelTemplate">
    	select * from sms_template_local where id=#{id}
    </select>

     <insert id="insertBatchFinanceHistory">
    	insert batch_finance_history(`type`,idList,otype,startTime,endTime,price,provinceNetPrice,commissionPrice,user,createtime)
    	values(#{type},#{idList},#{otype},#{startTime},#{endTime},#{price},#{provinceNetPrice},#{commissionPrice},#{user},now())
    </insert>

    <select id="listPageFinanceHistory" resultType="cn.roadm.bo.BitchUpdatePriceVO">
    	select * from batch_finance_history
    	<where>
    		<if test="startTime!=null and startTime!=''">
    			and createtime >= #{startTime}
    		</if>
    		<if test="endTime!=null and endTime!=''">
    			and createtime &lt; #{endTime}
    		</if>
    	</where>
    </select>


    <select id="exportFinanceHistory" resultType="Map">
    	select (case
    	when type=0 then '企业'
    	when type=1 then '通道'
    	end) type,idList,
    	(case
    	when otype=1 then '联通'
    	when otype=2 then '移动'
    	when otype=3 then '电信'
    	when otype=0 then '三网'
    	end) otype,
    	CONCAT(startTime,'-',endTime) seTime,
    	price,
    	provinceNetPrice,
    	commissionPrice,
    	user,
    	createtime
    	  from batch_finance_history
    	<where>
    		<if test="startTime!=null and startTime!=''">
    			and createtime >= #{startTime}
    		</if>
    		<if test="endTime!=null and endTime!=''">
    			and createtime &lt; #{endTime}
    		</if>
    	</where>
    </select>

    <select id="getMmsPriceRecordNew" resultType="cn.roadm.bo.PriceRecord">
         select list.*,
         oldPrice - newPrice adjustPrice,
        <if test="queryType=='spchannel'">
            c.loginname, chan.supplier_name, chan.cooperate_company,
        </if>
        spif.sp_saler,ent.full_name,sas.clientid,spif.is_api_billing
         from(
         <if test="nettype &lt;= 0 ">
             SELECT
             sp.id spid,
             sp.sp_name,
             sp.sp_type,
             sp.commission_price,
             sp.noProfit,
             sa.saleprice * 10000 * count( pr.sp_price ) newPrice,
             sum( pr.sp_price ) oldPrice,
             sum( pr.unkonw ) unknown,
             sum( pr.income ) income,
             sum( pr.cost ) cost,
             sum( pr.un_income ) un_income,
             sum( pr.un_cost ) un_cost,
             ifnull( sum( pr.succ ), 0 ) num,
             sum(ifnull( pr.fail, 0 )) fail,
             '全国' as province,
             0 as nettype,
             pr.otype
             <if test="queryType=='spchannel'">
                 ,pr.channelid
             </if>
             <if test="ismon==1">
                 ,pr.stat_time
                 <if test="queryType=='sp'">
                     ,pr.sp_price sprice
                 </if>
                 <if test="queryType=='spchannel'">
                     ,pr.sp_price sprice,
                     pr.channel_price cprice
                 </if>
             </if>
             FROM
             (
             SELECT
             prs.* ,
             ifnull( prs.sp_price, 0 )* prs.succ income,
             ifnull( prs.sp_price, 0 )* prs.unkonw un_income,
             ifnull( prs.channel_price, 0 )* prs.succ cost,
             ifnull( prs.channel_price, 0 )* prs.unkonw un_cost

             FROM
             (
             SELECT
             sum(
             ifnull( sps.arrive_succ, 0 )) succ,
             sum(
             ifnull( sps.arrive_fail, 0 )) fail,
             sum(
             ifnull( sps.submit_succ, 0 )) + sum(
             ifnull( sps.submit_fail, 0 )) - sum(
             ifnull( sps.arrive_fail, 0 )) - sum(
             ifnull( sps.arrive_succ, 0 )) unkonw,
             sps.spid,
             sps.channelid,
             sps.stat_time,
             sps.sp_price,
             sps.channel_price,
             sps.otype
             FROM
             mms_sp_province_summary sps
             <where>
                 ifnull(sps.nettype,0)=0
                 <if test="createtime!=null and createtime!=''">
                     and sps.stat_time &gt;= #{createtime}
                 </if>
                 <if test="createtime1!=null and createtime1!=''">
                     and sps.stat_time &lt; DATE_ADD(str_to_date(#{createtime1},'%Y-%m-%d %H:%i:%s'),INTERVAL 1 DAY)
                 </if>
                 <if test="channelid!=null and channelid!=''">
                     and sps.channelid=#{channelid}
                 </if>
                 <if test="spid!=null and spid!=''">
                     and sps.spid=#{spid}
                 </if>
                 <if test="otype!=null and otype>0">
                     and sps.otype=#{otype}
                 </if>
             </where>
             GROUP BY
             sps.spid,
             sps.channelid,
             sps.stat_time,
             sps.sp_price,
             sps.channel_price,
             sps.otype
             ) as prs
             ) pr inner join sms_sp_info sp ON pr.spid = sp.id
             left join sms_api_setting sa on sp.id=sa.sp_id
             <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>
                 <if test="sp_saler!=null and sp_saler!=''">
                     and sp.sp_saler like CONCAT('%', #{sp_saler}, '%')
                 </if>
                 <if test="salerList!=null and salerList.size()>0">
                     and sp.sp_saler in
                     <foreach collection="salerList" index="index" item="item" open="(" separator="," close=")">
                         '${item}'
                     </foreach>
                 </if>
             </where>
             GROUP BY
             sp.id,
             sp.sp_name,
             sp.commission_price,
             sp.sp_type,
             sp.noProfit,
             pr.otype
             <if test="queryType=='spchannel'">
                 ,pr.channelid
             </if>
             <if test="ismon==1">
                 ,pr.stat_time
                 <if test="queryType=='sp'">
                     ,pr.sp_price
                 </if>
                 <if test="queryType=='spchannel'">
                     ,pr.sp_price,pr.channel_price
                 </if>
             </if>
         </if>
         <if test="nettype &lt; 0  and otype &lt; 1">
             union all
         </if>
         <if test="nettype != 0  and otype &lt; 1">
             SELECT
             sp.id spid,
             sp.sp_name,
             sp.sp_type,
             sp.commission_price,
             sp.noProfit,
             sa.saleprice * 10000 * count( pr.sp_price ) newPrice,
             sum( pr.sp_price ) oldPrice,
             sum( pr.unkonw ) unknown,
             sum( pr.income ) income,
             sum( pr.cost ) cost,
             sum( pr.un_income ) un_income,
             sum( pr.un_cost ) un_cost,
             ifnull( sum( pr.succ ), 0 ) num,
             sum(ifnull( pr.fail, 0 )) fail,
             pr.province,
             1 as nettype,
             0 otype
             <if test="queryType=='spchannel'">
                 ,pr.channelid
             </if>
             <if test="ismon==1">
                 ,pr.stat_time
                 <if test="queryType=='sp'">
                     ,pr.sp_price sprice
                 </if>
                 <if test="queryType=='spchannel'">
                     ,pr.sp_price sprice,
                     pr.channel_price cprice
                 </if>
             </if>
             FROM
             (
             SELECT
             prs.* ,
             ifnull( prs.sp_price, 0 )* prs.succ income,
             ifnull( prs.sp_price, 0 )* prs.unkonw un_income,
             ifnull( prs.channel_price, 0 )* prs.succ cost,
             ifnull( prs.channel_price, 0 )* prs.unkonw un_cost

             FROM
             (
             SELECT
             sum(
             ifnull( sps.arrive_succ, 0 )) succ,
             sum(
             ifnull( sps.arrive_fail, 0 )) fail,
             sum(
             ifnull( sps.submit_succ, 0 )) + sum(
             ifnull( sps.submit_fail, 0 )) - sum(
             ifnull( sps.arrive_fail, 0 )) - sum(
             ifnull( sps.arrive_succ, 0 )) unkonw,
             sps.spid,
             sps.channelid,
             sps.stat_time,
             sps.sp_price,
             sps.channel_price,
             sps.province
             FROM
             mms_sp_province_summary sps
             <where>
                 ifnull(sps.nettype,0)=1
                 <if test="createtime!=null and createtime!=''">
                     and sps.stat_time &gt;= #{createtime}
                 </if>
                 <if test="createtime1!=null and createtime1!=''">
                     and sps.stat_time &lt; DATE_ADD(str_to_date(#{createtime1},'%Y-%m-%d %H:%i:%s'),INTERVAL 1 DAY)
                 </if>
                 <if test="channelid!=null and channelid!=''">
                     and sps.channelid=#{channelid}
                 </if>
                 <if test="spid!=null and spid!=''">
                     and sps.spid=#{spid}
                 </if>
             </where>
             GROUP BY
             sps.spid,
             sps.channelid,
             sps.stat_time,
             sps.sp_price,
             sps.province,
             sps.channel_price
             ) as prs
             ) pr inner join sms_sp_info sp ON pr.spid = sp.id
             left join sms_api_setting sa on sp.id=sa.sp_id
             <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>
                 <if test="sp_saler!=null and sp_saler!=''">
                     and sp.sp_saler like CONCAT('%', #{sp_saler}, '%')
                 </if>
                 <if test="salerList!=null and salerList.size()>0">
                     and sp.sp_saler in
                     <foreach collection="salerList" index="index" item="item" open="(" separator="," close=")">
                         '${item}'
                     </foreach>
                 </if>
             </where>
             GROUP BY
             sp.id,
             sp.sp_name,
             sp.commission_price,
             sp.sp_type,
             sp.noProfit,
             pr.province
             <if test="queryType=='spchannel'">
                 ,pr.channelid
             </if>
             <if test="ismon==1">
                 ,pr.stat_time
                 <if test="queryType=='sp'">
                     ,pr.sp_price
                 </if>
                 <if test="queryType=='spchannel'">
                     ,pr.sp_price,pr.channel_price
                 </if>
             </if>
         </if>
         ) list
        left join sms_api_socket_sp sas on sas.spid = list.spid
        left join sms_sp_info spif on spif.id = list.spid left join sms_enterprise ent on ent.id = spif.eid
        <if test="queryType=='spchannel'">
            left join (SELECT channelid,loginname FROM
            (SELECT k.id AS channelid,loginname FROM sms_carrier_channel_info k INNER JOIN sms_send_channel_info m ON k.id = m.id
            WHERE m.protocol_type = 20
            UNION ALL
            SELECT channelid,
            CASE
            WHEN channeltemplatevar->'$.appId' IS NOT NULL THEN JSON_UNQUOTE(channeltemplatevar->'$.appId')
            WHEN channeltemplatevar->'$.appid' IS NOT NULL THEN JSON_UNQUOTE(channeltemplatevar->'$.appid')
            WHEN channeltemplatevar->'$.LoginName' IS NOT NULL THEN JSON_UNQUOTE(channeltemplatevar->'$.LoginName')
            WHEN channeltemplatevar->'$.uname' IS NOT NULL THEN JSON_UNQUOTE(channeltemplatevar->'$.uname')
            WHEN channeltemplatevar->'$.accessKeyId' IS NOT NULL THEN JSON_UNQUOTE(channeltemplatevar->'$.accessKeyId')
            WHEN channeltemplatevar->'$.accessKey' IS NOT NULL THEN JSON_UNQUOTE(channeltemplatevar->'$.accessKey')
            WHEN channeltemplatevar->'$.username' IS NOT NULL THEN JSON_UNQUOTE(channeltemplatevar->'$.username')
            WHEN channeltemplatevar->'$.AccountId' IS NOT NULL THEN JSON_UNQUOTE(channeltemplatevar->'$.AccountId')
            WHEN channeltemplatevar->'$.Account' IS NOT NULL THEN JSON_UNQUOTE(channeltemplatevar->'$.Account')
            WHEN channeltemplatevar->'$.account' IS NOT NULL THEN JSON_UNQUOTE(channeltemplatevar->'$.account')
            WHEN channeltemplatevar->'$.AppKey' IS NOT NULL THEN JSON_UNQUOTE(channeltemplatevar->'$.AppKey')
            WHEN channeltemplatevar->'$.api_key' IS NOT NULL THEN JSON_UNQUOTE(channeltemplatevar->'$.api_key')
            WHEN channeltemplatevar->'$.apiKey' IS NOT NULL THEN JSON_UNQUOTE(channeltemplatevar->'$.apiKey')
            WHEN channeltemplatevar->'$.X_APP_ID' IS NOT NULL THEN JSON_UNQUOTE(channeltemplatevar->'$.X_APP_ID')
            END  AS loginname FROM mms_http_channel_template_config) b
            ) c ON c.channelid = list.channelid
             left join (select a.id, b.supplier_name, a.cooperate_company from mms_send_channel_info a left join channel_supplier b on a.supplier_id = b.id) chan on chan.id = list.channelid
        </if>
        <where>
             <if test="adjustPrice!=null and adjustPrice==0">
                 (oldPrice - newPrice) &lt;&gt; 0
             </if>
             <if test="adjustPrice!=null and adjustPrice==1">
                 (oldPrice - newPrice) = 0
             </if>
         </where>
     </select>

     <select id="listPageMmsPriceChannelNew" resultType="cn.roadm.bo.PriceRecord">
     select * from (
     <if test="nettype &lt;= 0 ">
     	 SELECT
			pr.channelid,
			sc.channel_name,
			sum( pr.unkonw ) unknown,
			sum( pr.income ) income,
			sum( pr.cost ) cost,
			sum( pr.un_income ) un_income,
			sum( pr.un_cost ) un_cost,
			ifnull( sum( pr.succ ), 0 ) num,
			sum(ifnull( pr.fail, 0 )) fail,
			'全国'  as province,
			0 nettype,
			pr.otype
			<if test="ismon==1">
				,pr.stat_time,pr.channel_price cprice
			</if>
		FROM
			(
			SELECT
				prs.* ,
					ifnull( prs.sp_price, 0 )* prs.succ income,
					ifnull( prs.sp_price, 0 )* prs.unkonw un_income,
					ifnull( prs.channel_price, 0 )* prs.succ cost,
					ifnull( prs.channel_price, 0 )* prs.unkonw un_cost

			FROM
				(
				SELECT
					sum(
					ifnull( sps.arrive_succ, 0 )) succ,
					sum(
					ifnull( sps.arrive_fail, 0 )) fail,
					sum(
						ifnull( sps.submit_succ, 0 )) + sum(
						ifnull( sps.submit_fail, 0 )) - sum(
						ifnull( sps.arrive_fail, 0 )) - sum(
						ifnull( sps.arrive_succ, 0 )) unkonw,
					sps.spid,
					sps.channelid,
					sps.stat_time,
					sps.sp_price,
					sps.channel_price,
					sps.otype
				FROM
					mms_sp_province_summary sps
				<where>
					ifnull(sps.nettype,0)=0
						<if test="createtime!=null and createtime!=''">
							and sps.stat_time &gt;= #{createtime}
						</if>
						<if test="createtime1!=null and createtime1!=''">
							and sps.stat_time &lt; DATE_ADD(str_to_date(#{createtime1},'%Y-%m-%d %H:%i:%s'),INTERVAL 1 DAY)
						</if>
						<if test="channelid!=null and channelid!=''">
							and sps.channelid=#{channelid}
						</if>
						<if test="otype!=null and otype>0">
							and sps.otype=#{otype}
						</if>
				</where>
				GROUP BY
					sps.spid,
					sps.channelid,
					sps.stat_time,
					sps.sp_price,
					sps.channel_price,
					sps.otype
					) as prs
			) pr left join mms_send_channel_info sc on pr.channelid=sc.id
			<where>
				<if test="channelid!=null and channelid!=''">
					and sc.id=#{channelid}
				</if>
			</where>
			GROUP BY
			pr.channelid,
			sc.channel_name,
			pr.otype
			<if test="ismon==1">
				,pr.stat_time,pr.channel_price
			</if>
			</if>
		<if test="nettype &lt; 0 and otype &lt; 1">
			union all
		</if>
		<if test="nettype != 0 and otype &lt; 1">
		SELECT
			pr.channelid,
			sc.channel_name,
			sum( pr.unkonw ) unknown,
			sum( pr.income ) income,
			sum( pr.cost ) cost,
			sum( pr.un_income ) un_income,
			sum( pr.un_cost ) un_cost,
			ifnull( sum( pr.succ ), 0 ) num,
			sum(ifnull( pr.fail, 0 )) fail,
			pr.province,
			1 nettype,
			0 otype
			<if test="ismon==1">
				,pr.stat_time,pr.channel_price cprice
			</if>
		FROM
			(
			SELECT
				prs.* ,
					ifnull( prs.sp_price, 0 )* prs.succ income,
					ifnull( prs.sp_price, 0 )* prs.unkonw un_income,
					ifnull( prs.channel_price, 0 )* prs.succ cost,
					ifnull( prs.channel_price, 0 )* prs.unkonw un_cost

			FROM
				(
				SELECT
					sum(
					ifnull( sps.arrive_succ, 0 )) succ,
					sum(
					ifnull( sps.arrive_fail, 0 )) fail,
					sum(
						ifnull( sps.submit_succ, 0 )) + sum(
						ifnull( sps.submit_fail, 0 )) - sum(
						ifnull( sps.arrive_fail, 0 )) - sum(
						ifnull( sps.arrive_succ, 0 )) unkonw,
					sps.spid,
					sps.channelid,
					sps.stat_time,
					sps.sp_price,
					sps.province,
					sps.channel_price
				FROM
					mms_sp_province_summary sps
				<where>
					ifnull(sps.nettype,0)=1
						<if test="createtime!=null and createtime!=''">
							and sps.stat_time &gt;= #{createtime}
						</if>
						<if test="createtime1!=null and createtime1!=''">
							and sps.stat_time &lt; DATE_ADD(str_to_date(#{createtime1},'%Y-%m-%d %H:%i:%s'),INTERVAL 1 DAY)
						</if>
						<if test="channelid!=null and channelid!=''">
							and sps.channelid=#{channelid}
						</if>
				</where>
				GROUP BY
					sps.spid,
					sps.channelid,
					sps.stat_time,
					sps.sp_price,
					sps.province,
					sps.channel_price
					) as prs
			) pr left join mms_send_channel_info sc on pr.channelid=sc.id
			<where>
				<if test="channelid!=null and channelid!=''">
					and sc.id=#{channelid}
				</if>
			</where>
			GROUP BY
			pr.channelid,
			sc.channel_name,
			pr.province
			<if test="ismon==1">
				,pr.stat_time,pr.channel_price
			</if>
			</if>) list
			<if test="orderType=='ASC'">
				<if test="col=='num'">
					order by num
				</if>
				<if test="col=='gross'">
					order by income-cost
				</if>
				<if test="col=='time'">
					order by stat_time
				</if>
			</if>
			<if test="orderType=='DESC'">
				<if test="col=='num'">
					order by num DESC
				</if>
				<if test="col=='gross'">
					order by income-cost DESC
				</if>
				<if test="col=='time'">
					order by stat_time DESC
				</if>
			</if>
     </select>

     <select id="getMmsPriceChannelNew" resultType="cn.roadm.bo.PriceRecord">
     	<if test="nettype &lt;= 0">
     	 SELECT
			sc.id channelid,
			sc.channel_name,
			sum( pr.unkonw ) unknown,
			sum( pr.income ) income,
			sum( pr.cost ) cost,
			sum( pr.un_income ) un_income,
			sum( pr.un_cost ) un_cost,
			ifnull( sum( pr.succ ), 0 ) num,
			sum(ifnull( pr.fail, 0 )) fail,
			'全国'  as province,
			0 nettype,
			pr.otype
			<if test="ismon==1">
				,pr.stat_time,pr.channel_price cprice
			</if>
		FROM
			(
			SELECT
				prs.* ,
					ifnull( prs.sp_price, 0 )* prs.succ income,
					ifnull( prs.sp_price, 0 )* prs.unkonw un_income,
					ifnull( prs.channel_price, 0 )* prs.succ cost,
					ifnull( prs.channel_price, 0 )* prs.unkonw un_cost

			FROM
				(
				SELECT
					sum(
					ifnull( sps.arrive_succ, 0 )) succ,
					sum(
					ifnull( sps.arrive_fail, 0 )) fail,
					sum(
						ifnull( sps.submit_succ, 0 )) + sum(
						ifnull( sps.submit_fail, 0 )) - sum(
						ifnull( sps.arrive_fail, 0 )) - sum(
						ifnull( sps.arrive_succ, 0 )) unkonw,
					sps.spid,
					sps.channelid,
					sps.stat_time,
					sps.sp_price,
					sps.channel_price,
					sps.otype
				FROM
					mms_sp_province_summary sps
				<where>
					ifnull(sps.nettype,0)=0
						<if test="createtime!=null and createtime!=''">
							and sps.stat_time &gt;= #{createtime}
						</if>
						<if test="createtime1!=null and createtime1!=''">
							and sps.stat_time &lt; DATE_ADD(str_to_date(#{createtime1},'%Y-%m-%d %H:%i:%s'),INTERVAL 1 DAY)
						</if>
						<if test="channelid!=null and channelid!=''">
							and sps.channelid=#{channelid}
						</if>
						<if test="otype!=null and otype>0">
							and otype=#{otype}
						</if>
				</where>
				GROUP BY
					sps.spid,
					sps.channelid,
					sps.stat_time,
					sps.sp_price,
					sps.channel_price,
					sps.otype
					) as prs
			) pr left join mms_send_channel_info sc on pr.channelid=sc.id
			<where>
				<if test="channelid!=null and channelid!=''">
					and sc.id=#{channelid}
				</if>
			</where>
			GROUP BY
			sc.id,
			sc.channel_name,
			pr.otype
			<if test="ismon==1">
				,pr.stat_time,pr.channel_price
			</if>
			</if>
		<if test="nettype &lt; 0  and otype &lt; 1">
			union all
		</if>
		<if test="nettype != 0  and otype &lt; 1">
		SELECT
			sc.id channelid,
			sc.channel_name,
			sum( pr.unkonw ) unknown,
			sum( pr.income ) income,
			sum( pr.cost ) cost,
			sum( pr.un_income ) un_income,
			sum( pr.un_cost ) un_cost,
			ifnull( sum( pr.succ ), 0 ) num,
			sum(ifnull( pr.fail, 0 )) fail,
			pr.province,
			1 nettype,
			0 otype
			<if test="ismon==1">
				,pr.stat_time,pr.channel_price cprice
			</if>
		FROM
			(
			SELECT
				prs.* ,
					ifnull( prs.sp_price, 0 )* prs.succ income,
					ifnull( prs.sp_price, 0 )* prs.unkonw un_income,
					ifnull( prs.channel_price, 0 )* prs.succ cost,
					ifnull( prs.channel_price, 0 )* prs.unkonw un_cost

			FROM
				(
				SELECT
					sum(
					ifnull( sps.arrive_succ, 0 )) succ,
					sum(
					ifnull( sps.arrive_fail, 0 )) fail,
					sum(
						ifnull( sps.submit_succ, 0 )) + sum(
						ifnull( sps.submit_fail, 0 )) - sum(
						ifnull( sps.arrive_fail, 0 )) - sum(
						ifnull( sps.arrive_succ, 0 )) unkonw,
					sps.spid,
					sps.channelid,
					sps.stat_time,
					sps.sp_price,
					sps.province,
					sps.channel_price
				FROM
					mms_sp_province_summary sps
				<where>
					ifnull(sps.nettype,0)=1
						<if test="createtime!=null and createtime!=''">
							and sps.stat_time &gt;= #{createtime}
						</if>
						<if test="createtime1!=null and createtime1!=''">
							and sps.stat_time &lt; DATE_ADD(str_to_date(#{createtime1},'%Y-%m-%d %H:%i:%s'),INTERVAL 1 DAY)
						</if>
						<if test="channelid!=null and channelid!=''">
							and sps.channelid=#{channelid}
						</if>
				</where>
				GROUP BY
					sps.spid,
					sps.channelid,
					sps.stat_time,
					sps.sp_price,
					sps.province,
					sps.channel_price
					) as prs
			) pr left join mms_send_channel_info sc on pr.channelid=sc.id
			<where>
				<if test="channelid!=null and channelid!=''">
					and sc.id=#{channelid}
				</if>
			</where>
			GROUP BY
			sc.id,
			sc.channel_name,
			pr.province
			<if test="ismon==1">
				,pr.stat_time,pr.channel_price
			</if>
			</if>
     </select>

     <select id="listPageMmsPriceRecordNew" resultType="cn.roadm.bo.PriceRecord">
     select * from(
     <if test="nettype &lt;= 0 ">
     	 SELECT
			sp.id spid,
			sp.sp_name,
			sp.sp_type,
			sp.commission_price,
			sp.noProfit,
			sum( pr.unkonw ) unknown,
			sum( pr.income ) income,
			sum( pr.cost ) cost,
			sum( pr.un_income ) un_income,
			sum( pr.un_cost ) un_cost,
			ifnull( sum( pr.succ ), 0 ) num,
			sum(ifnull( pr.fail, 0 )) fail,
			'全国' as province,
			0 as nettype,
			pr.otype
			<if test="queryType=='spchannel'">
				,pr.channelid
			</if>
			<if test="ismon==1">
				,pr.stat_time
				<if test="queryType=='sp'">
					,pr.sp_price sprice
				</if>
				<if test="queryType=='spchannel'">
					,pr.sp_price sprice,
					pr.channel_price cprice
				</if>
			</if>
		FROM
			(
			SELECT
				prs.* ,
					ifnull( prs.sp_price, 0 )* prs.succ income,
					ifnull( prs.sp_price, 0 )* prs.unkonw un_income,
					ifnull( prs.channel_price, 0 )* prs.succ cost,
					ifnull( prs.channel_price, 0 )* prs.unkonw un_cost

			FROM
				(
				SELECT
					sum(
					ifnull( sps.arrive_succ, 0 )) succ,
					sum(
					ifnull( sps.arrive_fail, 0 )) fail,
					sum(
						ifnull( sps.submit_succ, 0 )) + sum(
						ifnull( sps.submit_fail, 0 )) - sum(
						ifnull( sps.arrive_fail, 0 )) - sum(
						ifnull( sps.arrive_succ, 0 )) unkonw,
					sps.spid,
					sps.channelid,
					sps.stat_time,
					sps.sp_price,
					sps.channel_price,
					sps.otype
				FROM
					mms_sp_province_summary sps
				<where>
				     ifnull(sps.nettype,0)=0
						<if test="createtime!=null and createtime!=''">
							and sps.stat_time &gt;= #{createtime}
						</if>
						<if test="createtime1!=null and createtime1!=''">
							and sps.stat_time &lt; DATE_ADD(str_to_date(#{createtime1},'%Y-%m-%d %H:%i:%s'),INTERVAL 1 DAY)
						</if>
						<if test="channelid!=null and channelid!=''">
							and sps.channelid=#{channelid}
						</if>
						<if test="spid!=null and spid!=''">
							and sps.spid=#{spid}
						</if>
						<if test="otype!=null and otype>0">
							and sps.otype=#{otype}
						</if>
				</where>
				GROUP BY
					sps.spid,
					sps.channelid,
					sps.stat_time,
					sps.sp_price,
					sps.channel_price,
					sps.otype
					 ) as prs
			) pr inner join sms_sp_info sp ON pr.spid = sp.id
			<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>
                <if test="sp_saler!=null and sp_saler!=''">
                    and sp.sp_saler like CONCAT('%', #{sp_saler}, '%')
                </if>
                <if test="salerList!=null and salerList.size()>0">
                    and sp.sp_saler in
                    <foreach collection="salerList" index="index"  item="item" open="(" separator="," close=")">
                        '${item}'
                    </foreach>
                </if>
			</where>
			GROUP BY
			sp.id,
			sp.sp_name,
			sp.commission_price,
			sp.sp_type,
			sp.noProfit,
			pr.otype
			<if test="queryType=='spchannel'">
			,pr.channelid
			</if>
			<if test="ismon==1">
				,pr.stat_time
				<if test="queryType=='sp'">
					,pr.sp_price
				</if>
				<if test="queryType=='spchannel'">
					,pr.sp_price,pr.channel_price
				</if>
			</if>
			</if>
		<if test="nettype &lt; 0 and otype &lt; 1">
			union all
		</if>
		<if test="nettype != 0 and otype &lt; 1">
			SELECT
				sp.id spid,
				sp.sp_name,
				sp.sp_type,
				sp.commission_price,
				sp.noProfit,
				sum( pr.unkonw ) unknown,
				sum( pr.income ) income,
				sum( pr.cost ) cost,
				sum( pr.un_income ) un_income,
				sum( pr.un_cost ) un_cost,
				ifnull( sum( pr.succ ), 0 ) num,
				sum(ifnull( pr.fail, 0 )) fail,
				pr.province,
				1 as nettype,
				0 otype
				<if test="queryType=='spchannel'">
					,pr.channelid
				</if>
				<if test="ismon==1">
					,pr.stat_time
					<if test="queryType=='sp'">
						,pr.sp_price sprice
					</if>
					<if test="queryType=='spchannel'">
						,pr.sp_price sprice,
						pr.channel_price cprice
					</if>
				</if>
			FROM
				(
				SELECT
					prs.* ,
						ifnull( prs.sp_price, 0 )* prs.succ income,
						ifnull( prs.sp_price, 0 )* prs.unkonw un_income,
						ifnull( prs.channel_price, 0 )* prs.succ cost,
						ifnull( prs.channel_price, 0 )* prs.unkonw un_cost

				FROM
					(
					SELECT
						sum(
						ifnull( sps.arrive_succ, 0 )) succ,
						sum(
						ifnull( sps.arrive_fail, 0 )) fail,
						sum(
							ifnull( sps.submit_succ, 0 )) + sum(
							ifnull( sps.submit_fail, 0 )) - sum(
							ifnull( sps.arrive_fail, 0 )) - sum(
							ifnull( sps.arrive_succ, 0 )) unkonw,
						sps.spid,
						sps.channelid,
						sps.stat_time,
						sps.sp_price,
						sps.channel_price,
						sps.province
					FROM
						mms_sp_province_summary sps
					<where>
					     ifnull(sps.nettype,0)=1
							<if test="createtime!=null and createtime!=''">
								and sps.stat_time &gt;= #{createtime}
							</if>
							<if test="createtime1!=null and createtime1!=''">
								and sps.stat_time &lt; DATE_ADD(str_to_date(#{createtime1},'%Y-%m-%d %H:%i:%s'),INTERVAL 1 DAY)
							</if>
							<if test="channelid!=null and channelid!=''">
								and sps.channelid=#{channelid}
							</if>
							<if test="spid!=null and spid!=''">
								and sps.spid=#{spid}
							</if>
					</where>
					GROUP BY
						sps.spid,
						sps.channelid,
						sps.stat_time,
						sps.sp_price,
						sps.province,
						sps.channel_price
						 ) as prs
				) pr inner join sms_sp_info sp ON pr.spid = sp.id
				<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>
                    <if test="sp_saler!=null and sp_saler!=''">
                        and sp.sp_saler like CONCAT('%', #{sp_saler}, '%')
                    </if>
                    <if test="salerList!=null and salerList.size()>0">
                        and sp.sp_saler in
                        <foreach collection="salerList" index="index"  item="item" open="(" separator="," close=")">
                            '${item}'
                        </foreach>
                    </if>
				</where>
				GROUP BY
				sp.id,
				sp.sp_name,
				sp.commission_price,
				sp.sp_type,
				sp.noProfit,
				pr.province
				<if test="queryType=='spchannel'">
				,pr.channelid
				</if>
				<if test="ismon==1">
					,pr.stat_time
					<if test="queryType=='sp'">
						,pr.sp_price
					</if>
					<if test="queryType=='spchannel'">
						,pr.sp_price,pr.channel_price
					</if>
				</if>
			</if>) list
			<if test="orderType=='ASC'">
				<if test="col=='num'">
					order by num
				</if>
				<if test="col=='gross'">
					order by noProfit asc,income-cost asc
				</if>
				<if test="col=='time'">
					order by stat_time
				</if>
			</if>
			<if test="orderType=='DESC'">
				<if test="col=='num'">
					order by num DESC
				</if>
				<if test="col=='gross'">
					order by noProfit asc,income-cost DESC
				</if>
				<if test="col=='time'">
					order by stat_time DESC
				</if>
			</if>

     </select>

      <select id="getMmsPriceRecordNewCount" resultType="cn.roadm.bo.PriceRecord">
     	select spid,
			sp_name,
			sp_type,
			noProfit,
            ifnull((sum(oldPrice) - sum(newPrice)),0) adjustPrice,
			sum( income ) income,
			sum( cost ) cost,
			ifnull( sum( num ), 0 ) num,
			sum(ifnull( fail, 0 )) fail
	 from(
     	 SELECT
			sp.id spid,
			sp.sp_name,
			sp.sp_type,
			sp.noProfit,
            sa.saleprice * 10000 * count( pr.sp_price ) newPrice,
            sum( pr.sp_price ) oldPrice,
			sum( pr.income ) income,
			sum( pr.cost ) cost,
			ifnull( sum( pr.succ ), 0 ) num,
			sum(ifnull( pr.fail, 0 )) fail
		FROM
			(
			SELECT
				prs.* ,
					ifnull( prs.sp_price, 0 )* prs.succ income,
					ifnull( prs.sp_price, 0 )* prs.unkonw un_income,
					ifnull( prs.channel_price, 0 )* prs.succ cost,
					ifnull( prs.channel_price, 0 )* prs.unkonw un_cost

			FROM
				(
				SELECT
					sum(
					ifnull( sps.arrive_succ, 0 )) succ,
					sum(
					ifnull( sps.arrive_fail, 0 )) fail,
					sum(
						ifnull( sps.submit_succ, 0 )) + sum(
						ifnull( sps.submit_fail, 0 )) - sum(
						ifnull( sps.arrive_fail, 0 )) - sum(
						ifnull( sps.arrive_succ, 0 )) unkonw,
					sps.spid,
					sps.channelid,
					sps.stat_time,
					sps.sp_price,
					sps.channel_price
				FROM
					mms_sp_province_summary sps
				<where>
				     ifnull(sps.nettype,0)=0
						<if test="createtime!=null and createtime!=''">
							and sps.stat_time &gt;= #{createtime}
						</if>
						<if test="createtime1!=null and createtime1!=''">
							and sps.stat_time &lt; DATE_ADD(str_to_date(#{createtime1},'%Y-%m-%d %H:%i:%s'),INTERVAL 1 DAY)
						</if>
						<if test="channelid!=null and channelid!=''">
							and sps.channelid=#{channelid}
						</if>
						<if test="spid!=null and spid!=''">
							and sps.spid=#{spid}
						</if>
				</where>
				GROUP BY
					sps.spid,
					sps.channelid,
					sps.stat_time,
					sps.sp_price,
					sps.channel_price
					 ) as prs
			) pr inner join sms_sp_info sp ON pr.spid = sp.id
            left join sms_api_setting sa on sp.id=sa.sp_id
			<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>
                <if test="sp_saler!=null and sp_saler!=''">
                    and sp.sp_saler like CONCAT('%', #{sp_saler}, '%')
                </if>
                <if test="salerList!=null and salerList.size()>0">
                    and sp.sp_saler in
                    <foreach collection="salerList" index="index"  item="item" open="(" separator="," close=")">
                        '${item}'
                    </foreach>
                </if>
			</where>
			GROUP BY
			sp.id,
			sp.sp_name,
			sp.commission_price,
			sp.sp_type,
			sp.noProfit
			<if test="queryType=='spchannel'">
			,pr.channelid
			</if>
			<if test="ismon==1">
				,pr.stat_time
				<if test="queryType=='sp'">
					,pr.sp_price
				</if>
				<if test="queryType=='spchannel'">
					,pr.sp_price,pr.channel_price
				</if>
			</if>
		union all
		SELECT
			sp.id spid,
			sp.sp_name,
			sp.sp_type,
			sp.noProfit,
            sa.saleprice * 10000 * count( pr.sp_price ) newPrice,
            sum( pr.sp_price ) oldPrice,
			sum( pr.income ) income,
			sum( pr.cost ) cost,
			ifnull( sum( pr.succ ), 0 ) num,
			sum(ifnull( pr.fail, 0 )) fail
		FROM
			(
			SELECT
				prs.* ,
					ifnull( prs.sp_price, 0 )* prs.succ income,
					ifnull( prs.sp_price, 0 )* prs.unkonw un_income,
					ifnull( prs.channel_price, 0 )* prs.succ cost,
					ifnull( prs.channel_price, 0 )* prs.unkonw un_cost

			FROM
				(
				SELECT
					sum(
					ifnull( sps.arrive_succ, 0 )) succ,
					sum(
					ifnull( sps.arrive_fail, 0 )) fail,
					sum(
						ifnull( sps.submit_succ, 0 )) + sum(
						ifnull( sps.submit_fail, 0 )) - sum(
						ifnull( sps.arrive_fail, 0 )) - sum(
						ifnull( sps.arrive_succ, 0 )) unkonw,
					sps.spid,
					sps.channelid,
					sps.stat_time,
					sps.sp_price,
					sps.channel_price,
					sps.province
				FROM
					mms_sp_province_summary sps
				<where>
				     ifnull(sps.nettype,0)=1
						<if test="createtime!=null and createtime!=''">
							and sps.stat_time &gt;= #{createtime}
						</if>
						<if test="createtime1!=null and createtime1!=''">
							and sps.stat_time &lt; DATE_ADD(str_to_date(#{createtime1},'%Y-%m-%d %H:%i:%s'),INTERVAL 1 DAY)
						</if>
						<if test="channelid!=null and channelid!=''">
							and sps.channelid=#{channelid}
						</if>
						<if test="spid!=null and spid!=''">
							and sps.spid=#{spid}
						</if>
				</where>
				GROUP BY
					sps.spid,
					sps.channelid,
					sps.stat_time,
					sps.sp_price,
					sps.province,
					sps.channel_price
					 ) as prs
			) pr inner join sms_sp_info sp ON pr.spid = sp.id
            left join sms_api_setting sa on sp.id=sa.sp_id
			<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>
                <if test="sp_saler!=null and sp_saler!=''">
                    and sp.sp_saler like CONCAT('%', #{sp_saler}, '%')
                </if>
                <if test="salerList!=null and salerList.size()>0">
                    and sp.sp_saler in
                    <foreach collection="salerList" index="index"  item="item" open="(" separator="," close=")">
                        '${item}'
                    </foreach>
                </if>
			</where>
			GROUP BY
			sp.id,
			sp.sp_name,
			sp.commission_price,
			sp.sp_type,
			sp.noProfit,
			pr.province
			<if test="queryType=='spchannel'">
			,pr.channelid
			</if>
			<if test="ismon==1">
				,pr.stat_time
				<if test="queryType=='sp'">
					,pr.sp_price
				</if>
				<if test="queryType=='spchannel'">
					,pr.sp_price,pr.channel_price
				</if>
			</if>) list
             <where>
                 <if test="adjustPrice!=null and adjustPrice==0">
                     (oldPrice - newPrice) &lt;&gt; 0
                 </if>
                 <if test="adjustPrice!=null and adjustPrice==1">
                     (oldPrice - newPrice) = 0
                 </if>
             </where>
			GROUP BY
			spid,
			sp_name,
			sp_type,
			noProfit
			<if test="orderType=='ASC'">
				<if test="col=='num'">
					order by sum(num)
				</if>
				<if test="col=='gross'">
					order by noProfit asc,sum(income)-sum(cost)
				</if>
				<if test="col=='time'">
					order by stat_time
				</if>
			</if>
			<if test="orderType=='DESC'">
				<if test="col=='num'">
					order by sum(num) DESC
				</if>
				<if test="col=='gross'">
					order by noProfit asc,sum(income)-sum(cost) DESC
				</if>
				<if test="col=='time'">
					order by stat_time DESC
				</if>
			</if>
     </select>

    <!--获取彩信补发记录详情List-->
    <select id="listPageMmsReSendDetail" parameterType="TaskDetailInfo"
            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.RESEND_CHANNELID,
        <!-- 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
        from mms_arrive_resend st
        LEFT JOIN sms_sp_info sp
        ON st.sp_id = sp.id
        LEFT JOIN mms_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="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>
        </where>
        order by st.id desc
    </select>

    <!--获取彩信补发记录提交信息-->
    <select id="getMmsTaskDetailFromSubmit" parameterType="TaskDetailInfo"
            resultMap="TaskDetailInfoResultMap">
        select
        st.id,
        st.res_desc,
        st.send_time,
        st.res_content
        from sms_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>
        <if test="otype!=null and otype!=''">
            and st.otype=#{otype}
        </if>
        limit 1
    </select>

    <!--彩信发送类型-->
    <select id="getMmsTaskInfoById" parameterType="TaskInfo" resultMap="taskInfoMap">
        select tk.id,
        tk.sp_id,
        tk.content,
        tk.createid,
        tk.createtime,
        tk.total,
        tk.allnumber,
        tk.unicomnumber,
        tk.mobilenumber,
        tk.telecomnumber,
        tk.task_type,
        tk.status,

        sp.sp_audit_type,
        tk.send_type
        from mms_api_audit_task tk, sms_api_setting sp
        where sp.sp_id = tk.sp_id
        <if test="sp_id!=null and sp_id>0">
            and tk.sp_id=#{sp_id}
        </if>
        <if test="task_id!=null and task_id>0">
            and tk.id=#{task_id}
        </if>
    </select>

    <select id="listPageSaleProvisionInfo" parameterType="ProvisionInfo" resultMap="provisionInfoMap">
        SELECT
        id,
        sp_name,
        sp_saler,
        full_name,
        clientid,
        provision_price,
        serviceType,
        saleprice,
        <if test="type_channel!=null and type_channel == 'channel'">
            channelid,
        </if>
        <if test="type_day!=null and type_day == 'day'">
            statTime,
        </if>
        SUM( complaintsNum ) AS complaintsNum,
        SUM( totalSuccNum ) AS totalSuccNum,
        SUM( totalUnkNum ) AS totalUnkNum,
        SUM( channelProfit ) AS profit,
        Round( SUM( complaintsNum )*1000000/SUM(IFNULL( totalSuccNum,0)), 4 ) totalComplaintsRate
        FROM
        (
        SELECT
        sp.id,
        sp_name,
        sp_saler,
        se.full_name,
        sa.clientid,
        provision_price,
        se.serviceType,
        st.SALEPRICE,
        al.complaintsNum,
        al.CHANNELID,
        al.totalSuccNum,
        al.totalUnkNum,
        al.statTime,
        al.channelProfit
        FROM
        sms_sp_info sp
        LEFT JOIN sms_api_socket_sp sa ON sa.spid = sp.id
        LEFT JOIN sms_api_setting st ON st.SP_ID = sp.id
        LEFT JOIN sms_enterprise se ON se.id = sp.eid
        RIGHT JOIN (
        SELECT
        ssum.spid,
        ssum.CHANNELID,
        IFNULL( sc.complaintsNum, 0 ) AS complaintsNum,
        ssum.channelProfit,
        ssum.totalSuccNum,
        ssum.totalUnkNum,
        ssum.statTime
        FROM
        (
        SELECT
        SP_ID,
        CHANNELID,
        count(*) AS complaintsNum,
        DATE ( SEND_TIME ) AS sendTime
        FROM
        sms_complaint
        WHERE
        SEND_TIME &gt;= str_to_date( #{createTime}, '%Y-%m-%d' )
        AND SEND_TIME &lt; DATE_ADD( str_to_date( #{createTime1}, '%Y-%m-%d' ), INTERVAL 1 DAY )
        GROUP BY
        SP_ID,
        CHANNELID,
        sendTime
        ) sc
        RIGHT JOIN (
        SELECT
        ssp.spid,
        ssp.CHANNELID,
        SUM(Round(( ssp.sp_price/10000 - IFNULL( NULLIF(provision_price,''), IFNULL( channel_price, 0 )/10000 ))* arrive_succ, 4 )) channelProfit,
        SUM(
        IFNULL( arrive_succ, 0 )) totalSuccNum,
        SUM( IFNULL(submit_succ + submit_fail - arrive_succ - arrive_fail , 0 )) totalUnkNum,
        DATE ( stat_time ) AS statTime
        FROM
        sms_sp_province_summary ssp left join sms_sp_info sp on sp.id = ssp.spid
        WHERE
        stat_time &gt;= str_to_date( #{createTime}, '%Y-%m-%d' )
        AND stat_time &lt; DATE_ADD( str_to_date( #{createTime1}, '%Y-%m-%d' ), INTERVAL 1 DAY )
        AND CHANNELID != 0
        GROUP BY
        ssp.spid,
        ssp.CHANNELID,
        statTime
        ) ssum ON sc.SP_ID = ssum.spid
        AND sc.CHANNELID = ssum.CHANNELID
        AND sc.sendTime = ssum.statTime
        ) al ON al.spid = sp.id
        ) a
        <where>
        <if test="serviceType!=null and serviceType!=''">
            AND a.serviceType =#{serviceType}
        </if>
        <if test="sp_name!=null and sp_name!=''">
            and a.sp_name like concat('%',#{sp_name},'%')
        </if>
        <if test="sp_id!=null and sp_id!=''">
            and a.id=#{sp_id}
        </if>
        <if test="sp_saler!=null and sp_saler!=''">
            and a.sp_saler like CONCAT('%', #{sp_saler}, '%')
        </if>
        <if test="managerId != null and managerId != ''">
            and a.sp_saler in (select ifnull(seller,'') from sale_manager sm where managerId=#{managerId}) and
            a.sp_saler != ''
        </if>
        </where>
        GROUP BY
        id,
        sp_name,
        sp_saler,
        full_name,
        clientid,
        provision_price,
        serviceType,
        SALEPRICE
        <if test="type_channel!=null and type_channel == 'channel'">
            ,CHANNELID
        </if>
        <if test="type_day!=null and type_day == 'day'">
            ,statTime
        </if>
        <if test="col != null and col != '' and col=='provisionPrice'">
            order by provision_price ${orderType}
        </if>
        <if test="col != null and col != '' and col=='salePrice'">
            order by salePrice ${orderType}
        </if>
        <if test="col != null and col != '' and col=='complaintsNum'">
            order by complaintsNum ${orderType}
        </if>
        <if test="col != null and col != '' and col=='profit'">
            order by profit ${orderType}
        </if>
        <if test="col != null and col != '' and col=='totalComplaintsRate'">
            order by totalComplaintsRate ${orderType}
        </if>
        <if test="col != null and col != '' and col=='totalSuccNum'">
            order by totalSuccNum ${orderType}
        </if>
        <if test="type_day!=null and type_day == 'day'">
            order by statTime asc
        </if>
    </select>


    <select id="sumSaleProvisionInfo" parameterType="ProvisionInfo" resultMap="provisionInfoMap">
        SELECT
        id,
        sp_name,
        sp_saler,
        full_name,
        clientid,
        provision_price,
        serviceType,
        saleprice,
        <if test="type_channel!=null and type_channel == 'channel'">
            channelid,
        </if>
        <if test="type_day!=null and type_day == 'day'">
            statTime,
        </if>
        SUM( complaintsNum ) AS complaintsNum,
        SUM( totalSuccNum ) AS totalSuccNum,
        SUM( channelProfit ) AS profit,
        Round( SUM( complaintsNum )*1000000/SUM(IFNULL( totalSuccNum,0)), 4 ) totalComplaintsRate
        FROM
        (
        SELECT
        sp.id,
        sp_name,
        sp_saler,
        se.full_name,
        sa.clientid,
        provision_price,
        se.serviceType,
        st.SALEPRICE,
        al.complaintsNum,
        al.CHANNELID,
        al.totalSuccNum,
        al.statTime,
        al.channelProfit
        FROM
        sms_sp_info sp
        LEFT JOIN sms_api_socket_sp sa ON sa.spid = sp.id
        LEFT JOIN sms_api_setting st ON st.SP_ID = sp.id
        LEFT JOIN sms_enterprise se ON se.id = sp.eid
        RIGHT JOIN (
        SELECT
        ssum.spid,
        ssum.CHANNELID,
        IFNULL( sc.complaintsNum, 0 ) AS complaintsNum,
        ssum.channelProfit,
        ssum.totalSuccNum,
        ssum.statTime
        FROM
        (
        SELECT
        SP_ID,
        CHANNELID,
        count(*) AS complaintsNum,
        DATE ( SEND_TIME ) AS sendTime
        FROM
        sms_complaint
        WHERE
        SEND_TIME &gt;= str_to_date( #{createTime}, '%Y-%m-%d' )
        AND SEND_TIME &lt; DATE_ADD( str_to_date( #{createTime1}, '%Y-%m-%d' ), INTERVAL 1 DAY )
        GROUP BY
        SP_ID,
        CHANNELID,
        sendTime
        ) sc
        RIGHT JOIN (
        SELECT
        ssp.spid,
        ssp.CHANNELID,
        SUM(Round(( ssp.sp_price/10000 - IFNULL( NULLIF(provision_price,''), IFNULL( channel_price, 0 )/10000 ))* arrive_succ, 4 )) channelProfit,
        SUM(
        IFNULL( arrive_succ, 0 )) totalSuccNum,
        DATE ( stat_time ) AS statTime
        FROM
        sms_sp_province_summary ssp left join sms_sp_info sp on sp.id = ssp.spid
        WHERE
        stat_time &gt;= str_to_date( #{createTime}, '%Y-%m-%d' )
        AND stat_time &lt; DATE_ADD( str_to_date( #{createTime1}, '%Y-%m-%d' ), INTERVAL 1 DAY )
        AND CHANNELID != 0
        GROUP BY
        ssp.spid,
        ssp.CHANNELID,
        statTime
        ) ssum ON sc.SP_ID = ssum.spid
        AND sc.CHANNELID = ssum.CHANNELID
        AND sc.sendTime = ssum.statTime
        ) al ON al.spid = sp.id
        ) a
        <where>
            <if test="serviceType!=null and serviceType!=''">
                AND a.serviceType =#{serviceType}
            </if>
            <if test="sp_name!=null and sp_name!=''">
                and a.sp_name like concat('%',#{sp_name},'%')
            </if>
            <if test="sp_id!=null and sp_id!=''">
                and a.id=#{sp_id}
            </if>
            <if test="sp_saler!=null and sp_saler!=''">
                and a.sp_saler like CONCAT('%', #{sp_saler}, '%')
            </if>
            <if test="managerId != null and managerId != ''">
                and a.sp_saler in (select ifnull(seller,'') from sale_manager sm where managerId=#{managerId}) and
                a.sp_saler != ''
            </if>
        </where>
        GROUP BY
        id,
        sp_name,
        sp_saler,
        full_name,
        clientid,
        provision_price,
        serviceType,
        SALEPRICE
        <if test="type_channel!=null and type_channel == 'channel'">
            ,CHANNELID
        </if>
        <if test="type_day!=null and type_day == 'day'">
            ,statTime
        </if>
    </select>

    <!--彩信发送类型-->

    <select id="exportPlatformTaskTotal" parameterType="ProvisionInfo" resultMap="provisionInfoMap">
        SELECT
        id,
        sp_name,
        sp_saler,
        full_name,
        clientid,
        provision_price,
        serviceType,
        saleprice,
        <if test="type_channel!=null and type_channel == 'channel'">
            channelid,
        </if>
        <if test="type_day!=null and type_day == 'day'">
            statTime,
        </if>
        SUM( complaintsNum ) AS complaintsNum,
        SUM( totalSuccNum ) AS totalSuccNum,
        SUM( channelProfit ) AS profit,
        Round( SUM( complaintsNum )*1000000/SUM(IFNULL( totalSuccNum,0)), 4 ) totalComplaintsRate
        FROM
        (
        SELECT
        sp.id,
        sp_name,
        sp_saler,
        se.full_name,
        sa.clientid,
        provision_price,
        se.serviceType,
        st.SALEPRICE,
        al.complaintsNum,
        al.CHANNELID,
        al.totalSuccNum,
        al.statTime,
        al.channelProfit
        FROM
        sms_sp_info sp
        LEFT JOIN sms_api_socket_sp sa ON sa.spid = sp.id
        LEFT JOIN sms_api_setting st ON st.SP_ID = sp.id
        LEFT JOIN sms_enterprise se ON se.id = sp.eid
        RIGHT JOIN (
        SELECT
        ssum.spid,
        ssum.CHANNELID,
        IFNULL( sc.complaintsNum, 0 ) AS complaintsNum,
        ssum.channelProfit,
        ssum.totalSuccNum,
        ssum.statTime
        FROM
        (
        SELECT
        SP_ID,
        CHANNELID,
        count(*) AS complaintsNum,
        DATE ( SEND_TIME ) AS sendTime
        FROM
        sms_complaint
        WHERE
        SEND_TIME &gt;= str_to_date( #{createTime}, '%Y-%m-%d' )
        AND SEND_TIME &lt; DATE_ADD( str_to_date( #{createTime1}, '%Y-%m-%d' ), INTERVAL 1 DAY )
        GROUP BY
        SP_ID,
        CHANNELID,
        sendTime
        ) sc
        RIGHT JOIN (
        SELECT
        ssp.spid,
        ssp.CHANNELID,
        SUM(Round(( ssp.sp_price/10000 - IFNULL( NULLIF(provision_price,''), IFNULL( channel_price, 0 )/10000 ))* arrive_succ, 4 )) channelProfit,
        SUM(
        IFNULL( arrive_succ, 0 )) totalSuccNum,
        DATE ( stat_time ) AS statTime
        FROM
        sms_sp_province_summary ssp left join sms_sp_info sp on sp.id = ssp.spid
        WHERE
        stat_time &gt;= str_to_date( #{createTime}, '%Y-%m-%d' )
        AND stat_time &lt; DATE_ADD( str_to_date( #{createTime1}, '%Y-%m-%d' ), INTERVAL 1 DAY )
        AND CHANNELID != 0
        GROUP BY
        ssp.spid,
        ssp.CHANNELID,
        statTime
        ) ssum ON sc.SP_ID = ssum.spid
        AND sc.CHANNELID = ssum.CHANNELID
        AND sc.sendTime = ssum.statTime
        ) al ON al.spid = sp.id
        ) a
        <where>
        <if test="serviceType!=null and serviceType!=''">
            AND a.serviceType =#{serviceType}
        </if>
        <if test="sp_name!=null and sp_name!=''">
            and a.sp_name like concat('%',#{sp_name},'%')
        </if>
        <if test="sp_id!=null and sp_id!=''">
            and a.id=#{sp_id}
        </if>
        <if test="sp_saler!=null and sp_saler!=''">
            and a.sp_saler like CONCAT('%', #{sp_saler}, '%')
        </if>
        <if test="managerId != null and managerId != ''">
            and a.sp_saler in (select ifnull(seller,'') from sale_manager sm where managerId=#{managerId}) and
            a.sp_saler != ''
        </if>
        </where>
        GROUP BY
        id,
        sp_name,
        sp_saler,
        full_name,
        clientid,
        provision_price,
        serviceType,
        SALEPRICE
        <if test="type_channel!=null and type_channel == 'channel'">
            ,CHANNELID
        </if>
        <if test="type_day!=null and type_day == 'day'">
            ,statTime
        </if>
        <if test="col != null and col != '' and col=='provisionPrice'">
            order by provision_price ${orderType}
        </if>
        <if test="col != null and col != '' and col=='salePrice'">
            order by salePrice ${orderType}
        </if>
        <if test="col != null and col != '' and col=='complaintsNum'">
            order by complaintsNum ${orderType}
        </if>
        <if test="col != null and col != '' and col=='profit'">
            order by profit ${orderType}
        </if>
        <if test="col != null and col != '' and col=='totalComplaintsRate'">
            order by totalComplaintsRate ${orderType}
        </if>
        <if test="col != null and col != '' and col=='totalSuccNum'">
            order by totalSuccNum ${orderType}
        </if>
        <if test="type_day!=null and type_day == 'day'">
            order by statTime asc
        </if>
    </select>

    <select id="listPageSaleSum" parameterType="ProvisionInfo" resultMap="provisionInfoMap">
        SELECT
        sp_saler,
        full_name,
        <if test="type_day!=null and type_day == 'day'">
            statTime,
        </if>
        SUM( complaintsNum ) AS complaintsNum,
        SUM( totalSuccNum ) AS totalSuccNum,
        SUM( channelProfit ) - IFNULL(black_count,0)/10000 AS profit,
        SUM( totalProfit ) AS totalProfit
        FROM
        (
        SELECT
        sp.id,
        sp_name,
        sp_saler,
        se.full_name,
        sa.clientid,
        provision_price,
        se.serviceType,
        st.SALEPRICE,
        al.complaintsNum,
        al.CHANNELID,
        al.totalSuccNum,
        al.statTime,
        al.channelProfit,
        al.totalProfit,
        black_count
        FROM
        sms_sp_info sp
        LEFT JOIN sms_api_socket_sp sa ON sa.spid = sp.id
        LEFT JOIN sms_api_setting st ON st.SP_ID = sp.id
        LEFT JOIN sms_enterprise se ON se.id = sp.eid
        RIGHT JOIN (
        SELECT
        ssum.spid,
        ssum.CHANNELID,
        IFNULL( sc.complaintsNum, 0 ) AS complaintsNum,
        ssum.channelProfit,
        ssum.totalProfit,
        ssum.totalSuccNum,
        ssum.statTime
        FROM
        (
        SELECT
        SP_ID,
        CHANNELID,
        count(*) AS complaintsNum,
        DATE ( SEND_TIME ) AS sendTime
        FROM
        sms_complaint
        WHERE
        SEND_TIME &gt;= str_to_date( #{createTime}, '%Y-%m-%d' )
        AND SEND_TIME &lt; DATE_ADD( str_to_date( #{createTime1}, '%Y-%m-%d' ), INTERVAL 1 DAY )
        GROUP BY
        SP_ID,
        CHANNELID,
        sendTime
        ) sc
        RIGHT JOIN (
        SELECT
        ssp.spid,
        ssp.CHANNELID,
        SUM(Round(( ssp.sp_price/10000 - IFNULL( NULLIF(provision_price,''), IFNULL( channel_price, 0 )/10000))* arrive_succ, 4 )) channelProfit,
        SUM(Round( ssp.sp_price/10000* arrive_succ, 4 )) totalProfit,
        SUM(
        IFNULL( arrive_succ, 0 )) totalSuccNum,
        DATE ( stat_time ) AS statTime
        FROM
        sms_sp_province_summary ssp left join sms_sp_info sp on sp.id = ssp.spid
        WHERE
        stat_time &gt;= str_to_date( #{createTime}, '%Y-%m-%d' )
        AND stat_time &lt; DATE_ADD( str_to_date( #{createTime1}, '%Y-%m-%d' ), INTERVAL 1 DAY )
        AND CHANNELID != 0
        GROUP BY
        ssp.spid,
        ssp.CHANNELID,
        statTime
        ) ssum ON sc.SP_ID = ssum.spid
        AND sc.CHANNELID = ssum.CHANNELID
        AND sc.sendTime = ssum.statTime
        ) al ON al.spid = sp.id LEFT JOIN (select spid, ifnull(sum(bps.black_num*bpt.price),0) as black_count from black_phone_summary bps,sms_black_phone_type bpt where bps.black_type_id=bpt.id and bpt.type=3
        and bps.stat_time &gt;= #{createTime}
        and bps.stat_time &lt;date_add(#{createTime1},INTERVAL 1 DAY) group by spid) b on b.spid=sp.id
        ) a
        <where>
        <if test="serviceType!=null and serviceType!=''">
            AND a.serviceType =#{serviceType}
        </if>
        <if test="customerName!=null and customerName!=''">
            and a.full_name like concat('%',#{customerName},'%')
        </if>
        <if test="sp_id!=null and sp_id!=''">
            and a.id=#{sp_id}
        </if>
        <if test="sp_saler!=null and sp_saler!=''">
            and a.sp_saler like CONCAT('%', #{sp_saler}, '%')
        </if>
        <if test="managerId != null and managerId != ''">
            and a.sp_saler in (select ifnull(seller,'') from sale_manager sm where managerId=#{managerId}) and
            a.sp_saler != ''
        </if>
        </where>
        GROUP BY
        sp_saler,
        full_name,
        black_count
        <if test="type_day!=null and type_day == 'day'">
            ,statTime
        </if>
        <if test="col != null and col != '' and col=='complaintsNum'">
            order by complaintsNum ${orderType}
        </if>
        <if test="col != null and col != '' and col=='profit'">
            order by profit ${orderType}
        </if>
        <if test="col != null and col != '' and col=='totalProfit'">
            order by totalProfit ${orderType}
        </if>
        <if test="col != null and col != '' and col=='totalSuccNum'">
            order by totalSuccNum ${orderType}
        </if>
        <if test="type_day!=null and type_day == 'day'">
            order by statTime asc
        </if>
    </select>


    <select id="sumPageSaleSum" parameterType="ProvisionInfo" resultMap="provisionInfoMap">
        SELECT
        sp_saler,
        full_name,
        <if test="type_day!=null and type_day == 'day'">
            statTime,
        </if>
        SUM( complaintsNum ) AS complaintsNum,
        SUM( totalSuccNum ) AS totalSuccNum,
        SUM( channelProfit ) - IFNULL(black_count,0)/10000 AS profit,
        SUM( totalProfit ) AS totalProfit
        FROM
        (
        SELECT
        sp.id,
        sp_name,
        sp_saler,
        se.full_name,
        sa.clientid,
        provision_price,
        se.serviceType,
        st.SALEPRICE,
        al.complaintsNum,
        al.CHANNELID,
        al.totalSuccNum,
        al.statTime,
        al.channelProfit,
        al.totalProfit,
        black_count
        FROM
        sms_sp_info sp
        LEFT JOIN sms_api_socket_sp sa ON sa.spid = sp.id
        LEFT JOIN sms_api_setting st ON st.SP_ID = sp.id
        LEFT JOIN sms_enterprise se ON se.id = sp.eid
        RIGHT JOIN (
        SELECT
        ssum.spid,
        ssum.CHANNELID,
        IFNULL( sc.complaintsNum, 0 ) AS complaintsNum,
        ssum.channelProfit,
        ssum.totalProfit,
        ssum.totalSuccNum,
        ssum.statTime
        FROM
        (
        SELECT
        SP_ID,
        CHANNELID,
        count(*) AS complaintsNum,
        DATE ( SEND_TIME ) AS sendTime
        FROM
        sms_complaint
        WHERE
        SEND_TIME &gt;= str_to_date( #{createTime}, '%Y-%m-%d' )
        AND SEND_TIME &lt; DATE_ADD( str_to_date( #{createTime1}, '%Y-%m-%d' ), INTERVAL 1 DAY )
        GROUP BY
        SP_ID,
        CHANNELID,
        sendTime
        ) sc
        RIGHT JOIN (
        SELECT
        ssp.spid,
        ssp.CHANNELID,
        SUM(Round(( ssp.sp_price/10000 - IFNULL( NULLIF(provision_price,''), IFNULL( channel_price, 0 )/10000))* arrive_succ, 4 )) channelProfit,
        SUM(Round( ssp.sp_price/10000* arrive_succ, 4 )) totalProfit,
        SUM(
        IFNULL( arrive_succ, 0 )) totalSuccNum,
        DATE ( stat_time ) AS statTime
        FROM
        sms_sp_province_summary ssp left join sms_sp_info sp on sp.id = ssp.spid
        WHERE
        stat_time &gt;= str_to_date( #{createTime}, '%Y-%m-%d' )
        AND stat_time &lt; DATE_ADD( str_to_date( #{createTime1}, '%Y-%m-%d' ), INTERVAL 1 DAY )
        AND CHANNELID != 0
        GROUP BY
        ssp.spid,
        ssp.CHANNELID,
        statTime
        ) ssum ON sc.SP_ID = ssum.spid
        AND sc.CHANNELID = ssum.CHANNELID
        AND sc.sendTime = ssum.statTime
        ) al ON al.spid = sp.id LEFT JOIN (select spid, ifnull(sum(bps.black_num*bpt.price),0) as black_count from black_phone_summary bps,sms_black_phone_type bpt where bps.black_type_id=bpt.id and bpt.type=3
        and bps.stat_time &gt;= #{createTime}
        and bps.stat_time &lt;date_add(#{createTime1},INTERVAL 1 DAY) group by spid) b on b.spid=sp.id
        ) a
        <where>
            <if test="serviceType!=null and serviceType!=''">
                AND a.serviceType =#{serviceType}
            </if>
            <if test="customerName!=null and customerName!=''">
                and a.full_name like concat('%',#{customerName},'%')
            </if>
            <if test="sp_id!=null and sp_id!=''">
                and a.id=#{sp_id}
            </if>
            <if test="sp_saler!=null and sp_saler!=''">
                and a.sp_saler like CONCAT('%', #{sp_saler}, '%')
            </if>
            <if test="managerId != null and managerId != ''">
                and a.sp_saler in (select ifnull(seller,'') from sale_manager sm where managerId=#{managerId}) and
                a.sp_saler != ''
            </if>
        </where>
        GROUP BY
        sp_saler,
        full_name,
        black_count
        <if test="type_day!=null and type_day == 'day'">
            ,statTime
        </if>
    </select>

    <select id="listPageSpSignMmsTaskTotal" resultType="cn.roadm.bo.TaskInfo">
        select sp.id sp_id,
		sp.sp_name,
		tk.sign,
		vspp.sp_all_submit,
        <if test="ismon==1">
            tk.stat_time,
        </if>
		sum(tk.submit_succ) succ,
		sum(IFNULL(tk.submit_fail,0)) fail,
		sum(tk.arrive_succ) arrive_succ,
		<!-- sum(IFNULL(tk.submit_succ+tk.submit_fail-tk.arrive_succ-tk.arrive_fail,0)) unRecMsgnum, -->
		sum(IFNULL(tk.submit_succ,0))+sum(IFNULL(tk.submit_fail,0))-sum(IFNULL(tk.arrive_succ,0))-sum(IFNULL(tk.arrive_fail,0)) unRecMsgnum,
		sum(tk.arrive_fail) arrive_fail
		from mms_sp_tem_summary tk, sms_sp_info sp,
		(
		select sum(spp.submit_succ) sp_all_submit,spp.spid from
		mms_sp_tem_summary spp, sms_sp_info spinfo
		where spp.spid = spinfo.id
		<if test="sp_name!=null and sp_name!=''">
			and spinfo.sp_name like CONCAT('%',#{sp_name},'%')
		</if>
		<if test="sp_id!=null and sp_id>0">
			and spp.spid=#{sp_id}
		</if>
		<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>
		 group by spp.spid
		 ) vspp
		where tk.spid = sp.id and tk.spid = vspp.spid


		<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="sign!=null and sign!=''">
			and tk.sign like CONCAT('%',#{sign},'%')
		</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,tk.sign
        <if test="ismon==1">
            ,tk.stat_time
        </if>
		order by
        <choose>
            <when test="ismon == 1 and sort != null and sort != '' and sort == 'up'">
                tk.stat_time asc
            </when>
            <when test="ismon == 1 and sort != null and sort != '' and sort == 'down'">
                tk.stat_time desc
            </when>
            <otherwise>
                sp.id,succ desc
            </otherwise>
        </choose>
    </select>

    <select id="getThisTaskIdCount" resultType="java.lang.Integer">
        select count(1) from sms_send_task where id = #{taskId} and CREATETIME &gt;= DATE_SUB(NOW(), INTERVAL 30 DAY) and CREATETIME &lt;= NOW()
    </select>
</mapper>

