admin
2020-05-20 98b1a0affd69bbe63223c21fdd2c404e8bedfccb
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
<?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.UserSystemCouponGiveRecordMapper">
  <resultMap id="BaseResultMap" type="com.yeshi.fanli.entity.bus.user.UserSystemCouponGiveRecord">
    <id column="cgr_id" property="id" jdbcType="BIGINT"/>
    <result column="cgr_coupon_id" property="couponId" jdbcType="BIGINT"/>
    <result column="cgr_give_uid" property="giveUid" jdbcType="BIGINT"/>
    <result column="cgr_give_time" property="giveTime" jdbcType="TIMESTAMP"/>
    <result column="cgr_end_time" property="endTime" jdbcType="TIMESTAMP"/>
    <result column="cgr_receive_uid" property="receiveUid" jdbcType="BIGINT"/>
    <result column="cgr_receive_id" property="receiveId" jdbcType="BIGINT"/>
    <result column="cgr_receive_time" property="receiveTime" jdbcType="TIMESTAMP"/>
    <result column="cgr_state" property="state" jdbcType="INTEGER"/>
    
    <result column="couponName" property="couponName" jdbcType="VARCHAR"/>
  </resultMap>
  <sql id="Base_Column_List">cgr_id,cgr_coupon_id,cgr_give_uid,cgr_give_time,cgr_end_time,cgr_receive_uid,cgr_receive_id,cgr_receive_time,cgr_state</sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long">select
    <include refid="Base_Column_List"/>from yeshi_ec_user_system_coupon_give_record where cgr_id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from yeshi_ec_user_system_coupon_give_record where cgr_id = #{id,jdbcType=BIGINT}</delete>
  <insert id="insert" parameterType="com.yeshi.fanli.entity.bus.user.UserSystemCouponGiveRecord" useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_user_system_coupon_give_record (cgr_id,cgr_coupon_id,cgr_give_uid,cgr_give_time,cgr_end_time,cgr_receive_uid,cgr_receive_id,cgr_receive_time,cgr_state) values (#{id,jdbcType=BIGINT},#{couponId,jdbcType=BIGINT},#{giveUid,jdbcType=BIGINT},#{giveTime,jdbcType=TIMESTAMP},#{endTime,jdbcType=TIMESTAMP},#{receiveUid,jdbcType=BIGINT},#{receiveId,jdbcType=BIGINT},#{receiveTime,jdbcType=TIMESTAMP},#{state,jdbcType=INTEGER})</insert>
  <insert id="insertSelective" parameterType="com.yeshi.fanli.entity.bus.user.UserSystemCouponGiveRecord" useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_user_system_coupon_give_record
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">cgr_id,</if>
      <if test="couponId != null">cgr_coupon_id,</if>
      <if test="giveUid != null">cgr_give_uid,</if>
      <if test="giveTime != null">cgr_give_time,</if>
      <if test="endTime != null">cgr_end_time,</if>
      <if test="receiveUid != null">cgr_receive_uid,</if>
      <if test="receiveId != null">cgr_receive_id,</if>
      <if test="receiveTime != null">cgr_receive_time,</if>
      <if test="state != null">cgr_state,</if>
    </trim>values
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">#{id,jdbcType=BIGINT},</if>
      <if test="couponId != null">#{couponId,jdbcType=BIGINT},</if>
      <if test="giveUid != null">#{giveUid,jdbcType=BIGINT},</if>
      <if test="giveTime != null">#{giveTime,jdbcType=TIMESTAMP},</if>
      <if test="endTime != null">#{endTime,jdbcType=TIMESTAMP},</if>
      <if test="receiveUid != null">#{receiveUid,jdbcType=BIGINT},</if>
      <if test="receiveId != null">#{receiveId,jdbcType=BIGINT},</if>
      <if test="receiveTime != null">#{receiveTime,jdbcType=TIMESTAMP},</if>
      <if test="state != null">#{state,jdbcType=INTEGER},</if>
    </trim>
  </insert>
  <update id="updateByPrimaryKey" parameterType="com.yeshi.fanli.entity.bus.user.UserSystemCouponGiveRecord">update yeshi_ec_user_system_coupon_give_record set cgr_coupon_id = #{couponId,jdbcType=BIGINT},cgr_give_uid = #{giveUid,jdbcType=BIGINT},cgr_give_time = #{giveTime,jdbcType=TIMESTAMP},cgr_end_time = #{endTime,jdbcType=TIMESTAMP},cgr_receive_uid = #{receiveUid,jdbcType=BIGINT},cgr_receive_id = #{receiveId,jdbcType=BIGINT},cgr_receive_time = #{receiveTime,jdbcType=TIMESTAMP},cgr_state = #{state,jdbcType=INTEGER} where cgr_id = #{id,jdbcType=BIGINT}</update>
  <update id="updateByPrimaryKeySelective" parameterType="com.yeshi.fanli.entity.bus.user.UserSystemCouponGiveRecord">update yeshi_ec_user_system_coupon_give_record
    <set>
      <if test="couponId != null">cgr_coupon_id=#{couponId,jdbcType=BIGINT},</if>
      <if test="giveUid != null">cgr_give_uid=#{giveUid,jdbcType=BIGINT},</if>
      <if test="giveTime != null">cgr_give_time=#{giveTime,jdbcType=TIMESTAMP},</if>
      <if test="endTime != null">cgr_end_time=#{endTime,jdbcType=TIMESTAMP},</if>
      <if test="receiveUid != null">cgr_receive_uid=#{receiveUid,jdbcType=BIGINT},</if>
      <if test="receiveId != null">cgr_receive_id=#{receiveId,jdbcType=BIGINT},</if>
      <if test="receiveTime != null">cgr_receive_time=#{receiveTime,jdbcType=TIMESTAMP},</if>
      <if test="state != null">cgr_state=#{state,jdbcType=INTEGER},</if>
    </set> where cgr_id = #{id,jdbcType=BIGINT}
  </update>
  
   <select id="getRecordByUidAndCouponId" resultMap="BaseResultMap">
    SELECT * FROM yeshi_ec_user_system_coupon_give_record
    WHERE cgr_state = 0  AND cgr_give_uid = #{uid} AND  cgr_coupon_id = #{couponId} 
    ORDER BY cgr_give_time desc
    LIMIT 1 
  </select>
  
  <select id="getByCouponId" resultMap="BaseResultMap">
    SELECT * FROM yeshi_ec_user_system_coupon_give_record
    WHERE cgr_state = 0 AND  cgr_coupon_id = #{couponId} 
    ORDER BY cgr_give_time desc
    LIMIT 1 
  </select>
  
  
  <select id="overdueList" resultMap="BaseResultMap">
      SELECT * FROM yeshi_ec_user_system_coupon_give_record d
    WHERE d.`cgr_state` = 0 AND d.`cgr_end_time` IS NOT NULL AND d.`cgr_end_time` <![CDATA[<]]> NOW()
    LIMIT #{count}
  </select>
  
  <select id="overdueListByUser" resultMap="BaseResultMap">
      SELECT * FROM yeshi_ec_user_system_coupon_give_record d
    WHERE d.cgr_give_uid = #{uid} AND d.`cgr_state` = 0 AND d.`cgr_end_time` IS NOT NULL 
          AND d.`cgr_end_time` <![CDATA[<]]> NOW()
  </select>
  
   <select id="getByReceiveId" resultMap="BaseResultMap">
      SELECT * FROM yeshi_ec_user_system_coupon_give_record d
    WHERE d.cgr_receive_id = #{receiveId}
    LIMIT 1 
  </select>
  
  <select id="listGiveRecord" resultMap="BaseResultMap" >
      SELECT g.*,p.`sc_name` AS couponName FROM `yeshi_ec_user_system_coupon_give_record` g
    LEFT JOIN yeshi_ec_user_system_coupon c ON c.`usc_id` = g.`cgr_coupon_id`
    LEFT JOIN  yeshi_ec_system_coupon p ON p.`sc_id` = c.`usc_coupon_id`
    WHERE 1=1
        <if test="type != null">AND p.`sc_type` = #{type} </if>
        <if test="state != null">AND g.`cgr_state` = #{state} </if>
    ORDER BY g.`cgr_give_time` DESC
    LIMIT ${start},${count}
  </select>
  
  <select id="countGiveRecord" resultType="Long">
    SELECT IFNULL(COUNT(g.`cgr_id`),0) FROM `yeshi_ec_user_system_coupon_give_record` g
    LEFT JOIN yeshi_ec_user_system_coupon c ON c.`usc_id` = g.`cgr_coupon_id`
    LEFT JOIN  yeshi_ec_system_coupon p ON p.`sc_id` = c.`usc_coupon_id`
    WHERE 1=1
        <if test="type != null">AND p.`sc_type` = #{type} </if>
        <if test="state != null">AND g.`cgr_state` = #{state} </if>
  </select>
  
</mapper>