<?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.yeshi.fanli.dao.mybatis.user.UserSystemCouponMapper">
|
<resultMap id="BaseResultMap" type="com.yeshi.fanli.entity.bus.user.UserSystemCoupon">
|
<id column="usc_id" property="id" jdbcType="BIGINT"/>
|
<result column="usc_uid" property="uid" jdbcType="BIGINT"/>
|
<result column="usc_source" property="source" jdbcType="VARCHAR"/>
|
<result column="usc_give" property="give" jdbcType="VARCHAR"/>
|
<result column="usc_state" property="state" jdbcType="INTEGER"/>
|
<result column="usc_state_activate" property="stateActivated" jdbcType="INTEGER"/>
|
<result column="usc_start_time" property="startTime" jdbcType="TIMESTAMP"/>
|
<result column="usc_end_time" property="endTime" jdbcType="TIMESTAMP"/>
|
<result column="usc_use_time" property="useTime" jdbcType="TIMESTAMP"/>
|
<result column="usc_create_time" property="createTime" jdbcType="TIMESTAMP"/>
|
<result column="usc_update_time" property="updateTime" jdbcType="TIMESTAMP"/>
|
|
<association column="usc_coupon_id" property="systemCoupon"
|
javaType="com.yeshi.fanli.entity.system.SystemCoupon">
|
<id column="usc_coupon_id" property="id" jdbcType="BIGINT" />
|
</association>
|
</resultMap>
|
|
|
<resultMap id="AllResultMap" type="com.yeshi.fanli.entity.bus.user.UserSystemCoupon">
|
<id column="usc_id" property="id" jdbcType="BIGINT"/>
|
<result column="usc_uid" property="uid" jdbcType="BIGINT"/>
|
<result column="usc_source" property="source" jdbcType="VARCHAR"/>
|
<result column="usc_give" property="give" jdbcType="VARCHAR"/>
|
<result column="usc_state" property="state" jdbcType="INTEGER"/>
|
<result column="usc_state_activate" property="stateActivated" jdbcType="INTEGER"/>
|
<result column="usc_start_time" property="startTime" jdbcType="TIMESTAMP"/>
|
<result column="usc_end_time" property="endTime" jdbcType="TIMESTAMP"/>
|
<result column="usc_use_time" property="useTime" jdbcType="TIMESTAMP"/>
|
<result column="usc_create_time" property="createTime" jdbcType="TIMESTAMP"/>
|
<result column="usc_update_time" property="updateTime" jdbcType="TIMESTAMP"/>
|
|
<association property="systemCoupon" column="usc_coupon_id"
|
resultMap="com.yeshi.fanli.dao.mybatis.SystemCouponMapper.BaseResultMap"/>
|
</resultMap>
|
|
<resultMap id="ResultVOMap" type="com.yeshi.fanli.vo.user.UserSystemCouponVO">
|
<id column="usc_id" property="id" jdbcType="BIGINT"/>
|
<result column="usc_uid" property="uid" jdbcType="BIGINT"/>
|
<result column="usc_source" property="source" jdbcType="VARCHAR"/>
|
<result column="usc_give" property="give" jdbcType="VARCHAR"/>
|
<result column="usc_state" property="state" jdbcType="INTEGER"/>
|
<result column="usc_state_activate" property="stateActivated" jdbcType="INTEGER"/>
|
<result column="usc_start_time" property="startTime" jdbcType="TIMESTAMP"/>
|
<result column="usc_end_time" property="endTime" jdbcType="TIMESTAMP"/>
|
<result column="usc_use_time" property="useTime" jdbcType="TIMESTAMP"/>
|
<result column="usc_create_time" property="createTime" jdbcType="TIMESTAMP"/>
|
<result column="usc_update_time" property="updateTime" jdbcType="TIMESTAMP"/>
|
|
<association column="usc_coupon_id" property="systemCoupon"
|
javaType="com.yeshi.fanli.entity.system.SystemCoupon">
|
<id column="usc_coupon_id" property="id" jdbcType="BIGINT" />
|
</association>
|
|
</resultMap>
|
|
<sql id="Base_Column_List">usc_id,usc_uid,usc_coupon_id,usc_source,usc_give,usc_state,usc_state_activate,usc_start_time,usc_end_time,usc_use_time,usc_create_time,usc_update_time</sql>
|
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long">select
|
<include refid="Base_Column_List"/>from yeshi_ec_user_system_coupon where usc_id = #{id,jdbcType=BIGINT}
|
</select>
|
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from yeshi_ec_user_system_coupon where usc_id = #{id,jdbcType=BIGINT}</delete>
|
<insert id="insert" parameterType="com.yeshi.fanli.entity.bus.user.UserSystemCoupon" useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_user_system_coupon (usc_id,usc_uid,usc_coupon_id,usc_source,usc_give,usc_state,usc_state_activate,usc_start_time,usc_end_time,usc_use_time,usc_create_time,usc_update_time) values (#{id,jdbcType=BIGINT},#{uid,jdbcType=BIGINT},#{systemCoupon.id,jdbcType=BIGINT},#{source,jdbcType=VARCHAR},#{give,jdbcType=VARCHAR},#{state,jdbcType=INTEGER},#{stateActivated,jdbcType=INTEGER},#{startTime,jdbcType=TIMESTAMP},#{endTime,jdbcType=TIMESTAMP},#{useTime,jdbcType=TIMESTAMP},#{createTime,jdbcType=TIMESTAMP},#{updateTime,jdbcType=TIMESTAMP})</insert>
|
<insert id="insertSelective" parameterType="com.yeshi.fanli.entity.bus.user.UserSystemCoupon" useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_user_system_coupon
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
<if test="id != null">usc_id,</if>
|
<if test="uid != null">usc_uid,</if>
|
<if test="systemCoupon != null">usc_coupon_id,</if>
|
<if test="source != null">usc_source,</if>
|
<if test="give != null">usc_give,</if>
|
<if test="state != null">usc_state,</if>
|
<if test="stateActivated != null">usc_state_activate,</if>
|
<if test="startTime != null">usc_start_time,</if>
|
<if test="endTime != null">usc_end_time,</if>
|
<if test="useTime != null">usc_use_time,</if>
|
<if test="createTime != null">usc_create_time,</if>
|
<if test="updateTime != null">usc_update_time,</if>
|
</trim>values
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
<if test="id != null">#{id,jdbcType=BIGINT},</if>
|
<if test="uid != null">#{uid,jdbcType=BIGINT},</if>
|
<if test="systemCoupon != null">#{systemCoupon.id,jdbcType=BIGINT},</if>
|
<if test="source != null">#{source,jdbcType=VARCHAR},</if>
|
<if test="give != null">#{give,jdbcType=VARCHAR},</if>
|
<if test="state != null">#{state,jdbcType=INTEGER},</if>
|
<if test="stateActivated != null">#{stateActivated,jdbcType=INTEGER},</if>
|
<if test="startTime != null">#{startTime,jdbcType=TIMESTAMP},</if>
|
<if test="endTime != null">#{endTime,jdbcType=TIMESTAMP},</if>
|
<if test="useTime != null">#{useTime,jdbcType=TIMESTAMP},</if>
|
<if test="createTime != null">#{createTime,jdbcType=TIMESTAMP},</if>
|
<if test="updateTime != null">#{updateTime,jdbcType=TIMESTAMP},</if>
|
</trim>
|
</insert>
|
<update id="updateByPrimaryKey" parameterType="com.yeshi.fanli.entity.bus.user.UserSystemCoupon">update yeshi_ec_user_system_coupon set usc_uid = #{uid,jdbcType=BIGINT},usc_coupon_id = #{systemCoupon.id,jdbcType=BIGINT},usc_source = #{source,jdbcType=VARCHAR},usc_give = #{give,jdbcType=VARCHAR},usc_state = #{state,jdbcType=INTEGER},usc_state_activate = #{stateActivated,jdbcType=INTEGER},usc_start_time = #{startTime,jdbcType=TIMESTAMP},usc_end_time = #{endTime,jdbcType=TIMESTAMP},usc_use_time = #{useTime,jdbcType=TIMESTAMP},usc_create_time = #{createTime,jdbcType=TIMESTAMP},usc_update_time = #{updateTime,jdbcType=TIMESTAMP} where usc_id = #{id,jdbcType=BIGINT}</update>
|
<update id="updateByPrimaryKeySelective" parameterType="com.yeshi.fanli.entity.bus.user.UserSystemCoupon">update yeshi_ec_user_system_coupon
|
<set>
|
<if test="uid != null">usc_uid=#{uid,jdbcType=BIGINT},</if>
|
<if test="systemCoupon != null">usc_coupon_id=#{systemCoupon.id,jdbcType=BIGINT},</if>
|
<if test="source != null">usc_source=#{source,jdbcType=VARCHAR},</if>
|
<if test="give != null">usc_give=#{give,jdbcType=VARCHAR},</if>
|
<if test="state != null">usc_state=#{state,jdbcType=INTEGER},</if>
|
<if test="stateActivated != null">usc_state_activate=#{stateActivated,jdbcType=INTEGER},</if>
|
<if test="startTime != null">usc_start_time=#{startTime,jdbcType=TIMESTAMP},</if>
|
<if test="endTime != null">usc_end_time=#{endTime,jdbcType=TIMESTAMP},</if>
|
<if test="useTime != null">usc_use_time=#{useTime,jdbcType=TIMESTAMP},</if>
|
<if test="createTime != null">usc_create_time=#{createTime,jdbcType=TIMESTAMP},</if>
|
<if test="updateTime != null">usc_update_time=#{updateTime,jdbcType=TIMESTAMP},</if>
|
</set> where usc_id = #{id,jdbcType=BIGINT}
|
</update>
|
|
<select id="getUserCouponList" resultMap="BaseResultMap">
|
SELECT * FROM `yeshi_ec_user_system_coupon` uc
|
WHERE uc.`usc_uid`= #{uid}
|
ORDER BY uc.`usc_state`,uc.`usc_create_time` DESC
|
LIMIT #{start},#{count}
|
</select>
|
|
<select id="getUserCouponBySource" resultMap="BaseResultMap">
|
SELECT * FROM `yeshi_ec_user_system_coupon` uc
|
WHERE uc.`usc_uid`= #{uid} AND usc_source = #{source}
|
</select>
|
|
<select id="countTodatyUserCouponBySource" resultType="java.lang.Integer">
|
SELECT IFNULL(COUNT(uc.`usc_id`),0) FROM `yeshi_ec_user_system_coupon` uc
|
WHERE uc.`usc_uid`= #{uid} AND usc_source = #{source}
|
AND TO_DAYS(uc.`usc_create_time`) = TO_DAYS(NOW())
|
</select>
|
|
|
<select id="getCouponListOld" resultMap="ResultVOMap">
|
SELECT * FROM `yeshi_ec_user_system_coupon` uc
|
LEFT JOIN `yeshi_ec_system_coupon` c ON uc.`usc_coupon_id` = c.`sc_id`
|
WHERE uc.`usc_uid`= #{uid} AND DATEDIFF(NOW(), uc.`usc_end_time`)<![CDATA[<=]]> 30
|
AND (uc.`usc_give` IS NULL OR uc.`usc_give` = 0) AND c.`sc_type` NOT IN ('freeCoupon','freeCouponBuy','freeCouponGive')
|
ORDER BY uc.`usc_state`,uc.`usc_create_time` DESC
|
LIMIT #{start},#{count}
|
</select>
|
|
<select id="countCouponOld" resultType="java.lang.Long">
|
SELECT IFNULL(count(uc.`usc_id`),0) FROM `yeshi_ec_user_system_coupon` uc
|
LEFT JOIN `yeshi_ec_system_coupon` c ON uc.`usc_coupon_id` = c.`sc_id`
|
WHERE uc.`usc_uid`= #{uid} AND DATEDIFF(NOW(), uc.`usc_end_time`)<![CDATA[<=]]> 30
|
AND (uc.`usc_give` IS NULL OR uc.`usc_give` = 0) AND c.`sc_type` NOT IN ('freeCoupon','freeCouponBuy','freeCouponGive')
|
</select>
|
|
|
<select id="getUserCouponVOList" resultMap="ResultVOMap">
|
SELECT * FROM `yeshi_ec_user_system_coupon` uc
|
WHERE uc.`usc_uid`= #{uid} AND DATEDIFF(NOW(), uc.`usc_end_time`)<![CDATA[ <= ]]> 30
|
ORDER BY uc.`usc_state`,uc.`usc_create_time` DESC
|
LIMIT #{start},#{count}
|
</select>
|
|
<select id="countUserCouponList" resultType="java.lang.Long">
|
SELECT IFNULL(count(uc.`usc_id`),0) FROM `yeshi_ec_user_system_coupon` uc
|
WHERE uc.`usc_uid`= #{uid} AND DATEDIFF(NOW(), uc.`usc_end_time`)<![CDATA[ <= ]]> 30
|
</select>
|
|
<select id="getEnableListByCouponId" resultMap="ResultVOMap">
|
SELECT * FROM `yeshi_ec_user_system_coupon` uc
|
WHERE uc.`usc_uid`= #{uid} AND uc.usc_state = 1
|
AND DATE_FORMAT(CURDATE(),'%Y%m%d') <![CDATA[ >= ]]>DATE_FORMAT(uc.`usc_start_time`,'%Y%m%d')
|
<if test="activated != null">AND uc.usc_state_activate = #{activated}</if>
|
AND uc.usc_coupon_id in
|
<foreach collection="list" item="item" open="(" close=")"
|
separator=",">#{item}</foreach>
|
ORDER BY uc.usc_state_activate desc, uc.`usc_create_time`
|
</select>
|
|
<select id="getValidByUidAndType" resultMap="ResultVOMap">
|
SELECT * FROM `yeshi_ec_user_system_coupon` t
|
LEFT JOIN `yeshi_ec_system_coupon` c ON t.`usc_coupon_id` = c.`sc_id`
|
WHERE t.usc_state = 1 AND t.usc_state_activate = 1 AND t.usc_uid = #{uid}
|
AND c.`sc_type`= #{type} AND t.`usc_end_time` <![CDATA[>]]> NOW()
|
</select>
|
|
|
|
<select id="countUsableByUid" resultType="java.lang.Long">
|
SELECT IFNULL(count(cp.`usc_id`),0) FROM `yeshi_ec_user_system_coupon` cp
|
WHERE cp.`usc_state` = 1 AND cp.usc_state_activate = 1
|
AND cp.`usc_end_time` <![CDATA[>]]> NOW() AND cp.`usc_uid`= #{uid}
|
AND cp.usc_coupon_id in
|
<foreach collection="list" item="item" open="(" close=")"
|
separator=",">#{item}</foreach>
|
</select>
|
|
|
<select id="getCounponNowInvalid" resultMap="BaseResultMap">
|
SELECT * FROM `yeshi_ec_user_system_coupon` cp
|
WHERE <![CDATA[cp.`usc_state` <> 3 AND cp.`usc_state` <> 4]]>
|
AND DATE_FORMAT(CURDATE(),'%Y%m%d') <![CDATA[>]]> DATE_FORMAT(cp.`usc_end_time`,'%Y%m%d')
|
LIMIT #{count}
|
</select>
|
|
|
<select id="getCounponNowInvalidByUid" resultMap="BaseResultMap">
|
SELECT * FROM `yeshi_ec_user_system_coupon` cp
|
WHERE cp.`usc_uid` = #{uid} AND <![CDATA[cp.`usc_state` <> 3 AND cp.`usc_state` <> 4]]>
|
AND DATE_FORMAT(CURDATE(),'%Y%m%d') <![CDATA[>]]> DATE_FORMAT(cp.`usc_end_time`,'%Y%m%d')
|
</select>
|
|
<select id="getCouponByState" resultMap="BaseResultMap">
|
SELECT * FROM `yeshi_ec_user_system_coupon` cp
|
WHERE cp.`usc_uid` = #{uid}
|
<if test="state != null">
|
AND cp.`usc_state` = #{state}
|
</if>
|
</select>
|
|
<select id="getCouponByTypeAndNotActivated" resultMap="BaseResultMap">
|
SELECT * FROM yeshi_ec_user_system_coupon
|
WHERE usc_uid = #{uid} AND usc_coupon_id = #{couponId}
|
AND (usc_state_activate = 0 OR usc_state_activate is null)
|
</select>
|
|
<select id="getCouponByUsingTimeOut" resultMap="BaseResultMap">
|
SELECT * FROM `yeshi_ec_user_system_coupon` cp
|
WHERE cp.`usc_uid` = #{uid} AND cp.`usc_state` = 2 AND (cp.usc_give = 0 or cp.usc_give is null)
|
AND (UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(cp.`usc_use_time`)) <![CDATA[>]]> #{number}
|
AND cp.usc_coupon_id in
|
<foreach collection="list" item="item" open="(" close=")"
|
separator=",">#{item}</foreach>
|
</select>
|
|
<select id="getFreeCouponByType" resultMap="BaseResultMap">
|
SELECT * FROM `yeshi_ec_user_system_coupon` t
|
LEFT JOIN `yeshi_ec_system_coupon` c ON t.`usc_coupon_id` = c.`sc_id`
|
WHERE t.usc_uid = #{uid} AND c.`sc_type`= #{type}
|
</select>
|
|
<select id="getNeedActivateCouponByType" resultMap="AllResultMap">
|
SELECT * FROM `yeshi_ec_user_system_coupon` t
|
LEFT JOIN `yeshi_ec_system_coupon` c ON t.`usc_coupon_id` = c.`sc_id`
|
WHERE t.usc_uid = #{uid} AND c.`sc_type`= #{type} AND t.`usc_state` = 1
|
AND (t.usc_state_activate = 0 OR t.usc_state_activate is null)
|
AND t.`usc_end_time` <![CDATA[>]]> NOW()
|
ORDER BY usc_id
|
LIMIT 1
|
</select>
|
|
</mapper>
|