<?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.BasThresholdConfigMapper">
  <resultMap id="BaseResultMap" type="cn.cecep.talroad.domain.analysis.BasThresholdConfig">
    <!--@mbg.generated-->
    <!--@Table bas_threshold_config-->
    <id column="data_id" jdbcType="SMALLINT" property="dataId" />
    <result column="task_name" jdbcType="VARCHAR" property="taskName" />
    <result column="param_code" jdbcType="VARCHAR" property="paramCode" />
    <result column="param_name" jdbcType="VARCHAR" property="paramName" />
    <result column="frequency" jdbcType="VARCHAR" property="frequency" />
    <result column="threshold_value" jdbcType="NUMERIC" property="thresholdValue" />
    <result column="unit" jdbcType="VARCHAR" property="unit" />
    <result column="remark" jdbcType="VARCHAR" property="remark" />
    <result column="create_by" jdbcType="VARCHAR" property="createBy" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="update_by" jdbcType="VARCHAR" property="updateBy" />
    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
  </resultMap>
  <sql id="Base_Column_List">
    <!--@mbg.generated-->
    data_id, task_name, param_code, param_name, frequency, threshold_value, unit, remark, 
    create_by, create_time, update_by, update_time
  </sql>
  <update id="updateBatch" parameterType="java.util.List">
    <!--@mbg.generated-->
    update bas_threshold_config
    <trim prefix="set" suffixOverrides=",">
      <trim prefix="task_name = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when data_id = #{item.dataId,jdbcType=SMALLINT} then #{item.taskName,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="param_code = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when data_id = #{item.dataId,jdbcType=SMALLINT} then #{item.paramCode,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="param_name = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when data_id = #{item.dataId,jdbcType=SMALLINT} then #{item.paramName,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="frequency = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when data_id = #{item.dataId,jdbcType=SMALLINT} then #{item.frequency,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="threshold_value = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when data_id = #{item.dataId,jdbcType=SMALLINT} then #{item.thresholdValue,jdbcType=NUMERIC}
        </foreach>
      </trim>
      <trim prefix="unit = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when data_id = #{item.dataId,jdbcType=SMALLINT} then #{item.unit,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="remark = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when data_id = #{item.dataId,jdbcType=SMALLINT} then #{item.remark,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="create_by = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when data_id = #{item.dataId,jdbcType=SMALLINT} then #{item.createBy,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="create_time = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when data_id = #{item.dataId,jdbcType=SMALLINT} then #{item.createTime,jdbcType=TIMESTAMP}
        </foreach>
      </trim>
      <trim prefix="update_by = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when data_id = #{item.dataId,jdbcType=SMALLINT} then #{item.updateBy,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="update_time = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when data_id = #{item.dataId,jdbcType=SMALLINT} then #{item.updateTime,jdbcType=TIMESTAMP}
        </foreach>
      </trim>
    </trim>
    where data_id in
    <foreach close=")" collection="list" item="item" open="(" separator=", ">
      #{item.dataId,jdbcType=SMALLINT}
    </foreach>
  </update>
  <update id="updateBatchSelective" parameterType="java.util.List">
    <!--@mbg.generated-->
    update bas_threshold_config
    <trim prefix="set" suffixOverrides=",">

      <trim prefix="frequency = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.frequency != null">
            when data_id = #{item.dataId,jdbcType=SMALLINT} then #{item.frequency,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="threshold_value = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.thresholdValue != null">
            when data_id = #{item.dataId,jdbcType=SMALLINT} then #{item.thresholdValue,jdbcType=NUMERIC}
          </if>
        </foreach>
      </trim>
      <trim prefix="unit = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.unit != null">
            when data_id = #{item.dataId,jdbcType=SMALLINT} then #{item.unit,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>
      <trim prefix="remark = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.remark != null">
            when data_id = #{item.dataId,jdbcType=SMALLINT} then #{item.remark,jdbcType=VARCHAR}
          </if>
        </foreach>
      </trim>


      <trim prefix="update_time = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.updateTime != null">
            when data_id = #{item.dataId,jdbcType=SMALLINT} then  TO_TIMESTAMP( #{item.updateTime,jdbcType=TIMESTAMP}, 'YYYY-MM-DD HH24:MI:SS')
          </if>
        </foreach>
      </trim>
    </trim>
    where data_id in
    <foreach close=")" collection="list" item="item" open="(" separator=", ">
      #{item.dataId,jdbcType=SMALLINT}
    </foreach>
  </update>
  <insert id="batchInsert" parameterType="map">
    <!--@mbg.generated-->
    insert into bas_threshold_config
    (data_id, task_name, param_code, param_name, frequency, threshold_value, unit, remark, 
      create_by, create_time, update_by, update_time)
    values
    <foreach collection="list" item="item" separator=",">
      (#{item.dataId,jdbcType=SMALLINT}, #{item.taskName,jdbcType=VARCHAR}, #{item.paramCode,jdbcType=VARCHAR}, 
        #{item.paramName,jdbcType=VARCHAR}, #{item.frequency,jdbcType=VARCHAR}, #{item.thresholdValue,jdbcType=NUMERIC}, 
        #{item.unit,jdbcType=VARCHAR}, #{item.remark,jdbcType=VARCHAR}, #{item.createBy,jdbcType=VARCHAR}, 
        #{item.createTime,jdbcType=TIMESTAMP}, #{item.updateBy,jdbcType=VARCHAR}, #{item.updateTime,jdbcType=TIMESTAMP}
        )
    </foreach>
  </insert>
</mapper>