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

    <resultMap id="channelBatchTestMap" type="cn.roadm.bo.ChannelBatchTestBO">
        <id column="id" property="id"/>
        <result column="channel_id" property="channelId"/>
        <result column="channel_name" property="channelName"/>
        <result column="extend_file" property="extendFile"/>
        <result column="package_size" property="packageSize"/>
        <result column="send_interval" property="sendInterval"/>
        <result column="mdn" property="mdn"/>
        <result column="content" property="content"/>
        <result column="task_status" property="taskStatus"/>
        <result column="result" property="result"/>
        <result column="create_time" property="createTime"/>
        <result column="result_file" property="resultFile"/>
    </resultMap>

    <select id="listPageQueryChannelBatchTest" resultMap="channelBatchTestMap">
        select a.id, a.channel_id, b.channel_name, a.extend_file, a.package_size, a.send_interval, a.mdn, a.content, a.task_status, a.result, date_format(a.create_time, '%Y-%m-%d %H:%i:%s') as create_time from channel_test_task_record a
        left join sms_send_channel_info b on a.channel_id = b.id
        <where>
            <if test="channelId != null">
                channel_id = #{channelId}
            </if>
            <if test="channelName != null and channelName != ''">
                and channel_name like concat('%', #{channelName}, '%')
            </if>
            <if test="taskStatus != null">
                and task_status = #{taskStatus}
            </if>
            <if test="startTime != null and startTime != ''">
                and a.create_time &gt;= str_to_date(#{startTime}, '%Y-%m-%d %H:%i:%s')
            </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)
            </if>
        </where>
        order by create_time desc
    </select>

    <insert id="addChannelBatchTestTask">
        insert into channel_test_task_record(id, channel_id, extend_file, package_size, send_interval, mdn, content)
        values(#{id}, #{channelId}, #{extendFile}, #{packageSize}, #{sendInterval}, #{mdn}, #{content})
    </insert>

    <update id="updateTaskStatus">
        update channel_test_task_record set `task_status` = #{status}
        <if test="message != null and message != ''">
            , `result` = concat(IFNULL(`result`, ''), '&lt;br&gt;', #{message})
        </if>
        where `id` = #{taskId}
    </update>

    <select id="getChannelBatchTestDetailById" resultMap="channelBatchTestMap">
        select a.id, a.channel_id, a.extend_file, a.package_size, a.send_interval, a.mdn, a.content, a.task_status, a.result, a.result_file, date_format(a.create_time, '%Y-%m-%d %H:%i:%s') as create_time from channel_test_task_record a
        where a.id = #{taskId}
    </select>

    <select id="getSpChannelConfigById" resultType="cn.roadm.bo.ChannelInfo">
        select MOBILE_PREFIX, TELECOM_PREFIX, UNICOM_PREFIX from sms_send_channel_info where id = #{channelId}
    </select>

    <update id="updateCompareResultFile">
        update channel_test_task_record set result_file = #{filePath} where id = #{taskId}
    </update>

    <select id="queryArriveDetail" resultType="java.lang.String">
        select STAT_DESC from sms_arrive where CHANNELID = #{channelId} and MDN = #{mdn} and SN = #{serialNumber} and CALLMDN = #{callMdn} ORDER BY CREATE_TIME desc Limit 1
    </select>
</mapper>
