后台服务
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

348 linhas
13 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.WxCouponActionLogMapper">
  4. <resultMap id="BaseResultMap" type="com.iformall.domain.po.WxCouponActionLog">
  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="coupon_order_id" jdbcType="BIGINT" property="couponOrderId" />
  10. <result column="channel_type" jdbcType="INTEGER" property="channelType" />
  11. <result column="channel_id" jdbcType="BIGINT" property="channelId" />
  12. <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
  13. </resultMap>
  14. <sql id="allColumns">
  15. `id`,`tenant_id`,`parent_tenant_id`,`coupon_id`,`coupon_order_id`,`channel_type`,`channel_id`,`create_time`
  16. </sql>
  17. <sql id="dynamicWhereConditions">
  18. where 1 = 1
  19. <if test=" null != id ">
  20. and `id` = #{id}
  21. </if>
  22. <if test=" null != tenantId and '' != tenantId">
  23. and `tenant_id` = #{tenantId}
  24. </if>
  25. <if test=" null != parentTenantId and '' != parentTenantId">
  26. and `parent_tenant_id` = #{parentTenantId}
  27. </if>
  28. <if test=" null != couponId ">
  29. and `coupon_id` = #{couponId}
  30. </if>
  31. <if test=" null != couponOrderId ">
  32. and `coupon_order_id` = #{couponOrderId}
  33. </if>
  34. <if test=" null != channelType ">
  35. and `channel_type` = #{channelType}
  36. </if>
  37. <if test=" null != channelId ">
  38. and `channel_id` = #{channelId}
  39. </if>
  40. <if test=" null != createTime ">
  41. and `create_time` = #{createTime}
  42. </if>
  43. <if test=" null != startTime ">
  44. and `create_time` &gt;= #{startTime}
  45. </if>
  46. <if test=" null != endTime ">
  47. and `create_time` &lt;= #{endTime}
  48. </if>
  49. <if test=" null != ids ">
  50. and id in
  51. <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
  52. #{idItem}
  53. </foreach>
  54. </if>
  55. <if test=" null != sortColumns"> order by ${sortColumns} </if>
  56. </sql>
  57. <select id="selectById" parameterType="java.util.HashMap" resultMap="BaseResultMap">
  58. select <include refid="allColumns"/> from wx_coupon_action_log where id = #{id} and tenant_id = #{tenantId}
  59. </select>
  60. <delete id="deleteById" parameterType="java.util.HashMap">
  61. delete from wx_coupon_action_log where id = #{id} and tenant_id = #{tenantId}
  62. </delete>
  63. <select id="findList" parameterType="com.iformall.domain.po.WxCouponActionLog" resultMap="BaseResultMap">
  64. select
  65. <include refid="allColumns"/>
  66. from wx_coupon_action_log
  67. <include refid="dynamicWhereConditions" />
  68. </select>
  69. <select id="sceneDataMap" resultType="com.iformall.domain.vo.MarkingSceneDataReportVo" parameterType="hashmap">
  70. select DATE_FORMAT(create_time,'%m/%d') as xTime,
  71. (select Count(*) from (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  72. SELECT * from wx_coupon_action_log${tenantEntity.shardTableSuffix}
  73. </foreach>) c
  74. where DATE_FORMAT(create_time,'%m/%d')=xTime
  75. and c.channel_type=2
  76. <if test=" null != tenantId and '' != tenantId">
  77. and `tenant_id` = #{tenantId}
  78. </if>
  79. <if test=" null != parentTenantId and '' != parentTenantId">
  80. and `parent_tenant_id` = #{parentTenantId}
  81. </if>
  82. ) as parkSendCount,
  83. (select Count(*) from (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  84. SELECT * from wx_coupon_action_log${tenantEntity.shardTableSuffix}
  85. </foreach>) c
  86. where DATE_FORMAT(create_time,'%m/%d')=xTime
  87. and c.channel_type=3
  88. <if test=" null != tenantId and '' != tenantId">
  89. and `tenant_id` = #{tenantId}
  90. </if>
  91. <if test=" null != parentTenantId and '' != parentTenantId">
  92. and `parent_tenant_id` = #{parentTenantId}
  93. </if>
  94. ) as verifySendCount,
  95. (select Count(*) from (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  96. SELECT * from wx_coupon_action_log${tenantEntity.shardTableSuffix}
  97. </foreach>) c
  98. where DATE_FORMAT(create_time,'%m/%d')=xTime
  99. and c.channel_type=4
  100. <if test=" null != tenantId and '' != tenantId">
  101. and `tenant_id` = #{tenantId}
  102. </if>
  103. <if test=" null != parentTenantId and '' != parentTenantId">
  104. and `parent_tenant_id` = #{parentTenantId}
  105. </if>
  106. ) as microPaySendCount,
  107. (select Count(*) from (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  108. SELECT * from wx_coupon_action_log${tenantEntity.shardTableSuffix}
  109. </foreach>) c
  110. where DATE_FORMAT(create_time,'%m/%d')=xTime
  111. and c.channel_type=5
  112. <if test=" null != tenantId and '' != tenantId">
  113. and `tenant_id` = #{tenantId}
  114. </if>
  115. <if test=" null != parentTenantId and '' != parentTenantId">
  116. and `parent_tenant_id` = #{parentTenantId}
  117. </if>
  118. ) as orderSendCount,
  119. (select Count(*) from (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  120. SELECT * from wx_coupon_action_log${tenantEntity.shardTableSuffix}
  121. </foreach>) c
  122. where DATE_FORMAT(create_time,'%m/%d')=xTime
  123. and c.channel_type=7
  124. <if test=" null != tenantId and '' != tenantId">
  125. and `tenant_id` = #{tenantId}
  126. </if>
  127. <if test=" null != parentTenantId and '' != parentTenantId">
  128. and `parent_tenant_id` = #{parentTenantId}
  129. </if>
  130. ) as merchantSendCount
  131. from (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  132. SELECT * from wx_coupon_action_log${tenantEntity.shardTableSuffix}
  133. </foreach>) wx_coupon_action_log
  134. where channel_type in (2,3,4,5,7)
  135. <if test=" null != tenantId and '' != tenantId">
  136. and `tenant_id` = #{tenantId}
  137. </if>
  138. <if test=" null != parentTenantId and '' != parentTenantId">
  139. and `parent_tenant_id` = #{parentTenantId}
  140. </if>
  141. and create_time &gt;= #{startTime}
  142. and create_time &lt;= #{endTime}
  143. group by xTime
  144. order by xTime desc
  145. </select>
  146. <select id="getSceneDataMap" resultType="com.iformall.domain.vo.MarkingSceneDataReportTVo" parameterType="hashmap">
  147. select create_time_md as xTime, channel_type, count(create_time_md + '' + channel_type) as count
  148. from wx_coupon_action_log
  149. where channel_type in (2,3,4,5,7)
  150. and `tenant_id` = #{tenantId}
  151. and create_time &gt;= #{startTime}
  152. and create_time &lt;= #{endTime}
  153. group by create_time_md, channel_type
  154. order by create_time_md desc
  155. </select>
  156. <update id="updateCreateTimeMd" parameterType="hashmap">
  157. update wx_coupon_action_log
  158. set create_time_md = DATE_FORMAT(create_time,'%m/%d')
  159. where `tenant_id` = #{tenantId}
  160. </update>
  161. <select id="sceneDataMapJoinCouponOrder" resultType="com.iformall.domain.vo.MarkingSceneDataReportVo" parameterType="hashmap">
  162. select DATE_FORMAT(create_time,'%m/%d') AS xTime,
  163. COUNT(wx_coupon_order.id) as tempCount
  164. from (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  165. SELECT * from wx_coupon_action_log${tenantEntity.shardTableSuffix}
  166. </foreach>) wx_coupon_action_log
  167. left join (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  168. SELECT * from wx_coupon_order${tenantEntity.shardTableSuffix}
  169. </foreach>) wx_coupon_order on wx_coupon_action_log.coupon_order_id=wx_coupon_order.id
  170. where 1=1
  171. <if test=" null != tenantId and '' != tenantId">
  172. and wx_coupon_action_log.`tenant_id` = #{tenantId}
  173. </if>
  174. <if test=" null != parentTenantId and '' != parentTenantId">
  175. and wx_coupon_action_log.`parent_tenant_id` = #{parentTenantId}
  176. </if>
  177. and wx_coupon_action_log.create_time &gt;= #{startTime}
  178. and wx_coupon_action_log.create_time &lt;= #{endTime}
  179. and wx_coupon_action_log.channel_type = #{channelType}
  180. group by xTime
  181. order by xTime desc
  182. </select>
  183. <select id="sceneDataList" resultType="com.iformall.domain.vo.MarkingSceneDataVo" parameterType="com.iformall.domain.dto.MarkingCouponDataReportDto">
  184. select DATE_FORMAT(create_time,'%Y-%m-%d') as xtime,
  185. Count(*) as sendCount
  186. from wx_coupon_action_log
  187. where channel_type=#{channelType}
  188. <if test=" null != tenantId and '' != tenantId">
  189. and `tenant_id` = #{tenantId}
  190. </if>
  191. <if test=" null != parentTenantId and '' != parentTenantId">
  192. and `parent_tenant_id` = #{parentTenantId}
  193. </if>
  194. <if test=" null != startTime ">
  195. and create_time &gt;= #{startTime}
  196. </if>
  197. <if test=" null != endTime ">
  198. and create_time &lt;= #{endTime}
  199. </if>
  200. group by xtime
  201. <if test=" null != sortColumns"> order by ${sortColumns} </if>
  202. <if test=" null == sortColumns">order by xtime desc</if>
  203. </select>
  204. <select id="sceneDataJoinCouponOrderList" resultType="com.iformall.domain.vo.MarkingSceneDataReportVo"
  205. parameterType="hashmap">
  206. select DATE_FORMAT(cal.create_time,'%Y-%m-%d') AS xTime,
  207. COUNT(co.id) as tempCount
  208. from wx_coupon_action_log cal
  209. left join wx_coupon_order co on cal.coupon_order_id=co.id
  210. where co.coupon_order_status = 1
  211. <if test=" null != tenantId and '' != tenantId">
  212. and cal.`tenant_id` = #{tenantId}
  213. </if>
  214. <if test=" null != parentTenantId and '' != parentTenantId">
  215. and cal.`parent_tenant_id` = #{parentTenantId}
  216. </if>
  217. <if test=" null != startTime ">
  218. and cal.create_time &gt;= #{startTime}
  219. </if>
  220. <if test=" null != endTime ">
  221. and cal.create_time &lt;= #{endTime}
  222. </if>
  223. and cal.channel_type = #{channelType}
  224. group by xTime
  225. order by xTime desc
  226. </select>
  227. <select id="getCountByDateLimit" resultType="java.lang.Integer">
  228. select COUNT(*) FROM wx_coupon_action_log
  229. where channel_type in (2,3,4,5,7)
  230. and `tenant_id` = #{tenantId}
  231. and `create_time` &gt;= #{startTime}
  232. and `create_time` &lt;= #{endTime}
  233. </select>
  234. <select id="getCountByChannelId" resultType="java.lang.Integer">
  235. select COUNT(1) FROM wx_coupon_action_log
  236. where channel_type = #{channelType}
  237. and channel_id = #{channelId}
  238. <if test=" null != tenantId and '' != tenantId">
  239. and `tenant_id` = #{tenantId}
  240. </if>
  241. <if test=" null != parentTenantId and '' != parentTenantId">
  242. and `parent_tenant_id` = #{parentTenantId}
  243. </if>
  244. </select>
  245. <select id="getCountByUser" resultType="java.lang.Integer" parameterType="hashmap">
  246. select COUNT(*)
  247. FROM wx_coupon_action_log a, wx_coupon_order o
  248. WHERE a.coupon_order_id = o.id
  249. <if test=" null != tenantId and '' != tenantId">
  250. and a.`tenant_id` = #{tenantId}
  251. </if>
  252. <if test=" null != parentTenantId and '' != parentTenantId">
  253. and a.`parent_tenant_id` = #{parentTenantId}
  254. </if>
  255. AND o.c_user_id = #{cUserId}
  256. AND date(a.create_time) = curdate()
  257. </select>
  258. <select id="getCountByUserAndCoupon" resultType="java.lang.Integer" parameterType="hashmap">
  259. select COUNT(*)
  260. FROM wx_coupon_action_log a, wx_coupon_order o
  261. WHERE a.coupon_order_id = o.id
  262. <if test=" null != tenantId and '' != tenantId">
  263. and a.`tenant_id` = #{tenantId}
  264. </if>
  265. <if test=" null != parentTenantId and '' != parentTenantId">
  266. and a.`parent_tenant_id` = #{parentTenantId}
  267. </if>
  268. AND o.c_user_id = #{cUserId}
  269. AND a.coupon_id = #{couponId}
  270. AND date(a.create_time) between #{beginDate} and #{endDate}
  271. </select>
  272. <select id="getCountByUserAndCouponAndDate" resultType="java.lang.Integer" parameterType="hashmap">
  273. select COUNT(*)
  274. FROM wx_coupon_action_log a, wx_coupon_order o
  275. WHERE a.coupon_order_id = o.id
  276. <if test=" null != tenantId and '' != tenantId">
  277. and a.`tenant_id` = #{tenantId}
  278. </if>
  279. <if test=" null != parentTenantId and '' != parentTenantId">
  280. and a.`parent_tenant_id` = #{parentTenantId}
  281. </if>
  282. AND o.c_user_id = #{cUserId}
  283. <if test=" null != couponId ">
  284. AND a.coupon_id = #{couponId}
  285. </if>
  286. AND a.channel_type = #{channelType}
  287. and a.create_time &gt;= #{startTime}
  288. and a.create_time &lt;= #{endTime}
  289. </select>
  290. <select id="getActionLog" resultType="com.iformall.domain.vo.WxCouponActionLogVo">
  291. SELECT cal.id AS actionId,
  292. cal.coupon_id AS couponId,
  293. cal.create_time AS createDate,
  294. cs.id AS couponSendId,
  295. c.title,
  296. cu.nick_name AS userName,
  297. cu.phone,
  298. mbu.NAME AS operator
  299. FROM wx_coupon_action_log cal
  300. LEFT JOIN wx_coupon_send cs ON cal.channel_id = cs.id
  301. LEFT JOIN wx_coupon_order co ON cal.coupon_order_id = co.id
  302. LEFT JOIN wx_coupon c ON cal.coupon_id = c.id
  303. LEFT JOIN wx_c_user_basic_info cu ON cu.id = co.c_user_id
  304. LEFT JOIN wx_merchant_b_user mbu ON mbu.id = cal.operator_id
  305. <!-- and concat(mbu.merchant_id,'') = JSON_EXTRACT(cs.conditions , '$.id') -->
  306. WHERE cal.channel_type = #{channelType}
  307. AND cs.conditions -> '$.id' = concat(#{merchantId},'')
  308. <if test=" null != beginDate ">
  309. AND cal.create_time &gt;= #{beginDate}
  310. </if>
  311. <if test=" null != endDate ">
  312. AND cal.create_time &lt; #{endDate}
  313. </if>
  314. <if test=" null != sortColumns"> order by ${sortColumns} </if>
  315. </select>
  316. </mapper>