<?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.xingxi.master.ipInfo.mapper.IpInfoMapper">
        <resultMap type="IpInfo" id="IpInfoResult">
        <result property="ipId"    column="ipId"    />
        <result property="ipName"    column="ipName"    />
        <result property="ipUrl"    column="ipUrl"    />
        <result property="colorNo"    column="colorNo"    />
        <result property="sort"    column="sort"    />
        <result property="delFlag"    column="delFlag"    />
        <result property="createUser"    column="createUser"    />
        <result property="createTime"    column="createTime"    />
        <result property="updateUser"    column="updateUser"    />
        <result property="updateTime"    column="updateTime"    />
    </resultMap>

    <sql id="selectIpInfo">
        select ipId, ipName, ipUrl, colorNo, sort, delFlag, createUser, createTime, updateUser, updateTime from m_ipinfo
    </sql>

    <select id="selectIpInfoList" parameterType="IpInfo" resultMap="IpInfoResult">
        <include refid="selectIpInfo"/>
        <where>  
            <if test="ipName != null  and ipName != ''"> and ipName like concat('%', #{ipName}, '%')</if>
            <if test="ipUrl != null  and ipUrl != ''"> and ipUrl = #{ipUrl}</if>
            <if test="colorNo != null  and colorNo != ''"> and colorNo = #{colorNo}</if>
            <if test="delFlag != null  and delFlag != ''"> and delFlag = #{delFlag}</if>
            <if test="createUser != null  and createUser != ''"> and createUser = #{createUser}</if>
            <if test="createTime != null "> and createTime = #{createTime}</if>
            <if test="updateUser != null  and updateUser != ''"> and updateUser = #{updateUser}</if>
            <if test="updateTime != null "> and updateTime = #{updateTime}</if>
        </where>
        order by sort
    </select>
    
    <select id="selectIpInfoByIpId" parameterType="Long" resultMap="IpInfoResult">
        <include refid="selectIpInfo"/>
        where ipId = #{ipId}
        order by sort
    </select>
        
    <insert id="insertIpInfo" parameterType="IpInfo" useGeneratedKeys="true" keyProperty="ipId">
        insert into m_ipinfo
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="ipName != null">ipName,</if>
            <if test="ipUrl != null">ipUrl,</if>
            <if test="colorNo != null">colorNo,</if>
            <if test="sort != null">sort,</if>
            <if test="delFlag != null">delFlag,</if>
            <if test="createUser != null">createUser,</if>
            <if test="createTime != null">createTime,</if>
            <if test="updateUser != null">updateUser,</if>
            <if test="updateTime != null">updateTime,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="ipName != null">#{ipName},</if>
            <if test="ipUrl != null">#{ipUrl},</if>
            <if test="colorNo != null">#{colorNo},</if>
            <if test="sort != null">#{sort},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createUser != null">#{createUser},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateUser != null">#{updateUser},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <insert id="batchInsertIpInfo">
        insert into m_ipinfo( ipName, ipUrl, colorNo, sort, delFlag, createUser, createTime, updateUser, updateTime) values
        <foreach item="item" index="index" collection="list" separator=",">
            ( #{item.ipName}, #{item.ipUrl}, #{item.colorNo}, #{item.sort}, #{item.delFlag}, #{item.createUser}, #{item.createTime}, #{item.updateUser}, #{item.updateTime})
        </foreach>
    </insert>

    <update id="updateIpInfo" parameterType="IpInfo">
        update m_ipinfo
        <trim prefix="SET" suffixOverrides=",">
            <if test="ipName != null">ipName = #{ipName},</if>
            <if test="ipUrl != null">ipUrl = #{ipUrl},</if>
            <if test="colorNo != null">colorNo = #{colorNo},</if>
            <if test="sort != null">sort = #{sort},</if>
            <if test="delFlag != null">delFlag = #{delFlag},</if>
            <if test="createUser != null">createUser = #{createUser},</if>
            <if test="createTime != null">createTime = #{createTime},</if>
            <if test="updateUser != null">updateUser = #{updateUser},</if>
            <if test="updateTime != null">updateTime = #{updateTime},</if>
        </trim>
        where ipId = #{ipId}
    </update>

    <delete id="deleteIpInfoByIpId" parameterType="Long">
        delete from m_ipinfo where ipId = #{ipId}
    </delete>

    <delete id="deleteIpInfoByIpIds" parameterType="String">
        delete from m_ipinfo where ipId in 
        <foreach item="ipId" collection="array" open="(" separator="," close=")">
            #{ipId}
        </foreach>
    </delete>

    <update id="logicDeleteIpInfoByIpId" parameterType="Long">
        update m_ipinfo
            set delFlag = '1'
        where ipId = #{ipId}
    </update>

    <update id="logicDeleteIpInfoByIpIds" parameterType="String">
        update m_ipinfo
        set delFlag = '1'
        where ipId in
        <foreach item="ipId" collection="array" open="(" separator="," close=")">
            #{ipId}
        </foreach>
    </update>

    <update id="logicDeleteIpInfoByCondition" parameterType="IpInfo">
        update m_ipinfo
        set delFlag = '1'
        <where>
            <if test="ipName != null  and ipName != ''"> and ipName like concat('%', #{ipName}, '%')</if>
            <if test="ipUrl != null  and ipUrl != ''"> and ipUrl = #{ipUrl}</if>
            <if test="colorNo != null  and colorNo != ''"> and colorNo = #{colorNo}</if>
            <if test="sort != null "> and sort = #{sort}</if>
            <if test="delFlag != null  and delFlag != ''"> and delFlag = #{delFlag}</if>
            <if test="createUser != null  and createUser != ''"> and createUser = #{createUser}</if>
            <if test="createTime != null "> and createTime = #{createTime}</if>
            <if test="updateUser != null  and updateUser != ''"> and updateUser = #{updateUser}</if>
            <if test="updateTime != null "> and updateTime = #{updateTime}</if>
        </where>
    </update>
</mapper>