CouponCardMapper.xml 4.1 KB
Newer Older
1 2 3 4 5
<?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.CouponCardMapper">

    <sql id="FIELDS">
YunaiV's avatar
YunaiV committed
6 7
        id, template_id, title, status, user_id, take_type,
        price_available, valid_start_time, valid_end_time, preferential_type, percent_off, price_off,
8
        discount_price_limit, used_time,
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
        create_time
    </sql>

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

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

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

36 37 38 39 40 41 42 43 44 45 46 47 48 49
    <select id="selectListByUserIdAndStatus" resultType="CouponCardDO">
        SELECT
            <include refid="FIELDS" />
        FROM coupon_card
        <where>
            <if test="userId != null">
                AND user_id = #{userId}
            </if>
            <if test="status != null">
                AND status = #{status}
            </if>
        </where>
    </select>

50 51 52 53 54
    <select id="selectListByPage" resultType="CouponCardDO">
        SELECT
          <include refid="FIELDS" />
        FROM coupon_card
        <where>
55 56 57
            <if test="userId != null">
                AND user_id = #{userId}
            </if>
58 59 60 61 62 63 64 65 66 67 68 69
            <if test="status != null">
                AND status = #{status}
            </if>
        </where>
        LIMIT #{offset}, #{limit}
    </select>

    <select id="selectCountByPage" resultType="Integer">
        SELECT
          COUNT(1)
        FROM coupon_card
        <where>
70 71 72
            <if test="userId != null">
                AND user_id = #{userId}
            </if>
73 74 75 76 77 78
            <if test="status != null">
                AND status = #{status}
            </if>
        </where>
    </select>

79 80 81 82 83 84 85 86 87 88 89 90 91 92
    <select id="selectCountByUserIdAndTemplateId" resultType="Integer">
        SELECT
            COUNT(1)
        FROM coupon_card
        <where>
            <if test="userId != null">
                AND user_id = #{userId}
            </if>
            <if test="templateId != null">
                AND template_id = #{templateId}
            </if>
        </where>
    </select>

93 94
    <insert id="insert" parameterType="CouponCardDO" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
        INSERT INTO coupon_card (
YunaiV's avatar
YunaiV committed
95 96
          template_id, title, status, user_id, take_type,
          price_available, valid_start_time, valid_end_time, preferential_type, percent_off, price_off,
97
          discount_price_limit, used_time,
98 99
          create_time
        ) VALUES (
YunaiV's avatar
YunaiV committed
100 101
          #{templateId}, #{title}, #{status}, #{userId}, #{takeType},
          #{priceAvailable}, #{validStartTime}, #{validEndTime}, #{preferentialType}, #{percentOff}, #{priceOff},
102
          #{discountPriceLimit}, #{usedTime},
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
          #{createTime}
        )
    </insert>

    <update id="update" parameterType="CouponCardDO">
        UPDATE coupon_card
        <set>
            <if test="status != null">
                status = #{status},
            </if>
            <if test="usedTime != null">
                used_time = #{usedTime},
            </if>
        </set>
        WHERE id = #{id}
    </update>

120 121 122 123 124 125 126 127 128 129 130 131 132 133
    <update id="updateByIdAndStatus">
        UPDATE coupon_card
        <set>
            <if test="updateObj.status != null">
                status = #{updateObj.status},
            </if>
            <if test="updateObj.usedTime != null">
                used_time = #{updateObj.usedTime},
            </if>
        </set>
        WHERE id = #{id}
        AND status = #{status}
    </update>

134
</mapper>