<?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.ApiAuditSmsMapper">
    <resultMap type="TaskInfo" id="auditTaskMap">
        <id column="id" property="task_id" />
        <result column="content" property="content" />
        <result column="createtime" property="beginTime" />
        <result column="createid" property="createid" />
        <result column="total" property="total" />
        <result column="allnumber" property="allnumber" />
        <result column="mobilenumber" property="mobilenumber" />
        <result column="unicomnumber" property="unicomnumber" />
        <result column="telecomnumber" property="telecomnumber" />
        <result column="task_type" property="task_type" />
        <result column="status" property="status" />
        <result column="send_type" property="send_type" />
        <result column="sp_id" property="sp_id" />
        <result column="sp_name" property="sp_name" />
        <result column="audit_result" property="audit_result" />
        <result column="mdns" property="mdns" />
    </resultMap>

    <resultMap type="AuditResult" id="auditResultMap">
        <id column="id" property="id" />
        <result column="create_time" property="create_time" />
        <result column="audit_result" property="audit_result" />
        <result column="audit_opeator" property="audit_opeator" />
        <result column="audit_desc" property="audit_desc" />
        <result column="createtime" property="beginTime" />
        <result column="taskid" property="taskid" />
        <result column="allnumber" property="allnumber" />
        <result column="mobilenumber" property="mobilenumber" />
        <result column="unicomnumber" property="unicomnumber" />
        <result column="telecomnumber" property="telecomnumber" />
        <result column="send_type" property="send_type" />
        <result column="sp_id" property="sp_id" />
        <result column="sp_name" property="sp_name" />
        <result column="content" property="content" />
        <result column="audit_content" property="audit_content" />
        <result column="api_send_task_json" property="api_send_task_json" />
    </resultMap>

    <resultMap type="ChangeChannelTask" id="ChangeChannelTaskResultMap">
        <result column="task_id" property="task_id" />
        <result column="unicom_pa_id" property="unicom_pa_id" />
        <result column="mobile_pa_id" property="mobile_pa_id" />
        <result column="telcom_pa_id" property="telcom_pa_id" />
        <result column="unicom_callmdn" property="unicom_callmdn" />
        <result column="mobile_callmdn" property="mobile_callmdn" />
        <result column="telcom_callmdn" property="telcom_callmdn" />
        <result column="sp_id" property="sp_id" />
    </resultMap>


	<select id="listPageMmsAuditTask" parameterType="TaskInfo"
		resultMap="auditTaskMap">
		select ak.id,
		ak.sp_id,
		ak.content,
		ak.createtime,
		ak.total,
		ak.allnumber,
		ak.unicomnumber,
		ak.mobilenumber,
		ak.telecomnumber,
		ak.task_type,
		ak.status,
		ak.send_type,
		ak.audit_reason,
		ak.unicommdns,
		ak.mobilemdns,
		ak.telcommdns,
		ak.otype,
		ak.extendaccessnum,
		s.sp_name,
		s.platform,s.sp_desc
		from
		mms_api_audit_task ak, sms_sp_info s
		where s.id=ak.sp_id and ak.status=1
		<if test="platform!=null and platform!='' and platform >0">
			and s.platform =#{platform}
		</if>
		<if test="sp_name!=null and sp_name!=''">
			and s.sp_name like CONCAT('%',#{sp_name},'%')
		</if>
		<if test="sp_id!=null and sp_id>0">
			and s.id =#{sp_id}
		</if>
		<if test="content!=null and content!=''">
			and ak.content like CONCAT('%',#{content},'%')
		</if>
		<if test="sign!=null and sign!=''">

			and ak.sign=#{sign,jdbcType=VARCHAR}
			<!-- and ak.content like CONCAT('',#{sign},'%') -->
		</if>
		<if test="unicommdns!=null and unicommdns!=''">
			and ak.UNICOMMDNS  like CONCAT('%',#{unicommdns},'%')
		</if>
		<if test="mobilemdns!=null and mobilemdns!=''">
			and ak.mobilemdns  like CONCAT('%',#{mobilemdns},'%')
		</if>
		<if test="telcommdns!=null and telcommdns!=''">
			and ak.telcommdns like CONCAT('%',#{telcommdns},'%')
		</if>

		<if test="send_type!=null and send_type>0">
			and ak.send_type =#{send_type}
		</if>
		<if test="task_id!=null and task_id>0">
			and ak.id =#{task_id}
		</if>
		<if test="createTime!=null and createTime!=''">
            and ak.createtime&gt;=str_to_date(#{createTime},'%Y-%m-%d %H:%i:%S')
        </if>

        <if test="createTime1!=null and createTime1!=''">
            and ak.createtime&lt;=str_to_date(#{createTime1},'%Y-%m-%d %H:%i:%S')
        </if>
		<if test="templateId != null and templateId != ''">
			and ak.CONTENT like CONCAT('%', #{templateId}, '%')
		</if>
        <if test="otype>0">
        	and otype=#{otype}
        </if>
		<if test="sp_saler!=null and sp_saler!=''">
			and s.sp_saler = #{sp_saler}
		</if>
		<if test="salerList!=null and salerList.size()>0">
			and s.sp_saler in
			<foreach collection="salerList" index="index"  item="item" open="(" separator="," close=")">
				'${item}'
			</foreach>
		</if>

	</select>

	<select id="listPageAuditTask" parameterType="TaskInfo"
		resultMap="auditTaskMap">
		select ak.id,
		ak.sp_id,
		ak.content,
		ak.createtime,
		ak.total,
		ak.allnumber,
		ak.unicomnumber,
		ak.mobilenumber,
		ak.telecomnumber,
		ak.task_type,
		ak.status,
		ak.send_type,
		ak.audit_reason,
		ak.unicommdns,
		ak.mobilemdns,
		ak.telcommdns,
		ak.extendaccessnum,
		s.sp_name,
		s.platform,s.sp_desc ,
		ak.otype,
		CONCAT(ak.mobilemdns,IF(ak.mobilemdns='','',','),ak.unicommdns,IF(ak.unicommdns='','',','),ak.telcommdns) mdns
		from
		sms_api_audit_task ak, sms_sp_info s
		where s.id=ak.sp_id and ak.status=1
		<if test="platform!=null and platform!='' and platform >0">
			and s.platform =#{platform}
		</if>
		<if test="sp_name!=null and sp_name!=''">
			and s.sp_name like CONCAT('%',#{sp_name},'%')
		</if>
		<if test="sp_id!=null and sp_id>0">
			and s.id =#{sp_id}
		</if>
		<if test="content!=null and content!=''">
			and ak.content like CONCAT('%',#{content},'%')
		</if>
		<if test="sign!=null and sign!=''">

			and ak.sign=#{sign,jdbcType=VARCHAR}
			<!-- and ak.content like CONCAT('',#{sign},'%') -->
		</if>
		<if test="unicommdns!=null and unicommdns!=''">
			and ak.UNICOMMDNS  like CONCAT('%',#{unicommdns},'%')
		</if>
		<if test="mobilemdns!=null and mobilemdns!=''">
			and ak.mobilemdns  like CONCAT('%',#{mobilemdns},'%')
		</if>
		<if test="telcommdns!=null and telcommdns!=''">
			and ak.telcommdns like CONCAT('%',#{telcommdns},'%')
		</if>

		<if test="send_type!=null and send_type>0">
			and ak.send_type =#{send_type}
		</if>
		<if test="task_id!=null and task_id>0">
			and ak.id =#{task_id}
		</if>
		<if test="createTime!=null and createTime!=''">
            and ak.createtime&gt;=str_to_date(#{createTime},'%Y-%m-%d %H:%i:%S')
        </if>

        <if test="createTime1!=null and createTime1!=''">
            and ak.createtime&lt;=str_to_date(#{createTime1},'%Y-%m-%d %H:%i:%S')
        </if>
        <if test="otype>0">
        	and otype=#{otype}
        </if>
		<if test="sp_saler!=null and sp_saler!=''">
			and s.sp_saler = #{sp_saler}
		</if>
		<if test="salerList!=null and salerList.size()>0">
			and s.sp_saler in
			<foreach collection="salerList" index="index"  item="item" open="(" separator="," close=")">
				'${item}'
			</foreach>
		</if>
	</select>


	<select id="getAuditTask" parameterType="TaskInfo"
		resultMap="auditTaskMap">
		select ak.id,
		ak.sp_id,
		ak.content,
		ak.createid,
		ak.createtime,
		ak.total,
		ak.allnumber,
		ak.unicomnumber,
		ak.mobilenumber,
		ak.telecomnumber,
		ak.task_type,
		ak.status,
		ak.send_type,
		ak.audit_reason,
		ak.unicommdns,
		ak.mobilemdns,
		ak.telcommdns,
		ak.extendaccessnum,
		s.sp_name,
		s.platform,s.sp_desc,
		ak.otype
		from
		sms_api_audit_task ak, sms_sp_info s
		where s.id=ak.sp_id and ak.status=1
		<if test="task_id!=null and task_id>0">
			and ak.id =#{task_id}
		</if>
		<if test="otype>0">
			and otype=#{otype}
		</if>
		limit 1
	</select>

	<select id="getCronTask" parameterType="TaskInfo"
		resultMap="auditTaskMap">
		select ak.id,
		ak.sp_id,
		ak.content,
		ak.createtime,
		ak.total,
		ak.allnumber,
		ak.unicomnumber,
		ak.mobilenumber,
		ak.telecomnumber,
		ak.task_type,
		ak.status,
		ak.send_type,
		ak.audit_reason,
		ak.unicommdns,
		ak.mobilemdns,
		ak.telcommdns,
		ak.extendaccessnum,
		s.sp_name,
		s.platform,s.sp_desc,
		ak.otype
		from
		sms_api_crontab_task ak, sms_sp_info s
		where s.id=ak.sp_id and ak.status=2
		<if test="task_id!=null and task_id>0">
			and ak.id =#{task_id}
		</if>
		<if test="otype>0">
			and otype=#{otype}
		</if>
	</select>

	<select id="getAuditTaskMms" parameterType="TaskInfo"
		resultMap="auditTaskMap">
		select ak.id,
		ak.sp_id,
		ak.content,
		ak.createtime,
		ak.total,
		ak.allnumber,
		ak.unicomnumber,
		ak.mobilenumber,
		ak.telecomnumber,
		ak.task_type,
		ak.status,
		ak.send_type,
		ak.audit_reason,
		ak.unicommdns,
		ak.mobilemdns,
		ak.telcommdns,
		ak.extendaccessnum,
		s.sp_name,
		s.platform,s.sp_desc
		from
		mms_api_audit_task ak, sms_sp_info s
		where s.id=ak.sp_id and ak.status=1
		<if test="task_id!=null and task_id>0">
			and ak.id =#{task_id}
		</if>
	</select>

    <select id="getTaskInfoByContent" parameterType="TaskInfo" resultMap="auditTaskMap">
        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 sms_api_audit_task tk,
        sms_api_setting sp
        where sp.sp_id = tk.sp_id

        AND tk.status = 1

        <if test="sp_id!=null and sp_id>0">
            and tk.sp_id=#{sp_id}
        </if>
        <if test="content!=null and content!=null">
            and tk.content=#{content}
        </if>
        <if test="otype>0">
        	and tk.otype=#{otype}
        </if>
        	limit 0,10000
    </select>

    <select id="listPageAuditResult" parameterType="AuditResult" resultMap="auditResultMap">
        select
        s.sp_name,
        ar.id,
        ar.sp_id,
        ar.taskid,
        ar.audit_opeator,
        ar.create_time,
        ar.audit_result,

        ar.audit_desc
        from sms_sp_audit_result ar, sms_sp_info s
        where s.id = ar.sp_id
        <if test="audit_result != null and audit_result != 0">
            and ar.audit_result = #{audit_result}
        </if>

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

        <if test="sp_id!=null and sp_id>0">
            and s.id =#{sp_id}
        </if>

        <if test="taskid!=null and taskid>0">
            and ar.taskid =#{taskid}
        </if>

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

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

	<select id="auditResultSendTask" parameterType="AuditResult" resultMap="auditResultMap">
		select
			tk.total,
	        tk.content,
	        tk.createtime,
	        tk.allnumber,
	        tk.send_type,
	        tk.unicomnumber,
	        tk.mobilenumber,
	        tk.telecomnumber
	        from sms_send_task tk
	        where tk.id=#{taskid}
	        limit 1
	</select>

    <insert id="insertAuditResult"  useGeneratedKeys="true" keyProperty="id"  parameterType="AuditResult">
        insert into sms_sp_audit_result
        (SP_ID,TASKID,AUDIT_OPEATOR,AUDIT_RESULT,AUDIT_DESC,AUDIT_CONTENT,API_SEND_TASK_JSON,create_time) values
        (#{sp_id},#{taskid},#{audit_opeator,jdbcType=VARCHAR},#{audit_result},#{audit_desc,jdbcType=VARCHAR},#{audit_content,jdbcType=VARCHAR},#{api_send_task_json,jdbcType=VARCHAR},sysdate())
    </insert>

    <delete id="deleteAuditTaskById" parameterType="int">
        delete from sms_api_audit_task where id=#{id}
    </delete>

      <select id="getAuditTaskById" parameterType="int" resultType="long">
        select id from sms_api_audit_task where id=#{id} group by id
    </select>

    <select id="getChangeTaskByTaskId" resultType="ChangeChannelTask">
    	select * from sms_change_channel_task where task_id=#{task_id} limit 1
    </select>
    <insert id="insertChangeTask" parameterType="ChangeChannelTask">
        insert into sms_change_channel_task
        (task_id, mobile_pa_id, unicom_pa_id, telcom_pa_id, mobile_callmdn, unicom_callmdn, telcom_callmdn, sp_id)
        values
        (#{task_id}, #{mobile_pa_id}, #{unicom_pa_id}, #{telecom_pa_id}, #{mobile_callmdn,jdbcType=VARCHAR}, #{unicom_callmdn,jdbcType=VARCHAR}, #{telecom_callmdn,jdbcType=VARCHAR}, #{sp_id})
    </insert>
    <update id="updateChangeTask" parameterType="ChangeChannelTask">
    	update sms_change_channel_task
    	<set>
    		<if test="mobile_pa_id!=null and  mobile_pa_id!=''">
    			mobile_pa_id=#{mobile_pa_id}, mobile_callmdn=#{mobile_callmdn},
    		</if>
    		<if test="unicom_pa_id!=null and  unicom_pa_id!=''">
    			unicom_pa_id=#{unicom_pa_id}, unicom_callmdn=#{unicom_callmdn},
    		</if>
    		<if test="telecom_pa_id!=null and  telecom_pa_id!=''">
    			telecom_pa_id=#{telecom_pa_id}, telcom_callmdn=#{telecom_callmdn}
    		</if>
    	</set>
    	where task_id=#{task_id}
    </update>

    <insert id="insertListChangeTask" parameterType="java.util.ArrayList">
        insert into sms_change_channel_task
        (task_id, mobile_pa_id, unicom_pa_id, telcom_pa_id, mobile_callmdn, unicom_callmdn, telcom_callmdn, sp_id) values
        <foreach collection="list" item="item" index="index" separator=",">
            (
            #{item.task_id,jdbcType=NUMERIC},
            #{item.mobile_pa_id,jdbcType=NUMERIC},
            #{item.unicom_pa_id,jdbcType=NUMERIC},
            #{item.telecom_pa_id,jdbcType=NUMERIC},
            #{item.mobile_callmdn,jdbcType=VARCHAR},
            #{item.unicom_callmdn,jdbcType=VARCHAR},
            #{item.telecom_callmdn,jdbcType=VARCHAR},
            #{item.sp_id,jdbcType=NUMERIC}
            )
        </foreach>

    </insert>
  <!--  sh  -->
   <select id="listAuditResult" parameterType="TaskInfo" resultMap="auditTaskMap">
		select tk.sp_id,tk.id,tk.allnumber,tk.total from
		sms_api_audit_task tk,sms_sp_info si
		where tk.sp_id=si.id
		and tk.id in
		<foreach item="taskids" index="index" collection="taskids" open="(" separator="," close=")">
        	#{taskids}
        </foreach>

	</select>
	<insert id="insertListAuditResult"
		parameterType="java.util.ArrayList">
		insert into sms_sp_audit_result
		(SP_ID,TASKID,AUDIT_OPEATOR,AUDIT_RESULT,AUDIT_DESC,create_time)
		values
		<foreach collection="list" item="item" index="index"
			separator=",">
			(
			#{item.sp_id,jdbcType=NUMERIC},
			#{item.taskid,jdbcType=NUMERIC},
			#{item.audit_opeator,jdbcType=VARCHAR},
			#{item.audit_result,jdbcType=VARCHAR},
			#{item.audit_desc,jdbcType=VARCHAR},
			sysdate()
			)
		</foreach>

	</insert>
	<update id="updateListAuditSmsStatus"
		parameterType="Map">
		update
		sms_api_audit_task tk set
		tk.status=2 ,operator=#{operator},auditid=#{auditid}
		where tk.status=1 and tk.otype=#{otype} and tk.id in
		<foreach item="list" index="index" collection="list" open="("
			separator="," close=")">
			#{list}
		</foreach>
	</update>
	<update id="updateListAuditMmsStatus"
		parameterType="Map">
		update
		mms_api_audit_task tk set
		tk.status=2 ,operator=#{operator},auditid=#{auditid}
		where tk.status=1 and tk.otype=#{otype} and tk.id in
		<foreach item="list" index="index" collection="list" open="("
			separator="," close=")">
			#{list}
		</foreach>
	</update>

	<select id="listSearchAuditResult" parameterType="TaskInfo"
		resultMap="auditTaskMap">
		select tk.sp_id,tk.id,si.sp_name,tk.content,tk.allnumber,tk.total,tk.send_type from
		sms_api_audit_task tk,sms_sp_info si
		where tk.sp_id=si.id
		and tk.status=1
		<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="sp_name!=null and sp_name>0">
			and si.sp_name=#{sp_name}
		</if>
		<if test="send_type!=null and send_type>0">
			and tk.send_type =#{send_type}
		</if>
		<if test="content!=null and content!=''">
			and tk.content like CONCAT('%',#{content},'%')
		</if>
		<if test="sign!=null and sign!=''">
			<!-- and tk.content like CONCAT('',#{sign},'%') -->

			and tk.sign=#{sign,jdbcType=VARCHAR}
		</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>

		limit 0,10000
	</select>

	<update id="updateListAuditSmsStatusForSearch"
		parameterType="TaskInfo">
		update
		sms_api_audit_task tk set
		tk.status=#{status},operator=#{operator},auditid=#{auditid},
		change_channel= case otype
		when 1 then #{unicomChangeChannel}
		when 2 then #{mobileChangeChannel}
		when 3 then #{telecomChangeChannel}
		else '' end
		where tk.status=1
		<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>0">
			and tk.send_type =#{send_type}
		</if>
		<if test="isbatch==1">
			<if test="content!=null and content!=''">
				and tk.content =#{content}
			</if>
		</if>
		<if test="isbatch!=1">
			<if test="content!=null and content!=''">
				and tk.content like CONCAT('%',#{content},'%')
			</if>
		</if>
		<if test="sign!=null and sign!=''">
			<!-- and tk.content like CONCAT('',#{sign},'%') -->

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

        <if test="createTime1!=null and createTime1!=''">
            and tk.createtime&lt;=str_to_date(#{createTime1},'%Y-%m-%d %H:%i:%S')
        </if>
        <if test="unicommdns!=null and unicommdns!=''">
			and tk.UNICOMMDNS  like CONCAT('%',#{unicommdns},'%')
		</if>
		<if test="mobilemdns!=null and mobilemdns!=''">
			and tk.mobilemdns  like CONCAT('%',#{mobilemdns},'%')
		</if>
		<if test="telcommdns!=null and telcommdns!=''">
			and tk.telcommdns like CONCAT('%',#{telcommdns},'%')
		</if>
		<if test="otype>0">
			and otype=#{otype}
		</if>
         <if test="limit_num!=null and limit_num>0">
			limit #{limit_num}
		</if>
	</update>

	<update id="updateListCronSmsStatusForSearch"
		parameterType="TaskInfo">
		update
		sms_api_crontab_task tk set
		tk.status=#{status},operator=#{operator},auditid=#{auditid}
		where tk.status=2
		<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>0">
			and tk.send_type =#{send_type}
		</if>
		<if test="isbatch==1">
			<if test="content!=null and content!=''">
				and tk.content =#{content}
			</if>
		</if>
		<if test="isbatch!=1">
			<if test="content!=null and content!=''">
				and tk.content like CONCAT('%',#{content},'%')
			</if>
		</if>
		<if test="sign!=null and sign!=''">
			<!-- and tk.content like CONCAT('',#{sign},'%') -->

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

        <if test="createTime1!=null and createTime1!=''">
            and tk.createtime&lt;=str_to_date(#{createTime1},'%Y-%m-%d %H:%i:%S')
        </if>
        <if test="unicommdns!=null and unicommdns!=''">
			and tk.UNICOMMDNS  like CONCAT('%',#{unicommdns},'%')
		</if>
		<if test="mobilemdns!=null and mobilemdns!=''">
			and tk.mobilemdns  like CONCAT('%',#{mobilemdns},'%')
		</if>
		<if test="telcommdns!=null and telcommdns!=''">
			and tk.telcommdns like CONCAT('%',#{telcommdns},'%')
		</if>
		<if test="otype>0">
			and otype=#{otype}
		</if>
         <if test="limit_num!=null and limit_num>0">
			limit #{limit_num}
		</if>
	</update>

	<update id="updateListCronSmsTimeForSearch"
		parameterType="TaskInfo">
		update
		sms_api_crontab_task tk set
		tk.cron_time=#{cron_time},operator=#{operator},auditid=#{auditid}
		where tk.status=2
		<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>0">
			and tk.send_type =#{send_type}
		</if>
		<if test="isbatch==1">
			<if test="content!=null and content!=''">
				and tk.content =#{content}
			</if>
		</if>
		<if test="isbatch!=1">
			<if test="content!=null and content!=''">
				and tk.content like CONCAT('%',#{content},'%')
			</if>
		</if>
		<if test="sign!=null and sign!=''">
			<!-- and tk.content like CONCAT('',#{sign},'%') -->

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

        <if test="createTime1!=null and createTime1!=''">
            and tk.createtime&lt;=str_to_date(#{createTime1},'%Y-%m-%d %H:%i:%S')
        </if>
        <if test="unicommdns!=null and unicommdns!=''">
			and tk.UNICOMMDNS  like CONCAT('%',#{unicommdns},'%')
		</if>
		<if test="mobilemdns!=null and mobilemdns!=''">
			and tk.mobilemdns  like CONCAT('%',#{mobilemdns},'%')
		</if>
		<if test="telcommdns!=null and telcommdns!=''">
			and tk.telcommdns like CONCAT('%',#{telcommdns},'%')
		</if>
		<if test="otype>0">
			and otype=#{otype}
		</if>
         <if test="limit_num!=null and limit_num>0">
			limit #{limit_num}
		</if>
	</update>

	<update id="updateListAuditMmsStatusForSearch"
		parameterType="TaskInfo">
		update
		mms_api_audit_task tk set
		tk.status=#{status},operator=#{operator},auditid=#{auditid}
		where tk.status=1
		<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>0">
			and tk.send_type =#{send_type}
		</if>
		<if test="content!=null and content!=''">
			and tk.content like CONCAT('%',#{content},'%')
		</if>
		<if test="sign!=null and sign!=''">
			<!-- and tk.content like CONCAT('',#{sign},'%') -->

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

        <if test="createTime1!=null and createTime1!=''">
            and tk.createtime&lt;=str_to_date(#{createTime1},'%Y-%m-%d %H:%i:%S')
        </if>
        <if test="unicommdns!=null and unicommdns!=''">
			and tk.UNICOMMDNS  like CONCAT('%',#{unicommdns},'%')
		</if>
		<if test="mobilemdns!=null and mobilemdns!=''">
			and tk.mobilemdns  like CONCAT('%',#{mobilemdns},'%')
		</if>
		<if test="telcommdns!=null and telcommdns!=''">
			and tk.telcommdns like CONCAT('%',#{telcommdns},'%')
		</if>
		<if test="otype>0">
			and otype=#{otype}
		</if>
		<if test="templateId!=null and templateId!=''">
			and content=#{templateId}
		</if>
         <if test="limit_num!=null and limit_num>0">
			limit #{limit_num}
		</if>
	</update>

	<delete id="deleteListAuditTaskById" parameterType="java.util.ArrayList">
		delete from sms_api_audit_task where id in
		<foreach item="list" index="index" collection="list" open="(" separator="," close=")">
        	#{list}
        </foreach>
	</delete>
	<select id="getListAuditTask" parameterType="int" resultMap="auditTaskMap">
		select tk.sp_id,tk.id,tk.allnumber,tk.total,sp.sp_audit_type,tk.audit_reason,tk.content,tk.send_type from
		sms_api_audit_task tk,sms_api_setting sp
		where sp.sp_id = tk.sp_id
		and tk.status=2
		limit 0,10000
	</select>
	<select id="getListAuditTaskFailed" parameterType="int" resultMap="auditTaskMap">
		select tk.sp_id,tk.id,tk.allnumber,tk.total,sp.sp_audit_type,tk.audit_reason
		,tk.content,tk.send_type
		 from
		sms_api_audit_task tk,sms_api_setting sp
		where sp.sp_id = tk.sp_id
		and tk.status=3
		limit 0,10000
	</select>

	<update id="setUtf8mb4" parameterType="string">
		set names utf8mb4
	</update>

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

    <select id="getTaskByIdMms" parameterType="TaskInfo" resultType="int">
        select count(1) from mms_api_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="updateApiAuditTaskContent" parameterType="Map">
        update
        sms_api_audit_task set

        content =#{content,jdbcType=VARCHAR} ,
        ltcontent=#{ltcontent,jdbcType=VARCHAR},
        dxcontent=#{dxcontent,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=#{taskId}
        <if test="otype>0">
        	and otype=#{otype}
        </if>

    </update>
    <update id="updateApiAuditTaskById" parameterType="TaskInfo">
        update
        sms_api_audit_task set
       	status =#{status},operator=#{operator},auditid=#{auditid}
        where
        id=#{task_id} and status =1
        <if test="otype>0">
         	and otype=#{otype}
        </if>
    </update>
     <update id="updateApiCronTaskById" parameterType="TaskInfo">
        update
        sms_api_crontab_task set
       	status =#{status},operator=#{operator},auditid=#{auditid}
        where
        id=#{task_id} and status =2
        <if test="otype>0">
         	and otype=#{otype}
        </if>
    </update>
    <update id="updateMmsAuditTaskById" parameterType="TaskInfo">
        update
        mms_api_audit_task set
       	status =#{status},operator=#{operator},auditid=#{auditid}
        where
        id=#{task_id} and status =1
    </update>

    <update id="updateApiAuditTaskByContent" parameterType="TaskInfo">
        update
        sms_api_audit_task  set status =#{status}
        ,operator=#{operator},auditid=#{auditid}
        where status =1
          <if test="sp_id!=null and sp_id>0">
            and sp_id=#{sp_id}
        </if>
        <if test="content!=null and content!=''">
            and content=#{content}
        </if>
    </update>

     <update id="updateApiCronTaskByContent" parameterType="TaskInfo">
        update
        sms_api_crontab_task  set status =#{status}
        ,operator=#{operator},auditid=#{auditid}
        where status =2
          <if test="sp_id!=null and sp_id>0">
            and sp_id=#{sp_id}
        </if>
        <if test="content!=null and content!=''">
            and content=#{content}
        </if>
    </update>

    <update id="updateMmsAuditTaskByContent" parameterType="TaskInfo">
        update
        mms_api_audit_task  set status =#{status}
        ,operator=#{operator},auditid=#{auditid}
        where id=#{task_id} and status =1
          <if test="sp_id!=null and sp_id>0">
            and sp_id=#{sp_id}
        </if>
        <if test="content!=null and content!=null">
            and content=#{content}
        </if>
    </update>

    <update id="updateApiCronTaskFailByIds"
		parameterType="Map">
		update
		sms_api_crontab_task tk set
		tk.status=3,tk.operator=#{operator},auditid=#{auditid}
		where otype=#{otype} and tk.id in
<foreach item="list" index="index" collection="list" open="("
			separator="," close=")">
			#{list}
		</foreach>
 and tk.status=2
	</update>

	 <update id="updateApiAuditTaskFailByIds"
		parameterType="Map">
		update
		sms_api_audit_task tk set
		tk.status=3,tk.operator=#{operator},auditid=#{auditid}
		where otype=#{otype} and tk.id in
<foreach item="list" index="index" collection="list" open="("
			separator="," close=")">
			#{list}
		</foreach>
 and tk.status=1
	</update>


	<update id="updateMmsAuditTaskFailByIds"
		parameterType="Map">
		update
		mms_api_audit_task tk set
		tk.status=3,tk.operator=#{operator},auditid=#{auditid}
		where otype=#{otype} and tk.id in
<foreach item="list" index="index" collection="list" open="("
			separator="," close=")">
			#{list}
		</foreach>
 and tk.status=1
	</update>

	<update id="updateApiAuditTaskChangeFlag" parameterType="TaskInfo">
        update
        sms_api_audit_task set
       	changeflag =1
        where
        id=#{task_id}
        <if test="otype>0">
        	and otype =#{otype}
        </if>
    </update>

    <insert id="insertAuditBatchId" parameterType="TaskInfo">
        insert into sms_audit_batchid
        (batchid)
        values(#{auditid})
    </insert>

</mapper>
