<?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.tongran.rocketmq.mapper.InitialSwitchOpticalModuleMapper">
    
    <resultMap type="InitialSwitchOpticalModule" id="InitialSwitchOpticalModuleResult">
        <result property="id"    column="id"    />
        <result property="fiberEntIndex"    column="fiber_ent_index"    />
        <result property="fiberPortName"    column="fiber_port_name"    />
        <result property="hwEntityOpticalTxLowThreshold"    column="hw_entity_optical_tx_low_threshold"    />
        <result property="hwEntityOpticalRxLowThreshold"    column="hw_entity_optical_rx_low_threshold"    />
        <result property="hwEntityOpticalRxPower"    column="hw_entity_optical_rx_power"    />
        <result property="hwEntityOpticalTxPower"    column="hw_entity_optical_tx_power"    />
        <result property="clientId"    column="client_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
    </resultMap>

    <sql id="selectInitialSwitchOpticalModuleVo">
        select id, fiber_ent_index, fiber_port_name, hw_entity_optical_tx_low_threshold, hw_entity_optical_rx_low_threshold, hw_entity_optical_rx_power, hw_entity_optical_tx_power, client_id, create_time, update_time, create_by, update_by from initial_switch_optical_module
    </sql>

    <select id="selectInitialSwitchOpticalModuleList" parameterType="InitialSwitchOpticalModule" resultMap="InitialSwitchOpticalModuleResult">
        select id, fiber_ent_index, fiber_port_name, hw_entity_optical_tx_low_threshold, hw_entity_optical_rx_low_threshold, hw_entity_optical_rx_power, hw_entity_optical_tx_power, client_id, create_time, update_time, create_by, update_by from ${tableName}
        <where>  
            <if test="fiberEntIndex != null  and fiberEntIndex != ''"> and fiber_ent_index = #{fiberEntIndex}</if>
            <if test="fiberPortName != null  and fiberPortName != ''"> and fiber_port_name like concat('%', #{fiberPortName}, '%')</if>
            <if test="hwEntityOpticalTxLowThreshold != null "> and hw_entity_optical_tx_low_threshold = #{hwEntityOpticalTxLowThreshold}</if>
            <if test="hwEntityOpticalRxLowThreshold != null "> and hw_entity_optical_rx_low_threshold = #{hwEntityOpticalRxLowThreshold}</if>
            <if test="hwEntityOpticalRxPower != null "> and hw_entity_optical_rx_power = #{hwEntityOpticalRxPower}</if>
            <if test="hwEntityOpticalTxPower != null "> and hw_entity_optical_tx_power = #{hwEntityOpticalTxPower}</if>
            <if test="clientId != null  and clientId != ''"> and client_id = #{clientId}</if>
            <if test="startTime != null  and startTime != ''"> and create_time &gt;= #{startTime}</if>
            <if test="endTime != null  and endTime != ''"> and create_time &lt;= #{endTime}</if>
        </where>
    </select>
    
    <select id="selectInitialSwitchOpticalModuleById" parameterType="Long" resultMap="InitialSwitchOpticalModuleResult">
        <include refid="selectInitialSwitchOpticalModuleVo"/>
        where id = #{id}
    </select>

    <insert id="insertInitialSwitchOpticalModule" parameterType="InitialSwitchOpticalModule" useGeneratedKeys="true" keyProperty="id">
        insert IGNORE into initial_switch_optical_module
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="fiberEntIndex != null">fiber_ent_index,</if>
            <if test="fiberPortName != null">fiber_port_name,</if>
            <if test="hwEntityOpticalTxLowThreshold != null">hw_entity_optical_tx_low_threshold,</if>
            <if test="hwEntityOpticalRxLowThreshold != null">hw_entity_optical_rx_low_threshold,</if>
            <if test="hwEntityOpticalRxPower != null">hw_entity_optical_rx_power,</if>
            <if test="hwEntityOpticalTxPower != null">hw_entity_optical_tx_power,</if>
            <if test="clientId != null">client_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="fiberEntIndex != null">#{fiberEntIndex},</if>
            <if test="fiberPortName != null">#{fiberPortName},</if>
            <if test="hwEntityOpticalTxLowThreshold != null">#{hwEntityOpticalTxLowThreshold},</if>
            <if test="hwEntityOpticalRxLowThreshold != null">#{hwEntityOpticalRxLowThreshold},</if>
            <if test="hwEntityOpticalRxPower != null">#{hwEntityOpticalRxPower},</if>
            <if test="hwEntityOpticalTxPower != null">#{hwEntityOpticalTxPower},</if>
            <if test="clientId != null">#{clientId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
         </trim>
    </insert>

    <update id="updateInitialSwitchOpticalModule" parameterType="InitialSwitchOpticalModule">
        update initial_switch_optical_module
        <trim prefix="SET" suffixOverrides=",">
            <if test="fiberEntIndex != null">fiber_ent_index = #{fiberEntIndex},</if>
            <if test="fiberPortName != null">fiber_port_name = #{fiberPortName},</if>
            <if test="hwEntityOpticalTxLowThreshold != null">hw_entity_optical_tx_low_threshold = #{hwEntityOpticalTxLowThreshold},</if>
            <if test="hwEntityOpticalRxLowThreshold != null">hw_entity_optical_rx_low_threshold = #{hwEntityOpticalRxLowThreshold},</if>
            <if test="hwEntityOpticalRxPower != null">hw_entity_optical_rx_power = #{hwEntityOpticalRxPower},</if>
            <if test="hwEntityOpticalTxPower != null">hw_entity_optical_tx_power = #{hwEntityOpticalTxPower},</if>
            <if test="clientId != null">client_id = #{clientId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteInitialSwitchOpticalModuleById" parameterType="Long">
        delete from initial_switch_optical_module where id = #{id}
    </delete>

    <delete id="deleteInitialSwitchOpticalModuleByIds" parameterType="String">
        delete from initial_switch_optical_module where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <insert id="batchInitialSwitchOpticalModule" parameterType="InitialSwitchOpticalModule">
        insert IGNORE into ${tableName}
        (
        fiber_ent_index,
        fiber_port_name,
        hw_entity_optical_tx_low_threshold,
        hw_entity_optical_rx_low_threshold,
        hw_entity_optical_rx_power,
        hw_entity_optical_tx_power,
        client_id,
        create_time,
        update_time,
        create_by,
        update_by
        )
        values
        <foreach collection="list" item="item" separator=",">
            (
            #{item.fiberEntIndex},
            #{item.fiberPortName},
            #{item.hwEntityOpticalTxLowThreshold},
            #{item.hwEntityOpticalRxLowThreshold},
            #{item.hwEntityOpticalRxPower},
            #{item.hwEntityOpticalTxPower},
            #{item.clientId},
            #{item.createTime},
            #{item.updateTime},
            #{item.createBy},
            #{item.updateBy}
            )
        </foreach>
    </insert>
    <select id="switchOpticalModuleMsg" parameterType="InitialSwitchOpticalModule" resultMap="InitialSwitchOpticalModuleResult">
        select id, fiber_ent_index, fiber_port_name, hw_entity_optical_tx_low_threshold, hw_entity_optical_rx_low_threshold, hw_entity_optical_rx_power, hw_entity_optical_tx_power, client_id, create_time, update_time, create_by, update_by from ${tableName}
        <where>
            <if test="fiberEntIndex != null  and fiberEntIndex != ''"> and fiber_ent_index = #{fiberEntIndex}</if>
            <if test="fiberPortName != null  and fiberPortName != ''"> and fiber_port_name like concat('%', #{fiberPortName}, '%')</if>
            <if test="hwEntityOpticalTxLowThreshold != null "> and hw_entity_optical_tx_low_threshold = #{hwEntityOpticalTxLowThreshold}</if>
            <if test="hwEntityOpticalRxLowThreshold != null "> and hw_entity_optical_rx_low_threshold = #{hwEntityOpticalRxLowThreshold}</if>
            <if test="hwEntityOpticalRxPower != null "> and hw_entity_optical_rx_power = #{hwEntityOpticalRxPower}</if>
            <if test="hwEntityOpticalTxPower != null "> and hw_entity_optical_tx_power = #{hwEntityOpticalTxPower}</if>
            <if test="clientId != null  and clientId != ''"> and client_id = #{clientId}</if>
        </where>
        order by create_time desc limit 1
    </select>
    <select id="getAllModuleName" parameterType="InitialSwitchOpticalModule" resultType="java.util.Map">
        select name fiberPortName from all_moudle_name
        <where>
            <if test="clientId != null  and clientId != ''"> and client_id = #{clientId}</if>
        </where>
        group by name
    </select>

</mapper>