couponItemMapper.xml 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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_ITEM_CURRENT_USER_OPENID,
  110. COUPON_USE_END_DATE ,
  111. COUPON_RECEIVE_DATE ,
  112. COUPON_USE_STATUS ,
  113. COUPON_IS_DONATION ,
  114. COUPON_USE_DATE ,
  115. COUPON_ITEM_REMARK
  116. )
  117. VALUES
  118. (
  119. #{couponItemId},#{couponId},#{couponItemUseropenid},#{couponItemCurrentUserOpenid},#{couponUseEndDate},
  120. NOW(),#{couponUseStatus},#{couponUseDate},#{couponIsDonation},#{couponItemRemark}
  121. )
  122. </insert>
  123. <select id="getCouponItemById" resultType="CouponItemDto" parameterType="String">
  124. SELECT
  125. <include refid="allField"></include>
  126. FROM TB_IAMBERRY_COUPON_ITEM CI
  127. JOIN TB_IAMBERRY_COUPON_TYPE CT ON CI.COUPON_ID=CT.COUPON_ID
  128. WHERE CI.COUPON_ITEM_ID=#{couponItemId}
  129. </select>
  130. <!-- 根据id修改 -->
  131. <update id="updateCouponItemById" parameterType="CouponItem">
  132. UPDATE TB_IAMBERRY_COUPON_ITEM
  133. <set>
  134. <if test="couponUseEndDate!=null and couponUseEndDate!=''">
  135. COUPON_USE_END_DATE=#{couponUseEndDate},
  136. </if>
  137. <if test="couponUseStatus!=null and couponUseStatus!=''">
  138. COUPON_USE_STATUS=#{couponUseStatus},
  139. </if>
  140. <if test="couponUseDate!=null and couponUseDate!=''">
  141. COUPON_USE_DATE=#{couponUseDate},
  142. </if>
  143. <if test="couponItemRemark!=null and couponItemRemark!=''">
  144. COUPON_ITEM_REMARK=#{couponItemRemark},
  145. </if>
  146. </set>
  147. WHERE COUPON_ITEM_ID=#{couponItemId}
  148. <if test="couponItemUseropenid!=null and couponItemUseropenid!=''">
  149. AND COUPON_ITEM_USER_OPENID=#{couponItemUseropenid}
  150. </if>
  151. <if test="oldCouponUseStatus!=null and oldCouponUseStatus!=''">
  152. AND COUPON_USE_STATUS=#{oldCouponUseStatus}
  153. </if>
  154. </update>
  155. <update id="updateCouponItemList" parameterType="java.util.List">
  156. <foreach collection="list" item="item" index="index" separator=";" open="" close="">
  157. UPDATE TB_IAMBERRY_COUPON_ITEM
  158. <set>
  159. <if test="item.couponUseEndDate!=null and item.couponUseEndDate!=''">
  160. COUPON_USE_END_DATE=#{item.couponUseEndDate},
  161. </if>
  162. <if test="item.couponUseStatus!=null and item.couponUseStatus!=''">
  163. COUPON_USE_STATUS=#{item.couponUseStatus},
  164. </if>
  165. <if test="item.couponUseDate!=null and item.couponUseDate!=''">
  166. COUPON_USE_DATE=#{item.couponUseDate},
  167. </if>
  168. <if test="item.couponItemRemark!=null and item.couponItemRemark!=''">
  169. COUPON_ITEM_REMARK=#{item.couponItemRemark},
  170. </if>
  171. </set>
  172. WHERE COUPON_ITEM_ID=#{item.couponItemId}
  173. <if test="item.couponItemUseropenid!=null and item.couponItemUseropenid!=''">
  174. AND COUPON_ITEM_USER_OPENID=#{item.couponItemUseropenid}
  175. </if>
  176. <if test="item.oldCouponUseStatus!=null and item.oldCouponUseStatus!=''">
  177. AND COUPON_USE_STATUS=#{item.oldCouponUseStatus}
  178. </if>
  179. </foreach>
  180. </update>
  181. <!--根据openid查询是否已领取新人优惠券-->
  182. <select id="getIsReceive" parameterType="String" resultType="Integer">
  183. SELECT
  184. COUNT(1)
  185. FROM TB_IAMBERRY_COUPON_ITEM CI
  186. JOIN TB_IAMBERRY_COUPON_TYPE CT ON CI.COUPON_ID=CT.COUPON_ID
  187. where
  188. CI.COUPON_ITEM_USER_OPENID=#{openId}
  189. AND CT.COUPON_IS_NEW_PEOPLE = 1
  190. ORDER BY CI.COUPON_RECEIVE_DATE DESC
  191. </select>
  192. </mapper>