<?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.LuckDrawCountDao" >
  <resultMap id="BaseResultMap" type="com.ym.mec.biz.dal.entity.LuckDrawCount" >
    <id column="user_id_" property="userId" jdbcType="BIGINT" />
    <result column="used_count_" property="usedCount" jdbcType="INTEGER" />
    <result column="available_count_" property="availableCount" jdbcType="INTEGER" />
    <result column="available_amount_" property="availableAmount" jdbcType="BIGINT" />
    <result column="modify_on_" property="modifyOn" jdbcType="TIMESTAMP" />
  </resultMap>
  <sql id="Base_Column_List" >
    user_id_, used_count_, available_count_, available_amount_, modify_on_
  </sql>
  
  <select id="get" resultMap="BaseResultMap" parameterType="java.lang.Long" >
    select 
    <include refid="Base_Column_List" />
    from luck_draw_count
    where user_id_ = #{userId,jdbcType=BIGINT}
  </select>
  
  <select id="getLock" resultMap="BaseResultMap" parameterType="java.lang.Long" >
    select 
    <include refid="Base_Column_List" />
    from luck_draw_count
    where user_id_ = #{userId,jdbcType=BIGINT} for update
  </select>
  
  <select id="findAll" resultMap="BaseResultMap">
    select * from luck_draw_count
  </select>
  
  <delete id="delete" parameterType="java.lang.Long" >
    delete from luck_draw_count
    where user_id_ = #{userId,jdbcType=BIGINT}
  </delete>
  
  <insert id="insert" parameterType="com.ym.mec.biz.dal.entity.LuckDrawCount" >
    insert into luck_draw_count (user_id_, used_count_, available_count_, available_amount_,
      modify_on_)
    values (#{userId,jdbcType=BIGINT}, #{usedCount,jdbcType=INTEGER}, #{availableCount,jdbcType=INTEGER}, #{availableAmount,jdbcType=BIGINT},
      #{modifyOn,jdbcType=TIMESTAMP})
  </insert>
  
  <update id="update" parameterType="com.ym.mec.biz.dal.entity.LuckDrawCount" >
    update luck_draw_count
    <set >
      <if test="usedCount != null" >
        used_count_ = #{usedCount,jdbcType=INTEGER},
      </if>
      <if test="availableCount != null" >
        available_count_ = #{availableCount,jdbcType=INTEGER},
      </if>
      <if test="availableAmount != null" >
        available_amount_ = #{availableAmount,jdbcType=BIGINT},
      </if>
      <if test="modifyOn != null" >
        modify_on_ = #{modifyOn,jdbcType=TIMESTAMP},
      </if>
    </set>
    where user_id_ = #{userId,jdbcType=BIGINT}
  </update>
</mapper>