KuaishouLiveAccountReportMapper.xml 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.ruixuan.report.mapper.KuaishouLiveAccountReportMapper">
  6. <select id="operateHomePageHead" resultType="com.alibaba.fastjson.JSONObject">
  7. SELECT
  8. t1.*,
  9. IFNULL(ROUND((t1.costTotal - t2.costTotal) / t2.costTotal * 100, 2), 0) as 'costTotalRoi',
  10. IFNULL(ROUND((t1.selfOperationCostTotal - t2.selfOperationCostTotal) / t2.selfOperationCostTotal * 100, 2), 0)
  11. as 'selfOperationCostTotalRoi',
  12. IFNULL(ROUND(t1.selfOperationCostTotal / t1.costTotal * 100, 2), 0) as 'roi'
  13. FROM (
  14. SELECT
  15. SUM(cost_total) AS 'costTotal',
  16. COUNT(DISTINCT CASE WHEN t1.cost_total > 0 THEN t1.account_id ELSE 0 END) AS 'accountNum',
  17. SUM(CASE WHEN t1.account_type = 1 THEN cost_total ELSE 0 END) AS 'selfOperationCostTotal'
  18. FROM kuaishou_live_account_report_hourly_dw t1
  19. LEFT JOIN kuaishou_account t2 ON t1.account_id = t2.account_id
  20. WHERE report_date = #{today}
  21. AND hour &lt;= #{hour}
  22. <if test="userList != null and userList.size() > 0 ">
  23. AND user_id IN
  24. <foreach collection="userList" item="userId" open="(" separator="," close=")">
  25. #{userId}
  26. </foreach>
  27. </if>
  28. ) t1
  29. LEFT JOIN
  30. (
  31. SELECT
  32. SUM(cost_total) AS 'costTotal',
  33. SUM(CASE WHEN t1.account_type = 1 THEN cost_total ELSE 0 END) AS 'selfOperationCostTotal'
  34. FROM kuaishou_live_account_report_hourly_dw t1
  35. WHERE report_date = #{yesterday}
  36. AND hour &lt;= #{hour}
  37. <if test="userList != null and userList.size() > 0 ">
  38. AND user_id IN
  39. <foreach collection="userList" item="userId" open="(" separator="," close=")">
  40. #{userId}
  41. </foreach>
  42. </if>
  43. ) t2 ON 1 = 1
  44. </select>
  45. <select id="getCustomersNum" resultType="Integer">
  46. SELECT
  47. COUNT(DISTINCT advertiser_id)
  48. FROM
  49. kuaishou_live_account_report_hourly_dw t1
  50. LEFT JOIN kuaishou_account t2 ON t1.account_id = t2.account_id
  51. WHERE cost_total > 0
  52. <if test="userList != null and userList.size() > 0 ">
  53. AND user_id IN
  54. <foreach collection="userList" item="userId" open="(" separator="," close=")">
  55. #{userId}
  56. </foreach>
  57. </if>
  58. AND report_date = #{today}
  59. AND hour &lt;= #{hour}
  60. </select>
  61. <select id="getProjectCostListByHourly" resultType="com.alibaba.fastjson.JSONObject">
  62. SELECT * FROM (
  63. SELECT t1.*,
  64. IFNULL(ROUND((t1.costTotal - t2.costTotal) / t2.costTotal * 100, 2), 0) as 'costTotalRoi',
  65. IFNULL(ROUND((t1.roi - t2.roi) / t2.roi * 100, 2), 0) as 'rRoi'
  66. FROM (
  67. SELECT t1.project_id as 'projectId',
  68. t2.project_name as 'projectName',
  69. t2.operator_id as 'operatorId',
  70. t2.operator_name as 'operatorName',
  71. SUM(cost_total) as 'costTotal',
  72. IFNULL(ROUND(SUM(t1.gmv) / SUM(cost_total), 2), 0) as 'roi'
  73. FROM kuaishou_live_account_report_hourly_dw t1
  74. LEFT JOIN `kuaishou_project` t2 ON t1.project_id = t2.id
  75. WHERE report_date = #{today}
  76. AND hour &lt;= #{hour}
  77. AND t1.account_type = 1
  78. <if test="projectIds != null and projectIds.size() > 0 ">
  79. AND t1.project_id IN
  80. <foreach collection="projectIds" item="projectId" open="(" separator="," close=")">
  81. #{projectId}
  82. </foreach>
  83. </if>
  84. GROUP BY t1.project_id
  85. HAVING SUM(cost_total)>0
  86. ) t1
  87. LEFT JOIN
  88. (
  89. SELECT
  90. t1.project_id as 'projectId',
  91. SUM(cost_total) as 'costTotal',
  92. IFNULL(ROUND(SUM(t1.gmv) / SUM(cost_total), 2), 0) as 'roi'
  93. FROM kuaishou_live_account_report_hourly_dw t1
  94. WHERE report_date = #{yesterday}
  95. AND hour &lt;= #{hour}
  96. AND account_type = 1
  97. <if test="projectIds != null and projectIds.size() > 0 ">
  98. AND t1.project_id IN
  99. <foreach collection="projectIds" item="projectId" open="(" separator="," close=")">
  100. #{projectId}
  101. </foreach>
  102. </if>
  103. GROUP BY t1.project_id
  104. ) t2 ON t1.projectId = t2.projectId
  105. ) t ORDER BY costTotal desc
  106. </select>
  107. <select id="getProjectCostListByDaily" resultType="com.alibaba.fastjson.JSONObject">
  108. SELECT *
  109. FROM (
  110. SELECT t1.*,
  111. IFNULL(ROUND((t1.costTotal - t2.costTotal) / t2.costTotal * 100, 2), 0) as 'costTotalRoi',
  112. IFNULL(ROUND((t1.roi - t2.roi) / t2.roi * 100, 2), 0) as 'rRoi'
  113. FROM (
  114. SELECT t1.project_id as 'projectId',
  115. t2.project_name as 'projectName',
  116. t2.operator_id as 'operatorId',
  117. t2.operator_name as 'operatorName',
  118. SUM(cost_total) as 'costTotal',
  119. IFNULL(ROUND(SUM(t1.gmv) / SUM(cost_total), 2), 0) as 'roi'
  120. FROM kuaishou_live_account_report_daily_dw t1
  121. LEFT JOIN `kuaishou_project` t2 ON t1.project_id = t2.id
  122. WHERE report_date >= #{startDate}
  123. AND report_date &lt;= #{endDate}
  124. AND t1.account_type = 1
  125. <if test="projectIds != null and projectIds.size() > 0 ">
  126. AND t1.project_id IN
  127. <foreach collection="projectIds" item="projectId" open="(" separator="," close=")">
  128. #{projectId}
  129. </foreach>
  130. </if>
  131. GROUP BY t1.project_id
  132. HAVING SUM(cost_total)>0
  133. ) t1
  134. LEFT JOIN
  135. (
  136. SELECT
  137. project_id as 'projectId',
  138. SUM(cost_total) as 'costTotal',
  139. IFNULL(ROUND(SUM(gmv) / SUM(cost_total), 2), 0) as 'roi'
  140. FROM kuaishou_live_account_report_daily_dw
  141. WHERE report_date >=#{lastStart}
  142. AND report_date &lt;=#{lastEnd}
  143. AND account_type = 1
  144. <if test="projectIds != null and projectIds.size() > 0 ">
  145. AND project_id IN
  146. <foreach collection="projectIds" item="projectId" open="(" separator="," close=")">
  147. #{projectId}
  148. </foreach>
  149. </if>
  150. GROUP BY project_id
  151. ) t2 ON t1.projectId = t2.projectId
  152. ) t
  153. ORDER BY costTotal desc
  154. </select>
  155. <select id="getOperationsGroupCostByHourly" resultType="com.alibaba.fastjson.JSONObject">
  156. SELECT
  157. IFNULL(t1.costTotal,0) as 'costTotal',
  158. IFNULL(t1.perCost,0) as 'perCost',
  159. IFNULL(ROUND((t1.costTotal - t2.costTotal) / t2.costTotal * 100, 2), 0) as 'roi',
  160. IFNULL(t2.costTotal,0) as 'yesCostTotal'
  161. FROM (
  162. SELECT
  163. SUM(cost_total) as 'costTotal',
  164. IFNULL(ROUND(SUM(cost_total) / ${operateNum}/${days}, 2), 0) as 'perCost'
  165. FROM kuaishou_live_account_report_hourly_dw
  166. WHERE report_date = #{today}
  167. AND hour &lt;= #{hour}
  168. AND account_type = 1
  169. <if test="userList != null and userList.size() > 0 ">
  170. AND user_id IN
  171. <foreach collection="userList" item="userId" open="(" separator="," close=")">
  172. #{userId}
  173. </foreach>
  174. </if>
  175. ) t1
  176. LEFT JOIN
  177. (
  178. SELECT
  179. SUM(cost_total) as 'costTotal'
  180. FROM kuaishou_live_account_report_hourly_dw
  181. WHERE report_date = #{yesterday}
  182. AND hour &lt;= #{hour}
  183. AND account_type = 1
  184. <if test="userList != null and userList.size() > 0 ">
  185. AND user_id IN
  186. <foreach collection="userList" item="userId" open="(" separator="," close=")">
  187. #{userId}
  188. </foreach>
  189. </if>
  190. ) t2 ON 1 = 1
  191. </select>
  192. <select id="getOperationsGroupCostByDaily" resultType="com.alibaba.fastjson.JSONObject">
  193. SELECT
  194. IFNULL(t1.costTotal,0) as 'costTotal',
  195. IFNULL(t1.perCost,0) as 'perCost',
  196. IFNULL(ROUND((t1.costTotal - t2.costTotal) / t2.costTotal * 100, 2), 0) as 'roi',
  197. IFNULL(t2.costTotal,0) as 'yesCostTotal'
  198. FROM (
  199. SELECT
  200. SUM(cost_total) as 'costTotal',
  201. IFNULL(ROUND(SUM(cost_total) / ${operateNum}/${days}, 2), 0) as 'perCost'
  202. FROM kuaishou_live_account_report_daily_dw
  203. WHERE report_date >= #{startDate}
  204. AND report_date &lt;= #{endDate}
  205. AND account_type = 1
  206. <if test="userList != null and userList.size() > 0 ">
  207. AND user_id IN
  208. <foreach collection="userList" item="userId" open="(" separator="," close=")">
  209. #{userId}
  210. </foreach>
  211. </if>
  212. ) t1
  213. LEFT JOIN
  214. (
  215. SELECT
  216. SUM(cost_total) as 'costTotal'
  217. FROM kuaishou_live_account_report_daily_dw
  218. WHERE report_date >=#{lastStart}
  219. AND report_date &lt;=#{lastEnd}
  220. AND account_type = 1
  221. <if test="userList != null and userList.size() > 0 ">
  222. AND user_id IN
  223. <foreach collection="userList" item="userId" open="(" separator="," close=")">
  224. #{userId}
  225. </foreach>
  226. </if>
  227. ) t2 ON 1 = 1
  228. </select>
  229. <select id="getOperateCostListByHourly" resultType="com.alibaba.fastjson.JSONObject">
  230. SELECT
  231. t1.*,
  232. IFNULL( ROUND(( t1.costTotal - t2.costTotal )/ t2.costTotal * 100,2), 0) AS 'costTotalRoi',
  233. IFNULL(ROUND(t1.costTotal / t1.accountNum/${days}, 2), 0) as 'accountCost'
  234. FROM
  235. (
  236. SELECT
  237. t2.operator_id AS 'userId',
  238. t2.operator_name AS 'userName',
  239. SUM(cost_total) AS 'costTotal',
  240. count( DISTINCT CASE WHEN t1.cost_total > 0 THEN t1.account_id ELSE 0 END ) AS 'accountNum',
  241. count( DISTINCT CASE WHEN t1.cost_total > 0 THEN t1.project_id ELSE 0 END ) AS 'projectNum'
  242. FROM
  243. kuaishou_live_account_report_hourly_dw t1
  244. LEFT JOIN kuaishou_account t2 ON t1.account_id = t2.account_id
  245. WHERE report_date = #{today}
  246. AND hour &lt;= #{hour}
  247. AND t2.account_type = 1
  248. <if test="userList != null and userList.size() > 0 ">
  249. AND t1.user_id IN
  250. <foreach collection="userList" item="userId" open="(" separator="," close=")">
  251. #{userId}
  252. </foreach>
  253. </if>
  254. GROUP BY
  255. t1.user_id
  256. ORDER BY costTotal desc
  257. ) t1
  258. LEFT JOIN (
  259. SELECT
  260. user_id AS 'userId',
  261. SUM(cost_total) AS 'costTotal'
  262. FROM
  263. kuaishou_live_account_report_hourly_dw
  264. WHERE report_date = #{yesterday}
  265. AND hour &lt;= #{hour}
  266. AND account_type = 1
  267. <if test="userList != null and userList.size() > 0 ">
  268. AND user_id IN
  269. <foreach collection="userList" item="userId" open="(" separator="," close=")">
  270. #{userId}
  271. </foreach>
  272. </if>
  273. GROUP BY
  274. user_id
  275. ) t2 ON t1.userId = t2.userId
  276. </select>
  277. <select id="getOperateCostListByDaily" resultType="com.alibaba.fastjson.JSONObject">
  278. SELECT
  279. t1.*,
  280. IFNULL( ROUND(( t1.costTotal - t2.costTotal )/ t2.costTotal * 100,2), 0) AS 'costTotalRoi',
  281. IFNULL(ROUND(t1.costTotal / t1.accountNum/${days}, 2), 0) as 'accountCost'
  282. FROM
  283. (
  284. SELECT
  285. t2.operator_id AS 'userId',
  286. t2.operator_name AS 'userName',
  287. SUM(cost_total) AS 'costTotal',
  288. count( DISTINCT CASE WHEN t1.cost_total > 0 THEN t1.account_id ELSE 0 END ) AS 'accountNum',
  289. count( DISTINCT CASE WHEN t1.cost_total > 0 THEN t1.project_id ELSE 0 END ) AS 'projectNum'
  290. FROM
  291. kuaishou_live_account_report_daily_dw t1
  292. LEFT JOIN kuaishou_account t2 ON t1.account_id = t2.account_id
  293. WHERE report_date >= #{startDate}
  294. AND report_date &lt;= #{endDate}
  295. AND t2.account_type = 1
  296. <if test="userList != null and userList.size() > 0 ">
  297. AND user_id IN
  298. <foreach collection="userList" item="userId" open="(" separator="," close=")">
  299. #{userId}
  300. </foreach>
  301. </if>
  302. GROUP BY
  303. t1.user_id
  304. ORDER BY costTotal desc
  305. ) t1
  306. LEFT JOIN (
  307. SELECT
  308. user_id AS 'userId',
  309. SUM(cost_total) AS 'costTotal'
  310. FROM
  311. kuaishou_live_account_report_daily_dw
  312. WHERE report_date >=#{lastStart}
  313. AND report_date &lt;=#{lastEnd}
  314. AND account_type = 1
  315. <if test="userList != null and userList.size() > 0 ">
  316. AND user_id IN
  317. <foreach collection="userList" item="userId" open="(" separator="," close=")">
  318. #{userId}
  319. </foreach>
  320. </if>
  321. GROUP BY
  322. user_id
  323. ) t2 ON t1.userId = t2.userId
  324. </select>
  325. <select id="getOperateCostTotalByHourly" resultType="com.alibaba.fastjson.JSONObject">
  326. SELECT
  327. t1.*,
  328. IFNULL( ROUND(( t1.costTotal - t2.costTotal )/ t2.costTotal * 100,2), 0) AS 'costTotalRoi',
  329. IFNULL(ROUND(t1.costTotal / t1.accountNum/${days}, 2), 0) as 'accountCost'
  330. FROM
  331. (
  332. SELECT
  333. '汇总' AS 'userName',
  334. SUM(cost_total) AS 'costTotal',
  335. count( DISTINCT CASE WHEN t1.cost_total > 0 THEN t1.account_id ELSE 0 END ) AS 'accountNum',
  336. count( DISTINCT CASE WHEN t1.cost_total > 0 THEN t1.project_id ELSE 0 END ) AS 'projectNum'
  337. FROM
  338. kuaishou_live_account_report_hourly_dw t1
  339. LEFT JOIN kuaishou_account t2 ON t1.account_id = t2.account_id
  340. WHERE report_date = #{today}
  341. AND hour &lt;= #{hour}
  342. AND t2.account_type = 1
  343. <if test="userList != null and userList.size() > 0 ">
  344. AND t1.user_id IN
  345. <foreach collection="userList" item="userId" open="(" separator="," close=")">
  346. #{userId}
  347. </foreach>
  348. </if>
  349. ) t1
  350. LEFT JOIN (
  351. SELECT
  352. SUM(cost_total) AS 'costTotal'
  353. FROM
  354. kuaishou_live_account_report_hourly_dw
  355. WHERE report_date = #{yesterday}
  356. AND hour &lt;= #{hour}
  357. AND account_type = 1
  358. <if test="userList != null and userList.size() > 0 ">
  359. AND user_id IN
  360. <foreach collection="userList" item="userId" open="(" separator="," close=")">
  361. #{userId}
  362. </foreach>
  363. </if>
  364. ) t2 ON 1=1
  365. </select>
  366. <select id="getOperateCostTotalByDaily" resultType="com.alibaba.fastjson.JSONObject">
  367. SELECT
  368. t1.*,
  369. IFNULL(ROUND((t1.costTotal - t2.costTotal)/ t2.costTotal * 100,2), 0) AS 'costTotalRoi',
  370. IFNULL(ROUND(t1.costTotal / t1.accountNum/${days}, 2), 0) as 'accountCost'
  371. FROM
  372. (
  373. SELECT
  374. '汇总' AS 'userName',
  375. SUM(cost_total) AS 'costTotal',
  376. count( DISTINCT CASE WHEN t1.cost_total > 0 THEN t1.account_id ELSE 0 END ) AS 'accountNum',
  377. count( DISTINCT CASE WHEN t1.cost_total > 0 THEN t1.project_id ELSE 0 END ) AS 'projectNum'
  378. FROM
  379. kuaishou_live_account_report_daily_dw t1
  380. LEFT JOIN kuaishou_account t2 ON t1.account_id = t2.account_id
  381. WHERE report_date >= #{startDate}
  382. AND report_date &lt;= #{endDate}
  383. AND t2.account_type = 1
  384. <if test="userList != null and userList.size() > 0 ">
  385. AND user_id IN
  386. <foreach collection="userList" item="userId" open="(" separator="," close=")">
  387. #{userId}
  388. </foreach>
  389. </if>
  390. ) t1
  391. LEFT JOIN (
  392. SELECT
  393. SUM(cost_total) AS 'costTotal'
  394. FROM
  395. kuaishou_live_account_report_daily_dw
  396. WHERE report_date >=#{lastStart}
  397. AND report_date &lt;=#{lastEnd}
  398. AND account_type = 1
  399. <if test="userList != null and userList.size() > 0 ">
  400. AND user_id IN
  401. <foreach collection="userList" item="userId" open="(" separator="," close=")">
  402. #{userId}
  403. </foreach>
  404. </if>
  405. ) t2 ON 1=1
  406. </select>
  407. <select id="getOperateCostTrendChartListByHourly" resultType="com.alibaba.fastjson.JSONObject">
  408. SELECT
  409. hour as 'time',
  410. SUM(cost_total) AS 'costTotal'
  411. FROM
  412. kuaishou_live_account_report_hourly_dw
  413. WHERE account_type = 1
  414. AND report_date = #{today}
  415. <if test="userList != null and userList.size() > 0 ">
  416. AND user_id IN
  417. <foreach collection="userList" item="userId" open="(" separator="," close=")">
  418. #{userId}
  419. </foreach>
  420. </if>
  421. GROUP BY hour
  422. ORDER BY hour
  423. </select>
  424. <select id="getOperateCostTrendChartListByDaily" resultType="com.alibaba.fastjson.JSONObject">
  425. SELECT
  426. date_format(report_date, '%Y-%m-%d') as 'time',
  427. SUM(cost_total) AS 'costTotal'
  428. FROM
  429. kuaishou_live_account_report_daily_dw
  430. WHERE account_type = 1
  431. AND report_date >= #{startDate}
  432. AND report_date &lt;= #{endDate}
  433. <if test="userList != null and userList.size() > 0 ">
  434. AND user_id IN
  435. <foreach collection="userList" item="userId" open="(" separator="," close=")">
  436. #{userId}
  437. </foreach>
  438. </if>
  439. GROUP BY report_date
  440. ORDER BY report_date
  441. </select>
  442. <select id="getStatisticalReportHeadByHourly" resultType="com.alibaba.fastjson.JSONObject">
  443. SELECT
  444. ROUND(t1.costTotal,2)AS'costTotal',
  445. ROUND(t1.t0Gmv,2)AS't0Gmv',
  446. ROUND(t1.t0Roi,2)AS't0Roi',
  447. ROUND(t1.viewCost,2)AS'viewCost',
  448. ROUND(t1.orderCost,2)AS'orderCost',
  449. t1.upFans,
  450. IFNULL(ROUND((t1.costTotal - t2.costTotal)/ t2.costTotal * 100,2), 0) AS 'costTotalRoi',
  451. IFNULL(ROUND((t1.t0Gmv - t2.t0Gmv)/ t2.t0Gmv * 100,2), 0) AS 't0GmvRoi',
  452. IFNULL(ROUND((t1.t0Roi - t2.t0Roi)/ t2.t0Roi * 100,2), 0) AS 't0RoiRoi',
  453. IFNULL(ROUND((t1.viewCost - t2.viewCost)/ t2.viewCost * 100,2), 0) AS 'viewCostRoi',
  454. IFNULL(ROUND((t1.orderCost - t2.orderCost)/ t2.orderCost * 100,2), 0) AS 'orderCostRoi',
  455. IFNULL(ROUND((t1.upFans - t2.upFans)/ t2.upFans * 100,2), 0) AS 'upFansRoi'
  456. FROM
  457. (
  458. SELECT
  459. IFNULL(SUM(cost_total),0)AS'costTotal',
  460. IFNULL(SUM(gmv),0)AS't0Gmv',
  461. IFNULL(SUM(gmv)/SUM(cost_total),0)AS't0Roi',
  462. IFNULL(SUM(cost_total)/SUM(standard_live_played_started),0)AS'viewCost',
  463. IFNULL(SUM(merchant_reco_fans),0)AS'upFans',
  464. IFNULL(SUM(cost_total)/SUM(t0_order_cnt),0)AS'orderCost'
  465. FROM
  466. kuaishou_live_account_report_hourly_dw
  467. WHERE report_date = #{today}
  468. AND hour &lt;= #{hour}
  469. AND account_type = 1
  470. <if test="accountIdList != null and accountIdList.size() > 0 ">
  471. AND account_id in
  472. <foreach collection="accountIdList" item="accountId" open="(" separator="," close=")">
  473. #{accountId}
  474. </foreach>
  475. </if>
  476. )t1
  477. LEFT JOIN
  478. (
  479. SELECT
  480. IFNULL(SUM(cost_total),0)AS'costTotal',
  481. IFNULL(SUM(gmv),0)AS't0Gmv',
  482. IFNULL(SUM(gmv)/SUM(cost_total),0)AS't0Roi',
  483. IFNULL(SUM(cost_total)/SUM(standard_live_played_started),0)AS'viewCost',
  484. IFNULL(SUM(merchant_reco_fans),0)AS'upFans',
  485. IFNULL(SUM(cost_total)/SUM(t0_order_cnt),0)AS'orderCost'
  486. FROM
  487. kuaishou_live_account_report_hourly_dw
  488. WHERE report_date = #{yesterday}
  489. AND hour &lt;= #{hour}
  490. AND account_type = 1
  491. <if test="accountIdList != null and accountIdList.size() > 0 ">
  492. AND account_id in
  493. <foreach collection="accountIdList" item="accountId" open="(" separator="," close=")">
  494. #{accountId}
  495. </foreach>
  496. </if>
  497. )t2 ON 1=1
  498. </select>
  499. <select id="getStatisticalReportHeadByDaily" resultType="com.alibaba.fastjson.JSONObject">
  500. SELECT
  501. ROUND(t1.costTotal,2)AS'costTotal',
  502. ROUND(t1.t0Gmv,2)AS't0Gmv',
  503. ROUND(t1.t0Roi,2)AS't0Roi',
  504. ROUND(t1.viewCost,2)AS'viewCost',
  505. ROUND(t1.orderCost,2)AS'orderCost',
  506. t1.upFans,
  507. IFNULL(ROUND((t1.costTotal - t2.costTotal)/ t2.costTotal * 100,2), 0) AS 'costTotalRoi',
  508. IFNULL(ROUND((t1.t0Gmv - t2.t0Gmv)/ t2.t0Gmv * 100,2), 0) AS 't0GmvRoi',
  509. IFNULL(ROUND((t1.t0Roi - t2.t0Roi)/ t2.t0Roi * 100,2), 0) AS 't0RoiRoi',
  510. IFNULL(ROUND((t1.viewCost - t2.viewCost)/ t2.viewCost * 100,2), 0) AS 'viewCostRoi',
  511. IFNULL(ROUND((t1.orderCost - t2.orderCost)/ t2.orderCost * 100,2), 0) AS 'orderCostRoi',
  512. IFNULL(ROUND((t1.upFans - t2.upFans)/ t2.upFans * 100,2), 0) AS 'upFansRoi'
  513. FROM
  514. (
  515. SELECT
  516. IFNULL(SUM(cost_total),0)AS'costTotal',
  517. IFNULL(SUM(gmv),0)AS't0Gmv',
  518. IFNULL(SUM(gmv)/SUM(cost_total),0)AS't0Roi',
  519. IFNULL(SUM(cost_total)/SUM(standard_live_played_started),0)AS'viewCost',
  520. IFNULL(SUM(merchant_reco_fans),0)AS'upFans',
  521. IFNULL(SUM(cost_total)/SUM(t0_order_cnt),0)AS'orderCost'
  522. FROM
  523. kuaishou_live_account_report_daily_dw
  524. WHERE report_date >= #{startDate}
  525. AND report_date &lt;= #{endDate}
  526. AND account_type = 1
  527. <if test="accountIdList != null and accountIdList.size() > 0 ">
  528. AND account_id in
  529. <foreach collection="accountIdList" item="accountId" open="(" separator="," close=")">
  530. #{accountId}
  531. </foreach>
  532. </if>
  533. )t1
  534. LEFT JOIN
  535. (
  536. SELECT
  537. IFNULL(SUM(cost_total),0)AS'costTotal',
  538. IFNULL(SUM(gmv),0)AS't0Gmv',
  539. IFNULL(SUM(gmv)/SUM(cost_total),0)AS't0Roi',
  540. IFNULL(SUM(cost_total)/SUM(standard_live_played_started),0)AS'viewCost',
  541. IFNULL(SUM(merchant_reco_fans),0)AS'upFans',
  542. IFNULL(SUM(cost_total)/SUM(t0_order_cnt),0)AS'orderCost'
  543. FROM
  544. kuaishou_live_account_report_daily_dw
  545. WHERE report_date >= #{startDate}
  546. AND report_date &lt;= #{endDate}
  547. AND account_type = 1
  548. <if test="accountIdList != null and accountIdList.size() > 0 ">
  549. AND account_id in
  550. <foreach collection="accountIdList" item="accountId" open="(" separator="," close=")">
  551. #{accountId}
  552. </foreach>
  553. </if>
  554. )t2 ON 1=1
  555. </select>
  556. <select id="getvisitorStatisticsTrendChartListByHourly" resultType="com.alibaba.fastjson.JSONObject">
  557. SELECT
  558. hour as 'time',
  559. SUM(cost_total) AS 'costTotal'
  560. FROM
  561. kuaishou_live_account_report_hourly_dw
  562. WHERE account_type = 1
  563. AND report_date = #{today}
  564. <if test="accountIdList != null and accountIdList.size() > 0 ">
  565. AND account_id in
  566. <foreach collection="accountIdList" item="accountId" open="(" separator="," close=")">
  567. #{accountId}
  568. </foreach>
  569. </if>
  570. GROUP BY hour
  571. ORDER BY hour
  572. </select>
  573. <select id="getvisitorStatisticsTrendChartListByDaily" resultType="com.alibaba.fastjson.JSONObject">
  574. SELECT
  575. date_format(report_date, '%Y-%m-%d') as 'time',
  576. SUM(cost_total) AS 'costTotal'
  577. FROM
  578. kuaishou_live_account_report_daily_dw
  579. WHERE account_type = 1
  580. AND report_date >= #{startDate}
  581. AND report_date &lt;= #{endDate}
  582. <if test="accountIdList != null and accountIdList.size() > 0 ">
  583. AND account_id in
  584. <foreach collection="accountIdList" item="accountId" open="(" separator="," close=")">
  585. #{accountId}
  586. </foreach>
  587. </if>
  588. GROUP BY report_date
  589. ORDER BY report_date
  590. </select>
  591. <select id="getNodeAccountsCostByHourly" resultType="com.alibaba.fastjson.JSONObject">
  592. SELECT
  593. hour as 'time',
  594. account_id as 'accountId',
  595. account_name as 'accountName',
  596. SUM(cost_total) AS 'costTotal'
  597. FROM
  598. kuaishou_live_account_report_hourly_dw
  599. WHERE account_type = 1
  600. AND report_date = #{date}
  601. AND hour = #{hour}
  602. <if test="accountIdList != null and accountIdList.size() > 0 ">
  603. AND account_id in
  604. <foreach collection="accountIdList" item="accountId" open="(" separator="," close=")">
  605. #{accountId}
  606. </foreach>
  607. </if>
  608. GROUP BY account_id
  609. ORDER BY account_id
  610. </select>
  611. <select id="getNodeAccountsCostByDaily" resultType="com.alibaba.fastjson.JSONObject">
  612. SELECT
  613. date_format(report_date, '%Y-%m-%d') as 'time',
  614. account_id as 'accountId',
  615. account_name as 'accountName',
  616. SUM(cost_total) AS 'costTotal'
  617. FROM
  618. kuaishou_live_account_report_daily_dw
  619. WHERE account_type = 1
  620. AND report_date = #{date}
  621. <if test="accountIdList != null and accountIdList.size() > 0 ">
  622. AND account_id in
  623. <foreach collection="accountIdList" item="accountId" open="(" separator="," close=")">
  624. #{accountId}
  625. </foreach>
  626. </if>
  627. GROUP BY account_id
  628. ORDER BY account_id
  629. </select>
  630. <select id="getAccountDataReportByHourly" resultType="com.alibaba.fastjson.JSONObject">
  631. SELECT
  632. date_format(report_date, '%Y-%m-%d') as 'date',
  633. CONCAT(hour,':00-',(hour+1),':00') as 'time',
  634. hour,
  635. ${filedAll}
  636. FROM
  637. kuaishou_live_account_report_hourly_dw t1
  638. WHERE account_type = 1
  639. AND report_date = #{today}
  640. <if test="accountIdList != null and accountIdList.size() > 0 ">
  641. AND account_id in
  642. <foreach collection="accountIdList" item="accountId" open="(" separator="," close=")">
  643. #{accountId}
  644. </foreach>
  645. </if>
  646. GROUP BY hour
  647. ORDER BY hour
  648. </select>
  649. <select id="getAccountDataReportByDaily" resultType="com.alibaba.fastjson.JSONObject">
  650. SELECT
  651. date_format(report_date, '%Y-%m-%d') as 'time',
  652. ${filedAll}
  653. FROM
  654. kuaishou_live_account_report_daily_dw t1
  655. WHERE account_type = 1
  656. AND report_date >= #{startDate}
  657. AND report_date &lt;= #{endDate}
  658. <if test="accountIdList != null and accountIdList.size() > 0 ">
  659. AND account_id in
  660. <foreach collection="accountIdList" item="accountId" open="(" separator="," close=")">
  661. #{accountId}
  662. </foreach>
  663. </if>
  664. GROUP BY report_date
  665. ORDER BY report_date
  666. </select>
  667. <insert id="replaceKuaishouFields">
  668. replace
  669. into kuaishou_field_definition(
  670. user_id,
  671. json,
  672. column_type
  673. )values(
  674. #{request.userId},
  675. #{request.json},
  676. #{request.columnType}
  677. )
  678. </insert>
  679. <select id="getKuaishouFieldsByUserId" resultType="com.alibaba.fastjson.JSONObject">
  680. SELECT user_id as 'userId',
  681. json,
  682. column_type as 'columnType'
  683. FROM kuaishou_field_definition
  684. WHERE user_id = #{userId}
  685. AND column_type = #{columnType} Limit 1
  686. </select>
  687. </mapper>