<?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.ym.mec.biz.dal.dao.RedemptionCodeDao">
  <resultMap id="BaseResultMap" type="com.ym.mec.biz.dal.entity.AppRedemptionCode">
                       <id column="id_" jdbcType="INTEGER" property="id"/>
                                  <result column="url_" jdbcType="VARCHAR" property="url"/>
                                  <result column="code_" jdbcType="VARCHAR" property="code"/>
                                  <result column="user_id_" jdbcType="INTEGER" property="userId"/>
                                  <result column="import_time_" jdbcType="TIMESTAMP" property="importTime"/>
                                  <result column="update_time_" jdbcType="TIMESTAMP" property="updateTime"/>
                                  <result column="status_" jdbcType="VARCHAR" property="status"/>
                </resultMap>
  
  <sql id="Base_Column_List">    
                                        id_, url_, code_, user_id_, import_time_, update_time_, status_
  </sql>
  
   <insert id="insertBatch" keyColumn="id_" keyProperty="id" useGeneratedKeys="true"
            parameterType="com.ym.mec.biz.dal.entity.AppRedemptionCode">
       insert into app_redemption_code(url_, code_, user_id_, import_time_, update_time_, status_)
       values
       <foreach collection="entities" item="entity" separator=",">
       (#{entity.url}, #{entity.code}, #{entity.userId}, #{entity.importTime}, #{entity.updateTime}, #{entity.status})
       </foreach>
   </insert>

    <select id="findFirstNull" resultType="com.ym.mec.biz.dal.entity.AppRedemptionCode">
        select * from app_redemption_code rc where rc.user_id_ is null
        order by rc.import_time_ desc
        limit 1 for update;
    </select>

    <select id="findNull" resultType="java.lang.Integer">
        select count(1) from app_redemption_code rc where rc.user_id_ is null
    </select>

    <select id="getByUserId" resultType="com.ym.mec.biz.dal.entity.AppRedemptionCode">
        select * from app_redemption_code where user_id_ = #{userId}
    </select>


</mapper>
