<?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.microservices.zone.common.mapper.ZoneVisitsMapper">

    <resultMap type="ZoneVisits" id="ZoneVisitsResult">
        <result property="id" column="id"/>
        <result property="username" column="username"/>
        <result property="uuid" column="uuid"/>
        <result property="url" column="url"/>
        <result property="remark" column="remark"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectZoneVisitsVo">
        select id,
               username,
               uuid,
               url,
               remark,
               create_by,
               create_time,
               update_by,
               update_time
        from zone_visits
    </sql>

    <select id="selectZoneVisitsList" parameterType="ZoneVisits" resultMap="ZoneVisitsResult">
        <include refid="selectZoneVisitsVo"/>
        <where>
            <if test="username != null  and username != ''">and username like concat('%', #{username}, '%')</if>
            <if test="uuid != null  and uuid != ''">and uuid = #{uuid}</if>
            <if test="url != null  and url != ''">and url = #{url}</if>
        </where>
    </select>

    <select id="selectZoneVisitsById" parameterType="Long" resultMap="ZoneVisitsResult">
        <include refid="selectZoneVisitsVo"/>
        where id = #{id}
    </select>

    <insert id="insertZoneVisits" parameterType="ZoneVisits" useGeneratedKeys="true" keyProperty="id">
        insert into zone_visits
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="username != null">username,</if>
            <if test="uuid != null and uuid != ''">uuid,</if>
            <if test="url != null">url,</if>
            <if test="remark != null">remark,</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>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="username != null">#{username},</if>
            <if test="uuid != null and uuid != ''">#{uuid},</if>
            <if test="url != null">#{url},</if>
            <if test="remark != null">#{remark},</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>
        </trim>
    </insert>

    <update id="updateZoneVisits" parameterType="ZoneVisits">
        update zone_visits
        <trim prefix="SET" suffixOverrides=",">
            <if test="username != null">username = #{username},</if>
            <if test="uuid != null and uuid != ''">uuid = #{uuid},</if>
            <if test="url != null">url = #{url},</if>
            <if test="remark != null">remark = #{remark},</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>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteZoneVisitsById" parameterType="Long">
        delete
        from zone_visits
        where id = #{id}
    </delete>

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