25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

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