<?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="com.tofly.xrtygis.custom.mapper.CustomPollSourceMapper">


    <insert id="insertWarnHistory">
        insert into ${tableName} (ID, ITCD, WARN_TYPE, ISLOC, NOTES, ADDRESS, DURATION, NUM, ISCONFIRM,
                                  ISCLEAR, CONFIRM_TIME, CONFIRM_USER, SCADA_TIME, CREATE_TIME)
        select #{maxId},
               ITCD,
               WARN_TYPE,
               ISLOC,
               NOTES,
               ADDRESS,
               DURATION,
               NUM,
               ISCONFIRM,
               ISCLEAR,
               CONFIRM_TIME,
               CONFIRM_USER,
               SCADA_TIME,
               CREATE_TIME
        from (
                 select ITCD,
                        WARN_TYPE,
                        ISLOC,
                        NOTES,
                        ADDRESS,
                        DURATION,
                        NUM,
                        ISCONFIRM,
                        ISCLEAR,
                        CONFIRM_TIME,
                        CONFIRM_USER,
                        SCADA_TIME,
                        CREATE_TIME
                 from TF_YWPN_WARN_W
                 where ID = #{id})
    </insert>


    <select id="doesItExistTable" resultType="string">
        select TABLE_NAME
        from user_all_tables
        where table_name = #{tableName}
    </select>

    <update id="closeWarnHistory">
        update ${table}
        set ISCLEAR = '1'
        where ITCD = #{id}
    </update>

    <insert id="insertWarn" parameterType="com.tofly.xrtygis.entity.Warn">
        INSERT INTO TF_YWPN_WARN_W (id, itcd, warn_type, isloc, notes, address, isconfirm, isclear, scada_time,
                                    CREATE_TIME)
        VALUES (#{id}, #{itcd}, #{warnType}, #{isloc}, #{notes}, #{address},
                #{isconfirm}, #{isclear}, sysdate, sysdate)
    </insert>

</mapper>