Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 

180 строки
6.1 KiB

  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. <mapper namespace="com.iformall.mapper.WxCouponSendMapper">
  4. <resultMap id="BaseResultMap" type="com.iformall.domain.vo.WxCouponSendVo">
  5. <id column="id" jdbcType="BIGINT" property="id" />
  6. <result column="tenant_id" jdbcType="VARCHAR" property="tenantId" />
  7. <result column="coupon_id" jdbcType="BIGINT" property="couponId" />
  8. <result column="title" jdbcType="VARCHAR" property="title" />
  9. <result column="send_type" jdbcType="INTEGER" property="sendType" />
  10. <result column="conditions" jdbcType="VARCHAR" property="conditions" />
  11. <result column="status" jdbcType="INTEGER" property="status" />
  12. <result column="create_date" jdbcType="TIMESTAMP" property="createDate" />
  13. <result column="update_date" jdbcType="TIMESTAMP" property="updateDate" />
  14. <result column="merchant_name" jdbcType="VARCHAR" property="merchantName" />
  15. <result column="remain_inventory" jdbcType="INTEGER" property="remainInventory"/>
  16. <result column="inventory" jdbcType="INTEGER" property="inventory"/>
  17. <result column="use_limit_quantity" jdbcType="INTEGER" property="useLimitQuantity"/>
  18. <result column="valid_start_date" jdbcType="TIMESTAMP" property="validStartDate"/>
  19. <result column="valid_end_date" jdbcType="TIMESTAMP" property="validEndDate"/>
  20. <result column="send_sms" jdbcType="INTEGER" property="sendSms"/>
  21. <result column="valid_days" jdbcType="INTEGER" property="validDays"/>
  22. </resultMap>
  23. <sql id="allColumns">
  24. cs.id,cs.tenant_id,cs.coupon_id,cs.title,cs.send_type,cs.conditions,cs.status,cs.create_date,cs.update_date,
  25. cs.conditions -> '$.merchantSend' as merchantSend,
  26. cs.conditions -> '$.merchantLnventory' as merchantLnventory,
  27. cs.conditions -> '$.merchantRemain' as merchantRemain,
  28. (case when
  29. (select count(*) from wx_coupon_merchant xcm where xcm.product_id = cs.coupon_id and xcm.status = 0)=1
  30. then
  31. (select m.name from wx_merchant m, wx_coupon_merchant cm where m.id = cm.merchant_id and cm.product_id=cs.coupon_id and cm.status = 0)
  32. else
  33. '[多商户通用]'
  34. end) as merchant_name,
  35. c.remain_inventory, c.use_limit_quantity, c.inventory, c.valid_start_date, c.valid_end_date,c.valid_type,cs.send_sms,c.valid_days
  36. </sql>
  37. <sql id="dynamicWhereConditions">
  38. where 1 = 1
  39. <if test=" null != id ">
  40. and cs.id = #{id}
  41. </if>
  42. <if test=" null != tenantId ">
  43. and cs.tenant_id = #{tenantId}
  44. </if>
  45. <if test=" null != couponId ">
  46. and cs.coupon_id = #{couponId}
  47. </if>
  48. <if test=" null != title ">
  49. and cs.title like concat('%', #{title},'%')
  50. </if>
  51. <if test=" null != sendType ">
  52. and cs.send_type = #{sendType}
  53. </if>
  54. <if test=" null != status ">
  55. and cs.status = #{status}
  56. </if>
  57. <if test=" null != createDate ">
  58. and cs.create_date = #{createDate}
  59. </if>
  60. <if test=" null != updateDate ">
  61. and cs.update_date = #{updateDate}
  62. </if>
  63. <if test=" null != merchantName and ''!=merchantName">
  64. and cs.conditions -> '$.title' like concat('%',#{merchantName},'%')
  65. </if>
  66. <if test=" null != merchantId and ''!=merchantId ">
  67. and cs.conditions->'$.id' = concat(#{merchantId},'')
  68. </if>
  69. <if test=" null != merchantRemain">
  70. and cs.conditions -> '$.merchantRemain'> #{merchantRemain}
  71. </if>
  72. <if test=" null != ids ">
  73. and cs.id in
  74. <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
  75. #{idItem}
  76. </foreach>
  77. </if>
  78. <if test=" null != sendSms ">
  79. and cs.send_sms = #{sendSms}
  80. </if>
  81. <if test=" null != sortColumns">
  82. order by ${sortColumns}
  83. </if>
  84. </sql>
  85. <select id="findListVo" parameterType="com.iformall.domain.vo.WxCouponSendVo" resultMap="BaseResultMap">
  86. select <include refid="allColumns" /> from wx_coupon_send cs left join wx_coupon c on c.id = cs.coupon_id
  87. <include refid="dynamicWhereConditions" />
  88. </select>
  89. <select id="findListVoByValidType" parameterType="com.iformall.domain.vo.WxCouponSendVo" resultMap="BaseResultMap">
  90. select tt.* from (select
  91. <include refid="allColumns"/>
  92. from wx_coupon_send cs left join wx_coupon c on c.id = cs.coupon_id
  93. <include refid="dynamicWhereConditions"/>) as tt
  94. where 1=1
  95. and ((tt.valid_type=1
  96. <choose>
  97. <when test="expired == 0">
  98. and <![CDATA[ tt.valid_end_date >= now() ]]>
  99. </when>
  100. <when test="expired == 1">
  101. and <![CDATA[ tt.valid_end_date < now() ]]>
  102. </when>
  103. <otherwise>
  104. </otherwise>
  105. </choose>
  106. )
  107. <choose>
  108. <when test="expired == 0">
  109. or <![CDATA[ tt.valid_type = 2 ]]>
  110. </when>
  111. <when test="expired == 1">
  112. </when>
  113. <otherwise>
  114. or <![CDATA[ tt.valid_type = 2 ]]>
  115. </otherwise>
  116. </choose>
  117. )
  118. <if test=" null != sortCol">
  119. order by ${sortCol}
  120. </if>
  121. </select>
  122. <update id="updateStatusByCouponId" parameterType="com.iformall.domain.po.WxCouponChannel">
  123. update wx_coupon_send set status=#{status}
  124. where coupon_id=#{couponId}
  125. <if test=" null != tenantId ">
  126. and tenant_id = #{tenantId}
  127. </if>
  128. </update>
  129. <update id="updateBirthdayConfig" parameterType="com.iformall.domain.po.WxCouponSend">
  130. update wx_coupon_send
  131. set conditions=#{conditions},update_date = #{updateDate}
  132. where send_type = #{sendType}
  133. and tenant_id = #{tenantId}
  134. </update>
  135. <update id="offExpiriedCouponSendByCouponStatus">
  136. update wx_coupon_send cs, wx_coupon c
  137. set cs.status=1, cs.update_date = now()
  138. where c.id = cs.coupon_id and cs.status = 0 and
  139. ((c.status = 1) or (c.valid_type = 1 and c.valid_end_date &lt; now()))
  140. </update>
  141. <update id="reduceMerchantSend">
  142. update wx_coupon_send
  143. SET conditions = JSON_SET(conditions, '$.merchantRemain', #{merchantRemain} - #{number} , '$.merchantSend',
  144. #{merchantSend} + #{number})
  145. where id = #{id}
  146. and conditions -> '$.merchantRemain' = #{merchantRemain}
  147. </update>
  148. <update id="backMerchantSend">
  149. update wx_coupon_send
  150. SET conditions = JSON_SET(conditions, '$.merchantRemain', #{merchantRemain} + #{number} , '$.merchantSend',
  151. #{merchantSend} - #{number})
  152. where id = #{id}
  153. and conditions -> '$.merchantRemain' = #{merchantRemain}
  154. </update>
  155. </mapper>