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.
 
 
 
 
 

333 lines
14 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="coupon_id" jdbcType="BIGINT" property="couponId" />
  8. <result column="type" jdbcType="INTEGER" property="type" />
  9. <result column="title" jdbcType="VARCHAR" property="title" />
  10. <result column="target_ad" jdbcType="INTEGER" property="targetAd" />
  11. <result column="business" jdbcType="INTEGER" property="business" />
  12. <result column="sub_business" jdbcType="INTEGER" property="subBusiness" />
  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. <result column="qr_code" property="qrCode"/>
  20. </resultMap>
  21. <sql id="allColumns">
  22. cc.`id`,cc.`tenant_id`,cc.`coupon_id`,cc.`coupon_status`,cc.`type`,cc.`title`,cc.`target_ad`,cc.`business`,cc.`sub_business`,cc.`begin_time`,cc.`end_time`,cc.`status`,cc.`create_date`,cc.`update_date`,cc.`sub_target_id`,cc.qr_code
  23. </sql>
  24. <sql id="dynamicWhereConditions">
  25. where 1=1
  26. <if test="null != couponStatus">
  27. and c.status = #{couponStatus}
  28. </if>
  29. <if test="null != status ">
  30. and cc.status = #{status}
  31. </if>
  32. <if test="null == status ">
  33. and cc.status = 0
  34. </if>
  35. <if test=" null != id ">
  36. and cc.`id` = #{id}
  37. </if>
  38. <if test=" null != tenantId ">
  39. and cc.`tenant_id` = #{tenantId}
  40. </if>
  41. <if test=" null != couponId ">
  42. and cc.`coupon_id` = #{couponId}
  43. </if>
  44. <if test=" null != type ">
  45. and cc.`type` = #{type}
  46. </if>
  47. <if test=" null != title and ''!= title">
  48. and cc.`title` like concat('%', #{title},'%')
  49. </if>
  50. <if test=" null != targetAd ">
  51. and cc.`target_ad` = #{targetAd}
  52. </if>
  53. <if test=" null != business ">
  54. and cc.`business` = #{business}
  55. </if>
  56. <if test=" null != subBusiness ">
  57. and cc.`sub_business` = #{subBusiness}
  58. </if>
  59. <if test=" null != startdate and null!=enddate">
  60. and cc.`create_date` between #{startdate} and #{enddate}
  61. </if>
  62. <if test=" null != status ">
  63. and cc.`status` = #{status}
  64. </if>
  65. <if test=" null != createDate ">
  66. and cc.`create_date` = #{createDate}
  67. </if>
  68. <if test=" null != updateDate ">
  69. and cc.`update_date` = #{updateDate}
  70. </if>
  71. <if test=" null != subTargetId ">
  72. and cc.`sub_target_id` = #{subTargetId}
  73. </if>
  74. <if test=" null != supportTransfer ">
  75. and c.`support_transfer` = #{supportTransfer}
  76. </if>
  77. <if test=" null != userCredit ">
  78. and c.`credit_price` &lt;= #{userCredit}
  79. </if>
  80. <if test=" null != ids ">
  81. and cc.id in
  82. <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
  83. #{idItem}
  84. </foreach>
  85. </if>
  86. <if test=" null != couponIds ">
  87. and cc.coupon_id in
  88. <foreach collection="couponIds" index="index" item="couponIdsItem" open="(" separator="," close=")">
  89. #{couponIdsItem}
  90. </foreach>
  91. </if>
  92. <if test=" null != sortColumns"> order by ${sortColumns} </if>
  93. </sql>
  94. <select id="findList" parameterType="com.iformall.domain.po.WxCouponChannel" resultMap="BaseResultMap">
  95. select <include refid="allColumns" /> from wx_coupon_channel cc
  96. <include refid="dynamicWhereConditions" />
  97. </select>
  98. <update id="updateStatusByCouponId" parameterType="com.iformall.domain.po.WxCouponChannel">
  99. update wx_coupon_channel
  100. set status=#{status}, update_date=#{updateDate}
  101. where coupon_id=#{couponId}
  102. <if test=" null != tenantId ">
  103. and tenant_id = #{tenantId}
  104. </if>
  105. </update>
  106. <update id="updateEndTimeByCouponId" parameterType="com.iformall.domain.po.WxCouponChannel">
  107. update wx_coupon_channel
  108. set end_time = #{endTime}
  109. where coupon_id=#{couponId}
  110. <if test=" null != tenantId ">
  111. and tenant_id = #{tenantId}
  112. </if>
  113. </update>
  114. <sql id="CouponChannelVoColumns">
  115. <include refid="allColumns" />,
  116. c.remain_inventory,c.inventory,c.cover_img,c.title,c.sub_title,c.sale_price,
  117. c.use_price,c.price,c.unit,c.use_limit_quantity,c.send_type,c.support_transfer,c.press_limit_num,c.auto_refund,c.conditions,
  118. c.valid_type,c.valid_start_date,c.valid_end_date,c.valid_days,c.credit_price
  119. </sql>
  120. <resultMap id="CouponChannelVoMap" type="com.iformall.domain.vo.WxCouponChannelVo">
  121. <id column="id" jdbcType="BIGINT" property="id" />
  122. <result column="tenant_id" jdbcType="VARCHAR" property="tenantId" />
  123. <result column="coupon_id" jdbcType="BIGINT" property="couponId" />
  124. <result column="type" jdbcType="INTEGER" property="type" />
  125. <result column="title" jdbcType="VARCHAR" property="title" />
  126. <result column="target_ad" jdbcType="INTEGER" property="targetAd" />
  127. <result column="business" jdbcType="VARCHAR" property="business" />
  128. <result column="sub_business" jdbcType="INTEGER" property="subBusiness" />
  129. <result column="create_date" jdbcType="TIMESTAMP" property="createDate" />
  130. <result column="update_date" jdbcType="TIMESTAMP" property="updateDate" />
  131. <result column="sub_target_id" jdbcType="BIGINT" property="subTargetId" />
  132. <result column="remain_inventory" jdbcType="INTEGER" property="remainInventory"/>
  133. <result column="inventory" jdbcType="INTEGER" property="inventory"/>
  134. <result column="cover_img" jdbcType="VARCHAR" property="coverImg"/>
  135. <result column="title" jdbcType="VARCHAR" property="title"/>
  136. <result column="sub_title" jdbcType="VARCHAR" property="subTitle"/>
  137. <result column="sale_price" jdbcType="INTEGER" property="salePrice"/>
  138. <result column="use_price" jdbcType="INTEGER" property="usePrice"/>
  139. <result column="price" jdbcType="INTEGER" property="price"/>
  140. <result column="unit" jdbcType="INTEGER" property="unit"/>
  141. <result column="use_limit_quantity" jdbcType="INTEGER" property="useLimitQuantity"/>
  142. <result column="send_type" jdbcType="INTEGER" property="sendType"/>
  143. <result column="support_transfer" jdbcType="INTEGER" property="supportTransfer"/>
  144. <result column="press_limit_num" jdbcType="INTEGER" property="pressLimitNum"/>
  145. <result column="auto_refund" jdbcType="INTEGER" property="autoRefund"/>
  146. <result column="valid_type" jdbcType="INTEGER" property="validType"/>
  147. <result column="valid_start_date" jdbcType="TIMESTAMP" property="validStartDate"/>
  148. <result column="valid_end_date" jdbcType="TIMESTAMP" property="validEndDate"/>
  149. <result column="valid_days" jdbcType="INTEGER" property="validDays"/>
  150. <result column="qr_code" property="qrCode"/>
  151. <result column="conditions" jdbcType="VARCHAR" property="conditions" />
  152. <collection column="{productId=coupon_id}" property="merchantVoList"
  153. ofType="com.iformall.domain.vo.WxMerchantVo"
  154. javaType="java.util.List"
  155. select="com.iformall.mapper.WxCouponMerchantMapper.findMerchantNameList" >
  156. </collection>
  157. </resultMap>
  158. <select id="findVoList" parameterType="com.iformall.domain.po.WxCouponChannel" resultMap="CouponChannelVoMap">
  159. select <include refid="CouponChannelVoColumns" />
  160. from wx_coupon_channel cc
  161. left join wx_coupon c on cc.coupon_id = c.id
  162. <include refid="dynamicWhereConditions" />
  163. </select>
  164. <select id="findVoListByMerchant" parameterType="com.iformall.domain.po.WxCouponChannel" resultMap="CouponChannelVoMap">
  165. select <include refid="CouponChannelVoColumns" />
  166. ,mer.qr_code
  167. from wx_coupon_channel cc
  168. join wx_coupon_merchant cm
  169. on cm.product_id = cc.coupon_id
  170. and cm.status = 0
  171. <if test="merchantId != null">
  172. and cm.merchant_id=#{merchantId}
  173. </if>
  174. left join wx_coupon c on cc.coupon_id = c.id
  175. left join wx_merchant mer on cm.merchant_id = mer.id
  176. where cc.`target_ad` in (1,2,5,6,7)
  177. <if test="status != null">
  178. and cc.status=#{status}
  179. </if>
  180. <if test=" null != tenantId ">
  181. and cc.tenant_id = #{tenantId}
  182. </if>
  183. <if test=" null != sortColumns"> order by ${sortColumns} </if>
  184. </select>
  185. <sql id="WxCouponCVoColumn">
  186. cc.id,cc.coupon_id,cc.target_ad,cc.begin_time,cc.end_time,
  187. c.tenant_id,c.type,c.cover_img,c.cover_picture,c.detail_picture,c.title,c.sub_title,c.sale_price,c.use_price,
  188. c.use_limit_quantity,c.send_type,c.valid_type,c.valid_start_date,c.valid_end_date,
  189. c.valid_days,c.detail,c.price,c.unit,c.remain_inventory,c.inventory,c.remark,c.status,
  190. c.create_date,c.update_date,c.business,c.sub_business,c.support_transfer,c.press_limit_num, c.auto_refund,c.credit_price,c.conditions,
  191. cc.qr_code
  192. </sql>
  193. <sql id="CVoStatusColumn">
  194. cc.id,cc.coupon_id,c.remain_inventory,c.status
  195. </sql>
  196. <resultMap id="WxCouponCVoMap" type="com.iformall.domain.vo.WxCouponCVo">
  197. <id column="id" jdbcType="BIGINT" property="id"/>
  198. <result column="coupon_id" jdbcType="BIGINT" property="couponId" />
  199. <result column="type" jdbcType="INTEGER" property="type" />
  200. <result column="target_ad" jdbcType="INTEGER" property="targetAd" />
  201. <result column="begin_time" jdbcType="TIMESTAMP" property="beginTime"/>
  202. <result column="end_time" jdbcType="TIMESTAMP" property="endTime"/>
  203. <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
  204. <result column="type" jdbcType="INTEGER" property="type"/>
  205. <result column="cover_img" jdbcType="VARCHAR" property="coverImg"/>
  206. <result column="cover_picture" jdbcType="VARCHAR" property="coverPicture"/>
  207. <result column="detail_picture" jdbcType="VARCHAR" property="detailPicture"/>
  208. <result column="title" jdbcType="VARCHAR" property="title"/>
  209. <result column="sub_title" jdbcType="VARCHAR" property="subTitle"/>
  210. <result column="sale_price" jdbcType="INTEGER" property="salePrice"/>
  211. <result column="use_price" jdbcType="INTEGER" property="usePrice"/>
  212. <result column="use_limit_quantity" jdbcType="INTEGER" property="useLimitQuantity"/>
  213. <result column="send_type" jdbcType="INTEGER" property="sendType"/>
  214. <result column="valid_type" jdbcType="INTEGER" property="validType"/>
  215. <result column="valid_start_date" jdbcType="TIMESTAMP" property="validStartDate"/>
  216. <result column="valid_end_date" jdbcType="TIMESTAMP" property="validEndDate"/>
  217. <result column="valid_days" jdbcType="INTEGER" property="validDays"/>
  218. <result column="detail" jdbcType="VARCHAR" property="detail"/>
  219. <result column="price" jdbcType="INTEGER" property="price"/>
  220. <result column="unit" jdbcType="INTEGER" property="unit"/>
  221. <result column="remain_inventory" jdbcType="INTEGER" property="remainInventory"/>
  222. <result column="inventory" jdbcType="INTEGER" property="inventory"/>
  223. <result column="remark" jdbcType="VARCHAR" property="remark"/>
  224. <result column="status" jdbcType="INTEGER" property="status"/>
  225. <result column="create_date" jdbcType="TIMESTAMP" property="createDate"/>
  226. <result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/>
  227. <result column="business" jdbcType="INTEGER" property="business"/>
  228. <result column="subBusiness" jdbcType="INTEGER" property="subBusiness"/>
  229. <result column="support_transfer" jdbcType="INTEGER" property="supportTransfer"/>
  230. <result column="press_limit_num" jdbcType="INTEGER" property="pressLimitNum"/>
  231. <result column="auto_refund" jdbcType="INTEGER" property="autoRefund"/>
  232. <result column="qr_code" property="qrCode"/>
  233. <result column="conditions" jdbcType="VARCHAR" property="conditions" />
  234. <collection column="{productId=coupon_id}" property="merchantVoList"
  235. ofType="com.iformall.domain.vo.WxMerchantVo"
  236. javaType="java.util.List"
  237. select="com.iformall.mapper.WxCouponMerchantMapper.findMerchantVoList" >
  238. </collection>
  239. </resultMap>
  240. <select id="findVoDetail" parameterType="java.lang.Long" resultMap="WxCouponCVoMap">
  241. select
  242. <include refid="WxCouponCVoColumn"/>
  243. from wx_coupon_channel cc
  244. left join wx_coupon c on cc.coupon_id = c.id
  245. where cc.id = #{id}
  246. </select>
  247. <select id="findVoStatusDetail" parameterType="java.lang.Long" resultMap="WxCouponCVoMap">
  248. select
  249. <include refid="CVoStatusColumn"/>
  250. from wx_coupon c, wx_coupon_channel cc
  251. where cc.coupon_id = c.id and cc.id = #{id}
  252. </select>
  253. <select id="countCoupon" parameterType="com.iformall.domain.po.WxCouponChannel" resultType="java.lang.Integer">
  254. select count(distinct coupon_id) from wx_coupon_channel cc
  255. <include refid="dynamicWhereConditions" />
  256. </select>
  257. <select id="countCouponChannel" parameterType="com.iformall.domain.po.WxCouponChannel" resultType="java.lang.Integer">
  258. select count(*) from wx_coupon_channel cc
  259. <include refid="dynamicWhereConditions" />
  260. </select>
  261. <update id="offExpiriedCouponChannelByEndTime">
  262. update wx_coupon_channel SET status = 1, update_date = now()
  263. where status = 0 and end_time &lt; now()
  264. </update>
  265. <update id="offExpiriedCouponChannelByValidDate">
  266. update wx_coupon_channel cc, wx_coupon c SET cc.status = 1, cc.update_date = now()
  267. where cc.status = 0 and cc.coupon_id = c.id and c.valid_type = 1 and c.valid_end_date &lt; now()
  268. </update>
  269. <update id="offExpiriedCouponChannelByCouponStatus">
  270. update wx_coupon_channel cc, wx_coupon c SET cc.status = 1, cc.update_date = now()
  271. where cc.status = 0 and cc.coupon_id = c.id and c.status = 1
  272. </update>
  273. <update id="offExpiriedCouponChannel2ByEndTime">
  274. update wx_coupon_channel SET status = 1, update_date = now()
  275. where status = 0 and target_ad = 2 and end_time &lt; now()
  276. </update>
  277. <delete id="delByTopic" parameterType="com.iformall.domain.po.WxTopic">
  278. update wx_coupon_channel set status = 1 where sub_target_id = #{id}
  279. </delete>
  280. <select id="findQrcodeEmptyList" resultType="com.iformall.domain.po.WxCouponChannel">
  281. select * from wx_coupon_channel where qr_code is null
  282. </select>
  283. </mapper>