CouponTemplateMapper.xml 5.5 KB
Newer Older
1 2 3 4 5 6
<?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="cn.iocoder.mall.promotion.biz.dao.CouponTemplateMapper">

    <sql id="FIELDS">
        id, title, description, type, code_type,
7
        status, quota, total, price_available, range_type,
8
        range_values, date_type, valid_start_time, valid_end_time, fixed_start_term, fixed_end_term,
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
        preferential_type, percent_off, price_off, discount_price_limit, stat_fetch_num,
        create_time
    </sql>

<!--    <select id="selectListByPidAndStatusOrderBySort" resultType="CouponTemplateDO">-->
<!--        SELECT-->
<!--            <include refid="FIELDS" />-->
<!--        FROM coupon_template-->
<!--        WHERE pid = #{pid}-->
<!--        AND status = #{status}-->
<!--        AND deleted = 0-->
<!--        ORDER BY sort ASC-->
<!--    </select>-->

<!--    <select id="selectList" resultType="CouponTemplateDO">-->
<!--        SELECT-->
<!--          <include refid="FIELDS" />-->
<!--        FROM coupon_template-->
<!--        WHERE deleted = 0-->
<!--    </select>-->

    <select id="selectById" parameterType="Integer" resultType="CouponTemplateDO">
        SELECT
          <include refid="FIELDS" />
        FROM coupon_template
        WHERE id = #{id}
    </select>

    <select id="selectListByPage" resultType="CouponTemplateDO">
        SELECT
          <include refid="FIELDS" />
        FROM coupon_template
        <where>
42 43 44
            <if test="type != null">
                AND type = #{type}
            </if>
45
            <if test="title != null">
46
                AND title LIKE "%"#{title}"%"
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
            </if>
            <if test="status != null">
                AND status = #{status}
            </if>
            <if test="preferentialType != null">
                AND preferential_type = #{preferentialType}
            </if>
        </where>
        LIMIT #{offset}, #{limit}
    </select>

    <select id="selectCountByPage" resultType="Integer">
        SELECT
          COUNT(1)
        FROM coupon_template
        <where>
63 64 65
            <if test="type != null">
                AND type = #{type}
            </if>
66
            <if test="title != null">
67
                AND title LIKE "%"#{title}"%"
68 69 70 71 72 73 74 75 76 77 78 79 80
            </if>
            <if test="status != null">
                AND status = #{status}
            </if>
            <if test="preferentialType != null">
                AND preferential_type = #{preferentialType}
            </if>
        </where>
    </select>

    <insert id="insert" parameterType="CouponTemplateDO" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
        INSERT INTO coupon_template (
          title, description, type, code_type,
81
          status, quota, total, price_available, range_type,
82
          range_values, date_type, valid_start_time, valid_end_time, fixed_start_term, fixed_end_term,
83 84 85
          preferential_type, percent_off, price_off, discount_price_limit, stat_fetch_num,
          create_time
        ) VALUES (
86 87
          #{title}, #{description}, #{type}, #{codeType},
          #{status}, #{quota}, #{total}, #{priceAvailable}, #{rangeType},
88
          #{rangeValues}, #{dateType}, #{validStartTime}, #{validEndTime}, #{fixedStartTerm}, #{fixedEndTerm}
89
          #{preferentialType}, #{percentOff}, #{priceOff}, #{discountPriceLimit}, #{statFetchNum},
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
          #{createTime}
        )
    </insert>

    <update id="update" parameterType="CouponTemplateDO">
        UPDATE coupon_template
        <set>
            <if test="title != null">
                title = #{title},
            </if>
            <if test="description != null">
                description = #{description},
            </if>
            <if test="status != null">
                status = #{status},
            </if>
            <if test="quota != null">
                quota = #{quota},
            </if>
109 110
            <if test="total != null">
                total = #{total},
111 112
            </if>
            <if test="priceAvailable != null">
113
                price_available = #{priceAvailable},
114 115
            </if>
            <if test="rangeType != null">
116
                range_type = #{rangeType},
117 118
            </if>
            <if test="rangeValues != null">
119
                range_values = #{rangeValues},
120 121
            </if>
            <if test="dateType != null">
122
                date_type = #{dateType},
123 124
            </if>
            <if test="validStartTime != null">
125
                valid_start_time = #{validStartTime},
126 127
            </if>
            <if test="validEndTime != null">
128
                valid_end_time = #{validEndTime},
129
            </if>
130 131 132 133 134
            <if test="fixedStartTerm != null">
                fixed_start_term = #{fixedStartTerm},
            </if>
            <if test="fixedEndTerm != null">
                fixed_end_term = #{fixedEndTerm},
135 136
            </if>
            <if test="preferentialType != null">
137
                preferential_type = #{preferentialType},
138 139
            </if>
            <if test="percentOff != null">
140
                percent_off = #{percentOff},
141 142
            </if>
            <if test="priceOff != null">
143
                price_off = #{priceOff},
144 145
            </if>
            <if test="discountPriceLimit != null">
146
                discount_price_limit = #{discountPriceLimit},
147 148 149 150 151
            </if>
        </set>
        WHERE id = #{id}
    </update>

152 153 154 155 156 157 158
    <update id="updateStatFetchNumIncr" parameterType="Integer">
        UPDATE coupon_template
        SET stat_fetch_Num = stat_fetch_Num + 1
        WHERE id = #{id}
        AND total > stat_fetch_Num
    </update>

159
</mapper>