couponItemMapper.xml 7.1 KB

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