<?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.tsi.api.server.mybatis.TscSsipAppMapper">

    <select id="getDeviceAuthorizedInfo" parameterType="java.util.HashMap" resultType="com.tsi.api.server.vo.NaviAuthorizedVo">
        <![CDATA[
        SELECT TRIM(a.ipaddr) AS accessIpAddress, state AS state, useyn as useYn,
               IF (a.expiredt >= NOW(), 'N', 'Y') AS expired
          FROM tb_tsc_api_client a
         WHERE a.apitoken = #{deviceId}
           AND a.clientType = 'APP'
        ]]>
    </select>

    <select id="getVersion" resultType="com.tsi.api.server.vo.VersionVo">
        <![CDATA[
        SELECT TRIM(a.item)    AS item,
               TRIM(a.version) AS version,
               TRIM(a.value)   AS value
          FROM tb_tsc_version a
         WHERE app = 'APP'
     ]]>
    </select>

    <insert id="registerDevice" parameterType="com.tsi.api.server.vo.DeviceInfo">
        <![CDATA[
        INSERT INTO tb_tsc_api_client (apitoken, company, manager, phone, email, expiredt, eventdt, ipaddr, clientType, state, useyn)
        VALUES (#{deviceId}, #{company}, #{manager}, #{phone}, #{email}, now(), now(), '*', 'APP', 'R', 'Y')
        ]]>
    </insert>

    <insert id="insertInvokeHs" parameterType="com.tsi.api.server.vo.ApiInvokeVo">
        <![CDATA[
        INSERT INTO tb_tsc_api_invoke_hs (apiid, apitoken, ipaddr, eventdt, error)
        VALUES (#{apiId}, #{apiToken}, #{ipAddr}, now(), #{error})
        ]]>
    </insert>

    <select id="getNodeStatusList" resultType="com.tsi.api.server.vo.NodeStatusVo">
        <![CDATA[
        select a.nodeid as nodeId,
               a.name as name,
               a.latitude as lat,
               a.longitude as lng,
               a.nodetype as type,
               a.addnode as addNode,
               nvl(b.status, 0) as status
        from tb_tsc_node a
        left outer join tb_tsc_node_status b
          on a.nodeid = b.nodeid
       where a.useyn = 'Y'
     ]]>
    </select>

</mapper>
