<?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.willalp.device.mapper.NetworkConfigMapper">

    <resultMap type="NetworkConfig" id="NetworkConfigResult">
        <result property="networkConfigId" column="network_config_id"/>
        <result property="deviceId" column="device_id"/>
        <result property="deviceName" column="device_name"/>
        <result property="deviceServerIp" column="device_server_ip"/>
        <result property="socketPortNumber" column="socket_port_number"/>
        <result property="serverPortNumber" column="server_port_number"/>
        <result property="relationConfigId" column="relation_config_id"/>
        <result property="isDelete" column="is_delete"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectNetworkConfigVo">
        SELECT network_config_id,
               pd.device_id,
               pd.device_name,
               device_server_ip,
               socket_port_number,
               server_port_number,
               relation_config_id,
               pn.is_delete,
               pn.create_time,
               pn.update_time
        FROM pns_network_config pn
                 LEFT JOIN pns_device pd ON pd.device_id = pn.device_id
    </sql>

    <select id="selectNetworkConfigList" parameterType="NetworkConfig" resultMap="NetworkConfigResult">
        <include refid="selectNetworkConfigVo"/>
        <where>
            pn.is_delete = 0
            <if test="deviceId != null  and deviceId != ''">
                  and pn.device_id = #{deviceId}</if>
            <if test="deviceServerIp != null  and deviceServerIp != ''">
                  and device_server_ip = #{deviceServerIp}</if>
            <if test="socketPortNumber != null ">
                  and socket_port_number = #{socketPortNumber}</if>
            <if test="serverPortNumber != null ">
                  and server_port_number = #{serverPortNumber}</if>
            <if test="relationConfigId != null ">
                  and relation_config_id = #{relationConfigId}</if>
        </where>
    </select>
</mapper>
