You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

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