mitao
2025-01-17 afa0dbb4f54e7244835dd67ec33c3e545f122f71
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
<?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.ruoyi.member.mapper.coupon.CouponTotalMapper">
 
    <resultMap type="CouponTotal" id="CouponTotalResult">
        <result property="couponId"    column="coupon_id"    />
        <result property="sendCount"    column="send_count"    />
        <result property="sendUserCount"    column="send_user_count"    />
    </resultMap>
 
    <sql id="selectCouponTotalVo">
        select coupon_id, send_count, send_user_count from t_coupon_total
    </sql>
 
    <select id="selectCouponTotalList" parameterType="CouponTotal" resultMap="CouponTotalResult">
        <include refid="selectCouponTotalVo"/>
        <where>
            <if test="sendCount != null "> and send_count = #{sendCount}</if>
            <if test="sendUserCount != null "> and send_user_count = #{sendUserCount}</if>
        </where>
    </select>
 
    <select id="selectCouponTotalByCouponId" parameterType="String" resultMap="CouponTotalResult">
        <include refid="selectCouponTotalVo"/>
        where coupon_id = #{couponId}
    </select>
 
    <insert id="insertCouponTotal" parameterType="CouponTotal">
        insert into t_coupon_total
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="couponId != null">coupon_id,</if>
            <if test="sendCount != null">send_count,</if>
            <if test="sendUserCount != null">send_user_count,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="couponId != null">#{couponId},</if>
            <if test="sendCount != null">#{sendCount},</if>
            <if test="sendUserCount != null">#{sendUserCount},</if>
        </trim>
    </insert>
 
    <update id="updateCouponTotal" parameterType="CouponTotal">
        update t_coupon_total
        <trim prefix="SET" suffixOverrides=",">
            <if test="sendCount != null">send_count = #{sendCount},</if>
            <if test="sendUserCount != null">send_user_count = #{sendUserCount},</if>
        </trim>
        where coupon_id = #{couponId}
    </update>
 
    <delete id="deleteCouponTotalByCouponId" parameterType="String">
        delete from t_coupon_total where coupon_id = #{couponId}
    </delete>
 
    <delete id="deleteCouponTotalByCouponIds" parameterType="String">
        delete from t_coupon_total where coupon_id in
        <foreach item="couponId" collection="array" open="(" separator="," close=")">
            #{couponId}
        </foreach>
    </delete>
 
    <update id="updateCouponTotal">
        UPDATE t_coupon_total tct,t_coupon tc
        SET tct.send_count = tct.send_count + #{sendCount},tct.send_user_count = tct.send_user_count + #{sendUserCount}
        WHERE tct.coupon_id = #{couponId} AND tc.coupon_id = tct.coupon_id AND (tc.send_limit_flag = 0 OR (tc.send_limit_flag = 1 AND tct.send_count + #{sendCount} &lt;= tc.send_limit_number))
    </update>
</mapper>