<?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="cn.cecep.talroad.mapper.effective.PCodeRegionMapper">
  <resultMap id="BaseResultMap" type="cn.cecep.talroad.domain.effective.PCodeRegion">
    <!--@mbg.generated-->
    <!--@Table p_code_region-->
    <id column="region_id" jdbcType="BIGINT" property="regionId" />
    <result column="region_code" jdbcType="VARCHAR" property="regionCode" />
    <result column="region_name" jdbcType="VARCHAR" property="regionName" />
    <result column="region_lever" jdbcType="VARCHAR" property="regionLever" />
    <result column="region_tel" jdbcType="VARCHAR" property="regionTel" />
    <result column="parent_code" jdbcType="VARCHAR" property="parentCode" />
    <result column="delete_flag" jdbcType="SMALLINT" property="deleteFlag" />
    <result column="create_date" jdbcType="TIMESTAMP" property="createDate" />
    <result column="create_id" jdbcType="INTEGER" property="createId" />
    <result column="update_date" jdbcType="TIMESTAMP" property="updateDate" />
    <result column="update_id" jdbcType="INTEGER" property="updateId" />
    <result column="longitude" jdbcType="NUMERIC" property="longitude" />
    <result column="latitude" jdbcType="NUMERIC" property="latitude" />
    <result column="is168" jdbcType="SMALLINT" property="is168" />
    <result column="is74" jdbcType="SMALLINT" property="is74" />
    <result column="is28" jdbcType="SMALLINT" property="is28" />
    <result column="is337" jdbcType="SMALLINT" property="is337" />
  </resultMap>
  <sql id="Base_Column_List">
    <!--@mbg.generated-->
    region_id, region_code, region_name, region_lever, region_tel, parent_code, delete_flag,
    create_date, create_id, update_date, update_id, longitude, latitude, is168, is74,
    is28, is337
  </sql>
  <update id="updateBatch" parameterType="java.util.List">
    <!--@mbg.generated-->
    update p_code_region
    <trim prefix="set" suffixOverrides=",">
      <trim prefix="region_code = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when region_id = #{item.regionId,jdbcType=BIGINT} then #{item.regionCode,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="region_name = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when region_id = #{item.regionId,jdbcType=BIGINT} then #{item.regionName,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="region_lever = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when region_id = #{item.regionId,jdbcType=BIGINT} then #{item.regionLever,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="region_tel = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when region_id = #{item.regionId,jdbcType=BIGINT} then #{item.regionTel,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="parent_code = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when region_id = #{item.regionId,jdbcType=BIGINT} then #{item.parentCode,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="delete_flag = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when region_id = #{item.regionId,jdbcType=BIGINT} then #{item.deleteFlag,jdbcType=SMALLINT}
        </foreach>
      </trim>
      <trim prefix="create_date = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when region_id = #{item.regionId,jdbcType=BIGINT} then #{item.createDate,jdbcType=TIMESTAMP}
        </foreach>
      </trim>
      <trim prefix="create_id = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when region_id = #{item.regionId,jdbcType=BIGINT} then #{item.createId,jdbcType=INTEGER}
        </foreach>
      </trim>
      <trim prefix="update_date = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when region_id = #{item.regionId,jdbcType=BIGINT} then #{item.updateDate,jdbcType=TIMESTAMP}
        </foreach>
      </trim>
      <trim prefix="update_id = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when region_id = #{item.regionId,jdbcType=BIGINT} then #{item.updateId,jdbcType=INTEGER}
        </foreach>
      </trim>
      <trim prefix="longitude = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when region_id = #{item.regionId,jdbcType=BIGINT} then #{item.longitude,jdbcType=NUMERIC}
        </foreach>
      </trim>
      <trim prefix="latitude = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when region_id = #{item.regionId,jdbcType=BIGINT} then #{item.latitude,jdbcType=NUMERIC}
        </foreach>
      </trim>
      <trim prefix="is168 = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when region_id = #{item.regionId,jdbcType=BIGINT} then #{item.is168,jdbcType=SMALLINT}
        </foreach>
      </trim>
      <trim prefix="is74 = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when region_id = #{item.regionId,jdbcType=BIGINT} then #{item.is74,jdbcType=SMALLINT}
        </foreach>
      </trim>
      <trim prefix="is28 = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when region_id = #{item.regionId,jdbcType=BIGINT} then #{item.is28,jdbcType=SMALLINT}
        </foreach>
      </trim>
      <trim prefix="is337 = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when region_id = #{item.regionId,jdbcType=BIGINT} then #{item.is337,jdbcType=SMALLINT}
        </foreach>
      </trim>
    </trim>
    where region_id in
    <foreach close=")" collection="list" item="item" open="(" separator=", ">
      #{item.regionId,jdbcType=BIGINT}
    </foreach>
  </update>
  <update id="updateBatchSelective" parameterType="java.util.List">
    <!--@mbg.generated-->
    update p_code_region
    <trim prefix="set" suffixOverrides=",">
      <trim prefix="region_code = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.regionCode != null">
            when region_id = #{item.regionId,jdbcType=BIGINT} then #{item.regionCode,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="region_name = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.regionName != null">
            when region_id = #{item.regionId,jdbcType=BIGINT} then #{item.regionName,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="region_lever = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.regionLever != null">
            when region_id = #{item.regionId,jdbcType=BIGINT} then #{item.regionLever,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="region_tel = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.regionTel != null">
            when region_id = #{item.regionId,jdbcType=BIGINT} then #{item.regionTel,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="parent_code = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.parentCode != null">
            when region_id = #{item.regionId,jdbcType=BIGINT} then #{item.parentCode,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="delete_flag = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.deleteFlag != null">
            when region_id = #{item.regionId,jdbcType=BIGINT} then #{item.deleteFlag,jdbcType=SMALLINT}
          </if>
        </foreach>
      </trim>
      <trim prefix="create_date = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.createDate != null">
            when region_id = #{item.regionId,jdbcType=BIGINT} then #{item.createDate,jdbcType=TIMESTAMP}
          </if>
        </foreach>
      </trim>
      <trim prefix="create_id = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.createId != null">
            when region_id = #{item.regionId,jdbcType=BIGINT} then #{item.createId,jdbcType=INTEGER}
          </if>
        </foreach>
      </trim>
      <trim prefix="update_date = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.updateDate != null">
            when region_id = #{item.regionId,jdbcType=BIGINT} then #{item.updateDate,jdbcType=TIMESTAMP}
          </if>
        </foreach>
      </trim>
      <trim prefix="update_id = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.updateId != null">
            when region_id = #{item.regionId,jdbcType=BIGINT} then #{item.updateId,jdbcType=INTEGER}
          </if>
        </foreach>
      </trim>
      <trim prefix="longitude = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.longitude != null">
            when region_id = #{item.regionId,jdbcType=BIGINT} then #{item.longitude,jdbcType=NUMERIC}
          </if>
        </foreach>
      </trim>
      <trim prefix="latitude = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.latitude != null">
            when region_id = #{item.regionId,jdbcType=BIGINT} then #{item.latitude,jdbcType=NUMERIC}
          </if>
        </foreach>
      </trim>
      <trim prefix="is168 = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.is168 != null">
            when region_id = #{item.regionId,jdbcType=BIGINT} then #{item.is168,jdbcType=SMALLINT}
          </if>
        </foreach>
      </trim>
      <trim prefix="is74 = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.is74 != null">
            when region_id = #{item.regionId,jdbcType=BIGINT} then #{item.is74,jdbcType=SMALLINT}
          </if>
        </foreach>
      </trim>
      <trim prefix="is28 = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.is28 != null">
            when region_id = #{item.regionId,jdbcType=BIGINT} then #{item.is28,jdbcType=SMALLINT}
          </if>
        </foreach>
      </trim>
      <trim prefix="is337 = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.is337 != null">
            when region_id = #{item.regionId,jdbcType=BIGINT} then #{item.is337,jdbcType=SMALLINT}
          </if>
        </foreach>
      </trim>
    </trim>
    where region_id in
    <foreach close=")" collection="list" item="item" open="(" separator=", ">
      #{item.regionId,jdbcType=BIGINT}
    </foreach>
  </update>

    <insert id="batchInsert" parameterType="map">
    <!--@mbg.generated-->
    insert into p_code_region
    (region_id, region_code, region_name, region_lever, region_tel, parent_code, delete_flag,
      create_date, create_id, update_date, update_id, longitude, latitude, is168, is74,
      is28, is337)
    values
    <foreach collection="list" item="item" separator=",">
      (#{item.regionId,jdbcType=BIGINT}, #{item.regionCode,jdbcType=VARCHAR}, #{item.regionName,jdbcType=VARCHAR},
        #{item.regionLever,jdbcType=VARCHAR}, #{item.regionTel,jdbcType=VARCHAR}, #{item.parentCode,jdbcType=VARCHAR},
        #{item.deleteFlag,jdbcType=SMALLINT}, #{item.createDate,jdbcType=TIMESTAMP}, #{item.createId,jdbcType=INTEGER},
        #{item.updateDate,jdbcType=TIMESTAMP}, #{item.updateId,jdbcType=INTEGER}, #{item.longitude,jdbcType=NUMERIC},
        #{item.latitude,jdbcType=NUMERIC}, #{item.is168,jdbcType=SMALLINT}, #{item.is74,jdbcType=SMALLINT},
        #{item.is28,jdbcType=SMALLINT}, #{item.is337,jdbcType=SMALLINT})
    </foreach>
  </insert>

  <select id="findStationPullDataList" resultType="cn.cecep.talroad.domain.vo.PCodeStationVo"
          parameterType="java.lang.String">
    SELECT
    station.station_name as label,
    station.station_level,
    station.station_id  as value,
    station.station_code
    FROM
    p_code_station station
    WHERE
    1 = 1 and is_used='0' and station_type='1' and ( station.province_code=#{regionCode}::VARCHAR or station.city_code=#{regionCode}::VARCHAR  or station.district_code=#{regionCode}::VARCHAR or station.region_code=#{regionCode}::int )
    <foreach collection="levelCodeList" item="name" open="and  station.station_level in (" separator="," close=")">
      #{name} :: int
    </foreach>
  </select>


  <select id="selectMapConig" resultType="java.util.Map">
    select
      lat_max as "latMax",
      lat_min as "latMin",
      lng_max as "lngMax",
      lng_min as "lngMin"
    from t_version_config where region_code = #{regionCode}
  </select>
</mapper>
