<?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.admin.mapper.AuditQueueMapper">
    <resultMap type="cn.roadm.admin.dto.SmsApiAuditDO" id="TaskQueueMap">
        <result column="sp_id" property="spId"/>
        <result column="sp_name" property="spName"/>
        <result column="content" property="content"/>
        <result column="co" property="total"/>
        <result column="otype" property="otype"/>
    </resultMap>

    <select id="listPageQueryAuditQueue" resultMap="TaskQueueMap">
        select a.content, co, sp_id, otype, ss.sp_name from (select content, count(1) co, sp_id, otype
                                                             from sms_api_audit_task
        <where>
            status = 1
            <if test="queryVO.spId != null">
                and sp_id = #{queryVO.spId}
            </if>
            <if test="queryVO.content != null and queryVO.content != ''">
                and content like CONCAT('%', #{queryVO.content}, '%')
            </if>
            <if test="queryVO.otype != null and queryVO.otype > 0">
                and otype = #{queryVO.otype}
            </if>
        </where>
        GROUP BY content, sp_id, otype) a,
            sms_sp_info ss
        where ss.id = a.sp_id
        ORDER BY a.co desc
    </select>
</mapper>
