<?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.meterbaseverificationcode.mapper.MeterBaseVerificationCodeMapper">
  <resultMap id="BaseResultMap" type="com.steerinfo.baseinfo.meterbaseverificationcode.model.MeterBaseVerificationCode">
    <id column="VERIFICATION_CODE_NO" jdbcType="VARCHAR" property="verificationCodeNo" />
    <result column="VERIFICATION_CODE" jdbcType="VARCHAR" property="verificationCode" />
    <result column="MEMO" jdbcType="VARCHAR" property="memo" />
    <result column="VALID_FLAG" jdbcType="VARCHAR" property="validFlag" />
    <result column="CREATE_TIME" jdbcType="TIMESTAMP" property="createTime" />
    <result column="VAILD_TIME" jdbcType="TIMESTAMP" property="vaildTime" />
    <result column="PHONE_NUMBER" jdbcType="VARCHAR" property="phoneNumber" />
  </resultMap>
  <sql id="columns">
    VERIFICATION_CODE_NO, VERIFICATION_CODE, MEMO, VALID_FLAG, CREATE_TIME, VAILD_TIME, 
    PHONE_NUMBER
  </sql>
  <sql id="columns_alias">
    t.VERIFICATION_CODE_NO, t.VERIFICATION_CODE, t.MEMO, t.VALID_FLAG, t.CREATE_TIME, 
    t.VAILD_TIME, t.PHONE_NUMBER
  </sql>
  <sql id="select">
    SELECT <include refid="columns"/> FROM METER_BASE_VERIFICATION_CODE
  </sql>
  <sql id="select_alias">
    SELECT <include refid="columns_alias"/> FROM METER_BASE_VERIFICATION_CODE t
  </sql>
  <sql id="where">
    <where> 
      <if test="verificationCodeNo != null and verificationCodeNo != ''">
        and VERIFICATION_CODE_NO = #{verificationCodeNo}
      </if>
      <if test="verificationCode != null and verificationCode != ''">
        and VERIFICATION_CODE = #{verificationCode}
      </if>
      <if test="memo != null and memo != ''">
        and MEMO = #{memo}
      </if>
      <if test="validFlag != null and validFlag != ''">
        and VALID_FLAG = #{validFlag}
      </if>
      <if test="createTime != null">
        and TO_CHAR(CREATE_TIME,'yyyy-MM-dd') = #{createTime}
      </if>
      <if test="vaildTime != null">
        and TO_CHAR(VAILD_TIME,'yyyy-MM-dd') = #{vaildTime}
      </if>
      <if test="phoneNumber != null and phoneNumber != ''">
        and PHONE_NUMBER = #{phoneNumber}
      </if>
    </where>
  </sql>
  <sql id="whereLike">
    <where> 
      <if test="verificationCodeNo != null and verificationCodeNo != ''">
        and VERIFICATION_CODE_NO LIKE '%${verificationCodeNo}%'
      </if>
      <if test="verificationCode != null and verificationCode != ''">
        and VERIFICATION_CODE LIKE '%${verificationCode}%'
      </if>
      <if test="memo != null and memo != ''">
        and MEMO LIKE '%${memo}%'
      </if>
      <if test="validFlag != null and validFlag != ''">
        and VALID_FLAG LIKE '%${validFlag}%'
      </if>
      <if test="createTime != null">
        and TO_CHAR(CREATE_TIME,'yyyy-MM-dd') = #{createTime}
      </if>
      <if test="vaildTime != null">
        and TO_CHAR(VAILD_TIME,'yyyy-MM-dd') = #{vaildTime}
      </if>
      <if test="phoneNumber != null and phoneNumber != ''">
        and PHONE_NUMBER LIKE '%${phoneNumber}%'
      </if>
    </where>
  </sql>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    delete from METER_BASE_VERIFICATION_CODE
    where VERIFICATION_CODE_NO = #{verificationCodeNo,jdbcType=VARCHAR}
  </delete>
  <delete id="deleteBySelectiveElement" parameterType="java.util.HashMap">
    delete from METER_BASE_VERIFICATION_CODE
    where 1!=1 
      <if test="verificationCode != null and verificationCode != ''">
        or VERIFICATION_CODE = #{verificationCode}
      </if>
      <if test="memo != null and memo != ''">
        or MEMO = #{memo}
      </if>
      <if test="validFlag != null and validFlag != ''">
        or VALID_FLAG = #{validFlag}
      </if>
      <if test="createTime != null">
        or TO_CHAR(CREATE_TIME,'yyyy-MM-dd') = '#{createTime}'
      </if>
      <if test="vaildTime != null">
        or TO_CHAR(VAILD_TIME,'yyyy-MM-dd') = '#{vaildTime}'
      </if>
      <if test="phoneNumber != null and phoneNumber != ''">
        or PHONE_NUMBER = #{phoneNumber}
      </if>
  </delete>
  <insert id="insert" parameterType="com.steerinfo.baseinfo.meterbaseverificationcode.model.MeterBaseVerificationCode">
    insert into METER_BASE_VERIFICATION_CODE (VERIFICATION_CODE_NO, VERIFICATION_CODE, 
      MEMO, VALID_FLAG, CREATE_TIME, 
      VAILD_TIME, PHONE_NUMBER)
    values (#{verificationCodeNo,jdbcType=VARCHAR}, #{verificationCode,jdbcType=VARCHAR}, 
      #{memo,jdbcType=VARCHAR}, #{validFlag,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, 
      #{vaildTime,jdbcType=TIMESTAMP}, #{phoneNumber,jdbcType=VARCHAR})
  </insert>
  <insert id="insertSelective" parameterType="com.steerinfo.baseinfo.meterbaseverificationcode.model.MeterBaseVerificationCode">
    insert into METER_BASE_VERIFICATION_CODE
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="verificationCodeNo != null">
        VERIFICATION_CODE_NO,
      </if>
      <if test="verificationCode != null">
        VERIFICATION_CODE,
      </if>
      <if test="memo != null">
        MEMO,
      </if>
      <if test="validFlag != null">
        VALID_FLAG,
      </if>
      <if test="createTime != null">
        CREATE_TIME,
      </if>
      <if test="vaildTime != null">
        VAILD_TIME,
      </if>
      <if test="phoneNumber != null">
        PHONE_NUMBER,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="verificationCodeNo != null">
        #{verificationCodeNo,jdbcType=VARCHAR},
      </if>
      <if test="verificationCode != null">
        #{verificationCode,jdbcType=VARCHAR},
      </if>
      <if test="memo != null">
        #{memo,jdbcType=VARCHAR},
      </if>
      <if test="validFlag != null">
        #{validFlag,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="vaildTime != null">
        #{vaildTime,jdbcType=TIMESTAMP},
      </if>
      <if test="phoneNumber != null">
        #{phoneNumber,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKey" parameterType="com.steerinfo.baseinfo.meterbaseverificationcode.model.MeterBaseVerificationCode">
    update METER_BASE_VERIFICATION_CODE
    set VERIFICATION_CODE = #{verificationCode,jdbcType=VARCHAR},
      MEMO = #{memo,jdbcType=VARCHAR},
      VALID_FLAG = #{validFlag,jdbcType=VARCHAR},
      CREATE_TIME = #{createTime,jdbcType=TIMESTAMP},
      VAILD_TIME = #{vaildTime,jdbcType=TIMESTAMP},
      PHONE_NUMBER = #{phoneNumber,jdbcType=VARCHAR}
    where VERIFICATION_CODE_NO = #{verificationCodeNo,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.steerinfo.baseinfo.meterbaseverificationcode.model.MeterBaseVerificationCode">
    update METER_BASE_VERIFICATION_CODE
    <set>
      <if test="verificationCode != null">
        VERIFICATION_CODE = #{verificationCode,jdbcType=VARCHAR},
      </if>
      <if test="memo != null">
        MEMO = #{memo,jdbcType=VARCHAR},
      </if>
      <if test="validFlag != null">
        VALID_FLAG = #{validFlag,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        CREATE_TIME = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="vaildTime != null">
        VAILD_TIME = #{vaildTime,jdbcType=TIMESTAMP},
      </if>
      <if test="phoneNumber != null">
        PHONE_NUMBER = #{phoneNumber,jdbcType=VARCHAR},
      </if>
    </set>
    where VERIFICATION_CODE_NO = #{verificationCodeNo,jdbcType=VARCHAR}
  </update>
  <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
    <include refid="select"/>
    where VERIFICATION_CODE_NO = #{verificationCodeNo,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_VERIFICATION_CODE 
      (VERIFICATION_CODE_NO, 
      VERIFICATION_CODE, MEMO, VALID_FLAG, 
      CREATE_TIME, VAILD_TIME, PHONE_NUMBER
      )
    ( <foreach collection="list" item="item" separator="union all"> 
   select  
      #{item.verificationCodeNo,jdbcType=VARCHAR}, 
      #{item.verificationCode,jdbcType=VARCHAR}, #{item.memo,jdbcType=VARCHAR}, #{item.validFlag,jdbcType=VARCHAR}, 
      #{item.createTime,jdbcType=TIMESTAMP}, #{item.vaildTime,jdbcType=TIMESTAMP}, #{item.phoneNumber,jdbcType=VARCHAR}
       from dual  
   </foreach> )
  </insert>
  <update id="batchUpdate" parameterType="java.util.List">
     update METER_BASE_VERIFICATION_CODE
     set
       VERIFICATION_CODE_NO=
       <foreach collection="list" item="item" index="index" separator=" " open="case VERIFICATION_CODE_NO" close="end">
          when #{item.verificationCodeNo,jdbcType=VARCHAR} then #{item.verificationCodeNo,jdbcType=VARCHAR}
       </foreach>
       ,VERIFICATION_CODE=
       <foreach collection="list" item="item" index="index" separator=" " open="case VERIFICATION_CODE_NO" close="end">
          when #{item.verificationCodeNo,jdbcType=VARCHAR} then #{item.verificationCode,jdbcType=VARCHAR}
       </foreach>
       ,MEMO=
       <foreach collection="list" item="item" index="index" separator=" " open="case VERIFICATION_CODE_NO" close="end">
          when #{item.verificationCodeNo,jdbcType=VARCHAR} then #{item.memo,jdbcType=VARCHAR}
       </foreach>
       ,VALID_FLAG=
       <foreach collection="list" item="item" index="index" separator=" " open="case VERIFICATION_CODE_NO" close="end">
          when #{item.verificationCodeNo,jdbcType=VARCHAR} then #{item.validFlag,jdbcType=VARCHAR}
       </foreach>
       ,CREATE_TIME=
       <foreach collection="list" item="item" index="index" separator=" " open="case VERIFICATION_CODE_NO" close="end">
          when #{item.verificationCodeNo,jdbcType=VARCHAR} then #{item.createTime,jdbcType=TIMESTAMP}
       </foreach>
       ,VAILD_TIME=
       <foreach collection="list" item="item" index="index" separator=" " open="case VERIFICATION_CODE_NO" close="end">
          when #{item.verificationCodeNo,jdbcType=VARCHAR} then #{item.vaildTime,jdbcType=TIMESTAMP}
       </foreach>
       ,PHONE_NUMBER=
       <foreach collection="list" item="item" index="index" separator=" " open="case VERIFICATION_CODE_NO" close="end">
          when #{item.verificationCodeNo,jdbcType=VARCHAR} then #{item.phoneNumber,jdbcType=VARCHAR}
       </foreach>
     where VERIFICATION_CODE_NO in 
     <foreach collection="list" index="index" item="item" separator="," open="(" close=")">
    #{item.verificationCodeNo,jdbcType=VARCHAR}
     </foreach> 
  </update>
  <delete id="batchDelete" parameterType="java.util.List">
    delete from METER_BASE_VERIFICATION_CODE
    where VERIFICATION_CODE_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(VERIFICATION_CODE_NO, LENGTH(VERIFICATION_CODE_NO) - 4))),0) + 1,5,'0') VERIFICATION_CODE_NO
    FROM METER_BASE_VERIFICATION_CODE
  </select>

  <select id="getCode" parameterType="java.lang.String" resultMap="BaseResultMap">
    select * from METER_BASE_VERIFICATION_CODE where PHONE_NUMBER = #{phoneNumber} AND VALID_FLAG = '0' AND VAILD_TIME > TO_DATE(sysdate,'yyyy-MM-dd HH24:mi:ss')
  </select>

  <update id="updateVaild">
    update METER_BASE_VERIFICATION_CODE set VALID_FLAG = '1' where VERIFICATION_CODE_NO = #{verificationCodeNo}
  </update>
</mapper>