UserCouponMapper.xml 6.47 KB
<?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.yohoufo.dal.promotion.UserCouponMapper" >
  <resultMap id="BaseResultMap" type="com.yohoufo.dal.promotion.model.UserCoupon" >
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="uid" property="uid" jdbcType="INTEGER" />
    <result column="coupon_id" property="couponId" jdbcType="INTEGER" />
    <result column="coupon_type" property="couponType" jdbcType="TINYINT" />
    <result column="coupon_code" property="couponCode" jdbcType="VARCHAR" />
    <result column="status" property="status" jdbcType="TINYINT" />
    <result column="order_code" property="orderCode" jdbcType="BIGINT" />
    <result column="use_time" property="useTime" jdbcType="INTEGER" />
    <result column="start_time" property="startTime" jdbcType="INTEGER" />
    <result column="end_time" property="endTime" jdbcType="INTEGER" />
    <result column="create_time" property="createTime" jdbcType="INTEGER" />
  </resultMap>
  <sql id="Base_Column_List" >
    id, uid, coupon_id, coupon_type, coupon_code, status, order_code, use_time, start_time, 
    end_time, create_time
  </sql>

  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    select 
    <include refid="Base_Column_List" />
    from user_coupon
    where id = #{id,jdbcType=INTEGER}
  </select>


  <select id="selectUsableCouponByUid" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    select
    <include refid="Base_Column_List" />
    from user_coupon
    where uid = #{uid,jdbcType=INTEGER}
    <!-- 在有效时间范围内 -->
    and <![CDATA[ start_time > #{now, jdbcType=INTEGER} ]]>
    and <![CDATA[ end_time < #{now, jdbcType=INTEGER} ]]>
    <!-- 未使用-->
    and status = 0
  </select>


  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    select
    <include refid="Base_Column_List" />
    from user_coupon
    where id = #{id,jdbcType=INTEGER}
  </select>

  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
    delete from user_coupon
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.yohoufo.dal.promotion.model.UserCoupon" >
    insert into user_coupon (id, uid, coupon_id, 
      coupon_type, coupon_code, status, 
      order_code, use_time, start_time, 
      end_time, create_time)
    values (#{id,jdbcType=INTEGER}, #{uid,jdbcType=INTEGER}, #{couponId,jdbcType=INTEGER}, 
      #{couponType,jdbcType=TINYINT}, #{couponCode,jdbcType=VARCHAR}, #{status,jdbcType=TINYINT}, 
      #{orderCode,jdbcType=BIGINT}, #{useTime,jdbcType=INTEGER}, #{startTime,jdbcType=INTEGER}, 
      #{endTime,jdbcType=INTEGER}, #{createTime,jdbcType=INTEGER})
  </insert>
  <insert id="insertSelective" parameterType="com.yohoufo.dal.promotion.model.UserCoupon" >
    insert into user_coupon
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="uid != null" >
        uid,
      </if>
      <if test="couponId != null" >
        coupon_id,
      </if>
      <if test="couponType != null" >
        coupon_type,
      </if>
      <if test="couponCode != null" >
        coupon_code,
      </if>
      <if test="status != null" >
        status,
      </if>
      <if test="orderCode != null" >
        order_code,
      </if>
      <if test="useTime != null" >
        use_time,
      </if>
      <if test="startTime != null" >
        start_time,
      </if>
      <if test="endTime != null" >
        end_time,
      </if>
      <if test="createTime != null" >
        create_time,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        #{id,jdbcType=INTEGER},
      </if>
      <if test="uid != null" >
        #{uid,jdbcType=INTEGER},
      </if>
      <if test="couponId != null" >
        #{couponId,jdbcType=INTEGER},
      </if>
      <if test="couponType != null" >
        #{couponType,jdbcType=TINYINT},
      </if>
      <if test="couponCode != null" >
        #{couponCode,jdbcType=VARCHAR},
      </if>
      <if test="status != null" >
        #{status,jdbcType=TINYINT},
      </if>
      <if test="orderCode != null" >
        #{orderCode,jdbcType=BIGINT},
      </if>
      <if test="useTime != null" >
        #{useTime,jdbcType=INTEGER},
      </if>
      <if test="startTime != null" >
        #{startTime,jdbcType=INTEGER},
      </if>
      <if test="endTime != null" >
        #{endTime,jdbcType=INTEGER},
      </if>
      <if test="createTime != null" >
        #{createTime,jdbcType=INTEGER},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.yohoufo.dal.promotion.model.UserCoupon" >
    update user_coupon
    <set >
      <if test="uid != null" >
        uid = #{uid,jdbcType=INTEGER},
      </if>
      <if test="couponId != null" >
        coupon_id = #{couponId,jdbcType=INTEGER},
      </if>
      <if test="couponType != null" >
        coupon_type = #{couponType,jdbcType=TINYINT},
      </if>
      <if test="couponCode != null" >
        coupon_code = #{couponCode,jdbcType=VARCHAR},
      </if>
      <if test="status != null" >
        status = #{status,jdbcType=TINYINT},
      </if>
      <if test="orderCode != null" >
        order_code = #{orderCode,jdbcType=BIGINT},
      </if>
      <if test="useTime != null" >
        use_time = #{useTime,jdbcType=INTEGER},
      </if>
      <if test="startTime != null" >
        start_time = #{startTime,jdbcType=INTEGER},
      </if>
      <if test="endTime != null" >
        end_time = #{endTime,jdbcType=INTEGER},
      </if>
      <if test="createTime != null" >
        create_time = #{createTime,jdbcType=INTEGER},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.yohoufo.dal.promotion.model.UserCoupon" >
    update user_coupon
    set uid = #{uid,jdbcType=INTEGER},
      coupon_id = #{couponId,jdbcType=INTEGER},
      coupon_type = #{couponType,jdbcType=TINYINT},
      coupon_code = #{couponCode,jdbcType=VARCHAR},
      status = #{status,jdbcType=TINYINT},
      order_code = #{orderCode,jdbcType=BIGINT},
      use_time = #{useTime,jdbcType=INTEGER},
      start_time = #{startTime,jdbcType=INTEGER},
      end_time = #{endTime,jdbcType=INTEGER},
      create_time = #{createTime,jdbcType=INTEGER}
    where id = #{id,jdbcType=INTEGER}
  </update>
</mapper>