<?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.meterworkrailwayrecmain.mapper.MeterWorkRailwayRecMainMapper">
  <resultMap id="BaseResultMap" type="com.steerinfo.meterwork.meterworkrailwayrecmain.model.MeterWorkRailwayRecMain">
    <id column="ACTUAL_NO" jdbcType="VARCHAR" property="actualNo" />
    <result column="CREATE_TIME" jdbcType="TIMESTAMP" property="createTime" />
    <result column="CARRIAGE_NUM" jdbcType="DECIMAL" property="carriageNum" />
    <result column="BASE_SPOT_NO" jdbcType="VARCHAR" property="baseSpotNo" />
    <result column="BASE_SPOT_NAME" jdbcType="VARCHAR" property="baseSpotName" />
    <result column="VIDEO_NAME" jdbcType="VARCHAR" property="videoName" />
    <result column="SOUND_NAME" jdbcType="VARCHAR" property="soundName" />
    <result column="TRACK_WAY" jdbcType="VARCHAR" property="trackWay" />
    <result column="IS_DISPOSE" jdbcType="VARCHAR" property="isDispose" />
  </resultMap>
  <sql id="columns">
    ACTUAL_NO, CREATE_TIME, CARRIAGE_NUM, BASE_SPOT_NO, BASE_SPOT_NAME, VIDEO_NAME, SOUND_NAME, 
    TRACK_WAY, IS_DISPOSE
  </sql>
  <sql id="columns_alias">
    t.ACTUAL_NO, t.CREATE_TIME, t.CARRIAGE_NUM, t.BASE_SPOT_NO, t.BASE_SPOT_NAME, t.VIDEO_NAME, 
    t.SOUND_NAME, t.TRACK_WAY, t.IS_DISPOSE
  </sql>
  <sql id="select">
    SELECT <include refid="columns" /> FROM METER_WORK_RAILWAY_REC_MAIN
  </sql>
  <sql id="select_alias">
    SELECT <include refid="columns_alias" /> FROM METER_WORK_RAILWAY_REC_MAIN t
  </sql>
  <sql id="where">
    <where> 
      <if test="actualNo != null and actualNo != ''">
        and ACTUAL_NO = #{actualNo}
      </if>
      <if test="createTime != null">
        and TO_CHAR(CREATE_TIME,'yyyy-MM-dd') = #{createTime}
      </if>
      <if test="carriageNum != null">
        and CARRIAGE_NUM = #{carriageNum}
      </if>
      <if test="baseSpotNo != null and baseSpotNo != ''">
        and BASE_SPOT_NO = #{baseSpotNo}
      </if>
      <if test="baseSpotName != null and baseSpotName != ''">
        and BASE_SPOT_NAME = #{baseSpotName}
      </if>
      <if test="videoName != null and videoName != ''">
        and VIDEO_NAME = #{videoName}
      </if>
      <if test="soundName != null and soundName != ''">
        and SOUND_NAME = #{soundName}
      </if>
      <if test="trackWay != null and trackWay != ''">
        and TRACK_WAY = #{trackWay}
      </if>
      <if test="isDispose != null and isDispose != ''">
        and IS_DISPOSE = #{isDispose}
      </if>
    </where>
  </sql>
  <sql id="whereLike">
    <where> 
      <if test="actualNo != null and actualNo != ''">
        and ACTUAL_NO LIKE '%${actualNo}%'
      </if>
      <if test="createTime != null">
        and TO_CHAR(CREATE_TIME,'yyyy-MM-dd') = #{createTime}
      </if>
      <if test="carriageNum != null">
        and CARRIAGE_NUM = #{carriageNum}
      </if>
      <if test="baseSpotNo != null and baseSpotNo != ''">
        and BASE_SPOT_NO LIKE '%${baseSpotNo}%'
      </if>
      <if test="baseSpotName != null and baseSpotName != ''">
        and BASE_SPOT_NAME LIKE '%${baseSpotName}%'
      </if>
      <if test="videoName != null and videoName != ''">
        and VIDEO_NAME LIKE '%${videoName}%'
      </if>
      <if test="soundName != null and soundName != ''">
        and SOUND_NAME LIKE '%${soundName}%'
      </if>
      <if test="trackWay != null and trackWay != ''">
        and TRACK_WAY LIKE '%${trackWay}%'
      </if>
      <if test="isDispose != null and isDispose != ''">
        and IS_DISPOSE LIKE '%${isDispose}%'
      </if>
    </where>
  </sql>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    delete from METER_WORK_RAILWAY_REC_MAIN
    where ACTUAL_NO = #{actualNo,jdbcType=VARCHAR}
  </delete>
  <delete id="deleteBySelectiveElement" parameterType="java.util.HashMap">
    delete from METER_WORK_RAILWAY_REC_MAIN
    where 1!=1 
      <if test="createTime != null">
        or TO_CHAR(CREATE_TIME,'yyyy-MM-dd') = '#{createTime}'
      </if>
      <if test="carriageNum != null">
        or CARRIAGE_NUM = #{carriageNum}
      </if>
      <if test="baseSpotNo != null and baseSpotNo != ''">
        or BASE_SPOT_NO = #{baseSpotNo}
      </if>
      <if test="baseSpotName != null and baseSpotName != ''">
        or BASE_SPOT_NAME = #{baseSpotName}
      </if>
      <if test="videoName != null and videoName != ''">
        or VIDEO_NAME = #{videoName}
      </if>
      <if test="soundName != null and soundName != ''">
        or SOUND_NAME = #{soundName}
      </if>
      <if test="trackWay != null and trackWay != ''">
        or TRACK_WAY = #{trackWay}
      </if>
      <if test="isDispose != null and isDispose != ''">
        or IS_DISPOSE = #{isDispose}
      </if>
  </delete>
  <insert id="insert" parameterType="com.steerinfo.meterwork.meterworkrailwayrecmain.model.MeterWorkRailwayRecMain">
    insert into METER_WORK_RAILWAY_REC_MAIN (ACTUAL_NO, CREATE_TIME, CARRIAGE_NUM, 
      BASE_SPOT_NO, BASE_SPOT_NAME, VIDEO_NAME, 
      SOUND_NAME, TRACK_WAY, IS_DISPOSE
      )
    values (#{actualNo,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{carriageNum,jdbcType=DECIMAL}, 
      #{baseSpotNo,jdbcType=VARCHAR}, #{baseSpotName,jdbcType=VARCHAR}, #{videoName,jdbcType=VARCHAR}, 
      #{soundName,jdbcType=VARCHAR}, #{trackWay,jdbcType=VARCHAR}, #{isDispose,jdbcType=VARCHAR}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.steerinfo.meterwork.meterworkrailwayrecmain.model.MeterWorkRailwayRecMain">
    insert into METER_WORK_RAILWAY_REC_MAIN
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="actualNo != null">
        ACTUAL_NO,
      </if>
      <if test="createTime != null">
        CREATE_TIME,
      </if>
      <if test="carriageNum != null">
        CARRIAGE_NUM,
      </if>
      <if test="baseSpotNo != null">
        BASE_SPOT_NO,
      </if>
      <if test="baseSpotName != null">
        BASE_SPOT_NAME,
      </if>
      <if test="videoName != null">
        VIDEO_NAME,
      </if>
      <if test="soundName != null">
        SOUND_NAME,
      </if>
      <if test="trackWay != null">
        TRACK_WAY,
      </if>
      <if test="isDispose != null">
        IS_DISPOSE,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="actualNo != null">
        #{actualNo,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="carriageNum != null">
        #{carriageNum,jdbcType=DECIMAL},
      </if>
      <if test="baseSpotNo != null">
        #{baseSpotNo,jdbcType=VARCHAR},
      </if>
      <if test="baseSpotName != null">
        #{baseSpotName,jdbcType=VARCHAR},
      </if>
      <if test="videoName != null">
        #{videoName,jdbcType=VARCHAR},
      </if>
      <if test="soundName != null">
        #{soundName,jdbcType=VARCHAR},
      </if>
      <if test="trackWay != null">
        #{trackWay,jdbcType=VARCHAR},
      </if>
      <if test="isDispose != null">
        #{isDispose,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKey" parameterType="com.steerinfo.meterwork.meterworkrailwayrecmain.model.MeterWorkRailwayRecMain">
    update METER_WORK_RAILWAY_REC_MAIN
    set CREATE_TIME = #{createTime,jdbcType=TIMESTAMP},
      CARRIAGE_NUM = #{carriageNum,jdbcType=DECIMAL},
      BASE_SPOT_NO = #{baseSpotNo,jdbcType=VARCHAR},
      BASE_SPOT_NAME = #{baseSpotName,jdbcType=VARCHAR},
      VIDEO_NAME = #{videoName,jdbcType=VARCHAR},
      SOUND_NAME = #{soundName,jdbcType=VARCHAR},
      TRACK_WAY = #{trackWay,jdbcType=VARCHAR},
      IS_DISPOSE = #{isDispose,jdbcType=VARCHAR}
    where ACTUAL_NO = #{actualNo,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.steerinfo.meterwork.meterworkrailwayrecmain.model.MeterWorkRailwayRecMain">
    update METER_WORK_RAILWAY_REC_MAIN
    <set>
      <if test="createTime != null">
        CREATE_TIME = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="carriageNum != null">
        CARRIAGE_NUM = #{carriageNum,jdbcType=DECIMAL},
      </if>
      <if test="baseSpotNo != null">
        BASE_SPOT_NO = #{baseSpotNo,jdbcType=VARCHAR},
      </if>
      <if test="baseSpotName != null">
        BASE_SPOT_NAME = #{baseSpotName,jdbcType=VARCHAR},
      </if>
      <if test="videoName != null">
        VIDEO_NAME = #{videoName,jdbcType=VARCHAR},
      </if>
      <if test="soundName != null">
        SOUND_NAME = #{soundName,jdbcType=VARCHAR},
      </if>
      <if test="trackWay != null">
        TRACK_WAY = #{trackWay,jdbcType=VARCHAR},
      </if>
      <if test="isDispose != null">
        IS_DISPOSE = #{isDispose,jdbcType=VARCHAR},
      </if>
    </set>
    where ACTUAL_NO = #{actualNo,jdbcType=VARCHAR}
  </update>
  <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
    <include refid="select" />
    where ACTUAL_NO = #{actualNo,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_WORK_RAILWAY_REC_MAIN 
      (ACTUAL_NO, 
      CREATE_TIME, CARRIAGE_NUM, BASE_SPOT_NO, 
      BASE_SPOT_NAME, VIDEO_NAME, SOUND_NAME, 
      TRACK_WAY, IS_DISPOSE)
    ( <foreach collection="list" item="item" separator="union all"> 
   select  
      #{item.actualNo,jdbcType=VARCHAR}, 
      #{item.createTime,jdbcType=TIMESTAMP}, #{item.carriageNum,jdbcType=DECIMAL}, #{item.baseSpotNo,jdbcType=VARCHAR}, 
      #{item.baseSpotName,jdbcType=VARCHAR}, #{item.videoName,jdbcType=VARCHAR}, #{item.soundName,jdbcType=VARCHAR}, 
      #{item.trackWay,jdbcType=VARCHAR}, #{item.isDispose,jdbcType=VARCHAR} from dual  
   </foreach> )
  </insert>
  <update id="batchUpdate" parameterType="java.util.List">
     update METER_WORK_RAILWAY_REC_MAIN
     set
       ACTUAL_NO=
       <foreach close="end" collection="list" index="index" item="item" open="case ACTUAL_NO" separator=" ">
          when #{item.actualNo,jdbcType=VARCHAR} then #{item.actualNo,jdbcType=VARCHAR}
       </foreach>
       ,CREATE_TIME=
       <foreach close="end" collection="list" index="index" item="item" open="case ACTUAL_NO" separator=" ">
          when #{item.actualNo,jdbcType=VARCHAR} then #{item.createTime,jdbcType=TIMESTAMP}
       </foreach>
       ,CARRIAGE_NUM=
       <foreach close="end" collection="list" index="index" item="item" open="case ACTUAL_NO" separator=" ">
          when #{item.actualNo,jdbcType=VARCHAR} then #{item.carriageNum,jdbcType=DECIMAL}
       </foreach>
       ,BASE_SPOT_NO=
       <foreach close="end" collection="list" index="index" item="item" open="case ACTUAL_NO" separator=" ">
          when #{item.actualNo,jdbcType=VARCHAR} then #{item.baseSpotNo,jdbcType=VARCHAR}
       </foreach>
       ,BASE_SPOT_NAME=
       <foreach close="end" collection="list" index="index" item="item" open="case ACTUAL_NO" separator=" ">
          when #{item.actualNo,jdbcType=VARCHAR} then #{item.baseSpotName,jdbcType=VARCHAR}
       </foreach>
       ,VIDEO_NAME=
       <foreach close="end" collection="list" index="index" item="item" open="case ACTUAL_NO" separator=" ">
          when #{item.actualNo,jdbcType=VARCHAR} then #{item.videoName,jdbcType=VARCHAR}
       </foreach>
       ,SOUND_NAME=
       <foreach close="end" collection="list" index="index" item="item" open="case ACTUAL_NO" separator=" ">
          when #{item.actualNo,jdbcType=VARCHAR} then #{item.soundName,jdbcType=VARCHAR}
       </foreach>
       ,TRACK_WAY=
       <foreach close="end" collection="list" index="index" item="item" open="case ACTUAL_NO" separator=" ">
          when #{item.actualNo,jdbcType=VARCHAR} then #{item.trackWay,jdbcType=VARCHAR}
       </foreach>
       ,IS_DISPOSE=
       <foreach close="end" collection="list" index="index" item="item" open="case ACTUAL_NO" separator=" ">
          when #{item.actualNo,jdbcType=VARCHAR} then #{item.isDispose,jdbcType=VARCHAR}
       </foreach>
     where ACTUAL_NO in 
     <foreach close=")" collection="list" index="index" item="item" open="(" separator=",">
    #{item.actualNo,jdbcType=VARCHAR}
     </foreach> 
  </update>
  <delete id="batchDelete" parameterType="java.util.List">
    delete from METER_WORK_RAILWAY_REC_MAIN
    where ACTUAL_NO 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(ACTUAL_NO, LENGTH(ACTUAL_NO) - 3))),0) + 1,4,'0') ACTUAL_NO
    FROM METER_WORK_RAILWAY_REC_MAIN where instr(ACTUAL_NO,#{afl,jdbcType=VARCHAR})>0
  </select>

  <select id="getLcNo" parameterType="java.lang.String" resultType="java.lang.String">
    SELECT LPAD(NVL(MAX(TO_NUMBER(SUBSTR(sound_name,TO_NUMBER(instr(sound_name,'('))-3,3))),0) + 1,3,'0')
    FROM METER_WORK_RAILWAY_REC_MAIN where instr(sound_name,#{afl,jdbcType=VARCHAR})>0 AND base_spot_no=#{baseSpotNo,jdbcType=VARCHAR}
  </select>

  <select id="listBynoPage" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    <include refid="select"/>
    <where> 1 = 1
      <if test="actualNo != null and actualNo != ''">
        and ACTUAL_NO LIKE '%${actualNo}%'
      </if>
      <if test="createTime != null">
        and TO_CHAR(CREATE_TIME,'yyyy-MM-dd') = #{createTime}
      </if>
      <if test="carriageNum != null">
        and CARRIAGE_NUM = #{carriageNum}
      </if>
      <if test="baseSpotNo != null and baseSpotNo != ''">
        and BASE_SPOT_NO LIKE '%${baseSpotNo}%'
      </if>
      <if test="baseSpotName != null and baseSpotName != ''">
        and BASE_SPOT_NAME LIKE '%${baseSpotName}%'
      </if>
      <if test="videoName != null and videoName != ''">
        and VIDEO_NAME LIKE '%${videoName}%'
      </if>
      <if test="soundName != null and soundName != ''">
        and SOUND_NAME LIKE '%${soundName}%'
      </if>
      <if test="trackWay != null and trackWay != ''">
        and TRACK_WAY LIKE '%${trackWay}%'
      </if>
      <if test="isDispose != null and isDispose != ''">
        and IS_DISPOSE LIKE '%${isDispose}%'
      </if>
      <if test="startTime != null and endTime != null and startTime != '' and endTime != ''">
        and  create_time  >= TO_DATE(#{startTime}, 'yyyy-MM-dd HH24:mi:ss') and create_time  &lt;=  TO_DATE(#{endTime}, 'yyyy-MM-dd HH24:mi:ss')
      </if>
    </where>
    order by create_time desc
  </select>
  
</mapper>