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

<select id="listPageQueryInterRemain" resultType="cn.roadm.bo.InterRemainDO">
    SELECT a.`id`,
           a.`name`,
           a.`email`,
           a.`mdn`,
           a.`spid`                                      AS `spId`,
           b.sp_name                                     as spName,
           a.`number`,
           a.`status`,
           a.`scan_time`                                 AS scanTime,
           date_format(create_time, '%Y-%m-%d %H:%i:%s') AS createTime
    FROM inter_sp_alarm_info a
             left join sms_sp_info b on a.spid = b.id
    <where>
        a.status = 0
        <if test="spId != null and spId != ''">
           and a.spid = #{spId}
        </if>
        <if test="spName != null and spName != ''">
            and b.sp_name like concat('%', #{spName}, '%')
        </if>
    </where>
    order by create_time desc
</select>

<update id="deleteInterRemainAlarm">
    update inter_sp_alarm_info set status = 1 where id = #{id}
</update>

<insert id="addInterRemainAlarmApi">
    insert into inter_sp_alarm_info (name, email, mdn, spid, number, status, scan_time, create_time)
    values (#{name}, #{email}, #{mdn}, #{spId}, #{number}, #{status}, #{scanTime}, now())
</insert>

<update id="updateInterRemainAlarmApi">
    update inter_sp_alarm_info
    set name      = #{name},
        email     = #{email},
        mdn       = #{mdn},
        spid      = #{spId},
        number    = #{number},
        scan_time = #{scanTime}
    where id = #{id}
</update>

<select id="queryInterRemainById" resultType="cn.roadm.bo.InterRemainDO">
    SELECT `id`,
           `name`,
           `email`,
           `mdn`,
           `spid`                                        AS `spId`,
           `number`,
           `status`,
           `scan_time`                                   AS scanTime,
           date_format(create_time, '%Y-%m-%d %H:%i:%s') AS createTime
    FROM inter_sp_alarm_info
    where id = #{id}
</select>

    <select id="queryInterSpOptions" resultType="cn.roadm.bo.PageSelectOptionsVO">
        select id as value, sp_name as label from sms_sp_info where status = 1 and sp_scope = '1'
    </select>
</mapper>