<?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.mtragent.mapper.AllMtrClientMapper">

    <resultMap type="AllMtrClient" id="AllMtrClientResult">
        <result property="id"    column="id"    />
        <result property="mtrClientId"    column="mtr_client_id"    />
        <result property="clientId"    column="client_id"    />
        <result property="publicIp"    column="public_ip"    />
        <result property="failFlag"    column="fail_flag"    />
        <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="selectAllMtrClientVo">
        select id, mtr_client_id, client_id, public_ip, fail_flag, create_time, update_time, create_by, update_by from all_mtr_client
    </sql>

    <select id="selectAllMtrClientList" parameterType="AllMtrClient" resultMap="AllMtrClientResult">
        <include refid="selectAllMtrClientVo"/>
        <where>
            <if test="mtrClientId != null  and mtrClientId != ''"> and mtr_client_id = #{mtrClientId}</if>
            <if test="clientId != null  and clientId != ''"> and client_id = #{clientId}</if>
            <if test="publicIp != null  and publicIp != ''"> and public_ip = #{publicIp}</if>
            <if test="failFlag != null "> and fail_flag = #{failFlag}</if>
        </where>
    </select>

    <select id="selectAllMtrClientById" parameterType="Long" resultMap="AllMtrClientResult">
        <include refid="selectAllMtrClientVo"/>
        where id = #{id}
    </select>

    <insert id="insertAllMtrClient" parameterType="AllMtrClient" useGeneratedKeys="true" keyProperty="id">
        insert into all_mtr_client
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="mtrClientId != null and mtrClientId != ''">mtr_client_id,</if>
            <if test="clientId != null and clientId != ''">client_id,</if>
            <if test="publicIp != null and publicIp != ''">public_ip,</if>
            <if test="failFlag != null">fail_flag,</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="mtrClientId != null and mtrClientId != ''">#{mtrClientId},</if>
            <if test="clientId != null and clientId != ''">#{clientId},</if>
            <if test="publicIp != null and publicIp != ''">#{publicIp},</if>
            <if test="failFlag != null">#{failFlag},</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="updateAllMtrClient" parameterType="AllMtrClient">
        update all_mtr_client
        <trim prefix="SET" suffixOverrides=",">
            <if test="mtrClientId != null and mtrClientId != ''">mtr_client_id = #{mtrClientId},</if>
            <if test="clientId != null and clientId != ''">client_id = #{clientId},</if>
            <if test="publicIp != null and publicIp != ''">public_ip = #{publicIp},</if>
            <if test="failFlag != null">fail_flag = #{failFlag},</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="deleteAllMtrClientById" parameterType="Long">
        delete from all_mtr_client where id = #{id}
    </delete>

    <delete id="deleteAllMtrClientByIds" parameterType="String">
        delete from all_mtr_client where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <insert id="batchInsertAllMtrClient" parameterType="java.util.List">
        insert into all_mtr_client
        (mtr_client_id, client_id, public_ip, fail_flag, create_by, update_by)
        values
        <foreach collection="list" item="item" separator=",">
            (#{item.mtrClientId}, #{item.clientId}, #{item.publicIp}, #{item.failFlag}, #{item.createBy}, #{item.updateBy})
        </foreach>
        ON DUPLICATE KEY UPDATE
        public_ip = IF(NOT VALUES(public_ip) &lt;=&gt; public_ip, VALUES(public_ip), public_ip),
        fail_flag = IF(NOT VALUES(fail_flag) &lt;=&gt; fail_flag, VALUES(fail_flag), fail_flag)
    </insert>
</mapper>