couponItemMapper.xml 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <!-- 命名,每一个映射对象不一样
  4. namespace:必须与对应的接口全类名一致
  5. -->
  6. <mapper namespace="com.iamberry.wechat.service.mapper.CouponItemMapper">
  7. <sql id="allField">
  8. CI.COUPON_ITEM_ID couponItemId,
  9. CI.COUPON_ID couponId,
  10. CI.COUPON_ITEM_USER_OPENID useropenid,
  11. CI.COUPON_USE_END_DATE couponUseEndDate,
  12. CI.COUPON_RECEIVE_DATE couponReceiveDate,
  13. CI.COUPON_USE_STATUS couponUseStatus,
  14. CI.COUPON_USE_DATE couponUseDate,
  15. CI.COUPON_ITEM_REMARK couponItemRemark,
  16. CT.COUPON_NAME couponName,
  17. CT.COUPON_REDUCE couponReduce,
  18. CT.COUPON_CONSUME_ENOUGH couponConsumeEnough
  19. </sql>
  20. <!-- 查询优惠券详情列表 分页 -->
  21. <select id="getCouponItemDtoList" resultType="CouponItemDto" parameterType="CouponItemDto">
  22. SELECT
  23. <include refid="allField"></include>,
  24. CT.COUPON_TYPE couponType
  25. FROM TB_IAMBERRY_COUPON_ITEM CI
  26. JOIN TB_IAMBERRY_COUPON_TYPE CT ON CI.COUPON_ID=CT.COUPON_ID
  27. <where>
  28. <if test="couponId != null and couponId != ''">
  29. AND CI.COUPON_ID=#{couponId}
  30. </if>
  31. <if test="useropenid != null and useropenid != ''">
  32. AND CI.COUPON_ITEM_USER_OPENID=#{useropenid}
  33. </if>
  34. <!-- couponReduce 是将状态是7的优惠券 属于已使用的优惠券-->
  35. <if test="couponUseStatus != null and couponUseStatus != ''">
  36. AND CI.COUPON_USE_STATUS IN (#{couponUseStatus},#{couponReduce})
  37. </if>
  38. <if test="beginDate != null and beginDate != ''">
  39. AND CI.COUPON_USE_END_DATE<![CDATA[>]]>#{beginDate}
  40. </if>
  41. <if test="endDate != null and endDate != ''">
  42. AND CI.COUPON_USE_END_DATE<![CDATA[<]]>#{endDate}
  43. </if>
  44. <!-- 查已过期的优惠券时需去掉已经使用的优惠券 -->
  45. <if test="couponItemRemark != null and couponItemRemark != ''">
  46. AND CI.COUPON_USE_STATUS != 2
  47. </if>
  48. </where>
  49. ORDER BY CI.COUPON_RECEIVE_DATE DESC
  50. <if test="page!=null and page.recordBegin>0 and page.pageSize>0 ">
  51. LIMIT ${page.recordBegin},${page.pageSize}
  52. </if>
  53. <if test="page!=null and page.recordBegin==0 and page.pageSize>0 ">
  54. LIMIT ${page.pageSize}
  55. </if>
  56. </select>
  57. <!-- 查询优惠券详情总数 -->
  58. <select id="getCouponItemCount" resultType="Integer" parameterType="CouponItemDto">
  59. SELECT COUNT(COUPON_ITEM_ID) FROM TB_IAMBERRY_COUPON_ITEM
  60. <where>
  61. <if test="couponId != null and couponId != ''">
  62. COUPON_ID=#{couponId}
  63. </if>
  64. <if test="useropenid != null and useropenid != ''">
  65. AND COUPON_ITEM_USER_OPENID=#{useropenid}
  66. </if>
  67. <if test="couponUseStatus != null and couponUseStatus != ''">
  68. AND COUPON_USE_STATUS=#{couponUseStatus}
  69. </if>
  70. <if test="beginDate != null and beginDate != ''">
  71. AND COUPON_USE_END_DATE<![CDATA[>]]>#{beginDate}
  72. </if>
  73. <if test="endDate != null and endDate != ''">
  74. AND COUPON_USE_END_DATE<![CDATA[<]]>#{endDate}
  75. </if>
  76. </where>
  77. </select>
  78. <!-- 添加一张优惠券 -->
  79. <insert id="insertCouponItem" parameterType="CouponItem"
  80. useGeneratedKeys="true" keyProperty="couponItemId">
  81. INSERT INTO TB_IAMBERRY_COUPON_ITEM
  82. (
  83. COUPON_ITEM_ID ,
  84. COUPON_ID ,
  85. COUPON_ITEM_USER_OPENID ,
  86. COUPON_USE_END_DATE ,
  87. COUPON_RECEIVE_DATE ,
  88. COUPON_USE_STATUS ,
  89. COUPON_USE_DATE ,
  90. COUPON_ITEM_REMARK
  91. )
  92. VALUES
  93. (
  94. #{couponItemId},#{couponId},#{couponItemUseropenid},#{couponUseEndDate},
  95. NOW(),#{couponUseStatus},#{couponUseDate},#{couponItemRemark}
  96. )
  97. </insert>
  98. <select id="getCouponItemById" resultType="CouponItemDto" parameterType="String">
  99. SELECT
  100. <include refid="allField"></include>
  101. FROM TB_IAMBERRY_COUPON_ITEM CI
  102. JOIN TB_IAMBERRY_COUPON_TYPE CT ON CI.COUPON_ID=CT.COUPON_ID
  103. WHERE CI.COUPON_ITEM_ID=#{couponItemId}
  104. </select>
  105. <!-- 根据id修改 -->
  106. <update id="updateCouponItemById" parameterType="CouponItem">
  107. UPDATE TB_IAMBERRY_COUPON_ITEM
  108. <set>
  109. <if test="couponUseEndDate!=null and couponUseEndDate!=''">
  110. COUPON_USE_END_DATE=#{couponUseEndDate},
  111. </if>
  112. <if test="couponUseStatus!=null and couponUseStatus!=''">
  113. COUPON_USE_STATUS=#{couponUseStatus},
  114. </if>
  115. <if test="couponUseDate!=null and couponUseDate!=''">
  116. COUPON_USE_DATE=#{couponUseDate},
  117. </if>
  118. <if test="couponItemRemark!=null and couponItemRemark!=''">
  119. COUPON_ITEM_REMARK=#{couponItemRemark},
  120. </if>
  121. </set>
  122. WHERE COUPON_ITEM_ID=#{couponItemId}
  123. <if test="couponItemUseropenid!=null and couponItemUseropenid!=''">
  124. AND COUPON_ITEM_USER_OPENID=#{couponItemUseropenid}
  125. </if>
  126. <if test="oldCouponUseStatus!=null and oldCouponUseStatus!=''">
  127. AND COUPON_USE_STATUS=#{oldCouponUseStatus}
  128. </if>
  129. </update>
  130. <update id="updateCouponItemList" parameterType="java.util.List">
  131. <foreach collection="list" item="item" index="index" separator=";" open="" close="">
  132. UPDATE TB_IAMBERRY_COUPON_ITEM
  133. <set>
  134. <if test="item.couponUseEndDate!=null and item.couponUseEndDate!=''">
  135. COUPON_USE_END_DATE=#{item.couponUseEndDate},
  136. </if>
  137. <if test="item.couponUseStatus!=null and item.couponUseStatus!=''">
  138. COUPON_USE_STATUS=#{item.couponUseStatus},
  139. </if>
  140. <if test="item.couponUseDate!=null and item.couponUseDate!=''">
  141. COUPON_USE_DATE=#{item.couponUseDate},
  142. </if>
  143. <if test="item.couponItemRemark!=null and item.couponItemRemark!=''">
  144. COUPON_ITEM_REMARK=#{item.couponItemRemark},
  145. </if>
  146. </set>
  147. WHERE COUPON_ITEM_ID=#{item.couponItemId}
  148. <if test="item.couponItemUseropenid!=null and item.couponItemUseropenid!=''">
  149. AND COUPON_ITEM_USER_OPENID=#{item.couponItemUseropenid}
  150. </if>
  151. <if test="item.oldCouponUseStatus!=null and item.oldCouponUseStatus!=''">
  152. AND COUPON_USE_STATUS=#{item.oldCouponUseStatus}
  153. </if>
  154. </foreach>
  155. </update>
  156. </mapper>