<?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.meterwork.meterworkmeterscene.mapper.MeterWorkMeterSceneMapper">
  <resultMap id="BaseResultMap" type="com.steerinfo.meterwork.meterworkmeterscene.model.MeterWorkMeterScene">
    <id column="SCENE_NO" jdbcType="VARCHAR" property="sceneNo" />
    <result column="LINK_NO" jdbcType="VARCHAR" property="linkNo" />
    <result column="PROCESS_NO" jdbcType="VARCHAR" property="processNo" />
    <result column="SCENE_CODE" jdbcType="VARCHAR" property="sceneCode" />
    <result column="SCENE_NAME" jdbcType="VARCHAR" property="sceneName" />
    <result column="SCENE_NOTE" jdbcType="VARCHAR" property="sceneNote" />
    <result column="SCENE_ORDER_NUM" jdbcType="DECIMAL" property="sceneOrderNum" />
    <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" />
  </resultMap>
  <sql id="columns">
    SCENE_NO, LINK_NO, PROCESS_NO, SCENE_CODE, SCENE_NAME, SCENE_NOTE, SCENE_ORDER_NUM, 
    CREATE_MAN_NO, CREATE_MAN_NAME, CREATE_TIME
  </sql>
  <sql id="columns_alias">
    t.SCENE_NO, t.LINK_NO, t.PROCESS_NO, t.SCENE_CODE, t.SCENE_NAME, t.SCENE_NOTE, t.SCENE_ORDER_NUM, 
    t.CREATE_MAN_NO, t.CREATE_MAN_NAME, t.CREATE_TIME
  </sql>
  <sql id="select">
    SELECT <include refid="columns"/> FROM METER_WORK_METER_SCENE
  </sql>
  <sql id="select_alias">
    SELECT <include refid="columns_alias"/> FROM METER_WORK_METER_SCENE t
  </sql>
  <sql id="where">
    <where> 
      <if test="linkNo != null and linkNo != ''">
        and LINK_NO = #{linkNo}
      </if>
      <if test="processNo != null and processNo != ''">
        and PROCESS_NO = #{processNo}
      </if>
      <if test="sceneCode != null and sceneCode != ''">
        and SCENE_CODE = #{sceneCode}
      </if>
      <if test="sceneName != null and sceneName != ''">
        and SCENE_NAME = #{sceneName}
      </if>
      <if test="sceneNote != null and sceneNote != ''">
        and SCENE_NOTE = #{sceneNote}
      </if>
      <if test="sceneOrderNum != null">
        and SCENE_ORDER_NUM = #{sceneOrderNum}
      </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>
    </where>
  </sql>
  <sql id="whereLike">
    <where> 
      <if test="linkNo != null and linkNo != ''">
        and LINK_NO LIKE '%${linkNo}%'
      </if>
      <if test="processNo != null and processNo != ''">
        and PROCESS_NO LIKE '%${processNo}%'
      </if>
      <if test="sceneCode != null and sceneCode != ''">
        and SCENE_CODE LIKE '%${sceneCode}%'
      </if>
      <if test="sceneName != null and sceneName != ''">
        and SCENE_NAME LIKE '%${sceneName}%'
      </if>
      <if test="sceneNote != null and sceneNote != ''">
        and SCENE_NOTE LIKE '%${sceneNote}%'
      </if>
      <if test="sceneOrderNum != null">
        and SCENE_ORDER_NUM = #{sceneOrderNum}
      </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>
    </where>
  </sql>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    delete from METER_WORK_METER_SCENE
    where SCENE_NO = #{sceneNo,jdbcType=VARCHAR}
  </delete>
  <delete id="deleteBySelectiveElement" parameterType="java.util.HashMap">
    delete from METER_WORK_METER_SCENE
    where 1!=1 
      <if test="linkNo != null and linkNo != ''">
        or LINK_NO = #{linkNo}
      </if>
      <if test="processNo != null and processNo != ''">
        or PROCESS_NO = #{processNo}
      </if>
      <if test="sceneCode != null and sceneCode != ''">
        or SCENE_CODE = #{sceneCode}
      </if>
      <if test="sceneName != null and sceneName != ''">
        or SCENE_NAME = #{sceneName}
      </if>
      <if test="sceneNote != null and sceneNote != ''">
        or SCENE_NOTE = #{sceneNote}
      </if>
      <if test="sceneOrderNum != null">
        or SCENE_ORDER_NUM = #{sceneOrderNum}
      </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>
  </delete>
  <insert id="insert" parameterType="com.steerinfo.meterwork.meterworkmeterscene.model.MeterWorkMeterScene">
    insert into METER_WORK_METER_SCENE (SCENE_NO, LINK_NO, PROCESS_NO, 
      SCENE_CODE, SCENE_NAME, SCENE_NOTE, 
      SCENE_ORDER_NUM, CREATE_MAN_NO, CREATE_MAN_NAME, 
      CREATE_TIME)
    values (#{sceneNo,jdbcType=VARCHAR}, #{linkNo,jdbcType=VARCHAR}, #{processNo,jdbcType=VARCHAR}, 
      #{sceneCode,jdbcType=VARCHAR}, #{sceneName,jdbcType=VARCHAR}, #{sceneNote,jdbcType=VARCHAR}, 
      #{sceneOrderNum,jdbcType=DECIMAL}, #{createManNo,jdbcType=VARCHAR}, #{createManName,jdbcType=VARCHAR}, 
      #{createTime,jdbcType=TIMESTAMP})
  </insert>
  <insert id="insertSelective" parameterType="com.steerinfo.meterwork.meterworkmeterscene.model.MeterWorkMeterScene">
    insert into METER_WORK_METER_SCENE
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="sceneNo != null">
        SCENE_NO,
      </if>
      <if test="linkNo != null">
        LINK_NO,
      </if>
      <if test="processNo != null">
        PROCESS_NO,
      </if>
      <if test="sceneCode != null">
        SCENE_CODE,
      </if>
      <if test="sceneName != null">
        SCENE_NAME,
      </if>
      <if test="sceneNote != null">
        SCENE_NOTE,
      </if>
      <if test="sceneOrderNum != null">
        SCENE_ORDER_NUM,
      </if>
      <if test="createManNo != null">
        CREATE_MAN_NO,
      </if>
      <if test="createManName != null">
        CREATE_MAN_NAME,
      </if>
      <if test="createTime != null">
        CREATE_TIME,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="sceneNo != null">
        #{sceneNo,jdbcType=VARCHAR},
      </if>
      <if test="linkNo != null">
        #{linkNo,jdbcType=VARCHAR},
      </if>
      <if test="processNo != null">
        #{processNo,jdbcType=VARCHAR},
      </if>
      <if test="sceneCode != null">
        #{sceneCode,jdbcType=VARCHAR},
      </if>
      <if test="sceneName != null">
        #{sceneName,jdbcType=VARCHAR},
      </if>
      <if test="sceneNote != null">
        #{sceneNote,jdbcType=VARCHAR},
      </if>
      <if test="sceneOrderNum != null">
        #{sceneOrderNum,jdbcType=DECIMAL},
      </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>
    </trim>
  </insert>
  <update id="updateByPrimaryKey" parameterType="com.steerinfo.meterwork.meterworkmeterscene.model.MeterWorkMeterScene">
    update METER_WORK_METER_SCENE
    set LINK_NO = #{linkNo,jdbcType=VARCHAR},
      PROCESS_NO = #{processNo,jdbcType=VARCHAR},
      SCENE_CODE = #{sceneCode,jdbcType=VARCHAR},
      SCENE_NAME = #{sceneName,jdbcType=VARCHAR},
      SCENE_NOTE = #{sceneNote,jdbcType=VARCHAR},
      SCENE_ORDER_NUM = #{sceneOrderNum,jdbcType=DECIMAL},
      CREATE_MAN_NO = #{createManNo,jdbcType=VARCHAR},
      CREATE_MAN_NAME = #{createManName,jdbcType=VARCHAR},
      CREATE_TIME = #{createTime,jdbcType=TIMESTAMP}
    where SCENE_NO = #{sceneNo,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.steerinfo.meterwork.meterworkmeterscene.model.MeterWorkMeterScene">
    update METER_WORK_METER_SCENE
    <set>
      <if test="linkNo != null">
        LINK_NO = #{linkNo,jdbcType=VARCHAR},
      </if>
      <if test="processNo != null">
        PROCESS_NO = #{processNo,jdbcType=VARCHAR},
      </if>
      <if test="sceneCode != null">
        SCENE_CODE = #{sceneCode,jdbcType=VARCHAR},
      </if>
      <if test="sceneName != null">
        SCENE_NAME = #{sceneName,jdbcType=VARCHAR},
      </if>
      <if test="sceneNote != null">
        SCENE_NOTE = #{sceneNote,jdbcType=VARCHAR},
      </if>
      <if test="sceneOrderNum != null">
        SCENE_ORDER_NUM = #{sceneOrderNum,jdbcType=DECIMAL},
      </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>
    </set>
    where SCENE_NO = #{sceneNo,jdbcType=VARCHAR}
  </update>
  <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
    <include refid="select"/>
    where SCENE_NO = #{sceneNo,jdbcType=VARCHAR}
  </select>
  <select id="selectByParameters" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    <include refid="select"/>
    <include refid="where"/>
    order by scene_order_num
  </select>
  <select id="selectLikeByParameters" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    <include refid="select"/>
    <include refid="whereLike"/>
    order by scene_order_num
  </select>
  <insert id="batchInsert" parameterType="java.util.List">
    insert into METER_WORK_METER_SCENE 
      (SCENE_NO, 
      LINK_NO, PROCESS_NO, SCENE_CODE, 
      SCENE_NAME, SCENE_NOTE, SCENE_ORDER_NUM, 
      CREATE_MAN_NO, CREATE_MAN_NAME, CREATE_TIME
      )
    ( <foreach collection="list" item="item" separator="union all"> 
   select  
      #{item.sceneNo,jdbcType=VARCHAR}, 
      #{item.linkNo,jdbcType=VARCHAR}, #{item.processNo,jdbcType=VARCHAR}, #{item.sceneCode,jdbcType=VARCHAR}, 
      #{item.sceneName,jdbcType=VARCHAR}, #{item.sceneNote,jdbcType=VARCHAR}, #{item.sceneOrderNum,jdbcType=DECIMAL}, 
      #{item.createManNo,jdbcType=VARCHAR}, #{item.createManName,jdbcType=VARCHAR}, #{item.createTime,jdbcType=TIMESTAMP}
       from dual  
   </foreach> )
  </insert>
  <update id="batchUpdate" parameterType="java.util.List">
     update METER_WORK_METER_SCENE
     set
       SCENE_NO=
       <foreach collection="list" item="item" index="index" separator=" " open="case SCENE_NO" close="end">
          when #{item.sceneNo,jdbcType=VARCHAR} then #{item.sceneNo,jdbcType=VARCHAR}
       </foreach>
       ,LINK_NO=
       <foreach collection="list" item="item" index="index" separator=" " open="case SCENE_NO" close="end">
          when #{item.sceneNo,jdbcType=VARCHAR} then #{item.linkNo,jdbcType=VARCHAR}
       </foreach>
       ,PROCESS_NO=
       <foreach collection="list" item="item" index="index" separator=" " open="case SCENE_NO" close="end">
          when #{item.sceneNo,jdbcType=VARCHAR} then #{item.processNo,jdbcType=VARCHAR}
       </foreach>
       ,SCENE_CODE=
       <foreach collection="list" item="item" index="index" separator=" " open="case SCENE_NO" close="end">
          when #{item.sceneNo,jdbcType=VARCHAR} then #{item.sceneCode,jdbcType=VARCHAR}
       </foreach>
       ,SCENE_NAME=
       <foreach collection="list" item="item" index="index" separator=" " open="case SCENE_NO" close="end">
          when #{item.sceneNo,jdbcType=VARCHAR} then #{item.sceneName,jdbcType=VARCHAR}
       </foreach>
       ,SCENE_NOTE=
       <foreach collection="list" item="item" index="index" separator=" " open="case SCENE_NO" close="end">
          when #{item.sceneNo,jdbcType=VARCHAR} then #{item.sceneNote,jdbcType=VARCHAR}
       </foreach>
       ,SCENE_ORDER_NUM=
       <foreach collection="list" item="item" index="index" separator=" " open="case SCENE_NO" close="end">
          when #{item.sceneNo,jdbcType=VARCHAR} then #{item.sceneOrderNum,jdbcType=DECIMAL}
       </foreach>
       ,CREATE_MAN_NO=
       <foreach collection="list" item="item" index="index" separator=" " open="case SCENE_NO" close="end">
          when #{item.sceneNo,jdbcType=VARCHAR} then #{item.createManNo,jdbcType=VARCHAR}
       </foreach>
       ,CREATE_MAN_NAME=
       <foreach collection="list" item="item" index="index" separator=" " open="case SCENE_NO" close="end">
          when #{item.sceneNo,jdbcType=VARCHAR} then #{item.createManName,jdbcType=VARCHAR}
       </foreach>
       ,CREATE_TIME=
       <foreach collection="list" item="item" index="index" separator=" " open="case SCENE_NO" close="end">
          when #{item.sceneNo,jdbcType=VARCHAR} then #{item.createTime,jdbcType=TIMESTAMP}
       </foreach>
     where SCENE_NO in 
     <foreach collection="list" index="index" item="item" separator="," open="(" close=")">
    #{item.sceneNo,jdbcType=VARCHAR}
     </foreach> 
  </update>
  <delete id="batchDelete" parameterType="java.util.List">
    delete from METER_WORK_METER_SCENE
    where SCENE_NO in 
    <foreach collection="list" item="id" open="(" close=")" separator=",">
      #{id}
    </foreach>
  </delete>
  <!-- 友情提示！！！-->
  <!-- 请将自己写的代码放在此标签之下，方便以后粘贴复制。-->
  <select id="getNewID" parameterType="java.lang.String" resultType="java.lang.String">
    SELECT LPAD(NVL(MAX(TO_NUMBER(SUBSTR(SCENE_NO, LENGTH(SCENE_NO) -3))),0) + 1,4,'0') SCENE_NO
    FROM METER_WORK_METER_SCENE
  </select>
</mapper>