<?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.pcloud.book.record.mapper.IpDataMapper" >
  <resultMap id="BaseResultMap" type="com.pcloud.book.record.entity.IpData" >
    <id column="id" property="id" jdbcType="BIGINT" />
    <result column="ip" property="ip" jdbcType="VARCHAR" />
    <result column="region" property="region" jdbcType="VARCHAR" />
    <result column="region_id" property="regionId" jdbcType="VARCHAR" />
    <result column="city" property="city" jdbcType="VARCHAR" />
    <result column="city_id" property="cityId" jdbcType="VARCHAR" />
    <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
    <result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
  </resultMap>
  <sql id="Base_Column_List" >
    id, ip, region, region_id, city, city_id, create_time, update_time
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long" >
    select 
    <include refid="Base_Column_List" />
    from ip_data
    where id = #{id,jdbcType=BIGINT}
  </select>
  <select id="selectByIp" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List"/>
    from
    ip_data
    where
    ip = #{ip}
  </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long" >
    delete from ip_data
    where id = #{id,jdbcType=BIGINT}
  </delete>
  <insert id="insert" parameterType="com.pcloud.book.record.entity.IpData" >
    insert into ip_data (ip, region,
      region_id, city, city_id, 
      create_time, update_time)
    values (#{ip,jdbcType=VARCHAR}, #{region,jdbcType=VARCHAR},
      #{regionId,jdbcType=VARCHAR}, #{city,jdbcType=VARCHAR}, #{cityId,jdbcType=VARCHAR}, 
     now(), now())
  </insert>
  <insert id="insertSelective" parameterType="com.pcloud.book.record.entity.IpData" >
    insert into ip_data
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="ip != null" >
        ip,
      </if>
      <if test="region != null" >
        region,
      </if>
      <if test="regionId != null" >
        region_id,
      </if>
      <if test="city != null" >
        city,
      </if>
      <if test="cityId != null" >
        city_id,
      </if>
      <if test="createTime != null" >
        create_time,
      </if>
      <if test="updateTime != null" >
        update_time,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        #{id,jdbcType=BIGINT},
      </if>
      <if test="ip != null" >
        #{ip,jdbcType=VARCHAR},
      </if>
      <if test="region != null" >
        #{region,jdbcType=VARCHAR},
      </if>
      <if test="regionId != null" >
        #{regionId,jdbcType=VARCHAR},
      </if>
      <if test="city != null" >
        #{city,jdbcType=VARCHAR},
      </if>
      <if test="cityId != null" >
        #{cityId,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null" >
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateTime != null" >
        #{updateTime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.pcloud.book.record.entity.IpData" >
    update ip_data
    <set >
      <if test="ip != null" >
        ip = #{ip,jdbcType=VARCHAR},
      </if>
      <if test="region != null" >
        region = #{region,jdbcType=VARCHAR},
      </if>
      <if test="regionId != null" >
        region_id = #{regionId,jdbcType=VARCHAR},
      </if>
      <if test="city != null" >
        city = #{city,jdbcType=VARCHAR},
      </if>
      <if test="cityId != null" >
        city_id = #{cityId,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null" >
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateTime != null" >
        update_time = #{updateTime,jdbcType=TIMESTAMP},
      </if>
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.pcloud.book.record.entity.IpData" >
    update ip_data
    set ip = #{ip,jdbcType=VARCHAR},
      region = #{region,jdbcType=VARCHAR},
      region_id = #{regionId,jdbcType=VARCHAR},
      city = #{city,jdbcType=VARCHAR},
      city_id = #{cityId,jdbcType=VARCHAR},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      update_time = #{updateTime,jdbcType=TIMESTAMP}
    where id = #{id,jdbcType=BIGINT}
  </update>

  <select id="listCityByIp" resultType="com.pcloud.book.record.entity.IpData">
    select ip,city from ip_data where ip in
    <foreach collection="list" separator="," open="(" close=")" item="item">
      #{item}
    </foreach>
  </select>


</mapper>