<?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.CountrysideSewageRankingMapper">
  <resultMap id="BaseResultMap" type="com.lightinit.hsdatashow.entity.CountrysideSewageRanking">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="region_id" jdbcType="BIGINT" property="regionId" />
    <result column="data_year" jdbcType="INTEGER" property="dataYear" />
    <result column="quantity" jdbcType="DECIMAL" property="quantity" />
    <result column="growth" jdbcType="DECIMAL" property="growth" />
    <result column="created_at" jdbcType="TIMESTAMP" property="createdAt" />
    <result column="created_by" jdbcType="BIGINT" property="createdBy" />
    <result column="deleted_at" jdbcType="TIMESTAMP" property="deletedAt" />
    <result column="deleted_by" jdbcType="BIGINT" property="deletedBy" />
  </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, region_id, data_year, quantity, growth, created_at, created_by, deleted_at, deleted_by
  </sql>
  <select id="selectByExample" parameterType="com.lightinit.hsdatashow.entity.CountrysideSewageRankingExample" resultMap="BaseResultMap">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from countryside_sewage_ranking
    <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 countryside_sewage_ranking
    where id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    delete from countryside_sewage_ranking
    where id = #{id,jdbcType=BIGINT}
  </delete>
  <delete id="deleteByExample" parameterType="com.lightinit.hsdatashow.entity.CountrysideSewageRankingExample">
    delete from countryside_sewage_ranking
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.lightinit.hsdatashow.entity.CountrysideSewageRanking">
    <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into countryside_sewage_ranking (region_id, data_year, quantity, 
      growth, created_at, created_by, 
      deleted_at, deleted_by)
    values (#{regionId,jdbcType=BIGINT}, #{dataYear,jdbcType=INTEGER}, #{quantity,jdbcType=DECIMAL}, 
      #{growth,jdbcType=DECIMAL}, #{createdAt,jdbcType=TIMESTAMP}, #{createdBy,jdbcType=BIGINT}, 
      #{deletedAt,jdbcType=TIMESTAMP}, #{deletedBy,jdbcType=BIGINT})
  </insert>
  <insert id="insertSelective" parameterType="com.lightinit.hsdatashow.entity.CountrysideSewageRanking">
    <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into countryside_sewage_ranking
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="regionId != null">
        region_id,
      </if>
      <if test="dataYear != null">
        data_year,
      </if>
      <if test="quantity != null">
        quantity,
      </if>
      <if test="growth != null">
        growth,
      </if>
      <if test="createdAt != null">
        created_at,
      </if>
      <if test="createdBy != null">
        created_by,
      </if>
      <if test="deletedAt != null">
        deleted_at,
      </if>
      <if test="deletedBy != null">
        deleted_by,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="regionId != null">
        #{regionId,jdbcType=BIGINT},
      </if>
      <if test="dataYear != null">
        #{dataYear,jdbcType=INTEGER},
      </if>
      <if test="quantity != null">
        #{quantity,jdbcType=DECIMAL},
      </if>
      <if test="growth != null">
        #{growth,jdbcType=DECIMAL},
      </if>
      <if test="createdAt != null">
        #{createdAt,jdbcType=TIMESTAMP},
      </if>
      <if test="createdBy != null">
        #{createdBy,jdbcType=BIGINT},
      </if>
      <if test="deletedAt != null">
        #{deletedAt,jdbcType=TIMESTAMP},
      </if>
      <if test="deletedBy != null">
        #{deletedBy,jdbcType=BIGINT},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.lightinit.hsdatashow.entity.CountrysideSewageRankingExample" resultType="java.lang.Long">
    select count(*) from countryside_sewage_ranking
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    update countryside_sewage_ranking
    <set>
      <if test="record.id != null">
        id = #{record.id,jdbcType=BIGINT},
      </if>
      <if test="record.regionId != null">
        region_id = #{record.regionId,jdbcType=BIGINT},
      </if>
      <if test="record.dataYear != null">
        data_year = #{record.dataYear,jdbcType=INTEGER},
      </if>
      <if test="record.quantity != null">
        quantity = #{record.quantity,jdbcType=DECIMAL},
      </if>
      <if test="record.growth != null">
        growth = #{record.growth,jdbcType=DECIMAL},
      </if>
      <if test="record.createdAt != null">
        created_at = #{record.createdAt,jdbcType=TIMESTAMP},
      </if>
      <if test="record.createdBy != null">
        created_by = #{record.createdBy,jdbcType=BIGINT},
      </if>
      <if test="record.deletedAt != null">
        deleted_at = #{record.deletedAt,jdbcType=TIMESTAMP},
      </if>
      <if test="record.deletedBy != null">
        deleted_by = #{record.deletedBy,jdbcType=BIGINT},
      </if>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">
    update countryside_sewage_ranking
    set id = #{record.id,jdbcType=BIGINT},
      region_id = #{record.regionId,jdbcType=BIGINT},
      data_year = #{record.dataYear,jdbcType=INTEGER},
      quantity = #{record.quantity,jdbcType=DECIMAL},
      growth = #{record.growth,jdbcType=DECIMAL},
      created_at = #{record.createdAt,jdbcType=TIMESTAMP},
      created_by = #{record.createdBy,jdbcType=BIGINT},
      deleted_at = #{record.deletedAt,jdbcType=TIMESTAMP},
      deleted_by = #{record.deletedBy,jdbcType=BIGINT}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.lightinit.hsdatashow.entity.CountrysideSewageRanking">
    update countryside_sewage_ranking
    <set>
      <if test="regionId != null">
        region_id = #{regionId,jdbcType=BIGINT},
      </if>
      <if test="dataYear != null">
        data_year = #{dataYear,jdbcType=INTEGER},
      </if>
      <if test="quantity != null">
        quantity = #{quantity,jdbcType=DECIMAL},
      </if>
      <if test="growth != null">
        growth = #{growth,jdbcType=DECIMAL},
      </if>
      <if test="createdAt != null">
        created_at = #{createdAt,jdbcType=TIMESTAMP},
      </if>
      <if test="createdBy != null">
        created_by = #{createdBy,jdbcType=BIGINT},
      </if>
      <if test="deletedAt != null">
        deleted_at = #{deletedAt,jdbcType=TIMESTAMP},
      </if>
      <if test="deletedBy != null">
        deleted_by = #{deletedBy,jdbcType=BIGINT},
      </if>
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.lightinit.hsdatashow.entity.CountrysideSewageRanking">
    update countryside_sewage_ranking
    set region_id = #{regionId,jdbcType=BIGINT},
      data_year = #{dataYear,jdbcType=INTEGER},
      quantity = #{quantity,jdbcType=DECIMAL},
      growth = #{growth,jdbcType=DECIMAL},
      created_at = #{createdAt,jdbcType=TIMESTAMP},
      created_by = #{createdBy,jdbcType=BIGINT},
      deleted_at = #{deletedAt,jdbcType=TIMESTAMP},
      deleted_by = #{deletedBy,jdbcType=BIGINT}
    where id = #{id,jdbcType=BIGINT}
  </update>
  <select id="getCountrysideSewageRanking" parameterType="java.lang.Integer" resultType="com.lightinit.hsdatashow.model.admin.CountrysideGarbageModel">
    select cs.*,r.region_name regionName from countryside_sewage_ranking cs
    JOIN region r
    ON r.id = cs.region_id
    WHERE cs.data_year = #{year}
  </select>

  <select id="selectList" parameterType="com.lightinit.hsdatashow.entity.GarbageRegionExample" resultType="com.lightinit.hsdatashow.model.ms.GreenModel">
    select gr.*,r.region_name ,r.id regionId from countryside_sewage_ranking gr
    left join region r
    on gr.region_id = r.id
    <if test="page != null" >
      limit ${page.beginIndex},${page.pageSize}
    </if>
  </select>
  <select id="selectCount" parameterType="com.lightinit.hsdatashow.entity.GarbageRegionExample" resultType="java.lang.Long">
select count(*) from countryside_sewage_ranking gr
    left join region r
    on gr.region_id = r.id
  </select>
  <select id="findByDistributionId" parameterType="java.lang.Long" resultType="com.lightinit.hsdatashow.model.ms.GreenModel">
 select gr.*,r.region_name ,r.id regionId from countryside_sewage_ranking gr
    left join region r
    on gr.region_id = r.id
    where gr.id = #{id}
  </select>
</mapper>