<?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.steerinfo.baseinfo.meterbasegroupspot.mapper.MeterBaseGroupSpotMapper">
  <resultMap id="BaseResultMap" type="com.steerinfo.baseinfo.meterbasegroupspot.model.MeterBaseGroupSpot">
    <id column="GROUP_SPOT_ID" jdbcType="VARCHAR" property="groupSpotId" />
    <result column="GROUP_ID" jdbcType="VARCHAR" property="groupId" />
    <result column="GROUP_NAME" jdbcType="VARCHAR" property="groupName" />
    <result column="SPOT_ID" jdbcType="VARCHAR" property="spotId" />
    <result column="SPOT_NAME" jdbcType="VARCHAR" property="spotName" />
    <result column="VALUE_FLAG" jdbcType="VARCHAR" property="valueFlag" />
    <result column="CREATE_MAN_NO" jdbcType="VARCHAR" property="createManNo" />
    <result column="CREATE_MAN_NAME" jdbcType="VARCHAR" property="createManName" />
    <result column="CREATE_TIME" jdbcType="TIMESTAMP" property="createTime" />
    <result column="UPDATE_MAN_NO" jdbcType="VARCHAR" property="updateManNo" />
    <result column="UPDATE_MAN_NAME" jdbcType="VARCHAR" property="updateManName" />
    <result column="UPDATE_TIME" jdbcType="TIMESTAMP" property="updateTime" />
  </resultMap>
  <sql id="columns">
    GROUP_SPOT_ID, GROUP_ID, GROUP_NAME, SPOT_ID, SPOT_NAME, VALUE_FLAG, CREATE_MAN_NO, 
    CREATE_MAN_NAME, CREATE_TIME, UPDATE_MAN_NO, UPDATE_MAN_NAME, UPDATE_TIME
  </sql>
  <sql id="columns_alias">
    t.GROUP_SPOT_ID, t.GROUP_ID, t.GROUP_NAME, t.SPOT_ID, t.SPOT_NAME, t.VALUE_FLAG, 
    t.CREATE_MAN_NO, t.CREATE_MAN_NAME, t.CREATE_TIME, t.UPDATE_MAN_NO, t.UPDATE_MAN_NAME, 
    t.UPDATE_TIME
  </sql>
  <sql id="select">
    SELECT <include refid="columns" /> FROM METER_BASE_GROUP_SPOT
  </sql>
  <sql id="select_alias">
    SELECT <include refid="columns_alias" /> FROM METER_BASE_GROUP_SPOT t
  </sql>
  <sql id="where">
    <where> 
      <if test="groupSpotId != null and groupSpotId != ''">
        and GROUP_SPOT_ID = #{groupSpotId}
      </if>
      <if test="groupId != null and groupId != ''">
        and GROUP_ID = #{groupId}
      </if>
      <if test="groupName != null and groupName != ''">
        and GROUP_NAME = #{groupName}
      </if>
      <if test="spotId != null and spotId != ''">
        and SPOT_ID = #{spotId}
      </if>
      <if test="spotName != null and spotName != ''">
        and SPOT_NAME = #{spotName}
      </if>
      <if test="valueFlag != null and valueFlag != ''">
        and VALUE_FLAG = #{valueFlag}
      </if>
      <if test="createManNo != null and createManNo != ''">
        and CREATE_MAN_NO = #{createManNo}
      </if>
      <if test="createManName != null and createManName != ''">
        and CREATE_MAN_NAME = #{createManName}
      </if>
      <if test="createTime != null">
        and TO_CHAR(CREATE_TIME,'yyyy-MM-dd') = #{createTime}
      </if>
      <if test="updateManNo != null and updateManNo != ''">
        and UPDATE_MAN_NO = #{updateManNo}
      </if>
      <if test="updateManName != null and updateManName != ''">
        and UPDATE_MAN_NAME = #{updateManName}
      </if>
      <if test="updateTime != null">
        and TO_CHAR(UPDATE_TIME,'yyyy-MM-dd') = #{updateTime}
      </if>
    </where>
  </sql>
  <sql id="whereLike">
    <where> 
      <if test="groupSpotId != null and groupSpotId != ''">
        and GROUP_SPOT_ID LIKE '%${groupSpotId}%'
      </if>
      <if test="groupId != null and groupId != ''">
        and GROUP_ID LIKE '%${groupId}%'
      </if>
      <if test="groupName != null and groupName != ''">
        and GROUP_NAME LIKE '%${groupName}%'
      </if>
      <if test="spotId != null and spotId != ''">
        and SPOT_ID LIKE '%${spotId}%'
      </if>
      <if test="spotName != null and spotName != ''">
        and SPOT_NAME LIKE '%${spotName}%'
      </if>
      <if test="valueFlag != null and valueFlag != ''">
        and VALUE_FLAG LIKE '%${valueFlag}%'
      </if>
      <if test="createManNo != null and createManNo != ''">
        and CREATE_MAN_NO LIKE '%${createManNo}%'
      </if>
      <if test="createManName != null and createManName != ''">
        and CREATE_MAN_NAME LIKE '%${createManName}%'
      </if>
      <if test="createTime != null">
        and TO_CHAR(CREATE_TIME,'yyyy-MM-dd') = #{createTime}
      </if>
      <if test="updateManNo != null and updateManNo != ''">
        and UPDATE_MAN_NO LIKE '%${updateManNo}%'
      </if>
      <if test="updateManName != null and updateManName != ''">
        and UPDATE_MAN_NAME LIKE '%${updateManName}%'
      </if>
      <if test="updateTime != null">
        and TO_CHAR(UPDATE_TIME,'yyyy-MM-dd') = #{updateTime}
      </if>
    </where>
  </sql>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    delete from METER_BASE_GROUP_SPOT
    where GROUP_SPOT_ID = #{groupSpotId,jdbcType=VARCHAR}
  </delete>
  <delete id="deleteBySelectiveElement" parameterType="java.util.HashMap">
    delete from METER_BASE_GROUP_SPOT
    where 1!=1 
      <if test="groupId != null and groupId != ''">
        or GROUP_ID = #{groupId}
      </if>
      <if test="groupName != null and groupName != ''">
        or GROUP_NAME = #{groupName}
      </if>
      <if test="spotId != null and spotId != ''">
        or SPOT_ID = #{spotId}
      </if>
      <if test="spotName != null and spotName != ''">
        or SPOT_NAME = #{spotName}
      </if>
      <if test="valueFlag != null and valueFlag != ''">
        or VALUE_FLAG = #{valueFlag}
      </if>
      <if test="createManNo != null and createManNo != ''">
        or CREATE_MAN_NO = #{createManNo}
      </if>
      <if test="createManName != null and createManName != ''">
        or CREATE_MAN_NAME = #{createManName}
      </if>
      <if test="createTime != null">
        or TO_CHAR(CREATE_TIME,'yyyy-MM-dd') = '#{createTime}'
      </if>
      <if test="updateManNo != null and updateManNo != ''">
        or UPDATE_MAN_NO = #{updateManNo}
      </if>
      <if test="updateManName != null and updateManName != ''">
        or UPDATE_MAN_NAME = #{updateManName}
      </if>
      <if test="updateTime != null">
        or TO_CHAR(UPDATE_TIME,'yyyy-MM-dd') = '#{updateTime}'
      </if>
  </delete>
  <insert id="insert" parameterType="com.steerinfo.baseinfo.meterbasegroupspot.model.MeterBaseGroupSpot">
    insert into METER_BASE_GROUP_SPOT (GROUP_SPOT_ID, GROUP_ID, GROUP_NAME, 
      SPOT_ID, SPOT_NAME, VALUE_FLAG, 
      CREATE_MAN_NO, CREATE_MAN_NAME, CREATE_TIME, 
      UPDATE_MAN_NO, UPDATE_MAN_NAME, UPDATE_TIME
      )
    values (#{groupSpotId,jdbcType=VARCHAR}, #{groupId,jdbcType=VARCHAR}, #{groupName,jdbcType=VARCHAR}, 
      #{spotId,jdbcType=VARCHAR}, #{spotName,jdbcType=VARCHAR}, #{valueFlag,jdbcType=VARCHAR}, 
      #{createManNo,jdbcType=VARCHAR}, #{createManName,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, 
      #{updateManNo,jdbcType=VARCHAR}, #{updateManName,jdbcType=VARCHAR}, #{updateTime,jdbcType=TIMESTAMP}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.steerinfo.baseinfo.meterbasegroupspot.model.MeterBaseGroupSpot">
    insert into METER_BASE_GROUP_SPOT
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="groupSpotId != null">
        GROUP_SPOT_ID,
      </if>
      <if test="groupId != null">
        GROUP_ID,
      </if>
      <if test="groupName != null">
        GROUP_NAME,
      </if>
      <if test="spotId != null">
        SPOT_ID,
      </if>
      <if test="spotName != null">
        SPOT_NAME,
      </if>
      <if test="valueFlag != null">
        VALUE_FLAG,
      </if>
      <if test="createManNo != null">
        CREATE_MAN_NO,
      </if>
      <if test="createManName != null">
        CREATE_MAN_NAME,
      </if>
      <if test="createTime != null">
        CREATE_TIME,
      </if>
      <if test="updateManNo != null">
        UPDATE_MAN_NO,
      </if>
      <if test="updateManName != null">
        UPDATE_MAN_NAME,
      </if>
      <if test="updateTime != null">
        UPDATE_TIME,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="groupSpotId != null">
        #{groupSpotId,jdbcType=VARCHAR},
      </if>
      <if test="groupId != null">
        #{groupId,jdbcType=VARCHAR},
      </if>
      <if test="groupName != null">
        #{groupName,jdbcType=VARCHAR},
      </if>
      <if test="spotId != null">
        #{spotId,jdbcType=VARCHAR},
      </if>
      <if test="spotName != null">
        #{spotName,jdbcType=VARCHAR},
      </if>
      <if test="valueFlag != null">
        #{valueFlag,jdbcType=VARCHAR},
      </if>
      <if test="createManNo != null">
        #{createManNo,jdbcType=VARCHAR},
      </if>
      <if test="createManName != null">
        #{createManName,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateManNo != null">
        #{updateManNo,jdbcType=VARCHAR},
      </if>
      <if test="updateManName != null">
        #{updateManName,jdbcType=VARCHAR},
      </if>
      <if test="updateTime != null">
        #{updateTime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKey" parameterType="com.steerinfo.baseinfo.meterbasegroupspot.model.MeterBaseGroupSpot">
    update METER_BASE_GROUP_SPOT
    set GROUP_ID = #{groupId,jdbcType=VARCHAR},
      GROUP_NAME = #{groupName,jdbcType=VARCHAR},
      SPOT_ID = #{spotId,jdbcType=VARCHAR},
      SPOT_NAME = #{spotName,jdbcType=VARCHAR},
      VALUE_FLAG = #{valueFlag,jdbcType=VARCHAR},
      CREATE_MAN_NO = #{createManNo,jdbcType=VARCHAR},
      CREATE_MAN_NAME = #{createManName,jdbcType=VARCHAR},
      CREATE_TIME = #{createTime,jdbcType=TIMESTAMP},
      UPDATE_MAN_NO = #{updateManNo,jdbcType=VARCHAR},
      UPDATE_MAN_NAME = #{updateManName,jdbcType=VARCHAR},
      UPDATE_TIME = #{updateTime,jdbcType=TIMESTAMP}
    where GROUP_SPOT_ID = #{groupSpotId,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.steerinfo.baseinfo.meterbasegroupspot.model.MeterBaseGroupSpot">
    update METER_BASE_GROUP_SPOT
    <set>
      <if test="groupId != null">
        GROUP_ID = #{groupId,jdbcType=VARCHAR},
      </if>
      <if test="groupName != null">
        GROUP_NAME = #{groupName,jdbcType=VARCHAR},
      </if>
      <if test="spotId != null">
        SPOT_ID = #{spotId,jdbcType=VARCHAR},
      </if>
      <if test="spotName != null">
        SPOT_NAME = #{spotName,jdbcType=VARCHAR},
      </if>
      <if test="valueFlag != null">
        VALUE_FLAG = #{valueFlag,jdbcType=VARCHAR},
      </if>
      <if test="createManNo != null">
        CREATE_MAN_NO = #{createManNo,jdbcType=VARCHAR},
      </if>
      <if test="createManName != null">
        CREATE_MAN_NAME = #{createManName,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        CREATE_TIME = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateManNo != null">
        UPDATE_MAN_NO = #{updateManNo,jdbcType=VARCHAR},
      </if>
      <if test="updateManName != null">
        UPDATE_MAN_NAME = #{updateManName,jdbcType=VARCHAR},
      </if>
      <if test="updateTime != null">
        UPDATE_TIME = #{updateTime,jdbcType=TIMESTAMP},
      </if>
    </set>
    where GROUP_SPOT_ID = #{groupSpotId,jdbcType=VARCHAR}
  </update>
  <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
    <include refid="select" />
    where GROUP_SPOT_ID = #{groupSpotId,jdbcType=VARCHAR}
  </select>
  <select id="selectByParameters" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    <include refid="select" />
    <include refid="where" />
  </select>
  <select id="selectLikeByParameters" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    <include refid="select" />
    <include refid="whereLike" />
  </select>
  <insert id="batchInsert" parameterType="java.util.List">
    insert into METER_BASE_GROUP_SPOT 
      (GROUP_SPOT_ID, 
      GROUP_ID, GROUP_NAME, SPOT_ID, 
      SPOT_NAME, VALUE_FLAG, CREATE_MAN_NO, 
      CREATE_MAN_NAME, CREATE_TIME, 
      UPDATE_MAN_NO, UPDATE_MAN_NAME, UPDATE_TIME
      )
    ( <foreach collection="list" item="item" separator="union all"> 
   select  
      #{item.groupSpotId,jdbcType=VARCHAR}, 
      #{item.groupId,jdbcType=VARCHAR}, #{item.groupName,jdbcType=VARCHAR}, #{item.spotId,jdbcType=VARCHAR}, 
      #{item.spotName,jdbcType=VARCHAR}, #{item.valueFlag,jdbcType=VARCHAR}, #{item.createManNo,jdbcType=VARCHAR}, 
      #{item.createManName,jdbcType=VARCHAR}, #{item.createTime,jdbcType=TIMESTAMP}, 
      #{item.updateManNo,jdbcType=VARCHAR}, #{item.updateManName,jdbcType=VARCHAR}, #{item.updateTime,jdbcType=TIMESTAMP}
       from dual  
   </foreach> )
  </insert>
  <update id="batchUpdate" parameterType="java.util.List">
     update METER_BASE_GROUP_SPOT
     set
       GROUP_SPOT_ID=
       <foreach close="end" collection="list" index="index" item="item" open="case GROUP_SPOT_ID" separator=" ">
          when #{item.groupSpotId,jdbcType=VARCHAR} then #{item.groupSpotId,jdbcType=VARCHAR}
       </foreach>
       ,GROUP_ID=
       <foreach close="end" collection="list" index="index" item="item" open="case GROUP_SPOT_ID" separator=" ">
          when #{item.groupSpotId,jdbcType=VARCHAR} then #{item.groupId,jdbcType=VARCHAR}
       </foreach>
       ,GROUP_NAME=
       <foreach close="end" collection="list" index="index" item="item" open="case GROUP_SPOT_ID" separator=" ">
          when #{item.groupSpotId,jdbcType=VARCHAR} then #{item.groupName,jdbcType=VARCHAR}
       </foreach>
       ,SPOT_ID=
       <foreach close="end" collection="list" index="index" item="item" open="case GROUP_SPOT_ID" separator=" ">
          when #{item.groupSpotId,jdbcType=VARCHAR} then #{item.spotId,jdbcType=VARCHAR}
       </foreach>
       ,SPOT_NAME=
       <foreach close="end" collection="list" index="index" item="item" open="case GROUP_SPOT_ID" separator=" ">
          when #{item.groupSpotId,jdbcType=VARCHAR} then #{item.spotName,jdbcType=VARCHAR}
       </foreach>
       ,VALUE_FLAG=
       <foreach close="end" collection="list" index="index" item="item" open="case GROUP_SPOT_ID" separator=" ">
          when #{item.groupSpotId,jdbcType=VARCHAR} then #{item.valueFlag,jdbcType=VARCHAR}
       </foreach>
       ,CREATE_MAN_NO=
       <foreach close="end" collection="list" index="index" item="item" open="case GROUP_SPOT_ID" separator=" ">
          when #{item.groupSpotId,jdbcType=VARCHAR} then #{item.createManNo,jdbcType=VARCHAR}
       </foreach>
       ,CREATE_MAN_NAME=
       <foreach close="end" collection="list" index="index" item="item" open="case GROUP_SPOT_ID" separator=" ">
          when #{item.groupSpotId,jdbcType=VARCHAR} then #{item.createManName,jdbcType=VARCHAR}
       </foreach>
       ,CREATE_TIME=
       <foreach close="end" collection="list" index="index" item="item" open="case GROUP_SPOT_ID" separator=" ">
          when #{item.groupSpotId,jdbcType=VARCHAR} then #{item.createTime,jdbcType=TIMESTAMP}
       </foreach>
       ,UPDATE_MAN_NO=
       <foreach close="end" collection="list" index="index" item="item" open="case GROUP_SPOT_ID" separator=" ">
          when #{item.groupSpotId,jdbcType=VARCHAR} then #{item.updateManNo,jdbcType=VARCHAR}
       </foreach>
       ,UPDATE_MAN_NAME=
       <foreach close="end" collection="list" index="index" item="item" open="case GROUP_SPOT_ID" separator=" ">
          when #{item.groupSpotId,jdbcType=VARCHAR} then #{item.updateManName,jdbcType=VARCHAR}
       </foreach>
       ,UPDATE_TIME=
       <foreach close="end" collection="list" index="index" item="item" open="case GROUP_SPOT_ID" separator=" ">
          when #{item.groupSpotId,jdbcType=VARCHAR} then #{item.updateTime,jdbcType=TIMESTAMP}
       </foreach>
     where GROUP_SPOT_ID in 
     <foreach close=")" collection="list" index="index" item="item" open="(" separator=",">
    #{item.groupSpotId,jdbcType=VARCHAR}
     </foreach> 
  </update>
  <delete id="batchDelete" parameterType="java.util.List">
    delete from METER_BASE_GROUP_SPOT
    where GROUP_SPOT_ID in 
    <foreach close=")" collection="list" item="id" open="(" separator=",">
      #{id}
    </foreach>
  </delete>
  <!-- 友情提示！！！-->
  <!-- 请将自己写的代码放在此标签之下，方便以后粘贴复制。-->
  <select id="GetNewID" parameterType="java.lang.String" resultType="java.lang.String">
    SELECT LPAD(NVL(MAX(TO_NUMBER(SUBSTR(GROUP_SPOT_ID, LENGTH(GROUP_SPOT_ID) - 4))),0) + 1,5,'0') GROUP_SPOT_ID
    FROM METER_BASE_GROUP_SPOT where instr(GROUP_SPOT_ID,#{afl,jdbcType=VARCHAR})>0
  </select>

  <select id="queryByGroupSpot" resultMap="BaseResultMap">
    select * from METER_BASE_GROUP_SPOT
    WHERE 1=1
    <if test="valueFlag != null and valueFlag != ''" >
      and VALUE_FLAG = #{valueFlag}
    </if>
    <if test="groupId != null and groupId != ''">
      and GROUP_ID like '%${groupId}%'
    </if>
    <if test="groupName != null and groupName != ''">
      and GROUP_ID like '%${groupName}%'
    </if>
    <if test="spotId != null and spotId != ''">
      and SPOT_ID like '%${spotId}%'
    </if>
    <if test="spotName != null and spotName != ''">
      and SPOT_NAME like '%${spotName}%'
    </if>
    order by CREATE_TIME desc
  </select>

</mapper>