ConsumptionBalanceMapper.xml 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  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.fs.statis.mapper.ConsumptionBalanceMapper">
  6. <select id="rechargeConsumption" resultType="com.fs.statis.dto.ConsumptionBalanceDataDTO">
  7. select
  8. 14371277 AS balance,
  9. 103100 AS today_comsumption,
  10. 195280 AS yesterday_comsumption
  11. </select>
  12. <select id="dealerAggregated" resultType="com.fs.statis.dto.DealerAggregatedDTO">
  13. SELECT
  14. (SELECT COUNT(*) FROM COMPANY WHERE IS_DEL = 0) AS dealder_count,
  15. (SELECT COUNT(*) FROM COMPANY_USER CU INNER JOIN COMPANY C ON C.company_id = CU.company_id AND C.is_del = 0) AS group_mgr_count,
  16. (SELECT COUNT(*) FROM FS_USER) AS member_count,
  17. (SELECT COUNT(*) FROM FS_USER WHERE STATUS=1) AS normal_num,
  18. (SELECT COUNT(*) FROM FS_USER WHERE STATUS=0) AS black_num,
  19. (select COUNT(*) FROM qw_user WHERE is_del = 0) AS qw_member_num
  20. </select>
  21. <select id="analysisPreview" resultType="com.fs.statis.dto.AnalysisPreviewDTO">
  22. -- 观看人数
  23. select (select count(*) from fs_course_watch_log where create_time between #{startTime} and #{endTime} group by user_id) as watch_count,
  24. -- 完播人数
  25. (select count(*) from fs_course_watch_log where finish_time is not null and create_time between #{startTime} and #{endTime} group by user_id)
  26. as completed_user_count,
  27. -- 观看次数
  28. (select count(*) from fs_course_watch_log where create_time between #{startTime} and #{endTime}) as watch_count,
  29. -- 完播次数
  30. (select count(*) from fs_course_watch_log where create_time between #{startTime} and #{endTime}) as completed_count,
  31. -- 答题人数
  32. (select count(*) from fs_course_answer_logs where create_time between #{startTime} and #{endTime}) as answer_member_count,
  33. -- 正确人数
  34. (select count(*) from fs_course_answer_logs where is_right=1 AND create_time between #{startTime} and #{endTime}) as correct_user_count,
  35. -- 答题红包个数
  36. (select 0) as reward_type,
  37. (select 0) as reward_money
  38. </select>
  39. <select id="queryWatchCount" resultType="java.lang.Long">
  40. select count(log_id) from fs_course_watch_log
  41. <where>
  42. <if test="userType != null">
  43. and send_type=${userType}
  44. </if>
  45. <if test="startTime != null and endTime != null">
  46. and create_time between #{startTime} and #{endTime}
  47. </if>
  48. <if test="companyId != null">
  49. and company_id = #{companyId}
  50. </if>
  51. </where>
  52. </select>
  53. <select id="queryCompletedUserCount" resultType="java.lang.Long">
  54. select count(DISTINCT user_id) from fs_course_watch_log
  55. <where>
  56. finish_time is not null
  57. <if test="userType != null">
  58. and send_type=${userType}
  59. </if>
  60. <if test="startTime != null and endTime != null">
  61. and create_time between #{startTime} and #{endTime}
  62. </if>
  63. <if test="companyId != null">
  64. and company_id = #{companyId}
  65. </if>
  66. </where>
  67. </select>
  68. <select id="queryWatchUserCount" resultType="java.lang.Long">
  69. select count(distinct user_id) from fs_course_watch_log
  70. <where>
  71. <if test="userType != null">
  72. and send_type=${userType}
  73. </if>
  74. <if test="startTime != null and endTime != null">
  75. and create_time between #{startTime} and #{endTime}
  76. </if>
  77. <if test="companyId != null">
  78. and company_id = #{companyId}
  79. </if>
  80. </where>
  81. </select>
  82. <select id="queryCompletedCount" resultType="java.lang.Long">
  83. SELECT COUNT(log_id) FROM fs_course_watch_log
  84. <where>
  85. finish_time IS NOT NULL
  86. <if test="startTime != null and endTime != null">
  87. AND create_time BETWEEN #{startTime} AND #{endTime}
  88. </if>
  89. <if test="userType != null">
  90. and send_type=${userType}
  91. </if>
  92. <if test="companyId != null">
  93. and company_id = #{companyId}
  94. </if>
  95. </where>
  96. </select>
  97. <select id="queryAnswerMemberCount" resultType="java.lang.Long">
  98. SELECT COUNT(DISTINCT user_id) FROM fs_course_answer_logs
  99. <where>
  100. <if test="startTime != null and endTime != null">
  101. create_time BETWEEN #{startTime} AND #{endTime}
  102. </if>
  103. <if test="companyId != null">
  104. and company_id = #{companyId}
  105. </if>
  106. </where>
  107. </select>
  108. <select id="queryCorrectUserCount" resultType="java.lang.Long">
  109. SELECT COUNT(DISTINCT user_id) FROM fs_course_answer_logs
  110. <where>
  111. is_right = 1
  112. <if test="startTime != null and endTime != null">
  113. and create_time BETWEEN #{startTime} AND #{endTime}
  114. </if>
  115. <if test="companyId != null">
  116. and company_id = #{companyId}
  117. </if>
  118. </where>
  119. </select>
  120. <select id="queryRewardCount" resultType="java.lang.Long">
  121. select count(*) from fs_course_red_packet_log rpl
  122. left join fs_course_watch_log log
  123. on rpl.watch_log_id=log.log_id
  124. <where>
  125. <if test="startTime != null and endTime != null">
  126. and rpl.create_time BETWEEN #{startTime} AND #{endTime}
  127. </if>
  128. <if test="userType != null">
  129. and log.send_type = ${userType}
  130. </if>
  131. <if test="companyId != null">
  132. and log.company_id = #{companyId}
  133. </if>
  134. </where>
  135. </select>
  136. <select id="queryRewardMoney" resultType="java.math.BigDecimal">
  137. select sum(rpl.amount) from fs_course_red_packet_log rpl
  138. left join fs_course_watch_log log
  139. on rpl.watch_log_id=log.log_id
  140. <where>
  141. <if test="startTime != null and endTime != null">
  142. and rpl.create_time BETWEEN #{startTime} AND #{endTime}
  143. </if>
  144. <if test="userType != null">
  145. and log.send_type = ${userType}
  146. </if>
  147. <if test="companyId != null">
  148. and log.company_id = #{companyId}
  149. </if>
  150. </where>
  151. </select>
  152. <select id="smsBalance" resultType="java.lang.Long">
  153. select sum(remain_sms_count) from company_sms
  154. </select>
  155. <select id="smsBalanceCompany" resultType="java.lang.Long">
  156. select sum(remain_sms_count) from company_sms
  157. <where>
  158. <if test="companyId != null">
  159. company_id = #{companyId}
  160. </if>
  161. </where>
  162. </select>
  163. <select id="authorizationInfo" resultType="com.fs.statis.dto.AuthorizationInfoDTO">
  164. select version_limit,today_watch_user_count from fs_statistics_index limit 1
  165. </select>
  166. <select id="watchEndPlayTrend" resultType="com.fs.statis.dto.WatchEndPlayTrendDTO">
  167. SELECT
  168. <choose>
  169. <!-- 按小时分组 -->
  170. <when test="type == 0 or type == 1">
  171. DATE_FORMAT(create_time, '%H') AS start_date,
  172. </when>
  173. <!-- 按天分组 -->
  174. <when test="type == 2 or type == 3 or type == 4">
  175. DATE_FORMAT(create_time, '%Y-%m-%d') AS start_date,
  176. </when>
  177. </choose>
  178. COUNT(DISTINCT user_id) AS watch_user_count,
  179. COUNT(DISTINCT CASE WHEN log_type = 2 THEN user_id END) AS completed_user_count
  180. FROM
  181. fs_course_watch_log
  182. <where>
  183. <if test="startTime != null">
  184. create_time <![CDATA[>=]]> #{startTime}
  185. </if>
  186. <if test="endTime != null">
  187. AND create_time <![CDATA[<]]> #{endTime}
  188. </if>
  189. <if test="userType != null">
  190. AND send_type = ${userType}
  191. </if>
  192. </where>
  193. GROUP BY
  194. <choose>
  195. <when test="type == 0 or type == 1">DATE_FORMAT(create_time, '%H')</when>
  196. <when test="type == 2 or type == 3 or type == 4">DATE_FORMAT(create_time, '%Y-%m-%d')</when>
  197. </choose>
  198. ORDER BY
  199. start_date
  200. </select>
  201. <select id="deaMemberTopTen" resultType="com.fs.statis.dto.DeaMemberTopTenDTO">
  202. SELECT
  203. company_id,
  204. <if test="statisticalType == 0">
  205. count(DISTINCT user_id) AS watch_user_count
  206. </if>
  207. <if test="statisticalType == 1">
  208. COUNT(DISTINCT CASE WHEN log_type = 2 THEN user_id END) AS watch_user_count
  209. </if>
  210. FROM
  211. fs_course_watch_log
  212. <where>
  213. <if test="startTime != null">
  214. create_time <![CDATA[>=]]> #{startTime}
  215. </if>
  216. <if test="endTime != null">
  217. AND create_time <![CDATA[<]]> #{endTime}
  218. </if>
  219. <if test="userType != null">
  220. AND send_type = ${userType}
  221. </if>
  222. <if test="companyId != null">
  223. AND company_id = ${companyId}
  224. </if>
  225. </where>
  226. GROUP BY company_id
  227. limit 10
  228. </select>
  229. <!-- <select id="watchCourseTopTen" resultType="com.fs.statis.dto.CourseStatsDTO">-->
  230. <!-- SELECT-->
  231. <!-- w.course_id AS course_id,-->
  232. <!-- COUNT(DISTINCT w.user_id) AS watch_user_count,-->
  233. <!-- COUNT(DISTINCT CASE WHEN w.log_type = 2 THEN w.user_id END) AS completed_user_count,-->
  234. <!-- COUNT(DISTINCT a.user_id) AS answer_user_count,-->
  235. <!-- COUNT(DISTINCT CASE WHEN a.is_right = 1 THEN a.user_id END) AS correct_user_count-->
  236. <!-- FROM-->
  237. <!-- fs_course_watch_log w-->
  238. <!-- LEFT JOIN-->
  239. <!-- fs_course_answer_logs a ON w.video_id = a.video_id AND w.user_id = a.user_id-->
  240. <!-- <where>-->
  241. <!-- <if test="startTime != null">-->
  242. <!-- w.create_time <![CDATA[>=]]> #{startTime}-->
  243. <!-- </if>-->
  244. <!-- <if test="endTime != null">-->
  245. <!-- AND w.create_time <![CDATA[<]]> #{endTime}-->
  246. <!-- </if>-->
  247. <!-- <if test="userType != null">-->
  248. <!-- AND send_type = ${userType}-->
  249. <!-- </if>-->
  250. <!-- <if test="companyId != null">-->
  251. <!-- AND w.company_id = ${companyId}-->
  252. <!-- </if>-->
  253. <!-- </where>-->
  254. <!-- GROUP BY-->
  255. <!-- w.course_id-->
  256. <!-- ORDER BY-->
  257. <!-- &#45;&#45; 观看人数-->
  258. <!-- <if test="statisticalType == 0">-->
  259. <!-- COUNT(DISTINCT w.user_id)-->
  260. <!-- </if>-->
  261. <!-- <if test="statisticalType == 1">-->
  262. <!-- COUNT(DISTINCT CASE WHEN w.log_type = 2 THEN w.user_id END)-->
  263. <!-- </if>-->
  264. <!-- <if test="statisticalType == 2">-->
  265. <!-- COUNT(DISTINCT a.user_id)-->
  266. <!-- </if>-->
  267. <!-- <if test="statisticalType == 3">-->
  268. <!-- COUNT(DISTINCT CASE WHEN a.is_right = 1 THEN a.user_id END)-->
  269. <!-- </if>-->
  270. <!-- ${sort}-->
  271. <!-- LIMIT 10-->
  272. <!-- </select>-->
  273. <!-- 1. 按观看人数排序 -->
  274. <select id="watchCourseTopTenByWatch" resultType="com.fs.statis.dto.CourseStatsDTO">
  275. SELECT
  276. course_id AS courseId,
  277. COUNT(DISTINCT user_id) AS watch_user_count,
  278. COUNT(DISTINCT CASE WHEN log_type = 2 THEN user_id END) AS completed_user_count,
  279. 0 AS answer_user_count,
  280. 0 AS correct_user_count
  281. FROM fs_course_watch_log
  282. <where>
  283. <if test="startTime != null">create_time <![CDATA[>=]]> #{startTime}</if>
  284. <if test="endTime != null">AND create_time <![CDATA[<]]> #{endTime}</if>
  285. <if test="userType != null">AND send_type = #{userType}</if>
  286. <if test="companyId != null">AND company_id = #{companyId}</if>
  287. </where>
  288. GROUP BY course_id
  289. ORDER BY watch_user_count
  290. <choose>
  291. <when test="sort != null and sort == 'DESC'">DESC</when>
  292. <otherwise>ASC</otherwise>
  293. </choose>
  294. LIMIT 10
  295. </select>
  296. <!-- 2. 按完成人数排序 -->
  297. <select id="watchCourseTopTenByComplete" resultType="com.fs.statis.dto.CourseStatsDTO">
  298. SELECT
  299. course_id AS courseId,
  300. COUNT(DISTINCT user_id) AS watch_user_count,
  301. COUNT(DISTINCT CASE WHEN log_type = 2 THEN user_id END) AS completed_user_count,
  302. 0 AS answer_user_count,
  303. 0 AS correct_user_count
  304. FROM fs_course_watch_log
  305. <where>
  306. <if test="startTime != null">create_time <![CDATA[>=]]> #{startTime}</if>
  307. <if test="endTime != null">AND create_time <![CDATA[<]]> #{endTime}</if>
  308. <if test="userType != null">AND send_type = #{userType}</if>
  309. <if test="companyId != null">AND company_id = #{companyId}</if>
  310. </where>
  311. GROUP BY course_id
  312. ORDER BY completed_user_count
  313. <choose>
  314. <when test="sort != null and sort == 'DESC'">DESC</when>
  315. <otherwise>ASC</otherwise>
  316. </choose>
  317. LIMIT 10
  318. </select>
  319. <!-- 3. 按答题人数排序 -->
  320. <select id="watchCourseTopTenByAnswer" resultType="com.fs.statis.dto.CourseStatsDTO">
  321. SELECT
  322. w.course_id AS courseId,
  323. COUNT(DISTINCT w.user_id) AS watch_user_count,
  324. COUNT(DISTINCT CASE WHEN w.log_type = 2 THEN w.user_id END) AS completed_user_count,
  325. COUNT(DISTINCT a.user_id) AS answer_user_count,
  326. COUNT(DISTINCT CASE WHEN a.is_right = 1 THEN a.user_id END) AS correct_user_count
  327. FROM fs_course_watch_log w
  328. LEFT JOIN fs_course_answer_logs a ON w.video_id = a.video_id AND w.user_id = a.user_id
  329. <where>
  330. <if test="startTime != null">w.create_time <![CDATA[>=]]> #{startTime}</if>
  331. <if test="endTime != null">AND w.create_time <![CDATA[<]]> #{endTime}</if>
  332. <if test="userType != null">AND w.send_type = #{userType}</if>
  333. <if test="companyId != null">AND w.company_id = #{companyId}</if>
  334. <!-- <if test="startTime != null">AND a.create_time <![CDATA[>=]]> #{startTime}</if> -->
  335. <!-- <if test="endTime != null">AND a.create_time <![CDATA[<]]> #{endTime}</if> -->
  336. </where>
  337. GROUP BY w.course_id
  338. ORDER BY answer_user_count
  339. <choose>
  340. <when test="sort != null and sort == 'DESC'">DESC</when>
  341. <otherwise>ASC</otherwise>
  342. </choose>
  343. LIMIT 10
  344. </select>
  345. <!-- 4. 按正确人数排序 -->
  346. <select id="watchCourseTopTenByCorrect" resultType="com.fs.statis.dto.CourseStatsDTO">
  347. SELECT
  348. w.course_id AS courseId,
  349. COUNT(DISTINCT w.user_id) AS watch_user_count,
  350. COUNT(DISTINCT CASE WHEN w.log_type = 2 THEN w.user_id END) AS completed_user_count,
  351. COUNT(DISTINCT a.user_id) AS answer_user_count,
  352. COUNT(DISTINCT CASE WHEN a.is_right = 1 THEN a.user_id END) AS correct_user_count
  353. FROM fs_course_watch_log w
  354. LEFT JOIN fs_course_answer_logs a ON w.video_id = a.video_id AND w.user_id = a.user_id
  355. <where>
  356. <if test="startTime != null">w.create_time <![CDATA[>=]]> #{startTime}</if>
  357. <if test="endTime != null">AND w.create_time <![CDATA[<]]> #{endTime}</if>
  358. <if test="userType != null">AND w.send_type = #{userType}</if>
  359. <if test="companyId != null">AND w.company_id = #{companyId}</if>
  360. <if test="startTime != null">AND a.create_time <![CDATA[>=]]> #{startTime}</if>
  361. <if test="endTime != null">AND a.create_time <![CDATA[<]]> #{endTime}</if>
  362. </where>
  363. GROUP BY w.course_id
  364. ORDER BY correct_user_count
  365. <choose>
  366. <when test="sort != null and sort == 'DESC'">DESC</when>
  367. <otherwise>ASC</otherwise>
  368. </choose>
  369. LIMIT 10
  370. </select>
  371. <!-- 5. 批量补充答题数据 -->
  372. <select id="getAnswerStatsByCourseIds" resultType="com.fs.statis.dto.CourseStatsDTO">
  373. SELECT
  374. w.course_id AS courseId,
  375. COUNT(DISTINCT a.user_id) AS answer_user_count,
  376. COUNT(DISTINCT CASE WHEN a.is_right = 1 THEN a.user_id END) AS correct_user_count
  377. FROM fs_course_answer_logs a
  378. INNER JOIN fs_course_watch_log w ON a.video_id = w.video_id AND a.user_id = w.user_id
  379. <where>
  380. w.course_id IN
  381. <foreach collection="courseIds" item="courseId" open="(" close=")" separator=",">
  382. #{courseId}
  383. </foreach>
  384. <if test="param.startTime != null">AND w.create_time <![CDATA[>=]]> #{param.startTime}</if>
  385. <if test="param.endTime != null">AND w.create_time <![CDATA[<]]> #{param.endTime}</if>
  386. <if test="param.userType != null">AND w.send_type = #{param.userType}</if>
  387. <if test="param.companyId != null">AND w.company_id = #{param.companyId}</if>
  388. <if test="param.startTime != null">AND a.create_time <![CDATA[>=]]> #{param.startTime}</if>
  389. <if test="param.endTime != null">AND a.create_time <![CDATA[<]]> #{param.endTime}</if>
  390. </where>
  391. GROUP BY w.course_id
  392. </select>
  393. <select id="rewardMoneyTopTen" resultType="com.fs.statis.dto.RewardMoneyTopTenDTO">
  394. SELECT
  395. -- 按公司
  396. <if test="dataType == 0">
  397. rpl.company_id as company_id,
  398. </if>
  399. -- 按课程
  400. <if test="dataType == 1">
  401. rpl.course_id as course_id,
  402. </if>
  403. SUM(rpl.amount) as rewardMoney
  404. FROM
  405. fs_course_red_packet_log rpl
  406. left join fs_course_watch_log log
  407. on rpl.watch_log_id=log.log_id
  408. <where>
  409. <if test="startTime != null">
  410. AND rpl.create_time <![CDATA[>=]]> #{startTime}
  411. </if>
  412. <if test="endTime != null">
  413. AND rpl.create_time <![CDATA[<]]> #{endTime}
  414. </if>
  415. <if test="userType != null">
  416. and log.send_type = ${userType}
  417. </if>
  418. <if test="companyId != null">
  419. and log.company_id = ${companyId}
  420. </if>
  421. </where>
  422. GROUP BY
  423. <if test="dataType == 0">
  424. rpl.company_id
  425. </if>
  426. <if test="dataType == 1">
  427. rpl.course_id
  428. </if>
  429. ORDER BY
  430. rewardMoney DESC
  431. LIMIT 10
  432. </select>
  433. <select id="rewardMoneyTrendDTO" resultType="com.fs.statis.dto.RewardMoneyTrendDTO">
  434. select
  435. -- 今日/昨日 小时
  436. <if test="type == 0 or type == 1">
  437. DATE_FORMAT(rpl.create_time, '%H') AS start_date,
  438. </if>
  439. -- 本周/本月/上月 天
  440. <if test="type == 2 or type == 3 or type == 4">
  441. DATE_FORMAT(rpl.create_time, '%Y-%m-%d') AS start_date,
  442. </if>
  443. SUM(rpl.amount) as rewardMoney
  444. from fs_course_red_packet_log rpl
  445. left join fs_course_watch_log log
  446. on rpl.watch_log_id=log.log_id
  447. <where>
  448. <if test="startTime != null">
  449. rpl.create_time <![CDATA[>=]]> #{startTime}
  450. </if>
  451. <if test="endTime != null">
  452. AND rpl.create_time <![CDATA[<]]> #{endTime}
  453. </if>
  454. <if test="userType != null">
  455. and log.send_type = ${userType}
  456. </if>
  457. <if test="companyId != null">
  458. and log.company_id = ${companyId}
  459. </if>
  460. </where>
  461. group by start_date
  462. </select>
  463. <select id="getCurrentBalance" resultType="java.math.BigDecimal">
  464. select sum(money) from company where is_del=0
  465. </select>
  466. <select id="dealerAggregatedCompanyId" resultType="com.fs.statis.dto.DealerAggregatedDTO">
  467. SELECT
  468. 1 AS dealder_count,
  469. (SELECT COUNT(*) FROM COMPANY_USER
  470. <where>
  471. <if test="companyId != null">
  472. company_id = #{companyId}
  473. </if>
  474. </where>
  475. ) AS group_mgr_count,
  476. (SELECT COUNT(*) FROM FS_USER
  477. <where>
  478. <if test="companyId != null">
  479. company_id = #{companyId}
  480. </if>
  481. </where>
  482. ) AS member_count,
  483. (SELECT COUNT(*) FROM FS_USER
  484. <where>
  485. STATUS=1
  486. <if test="companyId != null">
  487. AND company_id = #{companyId}
  488. </if>
  489. </where>
  490. ) AS normal_num,
  491. (SELECT COUNT(*) FROM FS_USER
  492. <where>
  493. STATUS=0
  494. <if test="companyId != null">
  495. AND company_id = #{companyId}
  496. </if>
  497. </where>
  498. ) AS black_num,
  499. (select COUNT(*) FROM qw_user
  500. <where>
  501. <if test="companyId != null">
  502. AND company_id = ${companyId}
  503. </if>
  504. </where>
  505. ) AS qw_member_num
  506. </select>
  507. <select id="getCurrentBalanceCompanyId" resultType="java.math.BigDecimal">
  508. select sum(money) from company
  509. <where>
  510. <if test="companyId != null">
  511. company_id = #{companyId}
  512. </if>
  513. AND is_del=0
  514. </where>
  515. </select>
  516. </mapper>