<?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.StWaterGroundwaterMonitoringStationMapper">
  <resultMap id="BaseResultMap" type="com.lightinit.hsdatashow.entity.StWaterGroundwaterMonitoringStation">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="parent_id" jdbcType="BIGINT" property="parentId" />
    <result column="parent_code" jdbcType="VARCHAR" property="parentCode" />
    <result column="region_id" jdbcType="BIGINT" property="regionId" />
    <result column="region_code" jdbcType="VARCHAR" property="regionCode" />
    <result column="station_type" jdbcType="VARCHAR" property="stationType" />
    <result column="station_name" jdbcType="VARCHAR" property="stationName" />
    <result column="station_code" jdbcType="VARCHAR" property="stationCode" />
    <result column="station_description" jdbcType="VARCHAR" property="stationDescription" />
    <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, parent_id, parent_code, region_id, region_code, station_type, station_name, station_code, 
    station_description, remark, created_at, created_by, deleted_at, deleted_by
  </sql>
  <select id="selectByExample" parameterType="com.lightinit.hsdatashow.entity.StWaterGroundwaterMonitoringStationExample" resultMap="BaseResultMap">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from st_water_groundwater_monitoring_station
    <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_groundwater_monitoring_station
    where id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    delete from st_water_groundwater_monitoring_station
    where id = #{id,jdbcType=BIGINT}
  </delete>
  <delete id="deleteByExample" parameterType="com.lightinit.hsdatashow.entity.StWaterGroundwaterMonitoringStationExample">
    delete from st_water_groundwater_monitoring_station
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.lightinit.hsdatashow.entity.StWaterGroundwaterMonitoringStation">
    <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into st_water_groundwater_monitoring_station (parent_id, parent_code, region_id, 
      region_code, station_type, station_name, 
      station_code, station_description, remark, 
      created_at, created_by, deleted_at, 
      deleted_by)
    values (#{parentId,jdbcType=BIGINT}, #{parentCode,jdbcType=VARCHAR}, #{regionId,jdbcType=BIGINT}, 
      #{regionCode,jdbcType=VARCHAR}, #{stationType,jdbcType=VARCHAR}, #{stationName,jdbcType=VARCHAR}, 
      #{stationCode,jdbcType=VARCHAR}, #{stationDescription,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.StWaterGroundwaterMonitoringStation">
    <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into st_water_groundwater_monitoring_station
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="parentId != null">
        parent_id,
      </if>
      <if test="parentCode != null">
        parent_code,
      </if>
      <if test="regionId != null">
        region_id,
      </if>
      <if test="regionCode != null">
        region_code,
      </if>
      <if test="stationType != null">
        station_type,
      </if>
      <if test="stationName != null">
        station_name,
      </if>
      <if test="stationCode != null">
        station_code,
      </if>
      <if test="stationDescription != null">
        station_description,
      </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="parentId != null">
        #{parentId,jdbcType=BIGINT},
      </if>
      <if test="parentCode != null">
        #{parentCode,jdbcType=VARCHAR},
      </if>
      <if test="regionId != null">
        #{regionId,jdbcType=BIGINT},
      </if>
      <if test="regionCode != null">
        #{regionCode,jdbcType=VARCHAR},
      </if>
      <if test="stationType != null">
        #{stationType,jdbcType=VARCHAR},
      </if>
      <if test="stationName != null">
        #{stationName,jdbcType=VARCHAR},
      </if>
      <if test="stationCode != null">
        #{stationCode,jdbcType=VARCHAR},
      </if>
      <if test="stationDescription != null">
        #{stationDescription,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.StWaterGroundwaterMonitoringStationExample" resultType="java.lang.Long">
    select count(*) from st_water_groundwater_monitoring_station
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    update st_water_groundwater_monitoring_station
    <set>
      <if test="record.id != null">
        id = #{record.id,jdbcType=BIGINT},
      </if>
      <if test="record.parentId != null">
        parent_id = #{record.parentId,jdbcType=BIGINT},
      </if>
      <if test="record.parentCode != null">
        parent_code = #{record.parentCode,jdbcType=VARCHAR},
      </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.stationType != null">
        station_type = #{record.stationType,jdbcType=VARCHAR},
      </if>
      <if test="record.stationName != null">
        station_name = #{record.stationName,jdbcType=VARCHAR},
      </if>
      <if test="record.stationCode != null">
        station_code = #{record.stationCode,jdbcType=VARCHAR},
      </if>
      <if test="record.stationDescription != null">
        station_description = #{record.stationDescription,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_groundwater_monitoring_station
    set id = #{record.id,jdbcType=BIGINT},
      parent_id = #{record.parentId,jdbcType=BIGINT},
      parent_code = #{record.parentCode,jdbcType=VARCHAR},
      region_id = #{record.regionId,jdbcType=BIGINT},
      region_code = #{record.regionCode,jdbcType=VARCHAR},
      station_type = #{record.stationType,jdbcType=VARCHAR},
      station_name = #{record.stationName,jdbcType=VARCHAR},
      station_code = #{record.stationCode,jdbcType=VARCHAR},
      station_description = #{record.stationDescription,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.StWaterGroundwaterMonitoringStation">
    update st_water_groundwater_monitoring_station
    <set>
      <if test="parentId != null">
        parent_id = #{parentId,jdbcType=BIGINT},
      </if>
      <if test="parentCode != null">
        parent_code = #{parentCode,jdbcType=VARCHAR},
      </if>
      <if test="regionId != null">
        region_id = #{regionId,jdbcType=BIGINT},
      </if>
      <if test="regionCode != null">
        region_code = #{regionCode,jdbcType=VARCHAR},
      </if>
      <if test="stationType != null">
        station_type = #{stationType,jdbcType=VARCHAR},
      </if>
      <if test="stationName != null">
        station_name = #{stationName,jdbcType=VARCHAR},
      </if>
      <if test="stationCode != null">
        station_code = #{stationCode,jdbcType=VARCHAR},
      </if>
      <if test="stationDescription != null">
        station_description = #{stationDescription,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.StWaterGroundwaterMonitoringStation">
    update st_water_groundwater_monitoring_station
    set parent_id = #{parentId,jdbcType=BIGINT},
      parent_code = #{parentCode,jdbcType=VARCHAR},
      region_id = #{regionId,jdbcType=BIGINT},
      region_code = #{regionCode,jdbcType=VARCHAR},
      station_type = #{stationType,jdbcType=VARCHAR},
      station_name = #{stationName,jdbcType=VARCHAR},
      station_code = #{stationCode,jdbcType=VARCHAR},
      station_description = #{stationDescription,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="getJianCeZhanCount" resultType="java.lang.Long">
  select count(*) value from st_water_groundwater_monitoring_station swg
    JOIN region r ON swg.region_id = r.id
    <where>
      <if test="regionName !='' and regionName !=null">
        r.`region_name` = #{regionName}
      </if>
    </where>
  </select>
  <select id="getAreaConstitute" resultType="com.lightinit.hsdatashow.model.topic.water.NameAndValueModel">
      SELECT r.`region_name` NAME, COUNT(*) VALUE
      FROM `st_water_groundwater_monitoring_station` s
      JOIN region r ON s.`region_id` = r.`id`
      WHERE r.`parent_id`=2
      GROUP BY r.`region_name`
  </select>

  <select id="getMonitoringStationType" resultType="com.lightinit.hsdatashow.model.topic.water.NameAndValueModel">
      SELECT s.`station_type` NAME,COUNT(*) VALUE
      FROM `st_water_groundwater_monitoring_station` s
      GROUP BY s.`station_type`
  </select>
  <select id="getMonitoringStation" parameterType="com.lightinit.hsdatashow.model.topic.water.MonitoringStatioSearchModel" resultType="com.lightinit.hsdatashow.entity.StWaterGroundwaterMonitoringStation">
    <if test="stationName !=null and stationName!=''">
      <bind name="stationName" value="'%'+stationName+'%'" />
    </if>
    <if test="stationCode !=null and stationCode!=''">
      <bind name="stationCode" value="'%'+stationCode+'%'" />
    </if>
    <if test="stationType !=null and stationType!=''">
      <bind name="stationType" value="'%'+stationType+'%'" />
    </if>
    <if test="regionName !=null and regionName!=''">
      <bind name="regionName" value="'%'+regionName+'%'" />
    </if>
      SELECT r.`region_name`,s.`station_name`,s.`station_code`,s.`station_type` FROM `st_water_groundwater_monitoring_station` s
      JOIN region r ON s.`region_id` = r.`id`
      <where>
        <if test="stationName !=null and stationName !=''">
          s.station_name like #{stationName}
        </if>
        <if test="stationCode !=null and stationCode !=''">
         and s.station_code like #{stationCode}
        </if>
        <if test="stationType !=null and stationType !=''">
         and s.station_type like #{stationType}
        </if>
        <if test="regionName !=null and regionName !=''">
         and r.`region_name` like #{regionName}
        </if>
      </where>
  </select>
</mapper>