<?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.dcs.hnyz.mapper.CommunicationProtocolMapper">
    
    <resultMap type="CommunicationProtocol" id="CommunicationProtocolResult">
        <result property="protocolId"    column="protocol_id"    />
        <result property="protocolName"    column="protocol_name"    />
        <result property="code"    column="code"    />
        <result property="description"    column="description"    />
        <result property="networkSegment"    column="network_segment"    />
        <result property="defaultPort"    column="default_port"    />
        <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"    />
    </resultMap>

    <sql id="selectCommunicationProtocolVo">
        select protocol_id, protocol_name, code, description, network_segment, default_port, status, del_flag, create_by, create_time, update_by, update_time, remark from communication_protocol
    </sql>

    <select id="selectCommunicationProtocolList" parameterType="CommunicationProtocol" resultMap="CommunicationProtocolResult">
        <include refid="selectCommunicationProtocolVo"/>
        <where>  
            <if test="protocolName != null  and protocolName != ''"> and protocol_name like concat('%', #{protocolName}, '%')</if>
            <if test="code != null  and code != ''"> and code = #{code}</if>
            <if test="defaultPort != null  and defaultPort != ''"> and default_port = #{defaultPort}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="delFlag == null"> and del_flag = '0'</if>
        </where>
    </select>
    
    <select id="selectCommunicationProtocolByProtocolId" parameterType="Long" resultMap="CommunicationProtocolResult">
        <include refid="selectCommunicationProtocolVo"/>
        where protocol_id = #{protocolId}
    </select>

    <insert id="insertCommunicationProtocol" parameterType="CommunicationProtocol">
        insert into communication_protocol
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="protocolId != null">protocol_id,</if>
            <if test="protocolName != null">protocol_name,</if>
            <if test="code != null">code,</if>
            <if test="description != null">description,</if>
            <if test="networkSegment != null">network_segment,</if>
            <if test="defaultPort != null">default_port,</if>
            <if test="status != null">status,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="protocolId != null">#{protocolId},</if>
            <if test="protocolName != null">#{protocolName},</if>
            <if test="code != null">#{code},</if>
            <if test="description != null">#{description},</if>
            <if test="networkSegment != null">#{networkSegment},</if>
            <if test="defaultPort != null">#{defaultPort},</if>
            <if test="status != null">#{status},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateCommunicationProtocol" parameterType="CommunicationProtocol">
        update communication_protocol
        <trim prefix="SET" suffixOverrides=",">
            <if test="protocolName != null">protocol_name = #{protocolName},</if>
            <if test="code != null">code = #{code},</if>
            <if test="description != null">description = #{description},</if>
            <if test="networkSegment != null">network_segment = #{networkSegment},</if>
            <if test="defaultPort != null">default_port = #{defaultPort},</if>
            <if test="status != null">status = #{status},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where protocol_id = #{protocolId}
    </update>

    <delete id="deleteCommunicationProtocolByProtocolId" parameterType="Long">
        delete from communication_protocol where protocol_id = #{protocolId}
    </delete>

    <delete id="deleteCommunicationProtocolByProtocolIds" parameterType="String">
        delete from communication_protocol where protocol_id in 
        <foreach item="protocolId" collection="array" open="(" separator="," close=")">
            #{protocolId}
        </foreach>
    </delete>
</mapper>