<?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.PcNationalCityRankingHourMapper">
  <resultMap id="BaseResultMap" type="cn.cecep.talroad.domain.effective.PcNationalCityRankingHour">
    <!--@mbg.generated-->
    <!--@Table pc_national_city_ranking_hour-->
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="pcode" jdbcType="VARCHAR" property="pcode" />
    <result column="pname" jdbcType="VARCHAR" property="pname" />
    <result column="cityName" jdbcType="VARCHAR" property="cityname" />
    <result column="cityId" jdbcType="INTEGER" property="cityid" />
    <result column="aqi" jdbcType="VARCHAR" property="aqi" />
    <result column="maxPollution" jdbcType="VARCHAR" property="maxpollution" />
    <result column="pm25" jdbcType="VARCHAR" property="pm25" />
    <result column="pm10" jdbcType="VARCHAR" property="pm10" />
    <result column="o3" jdbcType="VARCHAR" property="o3" />
    <result column="so2" jdbcType="VARCHAR" property="so2" />
    <result column="no2" jdbcType="VARCHAR" property="no2" />
    <result column="co" jdbcType="VARCHAR" property="co" />
    <result column="date_time" jdbcType="TIMESTAMP" property="dateTime" />
    <result column="index_337" jdbcType="VARCHAR" property="index337" />
    <result column="is_337" jdbcType="VARCHAR" property="is337" />
    <result column="is_168" jdbcType="VARCHAR" property="is168" />
    <result column="index_168" jdbcType="VARCHAR" property="index168" />
    <result column="index_province_city" jdbcType="VARCHAR" property="indexProvinceCity" />
  </resultMap>
  <sql id="Base_Column_List">
    <!--@mbg.generated-->
    id, pcode, pname, cityName, cityId, aqi, maxPollution, pm25, pm10, o3, so2, no2,
    co, date_time, index_337, is_337, is_168, index_168
  </sql>
  <update id="updateBatch" parameterType="java.util.List">
    <!--@mbg.generated-->
    update pc_national_city_ranking_hour
    <trim prefix="set" suffixOverrides=",">
      <trim prefix="pcode = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.pcode,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="pname = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.pname,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="cityName = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.cityname,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="cityId = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.cityid,jdbcType=INTEGER}
        </foreach>
      </trim>
      <trim prefix="aqi = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.aqi,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="maxPollution = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.maxpollution,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="pm25 = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.pm25,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="pm10 = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.pm10,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="o3 = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.o3,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="so2 = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.so2,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="no2 = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.no2,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="co = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.co,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="date_time = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.dateTime,jdbcType=TIMESTAMP}
        </foreach>
      </trim>
      <trim prefix="index_337 = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.index337,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="is_337 = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.is337,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="is_168 = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.is168,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="index_168 = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.index168,jdbcType=VARCHAR}
        </foreach>
      </trim>
    </trim>
    where id in
    <foreach close=")" collection="list" item="item" open="(" separator=", ">
      #{item.id,jdbcType=INTEGER}
    </foreach>
  </update>
  <update id="updateBatchSelective" parameterType="java.util.List">
    <!--@mbg.generated-->
    update pc_national_city_ranking_hour
    <trim prefix="set" suffixOverrides=",">
      <trim prefix="pcode = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.pcode != null">
            when id = #{item.id,jdbcType=INTEGER} then #{item.pcode,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="pname = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.pname != null">
            when id = #{item.id,jdbcType=INTEGER} then #{item.pname,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="cityName = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.cityname != null">
            when id = #{item.id,jdbcType=INTEGER} then #{item.cityname,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="cityId = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.cityid != null">
            when id = #{item.id,jdbcType=INTEGER} then #{item.cityid,jdbcType=INTEGER}
          </if>
        </foreach>
      </trim>
      <trim prefix="aqi = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.aqi != null">
            when id = #{item.id,jdbcType=INTEGER} then #{item.aqi,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="maxPollution = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.maxpollution != null">
            when id = #{item.id,jdbcType=INTEGER} then #{item.maxpollution,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="pm25 = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.pm25 != null">
            when id = #{item.id,jdbcType=INTEGER} then #{item.pm25,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="pm10 = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.pm10 != null">
            when id = #{item.id,jdbcType=INTEGER} then #{item.pm10,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="o3 = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.o3 != null">
            when id = #{item.id,jdbcType=INTEGER} then #{item.o3,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="so2 = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.so2 != null">
            when id = #{item.id,jdbcType=INTEGER} then #{item.so2,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="no2 = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.no2 != null">
            when id = #{item.id,jdbcType=INTEGER} then #{item.no2,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="co = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.co != null">
            when id = #{item.id,jdbcType=INTEGER} then #{item.co,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="date_time = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.dateTime != null">
            when id = #{item.id,jdbcType=INTEGER} then #{item.dateTime,jdbcType=TIMESTAMP}
          </if>
        </foreach>
      </trim>
      <trim prefix="index_337 = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.index337 != null">
            when id = #{item.id,jdbcType=INTEGER} then #{item.index337,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="is_337 = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.is337 != null">
            when id = #{item.id,jdbcType=INTEGER} then #{item.is337,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="is_168 = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.is168 != null">
            when id = #{item.id,jdbcType=INTEGER} then #{item.is168,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="index_168 = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.index168 != null">
            when id = #{item.id,jdbcType=INTEGER} then #{item.index168,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
    </trim>
    where id in
    <foreach close=")" collection="list" item="item" open="(" separator=", ">
      #{item.id,jdbcType=INTEGER}
    </foreach>
  </update>
  <update id="updateBatchIndexProvince">
    <foreach collection="list" item="item"  separator=";">
      update pc_national_city_ranking_hour set index_province_city = #{item.indexProvinceCity}
      where id = #{item.id,jdbcType=INTEGER} and "cityId"= #{item.cityid,jdbcType=VARCHAR} and date_time =#{item.dateTime,jdbcType=TIMESTAMP}
    </foreach>
  </update>
  <select id="selectHourRankData"  resultMap="BaseResultMap">
      select * from pc_national_city_ranking_hour pncro
      where  pname ='河北'
        and  date_time = #{lastHourDate}
      order by cast(index_337 as int2) asc
    </select>
    <insert id="batchInsert" parameterType="map">
    <!--@mbg.generated-->
    insert into pc_national_city_ranking_hour
    (id, pcode, pname, cityName, cityId, aqi, maxPollution, pm25, pm10, o3, so2, no2,
      co, date_time, index_337, is_337, is_168, index_168)
    values
    <foreach collection="list" item="item" separator=",">
      (#{item.id,jdbcType=INTEGER}, #{item.pcode,jdbcType=VARCHAR}, #{item.pname,jdbcType=VARCHAR},
        #{item.cityname,jdbcType=VARCHAR}, #{item.cityid,jdbcType=INTEGER}, #{item.aqi,jdbcType=VARCHAR},
        #{item.maxpollution,jdbcType=VARCHAR}, #{item.pm25,jdbcType=VARCHAR}, #{item.pm10,jdbcType=VARCHAR},
        #{item.o3,jdbcType=VARCHAR}, #{item.so2,jdbcType=VARCHAR}, #{item.no2,jdbcType=VARCHAR},
        #{item.co,jdbcType=VARCHAR}, #{item.dateTime,jdbcType=TIMESTAMP}, #{item.index337,jdbcType=VARCHAR},
        #{item.is337,jdbcType=VARCHAR}, #{item.is168,jdbcType=VARCHAR}, #{item.index168,jdbcType=VARCHAR}
        )
    </foreach>
  </insert>
</mapper>
