UserCouponMapper.xml 4.22 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.yoho.ufo.dal.UserCouponMapper">
    <resultMap id="BaseResultMap" type="com.yoho.ufo.model.coupon.UserCoupon">
        <result column="id" property="id" jdbcType="INTEGER" />
        <result column="uid" property="uid" jdbcType="INTEGER" />
        <result column="coupon_id" property="couponId" jdbcType="INTEGER" />
        <result column="user_type" property="userType" jdbcType="INTEGER" />
        <result column="coupon_type" property="couponType" jdbcType="INTEGER" />
        <result column="coupon_code" property="couponCode" jdbcType="VARCHAR" />
        <result column="status" property="status" jdbcType="INTEGER" />
        <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" />
        <result column="coupon_token" property="couponToken" jdbcType="VARCHAR" />
    </resultMap>

    <sql id="Base_Column_List">
        id,uid,coupon_id,user_type,coupon_type,coupon_code,status,order_code,use_time,start_time,end_time,create_time,coupon_token
    </sql>


    <select id="selectByCouponIds" resultType="com.yoho.ufo.model.coupon.UserCouponNum">
        select
        count(uid) cnt, coupon_id
        from user_coupon
        where
        coupon_id IN
        <foreach collection="couponIds" item="couponId" open="(" separator="," close=")">
            #{couponId,jdbcType=INTEGER}
        </foreach>
        group by coupon_id
    </select>


    <select id="selectByCouponId" resultType="com.yoho.ufo.model.coupon.UserCouponNum">
        select
        count(uid) cnt, coupon_id
        from user_coupon
        where
        coupon_id=#{couponId,jdbcType=INTEGER}
        group by coupon_id
    </select>


    <select id="selectByCouponIdsAndStatus" resultType="com.yoho.ufo.model.coupon.UserCouponNum">
        select
        count(uid) cnt, coupon_id
        from user_coupon
        where
        status=1 and
        coupon_id IN
        <foreach collection="couponIds" item="couponId" open="(" separator="," close=")">
            #{couponId,jdbcType=INTEGER}
        </foreach>
        group by coupon_id
    </select>


    <select id="selectByCondition" resultType="com.yoho.ufo.model.coupon.UserCoupon">
        select <include refid="Base_Column_List"/> from user_coupon
        inner join (
            select id from user_coupon
            <where>
                <if test="param.couponId != null">
                    and coupon_Id=#{param.couponId}
                </if>
                <if test="param.couponCode != null">
                    and coupon_code=#{param.couponCode}
                </if>
                <if test="param.uid != null">
                    and uid=#{param.uid}
                </if>
                <if test="param.status != null">
                    and status=#{param.status}
                </if>
            </where>
            order by id desc
            <if test="param.size > 0">
                limit #{param.start},#{param.size}
            </if>
            )
        a using(id)
    </select>
    <select id="selectTotalByCondition" resultType="java.lang.Integer">
        select count(1) from user_coupon
        where 1=1
        <if test="param.couponId != null">
            and coupon_Id=#{param.couponId}
        </if>
        <if test="param.couponCode != null">
            and coupon_code=#{param.couponCode}
        </if>
        <if test="param.uid != null">
            and uid=#{param.uid}
        </if>
        <if test="param.status != null">
            and status=#{param.status}
        </if>
    </select>

    <update id="updateEndTimeOfOneUser" parameterType="com.yoho.ufo.model.coupon.UserCoupon" >
        update user_coupon set end_time = #{endTime}
        where uid = #{uid,jdbcType=INTEGER}
        and coupon_id = #{couponId,jdbcType=INTEGER}
        and coupon_code = #{couponCode,jdbcType=VARCHAR}
    </update>
</mapper>