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.
 
 
 
 
 

243 lines
7.9 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.WxCouponChannelMapper">
  4. <resultMap id="BaseResultMap" type="com.iformall.domain.po.WxCouponChannel">
  5. <id column="id" jdbcType="BIGINT" property="id" />
  6. <result column="tenant_id" jdbcType="VARCHAR" property="tenantId" />
  7. <result column="merchant_id" jdbcType="BIGINT" property="merchantId" />
  8. <result column="coupon_id" jdbcType="BIGINT" property="couponId" />
  9. <result column="type" jdbcType="INTEGER" property="type" />
  10. <result column="title" jdbcType="VARCHAR" property="title" />
  11. <result column="target_ad" jdbcType="INTEGER" property="targetAd" />
  12. <result column="business" jdbcType="VARCHAR" property="business" />
  13. <result column="begin_time" jdbcType="TIMESTAMP" property="beginTime" />
  14. <result column="end_time" jdbcType="TIMESTAMP" property="endTime" />
  15. <result column="status" jdbcType="INTEGER" property="status" />
  16. <result column="create_date" jdbcType="TIMESTAMP" property="createDate" />
  17. <result column="update_date" jdbcType="TIMESTAMP" property="updateDate" />
  18. <result column="sub_target_id" jdbcType="BIGINT" property="subTargetId" />
  19. </resultMap>
  20. <sql id="allColumns">
  21. `id`,`tenant_id`,`merchant_id`,`coupon_id`,`coupon_status`,`type`,`title`,`target_ad`,`business`,`begin_time`,`end_time`,`status`,`create_date`,`update_date`,`sub_target_id`
  22. </sql>
  23. <sql id="dynamicWhereConditions">
  24. where 1 = 1
  25. <if test=" null != id ">
  26. and `id` = #{id}
  27. </if>
  28. <if test=" null != tenantId ">
  29. and `tenant_id` = #{tenantId}
  30. </if>
  31. <if test=" null != merchantId ">
  32. and `merchant_id` = #{merchantId}
  33. </if>
  34. <if test=" null != couponId ">
  35. and `coupon_id` = #{couponId}
  36. </if>
  37. <if test=" null != type ">
  38. and `type` = #{type}
  39. </if>
  40. <if test=" null != title ">
  41. and `title` like concat('%', #{title},'%')
  42. </if>
  43. <if test=" null != targetAd ">
  44. and `target_ad` = #{targetAd}
  45. </if>
  46. <if test=" null != business and '0' == business">
  47. and JSON_CONTAINS(`business`->'$',JSON_ARRAY('0'))
  48. </if>
  49. <if test=" null != business and '0' != business">
  50. and (JSON_CONTAINS(`business`->'$',JSON_ARRAY('0')) or (JSON_CONTAINS(`business`->'$',JSON_ARRAY(#{business}))))
  51. </if>
  52. <if test=" null != beginTime ">
  53. and `begin_time` = #{beginTime}
  54. </if>
  55. <if test=" null != endTime ">
  56. and `end_time` = #{endTime}
  57. </if>
  58. <if test=" null != status ">
  59. and `status` = #{status}
  60. </if>
  61. <if test=" null != createDate ">
  62. and `create_date` = #{createDate}
  63. </if>
  64. <if test=" null != updateDate ">
  65. and `update_date` = #{updateDate}
  66. </if>
  67. <if test=" null != subTargetId ">
  68. and `sub_target_id` = #{subTargetId}
  69. </if>
  70. <if test=" null != ids ">
  71. and id in
  72. <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
  73. #{idItem}
  74. </foreach>
  75. </if>
  76. <if test=" null != couponIds ">
  77. and coupon_id in
  78. <foreach collection="couponIds" index="index" item="couponIdsItem" open="(" separator="," close=")">
  79. #{couponIdsItem}
  80. </foreach>
  81. </if>
  82. <if test=" null != sortColumns"> order by ${sortColumns} </if>
  83. </sql>
  84. <select id="findList" parameterType="com.iformall.domain.po.WxCouponChannel" resultMap="BaseResultMap">
  85. select <include refid="allColumns" /> from wx_coupon_channel
  86. <include refid="dynamicWhereConditions" />
  87. </select>
  88. <select id="findListByCouponIds" parameterType="com.iformall.domain.po.WxCouponChannel" resultMap="BaseResultMap">
  89. select <include refid="allColumns" /> from wx_coupon_channel
  90. <include refid="dynamicWhereConditions" />
  91. </select>
  92. <update id="updateStatusByCouponId" parameterType="com.iformall.domain.po.WxCouponChannel">
  93. update wx_coupon_channel set status=#{status} where tenant_id=#{tenantId} and coupon_id=#{couponId}
  94. </update>
  95. <resultMap id="CouponChannelVoMap" type="com.iformall.domain.vo.WxCouponChannelVo">
  96. <id column="id" jdbcType="BIGINT" property="id" />
  97. <result column="tenant_id" jdbcType="VARCHAR" property="tenantId" />
  98. <result column="merchant_id" jdbcType="BIGINT" property="merchantId" />
  99. <result column="coupon_id" jdbcType="BIGINT" property="couponId" />
  100. <result column="type" jdbcType="INTEGER" property="type" />
  101. <result column="title" jdbcType="VARCHAR" property="title" />
  102. <result column="target_ad" jdbcType="INTEGER" property="targetAd" />
  103. <result column="business" jdbcType="VARCHAR" property="business" />
  104. <result column="create_date" jdbcType="TIMESTAMP" property="createDate" />
  105. <result column="update_date" jdbcType="TIMESTAMP" property="updateDate" />
  106. <result column="sub_target_id" jdbcType="BIGINT" property="subTargetId" />
  107. </resultMap>
  108. <select id="findVoList" parameterType="com.iformall.domain.po.WxCouponChannel" resultMap="CouponChannelVoMap">
  109. select <include refid="allColumns" /> from wx_coupon_channel
  110. <include refid="dynamicWhereConditions" />
  111. </select>
  112. <select id="findVoListForCouponChannel2" parameterType="com.iformall.domain.po.WxCouponChannel" resultMap="CouponChannelVoMap">
  113. select <include refid="allColumns" /> from wx_coupon_channel
  114. where 1 = 1
  115. <if test=" null != id ">
  116. and `id` = #{id}
  117. </if>
  118. <if test=" null != tenantId ">
  119. and `tenant_id` = #{tenantId}
  120. </if>
  121. <if test=" null != merchantId ">
  122. and `merchant_id` = #{merchantId}
  123. </if>
  124. <if test=" null != couponId ">
  125. and `coupon_id` = #{couponId}
  126. </if>
  127. <if test=" null != type ">
  128. and `type` = #{type}
  129. </if>
  130. <if test=" null != title ">
  131. and `title` like concat('%', #{title},'%')
  132. </if>
  133. <if test=" null != targetAd ">
  134. and `target_ad` = #{targetAd}
  135. </if>
  136. <if test=" null != business and '0' == business">
  137. and JSON_CONTAINS(`business`->'$',JSON_ARRAY('0'))
  138. </if>
  139. <if test=" null != business and '0' != business">
  140. and (JSON_CONTAINS(`business`->'$',JSON_ARRAY('0')) or (JSON_CONTAINS(`business`->'$',JSON_ARRAY(#{business}))))
  141. </if>
  142. <if test=" null != beginTime ">
  143. and `begin_time` = #{beginTime}
  144. </if>
  145. <if test=" null != targetAd and 2 == targetAd">
  146. and `begin_time` &lt; now()
  147. and `end_time` &gt; now()
  148. </if>
  149. <if test=" null != endTime ">
  150. and `end_time` = #{endTime}
  151. </if>
  152. <if test=" null != status ">
  153. and `status` = #{status}
  154. </if>
  155. <if test=" null != createDate ">
  156. and `create_date` = #{createDate}
  157. </if>
  158. <if test=" null != updateDate ">
  159. and `update_date` = #{updateDate}
  160. </if>
  161. <if test=" null != subTargetId ">
  162. and `sub_target_id` = #{subTargetId}
  163. </if>
  164. <if test=" null != ids ">
  165. and id in
  166. <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
  167. #{idItem}
  168. </foreach>
  169. </if>
  170. <if test=" null != couponIds ">
  171. and coupon_id in
  172. <foreach collection="couponIds" index="index" item="couponIdsItem" open="(" separator="," close=")">
  173. #{couponIdsItem}
  174. </foreach>
  175. </if>
  176. <if test=" null != sortColumns"> order by ${sortColumns} </if>
  177. </select>
  178. <select id="countCoupon" parameterType="com.iformall.domain.po.WxCouponChannel" resultType="java.lang.Integer">
  179. select count(distinct coupon_id) from wx_coupon_channel
  180. <include refid="dynamicWhereConditions" />
  181. </select>
  182. <update id="offExpiriedCouponChannelByEndTime">
  183. update wx_coupon_channel SET status = 1, update_date = now()
  184. where status = 0 and end_time &lt; now()
  185. </update>
  186. <update id="offExpiriedCouponChannelByValidDate">
  187. update wx_coupon_channel cc, wx_coupon c SET cc.status = 1, cc.update_date = now()
  188. where cc.status = 0 and cc.coupon_id = c.id and c.valid_type = 1 and c.valid_end_date &lt; now()
  189. </update>
  190. <update id="offExpiriedCouponChannelByCouponStatus">
  191. update wx_coupon_channel cc, wx_coupon c SET cc.status = 1, cc.update_date = now()
  192. where cc.status = 0 and cc.coupon_id = c.id and c.status = 1
  193. </update>
  194. <update id="offExpiriedCouponChannel2ByEndTime">
  195. update wx_coupon_channel SET status = 1, update_date = now()
  196. where status = 0 and target_ad = 2 and end_time &lt; now()
  197. </update>
  198. </mapper>