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

    <resultMap id="platformTaskRecordMap" type="cn.roadm.admin.dto.PlatformTaskRecordDO">
        <id column="id" property="id"/>
        <result column="sp_id" property="spId"/>
        <result column="sp_name" property="spName"/>
        <result column="content" property="content"/>
        <result column="createtime" property="createTime"/>
        <result column="total" property="total"/>
        <result column="allnumber" property="allNumber"/>
        <result column="unicomnumber" property="unicomNumber"/>
        <result column="mobilenumber" property="mobileNumber"/>
        <result column="telecomnumber" property="telecomNumber"/>
        <result column="succ" property="success"/>
        <result column="fail" property="fail"/>
        <result column="arrive_succ" property="arriveSuccess"/>
        <result column="arrive_fail" property="arriveFail"/>
        <result column="task_type" property="taskType"/>
        <result column="status" property="status"/>
        <result column="endtime" property="endTime"/>
        <result column="descption" property="description"/>
        <result column="send_type" property="sendType"/>
        <result column="task_name" property="taskName"/>
        <result column="unRecMsgNum" property="unRecMsgNum"/>
    </resultMap>

    <select id="listPageQueryPlatformTaskRecord" resultMap="platformTaskRecordMap">
        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,
               (tk.allnumber - tk.arrive_succ - tk.arrive_fail) as unRecMsgnum,
               tk.send_type,
               tk.task_name
        from sms_send_task tk,
             sms_sp_info sp
        where sp.id = tk.sp_id
        <if test="queryVO.spName != null and queryVO.spName != ''">
            and sp.sp_name like CONCAT('%', #{queryVO.spName}, '%')
        </if>
        <if test="queryVO.content != null and queryVO.content != ''">
            and tk.content like CONCAT('%', #{queryVO.content}, '%')
        </if>
        <if test="queryVO.spId != null and queryVO.spId != ''">
            and tk.sp_id = #{queryVO.spId}
        </if>
        <if test="queryVO.taskId != null and queryVO.taskId != ''">
            and tk.id = #{queryVO.taskId}
        </if>
        <if test="queryVO.sendType != null and queryVO.sendType != ''">
            and tk.send_type = #{queryVO.sendType}
        </if>
        <if test="queryVO.startTime != null and queryVO.startTime != ''">
            and tk.createtime &gt;= str_to_date(#{queryVO.startTime}, '%Y-%m-%d')
        </if>

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

    <select id="selectExportPlatformTaskRecordList" resultMap="platformTaskRecordMap">
        select tk.id,
               tk.sp_id,
               sp.sp_name,
               tk.content,
               DATE_FORMAT(tk.createtime, '%Y-%m-%d %H:%i:%s') as 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,
               DATE_FORMAT(tk.endtime, '%Y-%m-%d %H:%i:%s') as endtime,
               (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="params.spName != null and params.spName != ''">
            and sp.sp_name like CONCAT('%', #{params.spName}, '%')
        </if>
        <if test="params.spId != null and params.spId != ''">
            and tk.sp_id = #{params.spId}
        </if>
        <if test="params.taskId != null and params.taskId > 0">
            and tk.id = #{params.taskId}
        </if>
        <if test="params.sendType != null and params.sendType != ''">
            and tk.send_type = #{params.sendType}
        </if>
        <if test="params.startTime != null and params.startTime != ''">
            and tk.createtime &gt;= str_to_date(#{params.startTime}, '%Y-%m-%d')
        </if>

        <if test="params.endTime != null and params.endTime != ''">
            and tk.createtime &lt;= DATE_ADD(str_to_date(#{params.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="batchSize != null">
            limit #{batchSize}
        </if>
    </select>
</mapper>
