<?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.ERmStationExceedMapper">
  <resultMap id="BaseResultMap" type="cn.cecep.talroad.domain.effective.ERmStationExceed">
    <!--@mbg.generated-->
    <!--@Table e_rm_station_exceed-->
    <id column="id" jdbcType="VARCHAR" property="id" />
    <result column="station_id" jdbcType="VARCHAR" property="stationId" />
    <result column="exceed_factor" jdbcType="VARCHAR" property="exceedFactor" />
    <result column="exceed_type" jdbcType="VARCHAR" property="exceedType" />
    <result column="exceed_time" jdbcType="TIMESTAMP" property="exceedTime" />
    <result column="exceed_delete" jdbcType="VARCHAR" property="exceedDelete" />
  </resultMap>
  <sql id="Base_Column_List">
    <!--@mbg.generated-->
    id, station_id, exceed_factor, exceed_type, exceed_time, exceed_delete
  </sql>
  <update id="updateBatch" parameterType="java.util.List">
    <!--@mbg.generated-->
    update e_rm_station_exceed
    <trim prefix="set" suffixOverrides=",">
      <trim prefix="station_id = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=VARCHAR} then #{item.stationId,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="exceed_factor = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=VARCHAR} then #{item.exceedFactor,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="exceed_type = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=VARCHAR} then #{item.exceedType,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="exceed_time = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=VARCHAR} then #{item.exceedTime,jdbcType=TIMESTAMP}
        </foreach>
      </trim>
      <trim prefix="exceed_delete = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=VARCHAR} then #{item.exceedDelete,jdbcType=VARCHAR}
        </foreach>
      </trim>
    </trim>
    where id in
    <foreach close=")" collection="list" item="item" open="(" separator=", ">
      #{item.id,jdbcType=VARCHAR}
    </foreach>
  </update>
  <update id="updateBatchSelective" parameterType="java.util.List">
    <!--@mbg.generated-->
    update e_rm_station_exceed
    <trim prefix="set" suffixOverrides=",">
      <trim prefix="station_id = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.stationId != null">
            when id = #{item.id,jdbcType=VARCHAR} then #{item.stationId,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="exceed_factor = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.exceedFactor != null">
            when id = #{item.id,jdbcType=VARCHAR} then #{item.exceedFactor,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="exceed_type = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.exceedType != null">
            when id = #{item.id,jdbcType=VARCHAR} then #{item.exceedType,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="exceed_time = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.exceedTime != null">
            when id = #{item.id,jdbcType=VARCHAR} then #{item.exceedTime,jdbcType=TIMESTAMP}
          </if>
        </foreach>
      </trim>
      <trim prefix="exceed_delete = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.exceedDelete != null">
            when id = #{item.id,jdbcType=VARCHAR} then #{item.exceedDelete,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
    </trim>
    where id in
    <foreach close=")" collection="list" item="item" open="(" separator=", ">
      #{item.id,jdbcType=VARCHAR}
    </foreach>
  </update>
  <insert id="batchInsert" parameterType="map">
    <!--@mbg.generated-->
    insert into e_rm_station_exceed
    (id, station_id, exceed_factor, exceed_type, exceed_time, exceed_delete)
    values
    <foreach collection="list" item="item" separator=",">
      (#{item.id,jdbcType=VARCHAR}, #{item.stationId,jdbcType=VARCHAR}, #{item.exceedFactor,jdbcType=VARCHAR}, 
        #{item.exceedType,jdbcType=VARCHAR}, #{item.exceedTime,jdbcType=TIMESTAMP}, #{item.exceedDelete,jdbcType=VARCHAR}
        )
    </foreach>
  </insert>

  <select id="selectListInfo" resultType="cn.cecep.talroad.vo.effective.ERmStationInfo">
    SELECT
      tcs.station_name,
      ese.exceed_factor,
      LOWER(ese.exceed_factor) lowerExceedFactor,
      ese.exceed_type,
      ese.exceed_time,
      tcs.lon longitude,
      tcs.lat latitude,
      tcs.id,
      std.type_name stationType,
      wind_power,
      wind_direction
    FROM
      "e_rm_station_exceed" AS ese
        LEFT JOIN t_cod_station AS tcs ON tcs.id = ese.station_id
        LEFT JOIN s_station_type_dict AS std ON std.data_id=tcs.station_type_dict_id
        LEFT JOIN t_cod_station_data_air AS tcsda ON tcsda.id=ese.data_air_id
    WHERE ese.exceed_delete='0'
    ORDER BY  ese.exceed_time DESC
    </select>

  <select id="selectGasAndHaveData" resultType="cn.cecep.talroad.vo.PcFactoryVo">
    SELECT
      pf.factory_name,
      pf.id,
      pf.production_lat,
      pf.production_lon,
      ii.name industryCategoryName
    FROM
      pc_factory pf
        LEFT JOIN "s_env_gas_mon_hour" seg ON pf.ID = seg.factory_id
        LEFT JOIN iot_industry ii ON pf.industry_category=ii.code
    WHERE seg.id IS NOT NULL
    GROUP BY pf.id,pf.factory_name,pf.production_lat,pf.production_lon,ii.name
    </select>

  <select id="selectStationList" resultType="cn.cecep.talroad.vo.effective.ERmStationInfo">

      SELECT
        tcs.station_name,
        tcs.lon longitude,
        tcs.lat latitude,
        tcs.id,
        std.type_name stationType

      FROM

        t_cod_station  tcs
          LEFT JOIN s_station_type_dict AS std ON std.data_id=tcs.station_type_dict_id

      ORDER BY  tcs.id DESC
  </select>
</mapper>