<?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.analysis.BasDeviceParamAnalyseMapper">
  <resultMap id="BaseResultMap" type="cn.cecep.talroad.domain.analysis.BasDeviceParamAnalyse">
    <!--@mbg.generated-->
    <!--@Table bas_device_param_analyse-->
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="data_type" jdbcType="CHAR" property="dataType" />
    <result column="device_type" jdbcType="VARCHAR" property="deviceType" />
    <result column="device_cart" jdbcType="VARCHAR" property="deviceCart" />
    <result column="device_cart_code" jdbcType="VARCHAR" property="deviceCartCode" />
    <result column="device_param_name" jdbcType="VARCHAR" property="deviceParamName" />
    <result column="device_param_code" jdbcType="VARCHAR" property="deviceParamCode" />
    <result column="device_param_unit" jdbcType="VARCHAR" property="deviceParamUnit" />
    <result column="contour_ew" jdbcType="CHAR" property="contourEw" />
    <result column="data_logic_abnormal_ew" jdbcType="CHAR" property="dataLogicAbnormalEw" />
    <result column="data_logic_fluctuate_ew" jdbcType="CHAR" property="dataLogicFluctuateEw" />
    <result column="data_logic_deficiency_ew" jdbcType="CHAR" property="dataLogicDeficiencyEw" />
    <result column="stop_threshold_value" jdbcType="VARCHAR" property="stopThresholdValue" />
    <result column="co_diffuse_threshold_value" jdbcType="VARCHAR" property="coDiffuseThresholdValue" />
    <result column="update_time" jdbcType="DATE" property="updateTime" />
    <result column="is_status" jdbcType="VARCHAR" property="isStatus" />
  </resultMap>
  <sql id="Base_Column_List">
    <!--@mbg.generated-->
    id, data_type, device_type, device_cart, device_cart_code, device_param_name, device_param_code,
    device_param_unit, contour_ew, data_logic_abnormal_ew, data_logic_fluctuate_ew, data_logic_deficiency_ew,
    stop_threshold_value, co_diffuse_threshold_value, update_time, is_status
  </sql>
  <update id="updateBatch" parameterType="java.util.List">
    <!--@mbg.generated-->
    update bas_device_param_analyse
    <trim prefix="set" suffixOverrides=",">
      <trim prefix="data_type = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.dataType,jdbcType=CHAR}
        </foreach>
      </trim>
      <trim prefix="device_type = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.deviceType,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="device_cart = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.deviceCart,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="device_cart_code = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.deviceCartCode,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="device_param_name = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.deviceParamName,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="device_param_code = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.deviceParamCode,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="device_param_unit = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.deviceParamUnit,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="contour_ew = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.contourEw,jdbcType=CHAR}
        </foreach>
      </trim>
      <trim prefix="data_logic_abnormal_ew = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.dataLogicAbnormalEw,jdbcType=CHAR}
        </foreach>
      </trim>
      <trim prefix="data_logic_fluctuate_ew = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.dataLogicFluctuateEw,jdbcType=CHAR}
        </foreach>
      </trim>
      <trim prefix="data_logic_deficiency_ew = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.dataLogicDeficiencyEw,jdbcType=CHAR}
        </foreach>
      </trim>
      <trim prefix="stop_threshold_value = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.stopThresholdValue,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="co_diffuse_threshold_value = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.coDiffuseThresholdValue,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="update_time = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.updateTime,jdbcType=DATE}
        </foreach>
      </trim>
      <trim prefix="is_status = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=BIGINT} then #{item.isStatus,jdbcType=VARCHAR}
        </foreach>
      </trim>
    </trim>
    where id in
    <foreach close=")" collection="list" item="item" open="(" separator=", ">
      #{item.id,jdbcType=BIGINT}
    </foreach>
  </update>
  <update id="updateBatchSelective" parameterType="java.util.List">
    <!--@mbg.generated-->
    update bas_device_param_analyse
    <trim prefix="set" suffixOverrides=",">




      <trim prefix="contour_ew = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.contourEw != null and item.contourEw.trim()!='' ">
            when id = #{item.id,jdbcType=BIGINT} then #{item.contourEw,jdbcType=CHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="data_logic_abnormal_ew = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.dataLogicAbnormalEw != null and item.dataLogicAbnormalEw.trim()!='' ">
            when id = #{item.id,jdbcType=BIGINT} then #{item.dataLogicAbnormalEw,jdbcType=CHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="data_logic_fluctuate_ew = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.dataLogicFluctuateEw != null and item.dataLogicFluctuateEw.trim()!='' ">
            when id = #{item.id,jdbcType=BIGINT} then #{item.dataLogicFluctuateEw,jdbcType=CHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="data_logic_deficiency_ew = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.dataLogicDeficiencyEw != null and item.dataLogicDeficiencyEw.trim()!='' ">
            when id = #{item.id,jdbcType=BIGINT} then #{item.dataLogicDeficiencyEw,jdbcType=CHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="stop_threshold_value = case" suffix="end,">
        <foreach collection="list" index="index" item="item">

          when id = #{item.id,jdbcType=BIGINT} then  #{item.stopThresholdValue,jdbcType=VARCHAR}

        </foreach>
      </trim>
      <trim prefix="co_diffuse_threshold_value = case" suffix="end,">
        <foreach collection="list" index="index" item="item">

          when id = #{item.id,jdbcType=BIGINT} then #{item.coDiffuseThresholdValue,jdbcType=VARCHAR}

        </foreach>
      </trim>
      <trim prefix="update_time = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.updateTime != null and
          (
          item.dataLogicDeficiencyEw.trim()!='' or
          item.dataLogicFluctuateEw.trim()!=''  or
          item.dataLogicAbnormalEw.trim()!=''  or
          item.contourEw.trim()!=''or
          item.deviceParamUnit.trim()!='' )">
            when id = #{item.id,jdbcType=BIGINT} then TO_TIMESTAMP( #{item.updateTime,jdbcType=TIMESTAMP}, 'YYYY-MM-DD HH24:MI:SS')
          </if>
        </foreach>
      </trim>

    </trim>
    where id in
    <foreach close=")" collection="list" item="item" open="(" separator=", ">
      #{item.id,jdbcType=BIGINT}
    </foreach>
  </update>
  <insert id="batchInsert" parameterType="map">
    <!--@mbg.generated-->
    insert into bas_device_param_analyse
    (id, data_type, device_type, device_cart, device_cart_code, device_param_name, device_param_code,
      device_param_unit, contour_ew, data_logic_abnormal_ew, data_logic_fluctuate_ew,
      data_logic_deficiency_ew, stop_threshold_value, co_diffuse_threshold_value, update_time,
      is_status)
    values
    <foreach collection="list" item="item" separator=",">
      (#{item.id,jdbcType=BIGINT}, #{item.dataType,jdbcType=CHAR}, #{item.deviceType,jdbcType=VARCHAR},
        #{item.deviceCart,jdbcType=VARCHAR}, #{item.deviceCartCode,jdbcType=VARCHAR}, #{item.deviceParamName,jdbcType=VARCHAR},
        #{item.deviceParamCode,jdbcType=VARCHAR}, #{item.deviceParamUnit,jdbcType=VARCHAR},
        #{item.contourEw,jdbcType=CHAR}, #{item.dataLogicAbnormalEw,jdbcType=CHAR}, #{item.dataLogicFluctuateEw,jdbcType=CHAR},
        #{item.dataLogicDeficiencyEw,jdbcType=CHAR}, #{item.stopThresholdValue,jdbcType=VARCHAR},
        #{item.coDiffuseThresholdValue,jdbcType=VARCHAR}, #{item.updateTime,jdbcType=DATE},
        #{item.isStatus,jdbcType=VARCHAR})
    </foreach>
  </insert>

  <select id="selectByDeviceParamCode" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List"/>
    from
    bas_device_param_analyse
    where device_param_code in (
    <foreach collection="deviceParamCodes" separator="," item="item">
      #{item}
    </foreach>
    )
  </select>
</mapper>
