CouponTemplateMapper.xml 5.8 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
        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>

37 38 39 40 41 42 43 44 45 46
    <select id="selectListByIds" resultType="CouponTemplateDO">
        SELECT
            <include refid="FIELDS"/>
        FROM coupon_template
        WHERE id IN
        <foreach item="id" collection="ids" separator="," open="(" close=")" index="">
            #{id}
        </foreach>
    </select>

47 48 49 50 51
    <select id="selectListByPage" resultType="CouponTemplateDO">
        SELECT
          <include refid="FIELDS" />
        FROM coupon_template
        <where>
52 53 54
            <if test="type != null">
                AND type = #{type}
            </if>
55
            <if test="title != null">
56
                AND title LIKE "%"#{title}"%"
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
            </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>
73 74 75
            <if test="type != null">
                AND type = #{type}
            </if>
76
            <if test="title != null">
77
                AND title LIKE "%"#{title}"%"
78 79 80 81 82 83 84 85 86 87 88 89 90
            </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,
91
          status, quota, total, price_available, range_type,
92
          range_values, date_type, valid_start_time, valid_end_time, fixed_start_term, fixed_end_term,
93 94 95
          preferential_type, percent_off, price_off, discount_price_limit, stat_fetch_num,
          create_time
        ) VALUES (
96 97
          #{title}, #{description}, #{type}, #{codeType},
          #{status}, #{quota}, #{total}, #{priceAvailable}, #{rangeType},
98
          #{rangeValues}, #{dateType}, #{validStartTime}, #{validEndTime}, #{fixedStartTerm}, #{fixedEndTerm}
99
          #{preferentialType}, #{percentOff}, #{priceOff}, #{discountPriceLimit}, #{statFetchNum},
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
          #{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>
119 120
            <if test="total != null">
                total = #{total},
121 122
            </if>
            <if test="priceAvailable != null">
123
                price_available = #{priceAvailable},
124 125
            </if>
            <if test="rangeType != null">
126
                range_type = #{rangeType},
127 128
            </if>
            <if test="rangeValues != null">
129
                range_values = #{rangeValues},
130 131
            </if>
            <if test="dateType != null">
132
                date_type = #{dateType},
133 134
            </if>
            <if test="validStartTime != null">
135
                valid_start_time = #{validStartTime},
136 137
            </if>
            <if test="validEndTime != null">
138
                valid_end_time = #{validEndTime},
139
            </if>
140 141 142 143 144
            <if test="fixedStartTerm != null">
                fixed_start_term = #{fixedStartTerm},
            </if>
            <if test="fixedEndTerm != null">
                fixed_end_term = #{fixedEndTerm},
145 146
            </if>
            <if test="preferentialType != null">
147
                preferential_type = #{preferentialType},
148 149
            </if>
            <if test="percentOff != null">
150
                percent_off = #{percentOff},
151 152
            </if>
            <if test="priceOff != null">
153
                price_off = #{priceOff},
154 155
            </if>
            <if test="discountPriceLimit != null">
156
                discount_price_limit = #{discountPriceLimit},
157 158 159 160 161
            </if>
        </set>
        WHERE id = #{id}
    </update>

162 163 164 165 166 167 168
    <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>

169
</mapper>