couponItemMapper.xml 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. <if test="couponType != null and couponType != '' and couponType=='10' ">
  35. AND (CT.coupon_type=1 OR CT.coupon_type=2)
  36. </if>
  37. <if test="couponType != null and couponType != '' and couponType=='11' ">
  38. AND CT.coupon_type=3
  39. </if>
  40. <!-- couponReduce 是将状态是7的优惠券 属于已使用的优惠券-->
  41. <if test="couponUseStatus != null and couponUseStatus != ''">
  42. AND CI.COUPON_USE_STATUS IN (#{couponUseStatus},#{couponReduce})
  43. </if>
  44. <if test="beginDate != null and beginDate != ''">
  45. AND CI.COUPON_USE_END_DATE<![CDATA[>]]>#{beginDate}
  46. </if>
  47. <if test="endDate != null and endDate != ''">
  48. AND CI.COUPON_USE_END_DATE<![CDATA[<]]>#{endDate}
  49. </if>
  50. <!-- 查已过期的优惠券时需去掉已经使用的优惠券 -->
  51. <if test="couponItemRemark != null and couponItemRemark != ''">
  52. AND CI.COUPON_USE_STATUS != 2
  53. </if>
  54. </where>
  55. ORDER BY CI.COUPON_RECEIVE_DATE DESC
  56. <if test="page!=null and page.recordBegin>0 and page.pageSize>0 ">
  57. LIMIT ${page.recordBegin},${page.pageSize}
  58. </if>
  59. <if test="page!=null and page.recordBegin==0 and page.pageSize>0 ">
  60. LIMIT ${page.pageSize}
  61. </if>
  62. </select>
  63. <!-- 查询优惠券详情总数 -->
  64. <select id="getCouponItemCount" resultType="Integer" parameterType="CouponItemDto">
  65. SELECT COUNT(COUPON_ITEM_ID) FROM TB_IAMBERRY_COUPON_ITEM
  66. <where>
  67. <if test="couponId != null and couponId != ''">
  68. COUPON_ID=#{couponId}
  69. </if>
  70. <if test="useropenid != null and useropenid != ''">
  71. AND COUPON_ITEM_USER_OPENID=#{useropenid}
  72. </if>
  73. <if test="couponUseStatus != null and couponUseStatus != ''">
  74. AND COUPON_USE_STATUS=#{couponUseStatus}
  75. </if>
  76. <if test="beginDate != null and beginDate != ''">
  77. AND COUPON_USE_END_DATE<![CDATA[>]]>#{beginDate}
  78. </if>
  79. <if test="endDate != null and endDate != ''">
  80. AND COUPON_USE_END_DATE<![CDATA[<]]>#{endDate}
  81. </if>
  82. </where>
  83. </select>
  84. <!-- 添加一张优惠券 -->
  85. <insert id="insertCouponItem" parameterType="CouponItem"
  86. useGeneratedKeys="true" keyProperty="couponItemId">
  87. INSERT INTO TB_IAMBERRY_COUPON_ITEM
  88. (
  89. COUPON_ITEM_ID ,
  90. COUPON_ID ,
  91. COUPON_ITEM_USER_OPENID ,
  92. COUPON_USE_END_DATE ,
  93. COUPON_RECEIVE_DATE ,
  94. COUPON_USE_STATUS ,
  95. COUPON_USE_DATE ,
  96. COUPON_ITEM_REMARK
  97. )
  98. VALUES
  99. (
  100. #{couponItemId},#{couponId},#{couponItemUseropenid},#{couponUseEndDate},
  101. NOW(),#{couponUseStatus},#{couponUseDate},#{couponItemRemark}
  102. )
  103. </insert>
  104. <select id="getCouponItemById" resultType="CouponItemDto" parameterType="String">
  105. SELECT
  106. <include refid="allField"></include>
  107. FROM TB_IAMBERRY_COUPON_ITEM CI
  108. JOIN TB_IAMBERRY_COUPON_TYPE CT ON CI.COUPON_ID=CT.COUPON_ID
  109. WHERE CI.COUPON_ITEM_ID=#{couponItemId}
  110. </select>
  111. <!-- 根据id修改 -->
  112. <update id="updateCouponItemById" parameterType="CouponItem">
  113. UPDATE TB_IAMBERRY_COUPON_ITEM
  114. <set>
  115. <if test="couponUseEndDate!=null and couponUseEndDate!=''">
  116. COUPON_USE_END_DATE=#{couponUseEndDate},
  117. </if>
  118. <if test="couponUseStatus!=null and couponUseStatus!=''">
  119. COUPON_USE_STATUS=#{couponUseStatus},
  120. </if>
  121. <if test="couponUseDate!=null and couponUseDate!=''">
  122. COUPON_USE_DATE=#{couponUseDate},
  123. </if>
  124. <if test="couponItemRemark!=null and couponItemRemark!=''">
  125. COUPON_ITEM_REMARK=#{couponItemRemark},
  126. </if>
  127. </set>
  128. WHERE COUPON_ITEM_ID=#{couponItemId}
  129. <if test="couponItemUseropenid!=null and couponItemUseropenid!=''">
  130. AND COUPON_ITEM_USER_OPENID=#{couponItemUseropenid}
  131. </if>
  132. <if test="oldCouponUseStatus!=null and oldCouponUseStatus!=''">
  133. AND COUPON_USE_STATUS=#{oldCouponUseStatus}
  134. </if>
  135. </update>
  136. <update id="updateCouponItemList" parameterType="java.util.List">
  137. <foreach collection="list" item="item" index="index" separator=";" open="" close="">
  138. UPDATE TB_IAMBERRY_COUPON_ITEM
  139. <set>
  140. <if test="item.couponUseEndDate!=null and item.couponUseEndDate!=''">
  141. COUPON_USE_END_DATE=#{item.couponUseEndDate},
  142. </if>
  143. <if test="item.couponUseStatus!=null and item.couponUseStatus!=''">
  144. COUPON_USE_STATUS=#{item.couponUseStatus},
  145. </if>
  146. <if test="item.couponUseDate!=null and item.couponUseDate!=''">
  147. COUPON_USE_DATE=#{item.couponUseDate},
  148. </if>
  149. <if test="item.couponItemRemark!=null and item.couponItemRemark!=''">
  150. COUPON_ITEM_REMARK=#{item.couponItemRemark},
  151. </if>
  152. </set>
  153. WHERE COUPON_ITEM_ID=#{item.couponItemId}
  154. <if test="item.couponItemUseropenid!=null and item.couponItemUseropenid!=''">
  155. AND COUPON_ITEM_USER_OPENID=#{item.couponItemUseropenid}
  156. </if>
  157. <if test="item.oldCouponUseStatus!=null and item.oldCouponUseStatus!=''">
  158. AND COUPON_USE_STATUS=#{item.oldCouponUseStatus}
  159. </if>
  160. </foreach>
  161. </update>
  162. <!-- 查询优惠券详情列表 分页 -->
  163. <select id="expiredAndNoTake" resultType="CouponItemDto" parameterType="CouponItemDto">
  164. SELECT
  165. <include refid="allField"></include>,
  166. CT.COUPON_TYPE couponType
  167. FROM TB_IAMBERRY_COUPON_ITEM CI
  168. JOIN TB_IAMBERRY_COUPON_TYPE CT ON CI.COUPON_ID=CT.COUPON_ID
  169. <where>
  170. <if test="couponId != null and couponId != ''">
  171. AND CI.COUPON_ID=#{couponId}
  172. </if>
  173. <if test="couponUseStatus != null">
  174. AND CI.COUPON_USE_STATUS = #{couponUseStatus}
  175. </if>
  176. <if test="beginDate != null and beginDate != ''">
  177. AND CI.COUPON_USE_END_DATE<![CDATA[>]]>#{beginDate}
  178. </if>
  179. <if test="endDate != null and endDate != ''">
  180. AND CI.COUPON_USE_END_DATE<![CDATA[<]]>#{endDate}
  181. </if>
  182. </where>
  183. ORDER BY CI.COUPON_RECEIVE_DATE DESC
  184. </select>
  185. </mapper>