<?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.lightinit.hsdatashow.mapper.HbCityAirQualityIndexMapper">
  <resultMap id="BaseResultMap" type="com.lightinit.hsdatashow.entity.HbCityAirQualityIndex">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="city_name" jdbcType="VARCHAR" property="cityName" />
    <result column="air_index" jdbcType="INTEGER" property="airIndex" />
    <result column="pollution_name" jdbcType="VARCHAR" property="pollutionName" />
    <result column="degree" jdbcType="VARCHAR" property="degree" />
    <result column="state" jdbcType="VARCHAR" property="state" />
    <result column="update_date" jdbcType="DATE" property="updateDate" />
    <result column="created_at" jdbcType="DATE" property="createdAt" />
  </resultMap>
  <sql id="Example_Where_Clause">
    <where>
      <foreach collection="oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Update_By_Example_Where_Clause">
    <where>
      <foreach collection="example.oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Base_Column_List">
    id, city_name, air_index, pollution_name, degree, state, update_date, created_at
  </sql>
  <select id="selectByExample" parameterType="com.lightinit.hsdatashow.entity.HbCityAirQualityIndexExample" resultMap="BaseResultMap">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from hb_city_air_quality_index
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from hb_city_air_quality_index
    where id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    delete from hb_city_air_quality_index
    where id = #{id,jdbcType=BIGINT}
  </delete>
  <delete id="deleteByExample" parameterType="com.lightinit.hsdatashow.entity.HbCityAirQualityIndexExample">
    delete from hb_city_air_quality_index
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.lightinit.hsdatashow.entity.HbCityAirQualityIndex">
    <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into hb_city_air_quality_index (city_name, air_index, pollution_name, 
      degree, state, update_date, 
      created_at)
    values (#{cityName,jdbcType=VARCHAR}, #{airIndex,jdbcType=INTEGER}, #{pollutionName,jdbcType=VARCHAR}, 
      #{degree,jdbcType=VARCHAR}, #{state,jdbcType=VARCHAR}, #{updateDate,jdbcType=DATE}, 
      #{createdAt,jdbcType=DATE})
  </insert>
  <insert id="insertSelective" parameterType="com.lightinit.hsdatashow.entity.HbCityAirQualityIndex">
    <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into hb_city_air_quality_index
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="cityName != null">
        city_name,
      </if>
      <if test="airIndex != null">
        air_index,
      </if>
      <if test="pollutionName != null">
        pollution_name,
      </if>
      <if test="degree != null">
        degree,
      </if>
      <if test="state != null">
        state,
      </if>
      <if test="updateDate != null">
        update_date,
      </if>
      <if test="createdAt != null">
        created_at,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="cityName != null">
        #{cityName,jdbcType=VARCHAR},
      </if>
      <if test="airIndex != null">
        #{airIndex,jdbcType=INTEGER},
      </if>
      <if test="pollutionName != null">
        #{pollutionName,jdbcType=VARCHAR},
      </if>
      <if test="degree != null">
        #{degree,jdbcType=VARCHAR},
      </if>
      <if test="state != null">
        #{state,jdbcType=VARCHAR},
      </if>
      <if test="updateDate != null">
        #{updateDate,jdbcType=DATE},
      </if>
      <if test="createdAt != null">
        #{createdAt,jdbcType=DATE},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.lightinit.hsdatashow.entity.HbCityAirQualityIndexExample" resultType="java.lang.Long">
    select count(*) from hb_city_air_quality_index
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    update hb_city_air_quality_index
    <set>
      <if test="record.id != null">
        id = #{record.id,jdbcType=BIGINT},
      </if>
      <if test="record.cityName != null">
        city_name = #{record.cityName,jdbcType=VARCHAR},
      </if>
      <if test="record.airIndex != null">
        air_index = #{record.airIndex,jdbcType=INTEGER},
      </if>
      <if test="record.pollutionName != null">
        pollution_name = #{record.pollutionName,jdbcType=VARCHAR},
      </if>
      <if test="record.degree != null">
        degree = #{record.degree,jdbcType=VARCHAR},
      </if>
      <if test="record.state != null">
        state = #{record.state,jdbcType=VARCHAR},
      </if>
      <if test="record.updateDate != null">
        update_date = #{record.updateDate,jdbcType=DATE},
      </if>
      <if test="record.createdAt != null">
        created_at = #{record.createdAt,jdbcType=DATE},
      </if>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">
    update hb_city_air_quality_index
    set id = #{record.id,jdbcType=BIGINT},
      city_name = #{record.cityName,jdbcType=VARCHAR},
      air_index = #{record.airIndex,jdbcType=INTEGER},
      pollution_name = #{record.pollutionName,jdbcType=VARCHAR},
      degree = #{record.degree,jdbcType=VARCHAR},
      state = #{record.state,jdbcType=VARCHAR},
      update_date = #{record.updateDate,jdbcType=DATE},
      created_at = #{record.createdAt,jdbcType=DATE}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.lightinit.hsdatashow.entity.HbCityAirQualityIndex">
    update hb_city_air_quality_index
    <set>
      <if test="cityName != null">
        city_name = #{cityName,jdbcType=VARCHAR},
      </if>
      <if test="airIndex != null">
        air_index = #{airIndex,jdbcType=INTEGER},
      </if>
      <if test="pollutionName != null">
        pollution_name = #{pollutionName,jdbcType=VARCHAR},
      </if>
      <if test="degree != null">
        degree = #{degree,jdbcType=VARCHAR},
      </if>
      <if test="state != null">
        state = #{state,jdbcType=VARCHAR},
      </if>
      <if test="updateDate != null">
        update_date = #{updateDate,jdbcType=DATE},
      </if>
      <if test="createdAt != null">
        created_at = #{createdAt,jdbcType=DATE},
      </if>
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.lightinit.hsdatashow.entity.HbCityAirQualityIndex">
    update hb_city_air_quality_index
    set city_name = #{cityName,jdbcType=VARCHAR},
      air_index = #{airIndex,jdbcType=INTEGER},
      pollution_name = #{pollutionName,jdbcType=VARCHAR},
      degree = #{degree,jdbcType=VARCHAR},
      state = #{state,jdbcType=VARCHAR},
      update_date = #{updateDate,jdbcType=DATE},
      created_at = #{createdAt,jdbcType=DATE}
    where id = #{id,jdbcType=BIGINT}
  </update>

  <!--sx-->
  <select id="getHBCityAirQualityIndexDate" resultType="String">
    SELECT DISTINCT(DATE_FORMAT(update_date,'%y/%m/%d')) FROM hb_city_air_quality_index ORDER BY update_date
  </select>

  <!--sx-->
  <select id="getHBCityAirQualityIndex" resultType="java.util.LinkedHashMap">
    SELECT DISTINCT city_name,CONCAT('[',GROUP_CONCAT(CAST(air_index AS CHAR)),']') AS dates FROM
    hb_city_air_quality_index
    GROUP BY city_name
  </select>

  <!--sx-->
  <select id="getHbAreaAirFineCount" resultType="com.lightinit.hsdatashow.model.admin.ChartModel">
    SELECT city_name AS `name`,COUNT(*) AS `value`  FROM hb_city_air_quality_index
    WHERE state='优'OR state='良'
    GROUP BY city_name
     ORDER BY `value` DESC
  </select>
</mapper>