<?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.meterbasevoicerelation.mapper.MeterBaseVoiceRelationMapper">
  <resultMap id="BaseResultMap" type="com.steerinfo.baseinfo.meterbasevoicerelation.model.MeterBaseVoiceRelation">
    <id column="RELATION_ID" jdbcType="VARCHAR" property="relationId" />
    <result column="VOICE_ID" jdbcType="VARCHAR" property="voiceId" />
    <result column="BASE_SPOT_ID" jdbcType="VARCHAR" property="baseSpotId" />
    <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">
    RELATION_ID, VOICE_ID, BASE_SPOT_ID, CREATE_MAN_NO, CREATE_MAN_NAME, CREATE_TIME
  </sql>
  <sql id="columns_alias">
    t.RELATION_ID, t.VOICE_ID, t.BASE_SPOT_ID, t.CREATE_MAN_NO, t.CREATE_MAN_NAME, t.CREATE_TIME
  </sql>
  <sql id="select">
    SELECT <include refid="columns"/> FROM METER_BASE_VOICE_RELATION
  </sql>
  <sql id="select_alias">
    SELECT <include refid="columns_alias"/> FROM METER_BASE_VOICE_RELATION t
  </sql>
  <sql id="where">
    <where> 
      <if test="relationId != null and relationId != ''">
        and RELATION_ID = #{relationId}
      </if>
      <if test="voiceId != null and voiceId != ''">
        and VOICE_ID = #{voiceId}
      </if>
      <if test="baseSpotId != null and baseSpotId != ''">
        and BASE_SPOT_ID = #{baseSpotId}
      </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="relationId != null and relationId != ''">
        and RELATION_ID LIKE '%${relationId}%'
      </if>
      <if test="voiceId != null and voiceId != ''">
        and VOICE_ID LIKE '%${voiceId}%'
      </if>
      <if test="baseSpotId != null and baseSpotId != ''">
        and BASE_SPOT_ID LIKE '%${baseSpotId}%'
      </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_BASE_VOICE_RELATION
    where RELATION_ID = #{relationId,jdbcType=VARCHAR}
  </delete>
  <delete id="deleteBySelectiveElement" parameterType="java.util.HashMap">
    delete from METER_BASE_VOICE_RELATION
    where 1!=1 
      <if test="voiceId != null and voiceId != ''">
        or VOICE_ID = #{voiceId}
      </if>
      <if test="baseSpotId != null and baseSpotId != ''">
        or BASE_SPOT_ID = #{baseSpotId}
      </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.baseinfo.meterbasevoicerelation.model.MeterBaseVoiceRelation">
    insert into METER_BASE_VOICE_RELATION (RELATION_ID, VOICE_ID, BASE_SPOT_ID, 
      CREATE_MAN_NO, CREATE_MAN_NAME, CREATE_TIME
      )
    values (#{relationId,jdbcType=VARCHAR}, #{voiceId,jdbcType=VARCHAR}, #{baseSpotId,jdbcType=VARCHAR}, 
      #{createManNo,jdbcType=VARCHAR}, #{createManName,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.steerinfo.baseinfo.meterbasevoicerelation.model.MeterBaseVoiceRelation">
    insert into METER_BASE_VOICE_RELATION
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="relationId != null">
        RELATION_ID,
      </if>
      <if test="voiceId != null">
        VOICE_ID,
      </if>
      <if test="baseSpotId != null">
        BASE_SPOT_ID,
      </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="relationId != null">
        #{relationId,jdbcType=VARCHAR},
      </if>
      <if test="voiceId != null">
        #{voiceId,jdbcType=VARCHAR},
      </if>
      <if test="baseSpotId != null">
        #{baseSpotId,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>
    </trim>
  </insert>
  <update id="updateByPrimaryKey" parameterType="com.steerinfo.baseinfo.meterbasevoicerelation.model.MeterBaseVoiceRelation">
    update METER_BASE_VOICE_RELATION
    set VOICE_ID = #{voiceId,jdbcType=VARCHAR},
      BASE_SPOT_ID = #{baseSpotId,jdbcType=VARCHAR},
      CREATE_MAN_NO = #{createManNo,jdbcType=VARCHAR},
      CREATE_MAN_NAME = #{createManName,jdbcType=VARCHAR},
      CREATE_TIME = #{createTime,jdbcType=TIMESTAMP}
    where RELATION_ID = #{relationId,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.steerinfo.baseinfo.meterbasevoicerelation.model.MeterBaseVoiceRelation">
    update METER_BASE_VOICE_RELATION
    <set>
      <if test="voiceId != null">
        VOICE_ID = #{voiceId,jdbcType=VARCHAR},
      </if>
      <if test="baseSpotId != null">
        BASE_SPOT_ID = #{baseSpotId,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>
    </set>
    where RELATION_ID = #{relationId,jdbcType=VARCHAR}
  </update>
  <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
    <include refid="select"/>
    where RELATION_ID = #{relationId,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_VOICE_RELATION 
      (RELATION_ID, 
      VOICE_ID, BASE_SPOT_ID, CREATE_MAN_NO, 
      CREATE_MAN_NAME, CREATE_TIME)
    ( <foreach collection="list" item="item" separator="union all"> 
   select  
      #{item.relationId,jdbcType=VARCHAR}, 
      #{item.voiceId,jdbcType=VARCHAR}, #{item.baseSpotId,jdbcType=VARCHAR}, #{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_BASE_VOICE_RELATION
     set
       RELATION_ID=
       <foreach collection="list" item="item" index="index" separator=" " open="case RELATION_ID" close="end">
          when #{item.relationId,jdbcType=VARCHAR} then #{item.relationId,jdbcType=VARCHAR}
       </foreach>
       ,VOICE_ID=
       <foreach collection="list" item="item" index="index" separator=" " open="case RELATION_ID" close="end">
          when #{item.relationId,jdbcType=VARCHAR} then #{item.voiceId,jdbcType=VARCHAR}
       </foreach>
       ,BASE_SPOT_ID=
       <foreach collection="list" item="item" index="index" separator=" " open="case RELATION_ID" close="end">
          when #{item.relationId,jdbcType=VARCHAR} then #{item.baseSpotId,jdbcType=VARCHAR}
       </foreach>
       ,CREATE_MAN_NO=
       <foreach collection="list" item="item" index="index" separator=" " open="case RELATION_ID" close="end">
          when #{item.relationId,jdbcType=VARCHAR} then #{item.createManNo,jdbcType=VARCHAR}
       </foreach>
       ,CREATE_MAN_NAME=
       <foreach collection="list" item="item" index="index" separator=" " open="case RELATION_ID" close="end">
          when #{item.relationId,jdbcType=VARCHAR} then #{item.createManName,jdbcType=VARCHAR}
       </foreach>
       ,CREATE_TIME=
       <foreach collection="list" item="item" index="index" separator=" " open="case RELATION_ID" close="end">
          when #{item.relationId,jdbcType=VARCHAR} then #{item.createTime,jdbcType=TIMESTAMP}
       </foreach>
     where RELATION_ID in 
     <foreach collection="list" index="index" item="item" separator="," open="(" close=")">
    #{item.relationId,jdbcType=VARCHAR}
     </foreach> 
  </update>
  <delete id="batchDelete" parameterType="java.util.List">
    delete from METER_BASE_VOICE_RELATION
    where RELATION_ID 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(RELATION_ID, LENGTH(RELATION_ID)-4 ))),0) + 1,5,'0') RELATION_ID
    FROM METER_BASE_VOICE_RELATION
  </select>
  
  <select id="selectRelationByParameters" parameterType="java.util.HashMap" resultType="hashmap">
    select a.RELATION_ID,a.CREATE_MAN_NO,a.CREATE_MAN_NAME,a.CREATE_TIME,b.VOICE_NO,b.VOICE_NAME,b.VOICE_FILE_NAME,b.VOICE_FILE_URL,c.BASE_SPOT_NO,c.BASE_SPOT_NAME from METER_BASE_VOICE_RELATION a
        inner join METER_BASE_VOICE b on a.VOICE_ID=b.VOICE_NO
	    inner Join METER_BASE_SPOT_INFO c on a.BASE_SPOT_ID=BASE_SPOT_NO
	order by a.CREATE_TIME desc
  </select>
</mapper>