<?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.fastbee.sip.mapper.MediaServerMapper">

    <resultMap type="com.fastbee.sip.domain.MediaServer" id="MediaServerResult">
        <result property="id"    column="id"    />
        <result property="serverId"    column="server_id"    />
        <result property="tenantId"    column="tenant_id"    />
        <result property="tenantName"    column="tenant_name"    />
        <result property="enabled"    column="enabled"    />
        <result property="protocol"    column="protocol"    />
        <result property="ip"    column="ip"    />
        <result property="domainAlias"    column="domain_alias"    />
        <result property="hookurl"    column="hookurl"    />
        <result property="secret"    column="secret"    />
        <result property="portHttp"    column="port_http"    />
        <result property="portHttps"    column="port_https"    />
        <result property="portRtmp"    column="port_rtmp"    />
        <result property="portRtsp"    column="port_rtsp"    />
        <result property="rtpProxyPort"    column="rtp_proxy_port"    />
        <result property="rtpEnable"    column="rtp_enable"    />
        <result property="rtpPortRange"    column="rtp_port_range"    />
        <result property="recordPort"    column="record_port"    />
        <result property="autoConfig"    column="auto_config"    />
        <result property="status"    column="status"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
        <result property="portWs"    column="port_ws"    />
    </resultMap>

    <sql id="selectMediaServerVo">
        select id, server_id, tenant_id, tenant_name, enabled, protocol, ip, domain_alias, hookurl, secret, port_http, port_https, port_rtmp, port_rtsp, rtp_proxy_port, rtp_enable, rtp_port_range, record_port, auto_config, status, del_flag, create_by, create_time, update_by, update_time, remark, port_ws from media_server
    </sql>

    <select id="selectMediaServerList" parameterType="MediaServer" resultMap="MediaServerResult">
        <include refid="selectMediaServerVo"/>
        <where>
            <if test="serverId != null  and serverId != ''"> and server_id = #{serverId}</if>
            <if test="tenantId != null "> and tenant_id = #{tenantId}</if>
            <if test="tenantName != null  and tenantName != ''"> and tenant_name like concat('%', #{tenantName}, '%')</if>
            <if test="enabled != null "> and enabled = #{enabled}</if>
            <if test="protocol != null  and protocol != ''"> and protocol = #{protocol}</if>
            <if test="ip != null  and ip != ''"> and ip = #{ip}</if>
            <if test="domainAlias != null  and domainAlias != ''"> and domain_alias = #{domainAlias}</if>
            <if test="hookurl != null  and hookurl != ''"> and hookurl = #{hookurl}</if>
            <if test="secret != null  and secret != ''"> and secret = #{secret}</if>
            <if test="portHttp != null "> and port_http = #{portHttp}</if>
            <if test="portHttps != null "> and port_https = #{portHttps}</if>
            <if test="portRtmp != null "> and port_rtmp = #{portRtmp}</if>
            <if test="portRtsp != null "> and port_rtsp = #{portRtsp}</if>
            <if test="rtpProxyPort != null "> and rtp_proxy_port = #{rtpProxyPort}</if>
            <if test="rtpEnable != null "> and rtp_enable = #{rtpEnable}</if>
            <if test="rtpPortRange != null  and rtpPortRange != ''"> and rtp_port_range = #{rtpPortRange}</if>
            <if test="recordPort != null "> and record_port = #{recordPort}</if>
            <if test="autoConfig != null "> and auto_config = #{autoConfig}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="portWs != null "> and port_ws = #{portWs}</if>
            and del_flag = '0'
        </where>
    </select>

    <select id="selectMediaServer" resultMap="MediaServerResult" parameterType="MediaServer">
        <include refid="selectMediaServerVo"/>
        <where>
            <if test="tenantId != null and tenantId != 0"> and tenant_id = #{tenantId}</if>
            and del_flag = '0'
        </where>
    </select>

    <select id="selectMediaServerBytenantId" parameterType="Long" resultMap="MediaServerResult">
        <include refid="selectMediaServerVo"/>
        where tenant_id = #{tenantId}
        and del_flag = '0'
    </select>
</mapper>
