<?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.ruoyi.manage.mapper.ChannelNumberMapper">
    
    <resultMap type="ChannelNumber" id="ChannelNumberResult">
        <result property="channelId"    column="channel_id"    />
        <result property="equipmentId"    column="equipment_id"    />
        <result property="equipmentNum"    column="equipment_num"    />
        <result property="equipmentName"    column="equipment_name"    />
        <result property="channelNum"    column="channel_num"    />
        <result property="port"    column="port"    />
        <result property="videoAddress"    column="video_address"    />
        <result property="account"    column="account"    />
        <result property="password"    column="password"    />
        <result property="protocolType"    column="protocol_type"    />
        <result property="channelDetails"    column="channel_details"    />
        <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="selectChannelNumberVo">
        select channel_id, channel_num,equipment_id, equipment_num, equipment_name, video_address,port, account,password,protocol_type, channel_details, del_flag, create_by, create_time, update_by, update_time, remark from channel_number
    </sql>

    <select id="selectChannelNumberList" parameterType="ChannelNumber" resultMap="ChannelNumberResult">
        <include refid="selectChannelNumberVo"/>
        <where>
            <if test="equipmentNum != null  and equipmentNum != ''"> and equipment_num  like concat('%', #{equipmentNum}, '%')</if>
            <if test="equipmentName != null  and equipmentName != ''"> and equipment_name like concat('%', #{equipmentName}, '%')</if>
            <if test="channelNum != null  and channelNum != ''"> and channel_num = #{channelNum}</if>
            <if test="videoAddress != null  and videoAddress != ''"> and video_address = #{videoAddress}</if>
            <if test="protocolType != null  and protocolType != ''"> and protocol_type = #{protocolType}</if>
            <if test="channelDetails != null  and channelDetails != ''"> and channel_details = #{channelDetails}</if>
        </where>
    </select>
    
    <select id="selectChannelNumberByChannelId" parameterType="ChannelNumber" resultMap="ChannelNumberResult">
        <include refid="selectChannelNumberVo"/>
        where channel_id = #{channelId}
    </select>
    <select id="selectChannelNumberByChannelNum" parameterType="string" resultMap="ChannelNumberResult">
        <include refid="selectChannelNumberVo"/>
        <where>
            <if test="equipmentId != null "> and equipment_id  =#{equipmentId}</if>
            <if test="channelNum != null  and channelNum != ''"> and channel_num = #{channelNum}</if>
        </where>
        limit 1
    </select>
    <insert id="insertChannelNumber" parameterType="ChannelNumber" useGeneratedKeys="true" keyProperty="channelId">
        insert into channel_number
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="equipmentId != null">equipment_id,</if>
            <if test="equipmentNum != null">equipment_num,</if>
            <if test="equipmentName != null">equipment_name,</if>
            <if test="channelNum != null">channel_num,</if>
            <if test="videoAddress != null">video_address,</if>
            <if test="account != null">account,</if>
            <if test="port != null">port,</if>
            <if test="password != null">password,</if>
            <if test="protocolType != null">protocol_type,</if>
            <if test="channelDetails != null">channel_details,</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="equipmentId != null">#{equipmentId},</if>
            <if test="equipmentNum != null">#{equipmentNum},</if>
            <if test="equipmentName != null">#{equipmentName},</if>
            <if test="channelNum != null">#{channelNum},</if>
            <if test="videoAddress != null">#{videoAddress},</if>
            <if test="account != null">#{account},</if>
            <if test="port != null">#{port},</if>
            <if test="password != null">#{password},</if>
            <if test="protocolType != null">#{protocolType},</if>
            <if test="channelDetails != null">#{channelDetails},</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="updateChannelNumber" parameterType="ChannelNumber">
        update channel_number
        <trim prefix="SET" suffixOverrides=",">
            <if test="equipmentId != null">equipment_id = #{equipmentId},</if>
            <if test="equipmentNum != null">equipment_num = #{equipmentNum},</if>
            <if test="equipmentName != null">equipment_name = #{equipmentName},</if>
            <if test="channelNum != null">channel_num = #{channelNum},</if>
            <if test="videoAddress != null">video_address = #{videoAddress},</if>
            <if test="account != null">account = #{account},</if>
            <if test="port != null">port = #{port},</if>
            <if test="password != null">password = #{password},</if>
            <if test="protocolType != null">protocol_type = #{protocolType},</if>
            <if test="channelDetails != null">channel_details = #{channelDetails},</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 channel_id = #{channelId}
    </update>

    <delete id="deleteChannelNumberByChannelId" parameterType="Long">
        delete from channel_number where channel_id = #{channelId}
    </delete>

    <delete id="deleteChannelNumberByChannelIds" parameterType="String">
        delete from channel_number where channel_id in 
        <foreach item="channelId" collection="array" open="(" separator="," close=")">
            #{channelId}
        </foreach>
    </delete>
</mapper>