couponItemMapper.xml 6.8 KB

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