yujian
2019-08-27 d8359ddb48dab5cc797a9d552e11fde571f4920c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<?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="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="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="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="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>
  
</mapper>