<?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="cn.iocoder.mall.user.dao.MobileCodeMapper">

    <insert id="insert" parameterType="MobileCodeDO">
        INSERT INTO mobile_code (
          id, mobile, code, today_index, used,
          userd_user_id, used_time, create_time
        ) VALUES (
          #{id}, #{mobile}, #{code}, #{todayIndex}, #{used},
          #{usedUserId}, #{usedTime}, #{createTime}
        )
    </insert>

    <update id="update" parameterType="MobileCodeDO">
        UPDATE mobile_code
        <set>
            <if test="used != null"> used = #{used}, </if>
            <if test="usedUserId != null"> userd_user_id = #{usedUserId}, </if>
            <if test="usedTime != null"> used_time = #{usedTime}, </if>
        </set>
        WHERE id = #{id}
    </update>

    <select id="selectLast1ByMobile" parameterType="String" resultType="MobileCodeDO">
      SELECT
          id, mobile, code, today_index, used,
          userd_user_id, used_time, create_time
      FROM mobile_code
      WHERE mobile = #{mobile}
      ORDER BY id DESC
      LIMIT 1
    </select>

</mapper>