<?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.StWaterLakeMapper">
  <resultMap id="BaseResultMap" type="com.lightinit.hsdatashow.entity.StWaterLake">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="region_id" jdbcType="BIGINT" property="regionId" />
    <result column="region_code" jdbcType="VARCHAR" property="regionCode" />
    <result column="lake_type" jdbcType="VARCHAR" property="lakeType" />
    <result column="lake_name" jdbcType="VARCHAR" property="lakeName" />
    <result column="lake_code" jdbcType="VARCHAR" property="lakeCode" />
    <result column="lake_description" jdbcType="VARCHAR" property="lakeDescription" />
    <result column="lake_area" jdbcType="DECIMAL" property="lakeArea" />
    <result column="lake_impoundage" jdbcType="DECIMAL" property="lakeImpoundage" />
    <result column="lake_chief" jdbcType="VARCHAR" property="lakeChief" />
    <result column="water_level_normal" jdbcType="DECIMAL" property="waterLevelNormal" />
    <result column="water_level_warning" jdbcType="DECIMAL" property="waterLevelWarning" />
    <result column="water_level_dead" jdbcType="DECIMAL" property="waterLevelDead" />
    <result column="water_quality" jdbcType="VARCHAR" property="waterQuality" />
    <result column="remark" jdbcType="VARCHAR" property="remark" />
    <result column="created_at" jdbcType="TIMESTAMP" property="createdAt" />
    <result column="created_by" jdbcType="VARCHAR" property="createdBy" />
    <result column="deleted_at" jdbcType="TIMESTAMP" property="deletedAt" />
    <result column="deleted_by" jdbcType="VARCHAR" 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, region_code, lake_type, lake_name, lake_code, lake_description, lake_area, 
    lake_impoundage, lake_chief, water_level_normal, water_level_warning, water_level_dead, 
    water_quality, remark, created_at, created_by, deleted_at, deleted_by
  </sql>
  <select id="selectByExample" parameterType="com.lightinit.hsdatashow.entity.StWaterLakeExample" resultMap="BaseResultMap">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from st_water_lake
    <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 st_water_lake
    where id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    delete from st_water_lake
    where id = #{id,jdbcType=BIGINT}
  </delete>
  <delete id="deleteByExample" parameterType="com.lightinit.hsdatashow.entity.StWaterLakeExample">
    delete from st_water_lake
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.lightinit.hsdatashow.entity.StWaterLake">
    <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into st_water_lake (region_id, region_code, lake_type, 
      lake_name, lake_code, lake_description, 
      lake_area, lake_impoundage, lake_chief, 
      water_level_normal, water_level_warning, water_level_dead, 
      water_quality, remark, created_at, 
      created_by, deleted_at, deleted_by
      )
    values (#{regionId,jdbcType=BIGINT}, #{regionCode,jdbcType=VARCHAR}, #{lakeType,jdbcType=VARCHAR}, 
      #{lakeName,jdbcType=VARCHAR}, #{lakeCode,jdbcType=VARCHAR}, #{lakeDescription,jdbcType=VARCHAR}, 
      #{lakeArea,jdbcType=DECIMAL}, #{lakeImpoundage,jdbcType=DECIMAL}, #{lakeChief,jdbcType=VARCHAR}, 
      #{waterLevelNormal,jdbcType=DECIMAL}, #{waterLevelWarning,jdbcType=DECIMAL}, #{waterLevelDead,jdbcType=DECIMAL}, 
      #{waterQuality,jdbcType=VARCHAR}, #{remark,jdbcType=VARCHAR}, #{createdAt,jdbcType=TIMESTAMP}, 
      #{createdBy,jdbcType=VARCHAR}, #{deletedAt,jdbcType=TIMESTAMP}, #{deletedBy,jdbcType=VARCHAR}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.lightinit.hsdatashow.entity.StWaterLake">
    <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into st_water_lake
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="regionId != null">
        region_id,
      </if>
      <if test="regionCode != null">
        region_code,
      </if>
      <if test="lakeType != null">
        lake_type,
      </if>
      <if test="lakeName != null">
        lake_name,
      </if>
      <if test="lakeCode != null">
        lake_code,
      </if>
      <if test="lakeDescription != null">
        lake_description,
      </if>
      <if test="lakeArea != null">
        lake_area,
      </if>
      <if test="lakeImpoundage != null">
        lake_impoundage,
      </if>
      <if test="lakeChief != null">
        lake_chief,
      </if>
      <if test="waterLevelNormal != null">
        water_level_normal,
      </if>
      <if test="waterLevelWarning != null">
        water_level_warning,
      </if>
      <if test="waterLevelDead != null">
        water_level_dead,
      </if>
      <if test="waterQuality != null">
        water_quality,
      </if>
      <if test="remark != null">
        remark,
      </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="regionCode != null">
        #{regionCode,jdbcType=VARCHAR},
      </if>
      <if test="lakeType != null">
        #{lakeType,jdbcType=VARCHAR},
      </if>
      <if test="lakeName != null">
        #{lakeName,jdbcType=VARCHAR},
      </if>
      <if test="lakeCode != null">
        #{lakeCode,jdbcType=VARCHAR},
      </if>
      <if test="lakeDescription != null">
        #{lakeDescription,jdbcType=VARCHAR},
      </if>
      <if test="lakeArea != null">
        #{lakeArea,jdbcType=DECIMAL},
      </if>
      <if test="lakeImpoundage != null">
        #{lakeImpoundage,jdbcType=DECIMAL},
      </if>
      <if test="lakeChief != null">
        #{lakeChief,jdbcType=VARCHAR},
      </if>
      <if test="waterLevelNormal != null">
        #{waterLevelNormal,jdbcType=DECIMAL},
      </if>
      <if test="waterLevelWarning != null">
        #{waterLevelWarning,jdbcType=DECIMAL},
      </if>
      <if test="waterLevelDead != null">
        #{waterLevelDead,jdbcType=DECIMAL},
      </if>
      <if test="waterQuality != null">
        #{waterQuality,jdbcType=VARCHAR},
      </if>
      <if test="remark != null">
        #{remark,jdbcType=VARCHAR},
      </if>
      <if test="createdAt != null">
        #{createdAt,jdbcType=TIMESTAMP},
      </if>
      <if test="createdBy != null">
        #{createdBy,jdbcType=VARCHAR},
      </if>
      <if test="deletedAt != null">
        #{deletedAt,jdbcType=TIMESTAMP},
      </if>
      <if test="deletedBy != null">
        #{deletedBy,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.lightinit.hsdatashow.entity.StWaterLakeExample" resultType="java.lang.Long">
    select count(*) from st_water_lake
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    update st_water_lake
    <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.regionCode != null">
        region_code = #{record.regionCode,jdbcType=VARCHAR},
      </if>
      <if test="record.lakeType != null">
        lake_type = #{record.lakeType,jdbcType=VARCHAR},
      </if>
      <if test="record.lakeName != null">
        lake_name = #{record.lakeName,jdbcType=VARCHAR},
      </if>
      <if test="record.lakeCode != null">
        lake_code = #{record.lakeCode,jdbcType=VARCHAR},
      </if>
      <if test="record.lakeDescription != null">
        lake_description = #{record.lakeDescription,jdbcType=VARCHAR},
      </if>
      <if test="record.lakeArea != null">
        lake_area = #{record.lakeArea,jdbcType=DECIMAL},
      </if>
      <if test="record.lakeImpoundage != null">
        lake_impoundage = #{record.lakeImpoundage,jdbcType=DECIMAL},
      </if>
      <if test="record.lakeChief != null">
        lake_chief = #{record.lakeChief,jdbcType=VARCHAR},
      </if>
      <if test="record.waterLevelNormal != null">
        water_level_normal = #{record.waterLevelNormal,jdbcType=DECIMAL},
      </if>
      <if test="record.waterLevelWarning != null">
        water_level_warning = #{record.waterLevelWarning,jdbcType=DECIMAL},
      </if>
      <if test="record.waterLevelDead != null">
        water_level_dead = #{record.waterLevelDead,jdbcType=DECIMAL},
      </if>
      <if test="record.waterQuality != null">
        water_quality = #{record.waterQuality,jdbcType=VARCHAR},
      </if>
      <if test="record.remark != null">
        remark = #{record.remark,jdbcType=VARCHAR},
      </if>
      <if test="record.createdAt != null">
        created_at = #{record.createdAt,jdbcType=TIMESTAMP},
      </if>
      <if test="record.createdBy != null">
        created_by = #{record.createdBy,jdbcType=VARCHAR},
      </if>
      <if test="record.deletedAt != null">
        deleted_at = #{record.deletedAt,jdbcType=TIMESTAMP},
      </if>
      <if test="record.deletedBy != null">
        deleted_by = #{record.deletedBy,jdbcType=VARCHAR},
      </if>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">
    update st_water_lake
    set id = #{record.id,jdbcType=BIGINT},
      region_id = #{record.regionId,jdbcType=BIGINT},
      region_code = #{record.regionCode,jdbcType=VARCHAR},
      lake_type = #{record.lakeType,jdbcType=VARCHAR},
      lake_name = #{record.lakeName,jdbcType=VARCHAR},
      lake_code = #{record.lakeCode,jdbcType=VARCHAR},
      lake_description = #{record.lakeDescription,jdbcType=VARCHAR},
      lake_area = #{record.lakeArea,jdbcType=DECIMAL},
      lake_impoundage = #{record.lakeImpoundage,jdbcType=DECIMAL},
      lake_chief = #{record.lakeChief,jdbcType=VARCHAR},
      water_level_normal = #{record.waterLevelNormal,jdbcType=DECIMAL},
      water_level_warning = #{record.waterLevelWarning,jdbcType=DECIMAL},
      water_level_dead = #{record.waterLevelDead,jdbcType=DECIMAL},
      water_quality = #{record.waterQuality,jdbcType=VARCHAR},
      remark = #{record.remark,jdbcType=VARCHAR},
      created_at = #{record.createdAt,jdbcType=TIMESTAMP},
      created_by = #{record.createdBy,jdbcType=VARCHAR},
      deleted_at = #{record.deletedAt,jdbcType=TIMESTAMP},
      deleted_by = #{record.deletedBy,jdbcType=VARCHAR}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.lightinit.hsdatashow.entity.StWaterLake">
    update st_water_lake
    <set>
      <if test="regionId != null">
        region_id = #{regionId,jdbcType=BIGINT},
      </if>
      <if test="regionCode != null">
        region_code = #{regionCode,jdbcType=VARCHAR},
      </if>
      <if test="lakeType != null">
        lake_type = #{lakeType,jdbcType=VARCHAR},
      </if>
      <if test="lakeName != null">
        lake_name = #{lakeName,jdbcType=VARCHAR},
      </if>
      <if test="lakeCode != null">
        lake_code = #{lakeCode,jdbcType=VARCHAR},
      </if>
      <if test="lakeDescription != null">
        lake_description = #{lakeDescription,jdbcType=VARCHAR},
      </if>
      <if test="lakeArea != null">
        lake_area = #{lakeArea,jdbcType=DECIMAL},
      </if>
      <if test="lakeImpoundage != null">
        lake_impoundage = #{lakeImpoundage,jdbcType=DECIMAL},
      </if>
      <if test="lakeChief != null">
        lake_chief = #{lakeChief,jdbcType=VARCHAR},
      </if>
      <if test="waterLevelNormal != null">
        water_level_normal = #{waterLevelNormal,jdbcType=DECIMAL},
      </if>
      <if test="waterLevelWarning != null">
        water_level_warning = #{waterLevelWarning,jdbcType=DECIMAL},
      </if>
      <if test="waterLevelDead != null">
        water_level_dead = #{waterLevelDead,jdbcType=DECIMAL},
      </if>
      <if test="waterQuality != null">
        water_quality = #{waterQuality,jdbcType=VARCHAR},
      </if>
      <if test="remark != null">
        remark = #{remark,jdbcType=VARCHAR},
      </if>
      <if test="createdAt != null">
        created_at = #{createdAt,jdbcType=TIMESTAMP},
      </if>
      <if test="createdBy != null">
        created_by = #{createdBy,jdbcType=VARCHAR},
      </if>
      <if test="deletedAt != null">
        deleted_at = #{deletedAt,jdbcType=TIMESTAMP},
      </if>
      <if test="deletedBy != null">
        deleted_by = #{deletedBy,jdbcType=VARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.lightinit.hsdatashow.entity.StWaterLake">
    update st_water_lake
    set region_id = #{regionId,jdbcType=BIGINT},
      region_code = #{regionCode,jdbcType=VARCHAR},
      lake_type = #{lakeType,jdbcType=VARCHAR},
      lake_name = #{lakeName,jdbcType=VARCHAR},
      lake_code = #{lakeCode,jdbcType=VARCHAR},
      lake_description = #{lakeDescription,jdbcType=VARCHAR},
      lake_area = #{lakeArea,jdbcType=DECIMAL},
      lake_impoundage = #{lakeImpoundage,jdbcType=DECIMAL},
      lake_chief = #{lakeChief,jdbcType=VARCHAR},
      water_level_normal = #{waterLevelNormal,jdbcType=DECIMAL},
      water_level_warning = #{waterLevelWarning,jdbcType=DECIMAL},
      water_level_dead = #{waterLevelDead,jdbcType=DECIMAL},
      water_quality = #{waterQuality,jdbcType=VARCHAR},
      remark = #{remark,jdbcType=VARCHAR},
      created_at = #{createdAt,jdbcType=TIMESTAMP},
      created_by = #{createdBy,jdbcType=VARCHAR},
      deleted_at = #{deletedAt,jdbcType=TIMESTAMP},
      deleted_by = #{deletedBy,jdbcType=VARCHAR}
    where id = #{id,jdbcType=BIGINT}
  </update>
  <select id="getHengshuiHu" resultType="com.lightinit.hsdatashow.entity.StWaterLake">
    SELECT lake_area,lake_impoundage,water_level_dead
    FROM st_water_lake
    WHERE lake_name = '衡水湖'
  </select>
  <select id="getHengshuiHuShuiwei" resultType="com.lightinit.hsdatashow.model.topic.water.HshxushuiReturnModel">
   select swl.water_level_normal normal,swl.water_level_warning warning,swlwl.water_level level
    from st_water_lake swl
    join st_water_lake_water_level swlwl
    on swl.id = swlwl.lake_id
    INNER JOIN
    (
        select lake_id , MAX(capture_time) AS maxtime
        from st_water_lake_water_level
        GROUP BY lake_id
    ) AS A
    ON swlwl.lake_id = A.lake_id and A.maxtime = swlwl.capture_time
    WHERE swl.lake_name = '衡水湖'
  </select>
</mapper>