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

    <resultMap type="ComplaintInfo" id="complaintResultMap">
        <id column="id" property="id" />
        <result column="taskid" property="taskId" />
        <result column="res_content" property="resContent" />
        <result column="sp_id" property="spId" />
        <result column="sp_name" property="spName" />
        <result column="send_time" property="sendTime" />
        <result column="create_time" property="createTime" />
        <result column="channel_name" property="channelName" />
        <result column="channelid" property="channelId" />
        <result column="mdnProvice" property="mdnProvice" />
        <result column="complaintTime" property="complaintTime" />
        <result column="count" property="count" />
        <result column="submit_time" property="submitTime" />
    </resultMap>

    <select id="listPageComplaints" parameterType="ComplaintInfo" resultMap="complaintResultMap">
        select c.id, c.taskid, c.mdn, c.callmdn, c.res_content, c.sp_id, c.send_time,c.mdnProvice,c.complaintTime
        , c.create_time, c.url ,c.type,c.otype, c.remark,c.channelid,c.submit_time, sc.channel_name, sp.sp_name
        from (select id, taskid, mdn, callmdn,res_content, sp_id, send_time,mdnProvice,complaintTime,create_time, url ,
        type,otype, remark,channelid,case when submit_time is null then send_time else submit_time end submit_time
        from sms_complaint) c, sms_send_channel_info sc, sms_sp_info sp
        where c.channelid = sc.id and c.sp_id = sp.id

        <if test="spId != null and spId != ''">
            and c.sp_id = #{spId}
        </if>

        <if test="mdnProvice != null and mdnProvice != ''">
            and c.mdnProvice = #{mdnProvice}
        </if>

        <if test="channelId != null and channelId != ''">
            and c.channelid = #{channelId}
        </if>

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

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

        <choose>
            <when test="queryTimeType!=null and queryTimeType ==1">
                <if test="beginTime!=null and beginTime!=''">
                    and c.send_time&gt;=#{beginTime}
                </if>
                <if test="endTime!=null and endTime!=''">
                    and c.send_time&lt;DATE_ADD(#{endTime},INTERVAL 1 DAY)
                </if>
            </when>
            <when test="queryTimeType!=null and queryTimeType ==2">
                <if test="beginTime!=null and beginTime!=''">
                    and c.create_time&gt;=#{beginTime}
                </if>
                <if test="endTime!=null and endTime!=''">
                    and c.create_time&lt;DATE_ADD(#{endTime},INTERVAL 1 DAY)
                </if>
            </when>
            <when test="queryTimeType!=null and queryTimeType ==3">
                <if test="beginTime!=null and beginTime!=''">
                    and c.complaintTime&gt;=#{beginTime}
                </if>
                <if test="endTime!=null and endTime!=''">
                    and c.complaintTime&lt;DATE_ADD(#{endTime},INTERVAL 1 DAY)
                </if>
            </when>
            <when test="queryTimeType!=null and queryTimeType ==4">
                <if test="beginTime!=null and beginTime!=''">
                    and c.submit_time&gt;=#{beginTime}
                </if>
                <if test="endTime!=null and endTime!=''">
                    and c.submit_time&lt;DATE_ADD(#{endTime},INTERVAL 1 DAY)
                </if>
            </when>
        </choose>
        order by c.create_time desc
    </select>

    <select id="getComplaintSumList" parameterType="ComplaintInfo" resultMap="complaintResultMap">
        select c.mdnProvice,count(c.id) as `count`
        from (select id, taskid, mdn, callmdn,res_content, sp_id, send_time,mdnProvice,complaintTime,create_time, url ,
        type,otype, remark,channelid,case when submit_time is null then send_time else submit_time end submit_time
        from sms_complaint) c, sms_send_channel_info sc, sms_sp_info sp
        where c.channelid = sc.id and c.sp_id = sp.id

        <if test="spId != null and spId != ''">
            and c.sp_id = #{spId}
        </if>

        <if test="mdnProvice != null and mdnProvice != ''">
            and c.mdnProvice = #{mdnProvice}
        </if>

        <if test="channelId != null and channelId != ''">
            and c.channelid = #{channelId}
        </if>

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

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

        <choose>
            <when test="queryTimeType!=null and queryTimeType ==1">
                <if test="beginTime!=null and beginTime!=''">
                    and c.send_time&gt;=#{beginTime}
                </if>
                <if test="endTime!=null and endTime!=''">
                    and c.send_time&lt;DATE_ADD(#{endTime},INTERVAL 1 DAY)
                </if>
            </when>
            <when test="queryTimeType!=null and queryTimeType ==2">
                <if test="beginTime!=null and beginTime!=''">
                    and c.create_time&gt;=#{beginTime}
                </if>
                <if test="endTime!=null and endTime!=''">
                    and c.create_time&lt;DATE_ADD(#{endTime},INTERVAL 1 DAY)
                </if>
            </when>
            <when test="queryTimeType!=null and queryTimeType ==3">
                <if test="beginTime!=null and beginTime!=''">
                    and c.complaintTime&gt;=#{beginTime}
                </if>
                <if test="endTime!=null and endTime!=''">
                    and c.complaintTime&lt;DATE_ADD(#{endTime},INTERVAL 1 DAY)
                </if>
            </when>
            <when test="queryTimeType!=null and queryTimeType ==4">
                <if test="beginTime!=null and beginTime!=''">
                    and c.submit_time&gt;=#{beginTime}
                </if>
                <if test="endTime!=null and endTime!=''">
                    and c.submit_time&lt;DATE_ADD(#{endTime},INTERVAL 1 DAY)
                </if>
            </when>
        </choose>
        group by c.mdnProvice
    </select>

    <select id="getComplaints" parameterType="ComplaintInfo" resultType="integer">
        select count(c.id)
        from sms_complaint c
        <where>
            <if test="channelId != null and channelId != ''">
                and c.channelid = #{channelId}
            </if>

            <if test="mdn != null and mdn != ''">
                and c.mdn = #{mdn}
            </if>
            <if test="callmdn != null and callmdn != ''">
                and c.callmdn = #{callmdn}
            </if>
            <if test="sendTime != null and sendTime != ''">
                and c.send_time <![CDATA[ = ]]> #{sendTime}
            </if>
        </where>

    </select>

     <select id="getComplaintById" parameterType="String" resultMap="complaintResultMap">
        select
        st.id,
        st.taskid,
        st.sp_id,
        st.channelid,
        sc.channel_name,
        sp.sp_name,
        st.mdn,
        st.res_content,
        st.callmdn,
        st.send_time,
        st.num,
        st.otype,
        st.sign,
        st.province mdnProvice
        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}
    </select>

    <insert id="insertComplaint" parameterType="ComplaintInfo">
        insert into sms_complaint
        (taskid, mdn, callmdn, res_content, sp_id, send_time, create_time, channelid, sign, otype, url ,type,
        remark,mdnProvice,complaintTime,submit_time)
        values
        (#{taskId}, #{mdn}, #{callmdn}, #{resContent}, #{spId}, #{sendTime}
        , now(), #{channelId}, #{sign}, #{otype}, #{url}, #{type}, #{remark}, #{mdnProvice}, #{complaintTime},#{submitTime})
    </insert>

    <delete id="deleteComplaintById" parameterType="int">
        delete from sms_complaint where id = #{id}
    </delete>

    <select id="listPageComplaintTotal" parameterType="TaskInfo" resultType="TaskInfo">
        select * 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,
        </if>
        <if test="type_channel!=null and type_channel!=''">
            spp.channelid,
        </if>
        <if test="type_day!=null and type_day!=''">
            spp.stat_time,
        </if>
        sum(ifnull(spp.arrive_succ, 0)) arrive_succ, sum(ifnull(complaintNumber,0)) complaintNumber
        FROM
        (
        select spid, channelid, stat_time, sum(arrive_succ) arrive_succ
        from sms_sp_province_summary
        <where>
            <if test="createTime!=null and createTime!=''">
                and stat_time&gt;=str_to_date(#{createTime},'%Y-%m-%d')
            </if>
            <if test="createTime1!=null and createTime1!=''">
                and 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 channelid=#{channelid}
            </if>
            <if test="sp_id!=null and sp_id>0">
                and spid=#{sp_id}
            </if>
        </where>
        group by spid, channelid, stat_time
        )spp
        LEFT JOIN sms_sp_info sp ON spp.spid = sp.id
        LEFT JOIN

        (
        select channelid,sp_id,to_days(submit_time) submit_time,count(id) complaintNumber from
        (select id,sp_id,channelid,case when submit_time is null then send_time else submit_time end submit_time,
        send_time,create_time,complaintTime
        from sms_complaint) tmp
        where 1=1

        <choose>
            <when test="queryTimeType!=null and queryTimeType ==1">
                <if test="createTime!=null and createTime!=''">
                    and send_time&gt;=#{createTime}
                </if>
                <if test="createTime1!=null and createTime1!=''">
                    and send_time&lt;DATE_ADD(#{createTime1},INTERVAL 1 DAY)
                </if>
            </when>
            <when test="queryTimeType!=null and queryTimeType ==2">
                <if test="createTime!=null and createTime!=''">
                    and create_time&gt;=#{createTime}
                </if>
                <if test="createTime1!=null and createTime1!=''">
                    and create_time&lt;DATE_ADD(#{createTime1},INTERVAL 1 DAY)
                </if>
            </when>
            <when test="queryTimeType!=null and queryTimeType ==3">
                <if test="createTime!=null and createTime!=''">
                    and complaintTime&gt;=#{createTime}
                </if>
                <if test="createTime1!=null and createTime1!=''">
                    and complaintTime&lt;DATE_ADD(#{createTime1},INTERVAL 1 DAY)
                </if>
            </when>
            <when test="queryTimeType!=null and queryTimeType ==4">
                <if test="createTime!=null and createTime!=''">
                    and submit_time&gt;=#{createTime}
                </if>
                <if test="createTime1!=null and createTime1!=''">
                    and submit_time&lt;DATE_ADD(#{createTime1},INTERVAL 1 DAY)
                </if>
            </when>
        </choose>

        <if test="sp_id!=null and sp_id>0">
            and sp_id=#{sp_id}
        </if>
        group by channelid,sp_id,to_days(submit_time )
        )

        c ON spp.spid = c.sp_id
        AND spp.channelid = c.channelid
        AND to_days( spp.stat_time ) = c.submit_time
        <where>
	        <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_channel!=null and type_channel!='' and channelid!=null and channelid >=0">
	            and spp.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 spp.spid=#{sp_id}
	        </if>
	        <if test="sp_type!=null and sp_type>0">
	            and sp.sp_type =#{sp_type}
	        </if>
        </where>
        <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_day!=null and type_day!=''">
                spp.stat_time,
            </if>
        </trim>
        ) sm where complaintNumber > 0
        <if test="orderType=='ASC'">
        	order by
        	<if test="col=='num'">
                complaintNumber
        	</if>
        	<if test="col=='per'">
        		complaintNumber*1000000/sm.arrive_succ
        	</if>
        </if>
        <if test="orderType=='DESC'">
        	order by
        	<if test="col=='num'">
                complaintNumber
        	</if>
        	<if test="col=='per'">
                complaintNumber*1000000/sm.arrive_succ
        	</if>
        	DESC
        </if>
    </select>

    <select id="listPageComplaintTotalNew" parameterType="TaskInfo" resultType="TaskInfo">
        select * from (
        SELECT
        <if test="type_operate!=null and type_operate!=''">
            spp.otype operateOtype,
        </if>
        <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!=''">
            spp.channelid,
        </if>
        <if test="type_day!=null and type_day!=''">
            spp.stat_time,
        </if>
        sum(ifnull(spp.arrive_succ, 0)) arrive_succ, sum(ifnull(complaintNumber,0)) complaintNumber
        FROM
        (
        select spid, channelid, stat_time, sum(arrive_succ) arrive_succ
        <if test="type_operate!=null and type_operate!=''">
            ,otype
        </if>
        from sms_sp_province_summary
        <where>
            <if test="createTime!=null and createTime!=''">
                and stat_time&gt;=str_to_date(#{createTime},'%Y-%m-%d')
            </if>
            <if test="createTime1!=null and createTime1!=''">
                and 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 channelid=#{channelid}
            </if>
            <if test="sp_id!=null and sp_id>0">
                and spid=#{sp_id}
            </if>
            <if test="type_operate!=null and type_operate!='' and operateOtypeSelect!=null">
                and otype = #{operateOtypeSelect}
            </if>
        </where>
        group by spid, channelid, stat_time
        <if test="type_operate!=null and type_operate!=''">
            , otype  <!-- 仅三网统计时追加otype分组 -->
        </if>
        )spp
        LEFT JOIN sms_sp_info sp ON spp.spid = sp.id
        LEFT JOIN

        (
        select channelid,sp_id,to_days(submit_time) submit_time,count(id) complaintNumber from
        (select id,sp_id,channelid,case when submit_time is null then send_time else submit_time end submit_time,
        send_time,create_time,complaintTime
        from sms_complaint) tmp
        where 1=1

        <choose>
            <when test="queryTimeType!=null and queryTimeType ==1">
                <if test="createTime!=null and createTime!=''">
                    and send_time&gt;=#{createTime}
                </if>
                <if test="createTime1!=null and createTime1!=''">
                    and send_time&lt;DATE_ADD(#{createTime1},INTERVAL 1 DAY)
                </if>
            </when>
            <when test="queryTimeType!=null and queryTimeType ==2">
                <if test="createTime!=null and createTime!=''">
                    and create_time&gt;=#{createTime}
                </if>
                <if test="createTime1!=null and createTime1!=''">
                    and create_time&lt;DATE_ADD(#{createTime1},INTERVAL 1 DAY)
                </if>
            </when>
            <when test="queryTimeType!=null and queryTimeType ==3">
                <if test="createTime!=null and createTime!=''">
                    and complaintTime&gt;=#{createTime}
                </if>
                <if test="createTime1!=null and createTime1!=''">
                    and complaintTime&lt;DATE_ADD(#{createTime1},INTERVAL 1 DAY)
                </if>
            </when>
            <when test="queryTimeType!=null and queryTimeType ==4">
                <if test="createTime!=null and createTime!=''">
                    and submit_time&gt;=#{createTime}
                </if>
                <if test="createTime1!=null and createTime1!=''">
                    and submit_time&lt;DATE_ADD(#{createTime1},INTERVAL 1 DAY)
                </if>
            </when>
        </choose>

        <if test="sp_id!=null and sp_id>0">
            and sp_id=#{sp_id}
        </if>
        group by channelid,sp_id,to_days(submit_time )
        )

        c ON spp.spid = c.sp_id
        AND spp.channelid = c.channelid
        AND to_days( spp.stat_time ) = c.submit_time
        <where>
	        <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_channel!=null and type_channel!='' and channelid!=null and channelid >=0">
	            and spp.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 spp.spid=#{sp_id}
	        </if>
	        <if test="sp_type!=null and sp_type>0">
	            and sp.sp_type =#{sp_type}
	        </if>
            <if test="type_operate!=null and type_operate!='' and operateOtypeSelect!=null">
                and spp.otype = #{operateOtypeSelect}
            </if>
        </where>
        <trim prefix="group by" suffixOverrides=",">
            <if test="type_operate!=null and type_operate!=''">
                spp.otype,  <!-- 按运营商分组 -->
            </if>
            <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_day!=null and type_day!=''">
                spp.stat_time,
            </if>
        </trim>
        ) sm where complaintNumber > 0
        <if test="orderType=='ASC'">
        	order by
        	<if test="col=='num'">
                complaintNumber
        	</if>
        	<if test="col=='per'">
        		complaintNumber*1000000/sm.arrive_succ
        	</if>
        </if>
        <if test="orderType=='DESC'">
        	order by
        	<if test="col=='num'">
                complaintNumber
        	</if>
        	<if test="col=='per'">
                complaintNumber*1000000/sm.arrive_succ
        	</if>
        	DESC
        </if>
    </select>

    <select id="getComplaintTotalByType" parameterType="TaskInfo" resultType="Integer">
        select
        count(id) complaintNumber from
        (select id,sp_id,channelid,type,case when submit_time is null then send_time else submit_time end submit_time,
        send_time,create_time,complaintTime from sms_complaint)a
        where 1=1 and channelid!=0
        <choose>
            <when test="queryTimeType!=null and queryTimeType ==1">
                <if test="createTime!=null and createTime!=''">
                    and send_time&gt;=#{createTime}
                </if>
                <if test="createTime1!=null and createTime1!=''">
                    and send_time&lt;DATE_ADD(#{createTime1},INTERVAL 1 DAY)
                </if>
            </when>
            <when test="queryTimeType!=null and queryTimeType ==2">
                <if test="createTime!=null and createTime!=''">
                    and create_time&gt;=#{createTime}
                </if>
                <if test="createTime1!=null and createTime1!=''">
                    and create_time&lt;DATE_ADD(#{createTime1},INTERVAL 1 DAY)
                </if>
            </when>
            <when test="queryTimeType!=null and queryTimeType ==3">
                <if test="createTime!=null and createTime!=''">
                    and complaintTime&gt;=#{createTime}
                </if>
                <if test="createTime1!=null and createTime1!=''">
                    and complaintTime&lt;DATE_ADD(#{createTime1},INTERVAL 1 DAY)
                </if>
            </when>
            <when test="queryTimeType!=null and queryTimeType ==4">
                <if test="createTime!=null and createTime!=''">
                    and submit_time&gt;=#{createTime}
                </if>
                <if test="createTime1!=null and createTime1!=''">
                    and submit_time&lt;DATE_ADD(#{createTime1},INTERVAL 1 DAY)
                </if>
            </when>
        </choose>

		<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="otype==0">
			and type=0
		</if>
		<if test="otype>0">
			and type>0
		</if>
		<trim prefix="group by" suffixOverrides=",">
            <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!=''">
                channelid,
            </if>
            <if test="type_day!=null and type_day!=''">
                stat_time
            </if>
        </trim>
	</select>

    <select id="exportComplaints" parameterType="ComplaintInfo" resultType="map">
        select  c.mdn as MDN, c.res_content as RES_CONTENT, c.sp_id as SP_ID, DATE_FORMAT(c.send_time,'%Y-%m-%d %H:%i:%S') as SEND_TIME,
        sc.channel_name as CHANNEL_NAME, sp.sp_name as SP_NAME
        from (select id, taskid, mdn, callmdn,res_content, sp_id, send_time,mdnProvice,complaintTime,create_time, url ,
        type,otype, remark,channelid,case when submit_time is null then send_time else submit_time end submit_time
        from sms_complaint) c, sms_send_channel_info sc, sms_sp_info sp
        where c.channelid = sc.id and c.sp_id = sp.id

        <if test="spId != null and spId != ''">
            and c.sp_id = #{spId}
        </if>

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

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

<!--        <if test="beginTime != null and beginTime != ''">-->
<!--            and c.create_time&gt;=str_to_date(#{beginTime},'%Y-%m-%d')-->
<!--        </if>-->
<!--        <if test="endTime != null and endTime != ''">-->
<!--            and c.create_time&lt;DATE_ADD(str_to_date(#{endTime},'%Y-%m-%d'),INTERVAL 1 DAY)-->
<!--        </if>-->
        <if test="channelId != null and channelId != ''">
            and c.channelid = #{channelId}
        </if>
        <choose>
            <when test="queryTimeType!=null and queryTimeType ==1">
                <if test="beginTime!=null and beginTime!=''">
                    and c.send_time&gt;=#{beginTime}
                </if>
                <if test="endTime!=null and endTime!=''">
                    and c.send_time&lt;DATE_ADD(#{endTime},INTERVAL 1 DAY)
                </if>
            </when>
            <when test="queryTimeType!=null and queryTimeType ==2">
                <if test="beginTime!=null and beginTime!=''">
                    and c.create_time&gt;=#{beginTime}
                </if>
                <if test="endTime!=null and endTime!=''">
                    and c.create_time&lt;DATE_ADD(#{endTime},INTERVAL 1 DAY)
                </if>
            </when>
            <when test="queryTimeType!=null and queryTimeType ==3">
                <if test="beginTime!=null and beginTime!=''">
                    and c.complaintTime&gt;=#{beginTime}
                </if>
                <if test="endTime!=null and endTime!=''">
                    and c.complaintTime&lt;DATE_ADD(#{endTime},INTERVAL 1 DAY)
                </if>
            </when>
            <when test="queryTimeType!=null and queryTimeType ==4">
                <if test="beginTime!=null and beginTime!=''">
                    and c.submit_time&gt;=#{beginTime}
                </if>
                <if test="endTime!=null and endTime!=''">
                    and c.submit_time&lt;DATE_ADD(#{endTime},INTERVAL 1 DAY)
                </if>
            </when>
        </choose>
        order by c.create_time desc
    </select>

</mapper>
