<?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.BasDeviceParamMapper">
  <resultMap id="BaseResultMap" type="cn.cecep.talroad.domain.analysis.BasDeviceParam">
    <!--@mbg.generated-->
    <!--@Table bas_device_param-->
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="device_id" jdbcType="VARCHAR" property="deviceId" />
    <result column="param_id" jdbcType="VARCHAR" property="paramId" />
    <result column="industry" jdbcType="VARCHAR" property="industry" />
    <result column="device_type" jdbcType="VARCHAR" property="deviceType" />
    <result column="facility_type" jdbcType="VARCHAR" property="facilityType" />
    <result column="normal_value" jdbcType="DOUBLE" property="normalValue" />
    <result column="min_value" jdbcType="DOUBLE" property="minValue" />
    <result column="max_value" jdbcType="DOUBLE" property="maxValue" />
    <result column="q1_value" jdbcType="DOUBLE" property="q1Value" />
    <result column="q2_value" jdbcType="DOUBLE" property="q2Value" />
    <result column="is_online" jdbcType="SMALLINT" property="isOnline" />
    <result column="standby_num" jdbcType="INTEGER" property="standbyNum" />
    <result column="multi_num" jdbcType="INTEGER" property="multiNum" />
    <result column="over_max_val" jdbcType="DOUBLE" property="overMaxVal" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="release_value" jdbcType="SMALLINT" property="releaseValue" />
    <result column="stop_value" jdbcType="DOUBLE" property="stopValue" />
    <result column="device_site_id" jdbcType="VARCHAR" property="deviceSiteId" />
    <result column="param_name" jdbcType="VARCHAR" property="paramName" />
    <result column="param_unit" jdbcType="VARCHAR" property="paramUnit" />
    <result column="is_status" jdbcType="CHAR" property="isStatus" />
    <result column="data_type" jdbcType="CHAR" property="dataType" />
    <result column="device_name" jdbcType="VARCHAR" property="deviceName" />
    <result column="factory_name" jdbcType="VARCHAR" property="factoryName" />
  </resultMap>
  <sql id="Base_Column_List">
    <!--@mbg.generated-->
    id, device_id, param_id, industry, device_type, facility_type, normal_value, min_value, 
    max_value, q1_value, q2_value, is_online, standby_num, multi_num, over_max_val, create_time, 
    release_value, stop_value, device_site_id, param_name, param_unit, is_status, data_type, 
    device_name, factory_name
  </sql>
  <update id="updateBatch" parameterType="java.util.List">
    <!--@mbg.generated-->
    update bas_device_param
    <trim prefix="set" suffixOverrides=",">
      <trim prefix="device_id = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.deviceId,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="param_id = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.paramId,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="industry = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.industry,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="device_type = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.deviceType,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="facility_type = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.facilityType,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="normal_value = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.normalValue,jdbcType=DOUBLE}
        </foreach>
      </trim>
      <trim prefix="min_value = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.minValue,jdbcType=DOUBLE}
        </foreach>
      </trim>
      <trim prefix="max_value = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.maxValue,jdbcType=DOUBLE}
        </foreach>
      </trim>
      <trim prefix="q1_value = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.q1Value,jdbcType=DOUBLE}
        </foreach>
      </trim>
      <trim prefix="q2_value = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.q2Value,jdbcType=DOUBLE}
        </foreach>
      </trim>
      <trim prefix="is_online = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.isOnline,jdbcType=SMALLINT}
        </foreach>
      </trim>
      <trim prefix="standby_num = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.standbyNum,jdbcType=INTEGER}
        </foreach>
      </trim>
      <trim prefix="multi_num = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.multiNum,jdbcType=INTEGER}
        </foreach>
      </trim>
      <trim prefix="over_max_val = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.overMaxVal,jdbcType=DOUBLE}
        </foreach>
      </trim>
      <trim prefix="create_time = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.createTime,jdbcType=TIMESTAMP}
        </foreach>
      </trim>
      <trim prefix="release_value = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.releaseValue,jdbcType=SMALLINT}
        </foreach>
      </trim>
      <trim prefix="stop_value = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.stopValue,jdbcType=DOUBLE}
        </foreach>
      </trim>
      <trim prefix="device_site_id = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.deviceSiteId,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="param_name = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.paramName,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="param_unit = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.paramUnit,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="is_status = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.isStatus,jdbcType=CHAR}
        </foreach>
      </trim>
      <trim prefix="data_type = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.dataType,jdbcType=CHAR}
        </foreach>
      </trim>
      <trim prefix="device_name = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.deviceName,jdbcType=VARCHAR}
        </foreach>
      </trim>
      <trim prefix="factory_name = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          when id = #{item.id,jdbcType=INTEGER} then #{item.factoryName,jdbcType=VARCHAR}
        </foreach>
      </trim>
    </trim>
    where id in
    <foreach close=")" collection="list" item="item" open="(" separator=", ">
      #{item.id,jdbcType=INTEGER}
    </foreach>
  </update>
  <update id="updateBatchSelective" parameterType="java.util.List">
    <!--@mbg.generated-->
    update bas_device_param
    <trim prefix="set" suffixOverrides=",">
      <trim prefix="normal_value = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.normalValue != null">
            when id = #{item.id,jdbcType=INTEGER} then #{item.normalValue,jdbcType=DOUBLE}
          </if>
        </foreach>
      </trim>
      <trim prefix="min_value = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.minValue != null">
            when id = #{item.id,jdbcType=INTEGER} then #{item.minValue,jdbcType=DOUBLE}
          </if>
        </foreach>
      </trim>
      <trim prefix="max_value = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.maxValue != null">
            when id = #{item.id,jdbcType=INTEGER} then #{item.maxValue,jdbcType=DOUBLE}
          </if>
        </foreach>
      </trim>
      <trim prefix="is_online = case" suffix="end,">
        <foreach collection="list" index="index" item="item">
          <if test="item.isOnline != null">
            when id = #{item.id,jdbcType=INTEGER} then #{item.isOnline,jdbcType=SMALLINT}
          </if>
        </foreach>
      </trim>
    </trim>
    where id in
    <foreach close=")" collection="list" item="item" open="(" separator=", ">
      #{item.id,jdbcType=INTEGER}
    </foreach>
  </update>
  <insert id="batchInsert" parameterType="map">
    <!--@mbg.generated-->
    insert into bas_device_param
    (id, device_id, param_id, industry, device_type, facility_type, normal_value, min_value, 
      max_value, q1_value, q2_value, is_online, standby_num, multi_num, over_max_val, 
      create_time, release_value, stop_value, device_site_id, param_name, param_unit, 
      is_status, data_type, device_name, factory_name)
    values
    <foreach collection="list" item="item" separator=",">
      (#{item.id,jdbcType=INTEGER}, #{item.deviceId,jdbcType=VARCHAR}, #{item.paramId,jdbcType=VARCHAR}, 
        #{item.industry,jdbcType=VARCHAR}, #{item.deviceType,jdbcType=VARCHAR}, #{item.facilityType,jdbcType=VARCHAR}, 
        #{item.normalValue,jdbcType=DOUBLE}, #{item.minValue,jdbcType=DOUBLE}, #{item.maxValue,jdbcType=DOUBLE}, 
        #{item.q1Value,jdbcType=DOUBLE}, #{item.q2Value,jdbcType=DOUBLE}, #{item.isOnline,jdbcType=SMALLINT}, 
        #{item.standbyNum,jdbcType=INTEGER}, #{item.multiNum,jdbcType=INTEGER}, #{item.overMaxVal,jdbcType=DOUBLE}, 
        #{item.createTime,jdbcType=TIMESTAMP}, #{item.releaseValue,jdbcType=SMALLINT}, 
        #{item.stopValue,jdbcType=DOUBLE}, #{item.deviceSiteId,jdbcType=VARCHAR}, #{item.paramName,jdbcType=VARCHAR}, 
        #{item.paramUnit,jdbcType=VARCHAR}, #{item.isStatus,jdbcType=CHAR}, #{item.dataType,jdbcType=CHAR}, 
        #{item.deviceName,jdbcType=VARCHAR}, #{item.factoryName,jdbcType=VARCHAR})
    </foreach>
  </insert>

  <select id="pageDao" resultMap="BaseResultMap">
    SELECT
      bdp.*,
      bd.NAME AS device_name,
      pf.factory_name
    FROM
      "bas_device_param" bdp
        LEFT JOIN bas_device bd ON bd.device_id = bdp.device_id
        LEFT JOIN pc_factory pf ON pf."id"=bd.factory_id
    <where>
      <if test="query.dataType != null and query.dataType != ''">
        AND bdp.data_type=#{query.dataType,jdbcType=VARCHAR}
      </if>
      <if test="query.deviceName != null and query.deviceName.trim()!= ''">
        AND bd.NAME LIKE CONCAT ('%',#{query.deviceName,jdbcType=VARCHAR},'%')
      </if>
      <if test="query.factoryName  != null and query.factoryName.trim()!= ''">
        AND pf.factory_name LIKE CONCAT ('%',#{query.factoryName,jdbcType=VARCHAR},'%')
      </if>
      <if test="query.deviceId != null and query.deviceId.trim()!= ''">
        AND bdp.device_id LIKE CONCAT ('%',#{query.deviceId,jdbcType=VARCHAR},'%')
      </if>
      <if test="query.isOnline != null">
        AND bdp.is_online =#{query.isOnline,jdbcType=VARCHAR}
      </if>
      <if test="query.paramName != null and query.paramName.trim()!= ''">
        AND bdp.param_name LIKE CONCAT ('%',#{query.paramName,jdbcType=VARCHAR},'%')
      </if>
    </where>
    ORDER BY pf.id DESC,bdp.device_id  DESC,bdp.param_id DESC
    </select>
</mapper>