<?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.LuckDrawGroupDao" >
  <resultMap id="BaseResultMap" type="com.ym.mec.biz.dal.entity.LuckDrawGroup" >
    <id column="id_" property="id" jdbcType="INTEGER" />
    <result column="name_" property="name" jdbcType="VARCHAR" />
    <result column="consume_type_" property="consumeType" jdbcType="VARCHAR" />
    <result column="consume_value_" property="consumeValue" jdbcType="INTEGER" />
    <result column="start_time_" property="startTime" jdbcType="TIMESTAMP" />
    <result column="end_time_" property="endTime" jdbcType="TIMESTAMP" />
    <result column="create_on_" property="createOn" jdbcType="TIMESTAMP" />
  </resultMap>
  
  <sql id="Base_Column_List" >
    id_, name_, consume_type_, consume_value_, start_time_, end_time_, create_on_
  </sql>
  
  <select id="get" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    select 
    <include refid="Base_Column_List" />
    from luck_draw_group
    where id_ = #{id,jdbcType=INTEGER}
  </select>
  
  <select id="findAll" resultMap="BaseResultMap" parameterType="map" >
    select * from luck_draw_group
  </select>
  
  <delete id="delete" parameterType="java.lang.Integer" >
    delete from luck_draw_group
    where id_ = #{id,jdbcType=INTEGER}
  </delete>
  
  <insert id="insert" parameterType="com.ym.mec.biz.dal.entity.LuckDrawGroup" >
    insert into luck_draw_group (id_, name_, consume_type_, consume_value_,
      start_time_, end_time_, create_on_
      )
    values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{consumeType,jdbcType=VARCHAR}, #{consumeValue,jdbcType=INTEGER},
      #{startTime,jdbcType=TIMESTAMP}, #{endTime,jdbcType=TIMESTAMP}, #{createOn,jdbcType=TIMESTAMP}
      )
  </insert>

  <update id="update" parameterType="com.ym.mec.biz.dal.entity.LuckDrawGroup" >
    update luck_draw_group
    <set >
      <if test="name != null" >
        name_ = #{name,jdbcType=VARCHAR},
      </if>
      <if test="consumeType != null" >
        consume_type_ = #{consumeType,jdbcType=VARCHAR},
      </if>
      <if test="consumeValue != null" >
        consume_value_ = #{consumeValue,jdbcType=INTEGER},
      </if>
      <if test="startTime != null" >
        start_time_ = #{startTime,jdbcType=TIMESTAMP},
      </if>
      <if test="endTime != null" >
        end_time_ = #{endTime,jdbcType=TIMESTAMP},
      </if>
      <if test="createOn != null" >
        create_on_ = #{createOn,jdbcType=TIMESTAMP},
      </if>
    </set>
    where id_ = #{id,jdbcType=INTEGER}
  </update>

	<select id="queryCount" parameterType="map" resultType="int">
		select count(*) from luck_draw_group
		<where>
			<if test="search != null">
				and name_ like concat('%',#{search},'%')
			</if>
		</where>
	</select>

	<select id="queryPage" parameterType="map" resultMap="BaseResultMap">
		select * from luck_draw_group
		<where>
			<if test="search != null">
				and name_ like concat('%',#{search},'%')
			</if>
		</where>
		order by create_on_ desc
		<include refid="global.limit" />
	</select>
</mapper>