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
<?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.UserSystemCouponRecordMapper">
  <resultMap id="BaseResultMap" type="com.yeshi.fanli.entity.bus.user.UserSystemCouponRecord">
    <id column="ucr_id" property="id" jdbcType="BIGINT"/>
    <result column="ucr_good_id" property="goodId" jdbcType="BIGINT"/>
    <result column="ucr_good_source" property="goodSource" jdbcType="VARCHAR"/>
    <result column="ucr_coupon_type" property="couponType" jdbcType="VARCHAR"/>
    <result column="ucr_order_no" property="orderNo" jdbcType="VARCHAR"/>
    <result column="ucr_state" property="state" jdbcType="INTEGER"/>
    <result column="ucr_create_time" property="createTime" jdbcType="TIMESTAMP"/>
    <result column="ucr_update_time" property="updateTime" jdbcType="TIMESTAMP"/>
    
    <association property="userSystemCoupon" column="ucr_user_coupon_id" 
        resultMap="com.yeshi.fanli.dao.mybatis.user.UserSystemCouponMapper.BaseResultMap"/>
        
  </resultMap>
  <sql id="Base_Column_List">ucr_id,ucr_good_id,ucr_good_source,ucr_user_coupon_id,ucr_coupon_type,ucr_order_no,ucr_state,ucr_create_time,ucr_update_time</sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long">select
    <include refid="Base_Column_List"/>from yeshi_ec_user_system_coupon_record where ucr_id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from yeshi_ec_user_system_coupon_record where ucr_id = #{id,jdbcType=BIGINT}</delete>
  <insert id="insert" parameterType="com.yeshi.fanli.entity.bus.user.UserSystemCouponRecord" useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_user_system_coupon_record (ucr_id,ucr_good_id,ucr_good_source,ucr_user_coupon_id,ucr_coupon_type,ucr_order_no,ucr_state,ucr_create_time,ucr_update_time) values (#{id,jdbcType=BIGINT},#{goodId,jdbcType=BIGINT},#{goodSource,jdbcType=VARCHAR},#{userSystemCoupon.id,jdbcType=BIGINT},#{couponType,jdbcType=VARCHAR},#{orderNo,jdbcType=VARCHAR},#{state,jdbcType=INTEGER},#{createTime,jdbcType=TIMESTAMP},#{updateTime,jdbcType=TIMESTAMP})</insert>
  <insert id="insertSelective" parameterType="com.yeshi.fanli.entity.bus.user.UserSystemCouponRecord" useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_user_system_coupon_record
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">ucr_id,</if>
      <if test="goodId != null">ucr_good_id,</if>
      <if test="goodSource != null">ucr_good_source,</if>
      <if test="userSystemCoupon != null">ucr_user_coupon_id,</if>
      <if test="couponType != null">ucr_coupon_type,</if>
      <if test="orderNo != null">ucr_order_no,</if>
      <if test="state != null">ucr_state,</if>
      <if test="createTime != null">ucr_create_time,</if>
      <if test="updateTime != null">ucr_update_time,</if>
    </trim>values
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">#{id,jdbcType=BIGINT},</if>
      <if test="goodId != null">#{goodId,jdbcType=BIGINT},</if>
      <if test="goodSource != null">#{goodSource,jdbcType=VARCHAR},</if>
      <if test="userSystemCoupon != null">#{userSystemCoupon.id,jdbcType=BIGINT},</if>
      <if test="couponType != null">#{couponType,jdbcType=VARCHAR},</if>
      <if test="orderNo != null">#{orderNo,jdbcType=VARCHAR},</if>
      <if test="state != null">#{state,jdbcType=INTEGER},</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.UserSystemCouponRecord">update yeshi_ec_user_system_coupon_record set ucr_good_id = #{goodId,jdbcType=BIGINT},ucr_good_source = #{goodSource,jdbcType=VARCHAR},ucr_user_coupon_id = #{userSystemCoupon.id,jdbcType=BIGINT},ucr_coupon_type = #{couponType,jdbcType=VARCHAR},ucr_order_no = #{orderNo,jdbcType=VARCHAR},ucr_state = #{state,jdbcType=INTEGER},ucr_create_time = #{createTime,jdbcType=TIMESTAMP},ucr_update_time = #{updateTime,jdbcType=TIMESTAMP} where ucr_id = #{id,jdbcType=BIGINT}</update>
  <update id="updateByPrimaryKeySelective" parameterType="com.yeshi.fanli.entity.bus.user.UserSystemCouponRecord">update yeshi_ec_user_system_coupon_record
    <set>
      <if test="goodId != null">ucr_good_id=#{goodId,jdbcType=BIGINT},</if>
      <if test="goodSource != null">ucr_good_source=#{goodSource,jdbcType=VARCHAR},</if>
      <if test="userSystemCoupon != null">ucr_user_coupon_id=#{userSystemCoupon.id,jdbcType=BIGINT},</if>
      <if test="couponType != null">ucr_coupon_type=#{couponType,jdbcType=VARCHAR},</if>
      <if test="orderNo != null">ucr_order_no=#{orderNo,jdbcType=VARCHAR},</if>
      <if test="state != null">ucr_state=#{state,jdbcType=INTEGER},</if>
      <if test="createTime != null">ucr_create_time=#{createTime,jdbcType=TIMESTAMP},</if>
      <if test="updateTime != null">ucr_update_time=#{updateTime,jdbcType=TIMESTAMP},</if>
    </set> where ucr_id = #{id,jdbcType=BIGINT}
  </update>
  
  
  <select id="getRecordByState" resultMap="BaseResultMap">
      SELECT * FROM  `yeshi_ec_user_system_coupon_record` cd 
      LEFT JOIN `yeshi_ec_user_system_coupon` uc ON uc.`usc_id` = cd.`ucr_user_coupon_id`
    WHERE uc.`usc_uid` = #{uid} AND cd.`ucr_state` = #{state}
  </select>
  
  <select id="getRecordByOrderNo" resultMap="BaseResultMap">
      SELECT * FROM  `yeshi_ec_user_system_coupon_record` cd 
      LEFT JOIN `yeshi_ec_user_system_coupon` uc ON uc.`usc_id` = cd.`ucr_user_coupon_id`
    WHERE cd.`ucr_order_no` = #{orderNo} 
        <if test="state != null">
            AND cd.`ucr_state` = #{state}
        </if>
  </select>
  
  <select id="getRecordByOrderNoList" resultMap="BaseResultMap">
    SELECT * FROM  `yeshi_ec_user_system_coupon_record` cd 
      LEFT JOIN `yeshi_ec_user_system_coupon` uc ON uc.`usc_id` = cd.`ucr_user_coupon_id`
    WHERE <if test="source == 1">(cd.ucr_good_source = 0 or cd.ucr_good_source = 1)</if>
          <if test="source == 2">cd.ucr_good_source = 2</if>
            <if test="source == 3">cd.ucr_good_source = 3</if>
            AND cd.`ucr_order_no` in
        <foreach collection="list" item="item" open="(" close=")"
            separator=",">#{item}</foreach>
  </select>
  
  <select id="getNearByUserCouponId" resultMap="BaseResultMap">
    SELECT * FROM  `yeshi_ec_user_system_coupon_record`
    WHERE ucr_user_coupon_id = #{userCouponId}
    ORDER BY ucr_create_time DESC
    LIMIT 1
  </select>
  
</mapper>