<?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.boco.nbd.wios.flow.mapper.def.SecretPhoneMapper">

<resultMap id="BaseResultMap" type="com.boco.nbd.wios.flow.entity.SecretPhone">
  <id column="phone" jdbcType="VARCHAR" property="phone" />
  <result column="secret_no" jdbcType="VARCHAR" property="secretNo" />
  <result column="pool_key" jdbcType="VARCHAR" property="poolKey" />
  <result column="expired_time" jdbcType="TIMESTAMP" property="expiredTime" />
  <result column="subs_id" jdbcType="VARCHAR" property="subsId" />
  <result column="status" jdbcType="INTEGER" property="status" />
  <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
  <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
</resultMap>


<sql id="Base_Column_List">
  phone, secret_no, pool_key, expired_time, subs_id, status, update_time, create_time
</sql>


<delete id="delete" parameterType="java.lang.String">
  delete from t_secret_phone
  where phone = #{phone,jdbcType=VARCHAR}
</delete>


<insert id="insert" parameterType="com.boco.nbd.wios.flow.entity.SecretPhone">
  insert into t_secret_phone (phone, secret_no, pool_key,
    expired_time, subs_id, status,
    update_time, create_time)
  values (#{phone,jdbcType=VARCHAR}, #{secretNo,jdbcType=VARCHAR}, #{poolKey,jdbcType=VARCHAR},
    #{expiredTime,jdbcType=TIMESTAMP}, #{subsId,jdbcType=VARCHAR}, #{status,jdbcType=INTEGER},
    #{updateTime,jdbcType=TIMESTAMP}, #{createTime,jdbcType=TIMESTAMP})
</insert>


<insert id="insertDynamic" parameterType="com.boco.nbd.wios.flow.entity.SecretPhone">
  insert into t_secret_phone
  <trim prefix="(" suffix=")" suffixOverrides=",">
    <if test="phone != null">
      phone,
    </if>
    <if test="secretNo != null">
      secret_no,
    </if>
    <if test="poolKey != null">
      pool_key,
    </if>
    <if test="expiredTime != null">
      expired_time,
    </if>
    <if test="subsId != null">
      subs_id,
    </if>
    <if test="status != null">
      status,
    </if>
    <if test="updateTime != null">
      update_time,
    </if>
    <if test="createTime != null">
      create_time,
    </if>
  </trim>
  <trim prefix="values (" suffix=")" suffixOverrides=",">
    <if test="phone != null">
      #{phone,jdbcType=VARCHAR},
    </if>
    <if test="secretNo != null">
      #{secretNo,jdbcType=VARCHAR},
    </if>
    <if test="poolKey != null">
      #{poolKey,jdbcType=VARCHAR},
    </if>
    <if test="expiredTime != null">
      #{expiredTime,jdbcType=TIMESTAMP},
    </if>
    <if test="subsId != null">
      #{subsId,jdbcType=VARCHAR},
    </if>
    <if test="status != null">
      #{status,jdbcType=INTEGER},
    </if>
    <if test="updateTime != null">
      #{updateTime,jdbcType=TIMESTAMP},
    </if>
    <if test="createTime != null">
      #{createTime,jdbcType=TIMESTAMP},
    </if>
  </trim>
</insert>


<update id="updateDynamic" parameterType="com.boco.nbd.wios.flow.entity.SecretPhone">
  update t_secret_phone
  <set>
    <if test="secretNo != null">
      secret_no = #{secretNo,jdbcType=VARCHAR},
    </if>
    <if test="poolKey != null">
      pool_key = #{poolKey,jdbcType=VARCHAR},
    </if>
    <if test="expiredTime != null">
      expired_time = #{expiredTime,jdbcType=TIMESTAMP},
    </if>
    <if test="subsId != null">
      subs_id = #{subsId,jdbcType=VARCHAR},
    </if>
    <if test="status != null">
      status = #{status,jdbcType=INTEGER},
    </if>
    <if test="updateTime != null">
      update_time = #{updateTime,jdbcType=TIMESTAMP},
    </if>
    <if test="createTime != null">
      create_time = #{createTime,jdbcType=TIMESTAMP},
    </if>
  </set>
  where phone = #{phone,jdbcType=VARCHAR}
</update>


<update id="update" parameterType="com.boco.nbd.wios.flow.entity.SecretPhone">
  update t_secret_phone
  set secret_no = #{secretNo,jdbcType=VARCHAR},
    pool_key = #{poolKey,jdbcType=VARCHAR},
    expired_time = #{expiredTime,jdbcType=TIMESTAMP},
    subs_id = #{subsId,jdbcType=VARCHAR},
    status = #{status,jdbcType=INTEGER},
    update_time = #{updateTime,jdbcType=TIMESTAMP},
    create_time = #{createTime,jdbcType=TIMESTAMP}
  where phone = #{phone,jdbcType=VARCHAR}
</update>


<select id="selectByPhone" parameterType="java.lang.String" resultMap="BaseResultMap">
  select
	<include refid="Base_Column_List" />
  from  t_secret_phone
  where phone = #{phone,jdbcType=VARCHAR} and status=1
</select>

<select id="selectByExample" parameterType="com.boco.nbd.wios.flow.entity.SecretPhone"
        resultType="com.boco.nbd.wios.flow.entity.SecretPhone">
   select t.* from t_secret_phone t
   <where>
	    <if test="secretNo != null and secretNo !=''">
	        and t.secret_no = #{secretNo}
	    </if>
	    <if test="status != null">
	        and t.status = #{status}
	    </if>
   </where>
   order by t.create_time desc
</select>

<select id="selectExpired"
        resultType="com.boco.nbd.wios.flow.entity.SecretPhone">
   select t.* from t_secret_phone t
   where t.expired_time &lt;= now() and t.status=1
</select>
  
</mapper>