<?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.RegionMapMapper" >
  <resultMap id="BaseResultMap" type="com.pcloud.book.record.entity.RegionMap" >
    <id column="id" property="id" jdbcType="BIGINT" />
    <result column="region_code" property="regionCode" jdbcType="VARCHAR" />
    <result column="level" property="level" jdbcType="INTEGER" />
    <result column="region_name" property="regionName" jdbcType="VARCHAR" />
    <result column="alphabet" property="alphabet" jdbcType="CHAR" />
    <result column="parent_id" property="parentId" jdbcType="INTEGER" />
    <result column="short_name" property="shortName" jdbcType="VARCHAR" />
  </resultMap>
  <sql id="Base_Column_List" >
    id, region_code, level, region_name, alphabet, parent_id, short_name
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long" >
    select 
    <include refid="Base_Column_List" />
    from region_map
    where id = #{id,jdbcType=BIGINT}
  </select>
  <select id="getCitysByPY" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List"/>
    from
    region_map
    <where>
      <if test="keyword != null">
        region_name like concat("%",#{keyword},"%")
      </if>
    </where>
    order by region_code
  </select>
  <select id="getCitysByCodes" resultMap="BaseResultMap" parameterType="list">
    select
    <include refid="Base_Column_List"/>
    from
    region_map
    where
    region_code
    in
    <foreach collection="list" item="item" index="index" open="(" close=")" separator=",">
      #{item}
    </foreach>
  </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long" >
    delete from region_map
    where id = #{id,jdbcType=BIGINT}
  </delete>
  <insert id="insert" parameterType="com.pcloud.book.record.entity.RegionMap" >
    insert into region_map (id, region_code, level, 
      region_name, alphabet, parent_id, 
      short_name)
    values (#{id,jdbcType=BIGINT}, #{regionCode,jdbcType=INTEGER}, #{level,jdbcType=INTEGER}, 
      #{regionName,jdbcType=VARCHAR}, #{alphabet,jdbcType=CHAR}, #{parentId,jdbcType=INTEGER}, 
      #{shortName,jdbcType=VARCHAR})
  </insert>
  <insert id="insertSelective" parameterType="com.pcloud.book.record.entity.RegionMap" >
    insert into region_map
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="regionCode != null" >
        region_code,
      </if>
      <if test="level != null" >
        level,
      </if>
      <if test="regionName != null" >
        region_name,
      </if>
      <if test="alphabet != null" >
        alphabet,
      </if>
      <if test="parentId != null" >
        parent_id,
      </if>
      <if test="shortName != null" >
        short_name,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        #{id,jdbcType=BIGINT},
      </if>
      <if test="regionCode != null" >
        #{regionCode,jdbcType=INTEGER},
      </if>
      <if test="level != null" >
        #{level,jdbcType=INTEGER},
      </if>
      <if test="regionName != null" >
        #{regionName,jdbcType=VARCHAR},
      </if>
      <if test="alphabet != null" >
        #{alphabet,jdbcType=CHAR},
      </if>
      <if test="parentId != null" >
        #{parentId,jdbcType=INTEGER},
      </if>
      <if test="shortName != null" >
        #{shortName,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.pcloud.book.record.entity.RegionMap" >
    update region_map
    <set >
      <if test="regionCode != null" >
        region_code = #{regionCode,jdbcType=INTEGER},
      </if>
      <if test="level != null" >
        level = #{level,jdbcType=INTEGER},
      </if>
      <if test="regionName != null" >
        region_name = #{regionName,jdbcType=VARCHAR},
      </if>
      <if test="alphabet != null" >
        alphabet = #{alphabet,jdbcType=CHAR},
      </if>
      <if test="parentId != null" >
        parent_id = #{parentId,jdbcType=INTEGER},
      </if>
      <if test="shortName != null" >
        short_name = #{shortName,jdbcType=VARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.pcloud.book.record.entity.RegionMap" >
    update region_map
    set region_code = #{regionCode,jdbcType=INTEGER},
      level = #{level,jdbcType=INTEGER},
      region_name = #{regionName,jdbcType=VARCHAR},
      alphabet = #{alphabet,jdbcType=CHAR},
      parent_id = #{parentId,jdbcType=INTEGER},
      short_name = #{shortName,jdbcType=VARCHAR}
    where id = #{id,jdbcType=BIGINT}
  </update>
  <select id="getCitysByCode" resultType="java.lang.String">
    select region_name from region_map where region_code =#{cityCode}
  </select>

</mapper>