ConsumptionBalanceMapper.xml 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  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) AS dealder_count,
  15. (SELECT COUNT(*) FROM COMPANY_USER) 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) 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. <if test="companyUserId != null">
  52. and company_user_id = #{companyUserId}
  53. </if>
  54. </where>
  55. </select>
  56. <select id="queryCompletedUserCount" resultType="java.lang.Long">
  57. select count(DISTINCT user_id) from fs_course_watch_log
  58. <where>
  59. finish_time is not null
  60. <if test="userType != null">
  61. and send_type=${userType}
  62. </if>
  63. <if test="startTime != null and endTime != null">
  64. and create_time between #{startTime} and #{endTime}
  65. </if>
  66. <if test="companyId != null">
  67. and company_id = #{companyId}
  68. </if>
  69. <if test="companyUserId != null">
  70. and company_user_id = #{companyUserId}
  71. </if>
  72. </where>
  73. </select>
  74. <select id="queryWatchUserCount" resultType="java.lang.Long">
  75. select count(distinct user_id) from fs_course_watch_log
  76. <where>
  77. <if test="userType != null">
  78. and send_type=${userType}
  79. </if>
  80. <if test="startTime != null and endTime != null">
  81. and create_time between #{startTime} and #{endTime}
  82. </if>
  83. <if test="companyId != null">
  84. and company_id = #{companyId}
  85. </if>
  86. <if test="companyUserId != null">
  87. and company_user_id = #{companyUserId}
  88. </if>
  89. </where>
  90. </select>
  91. <select id="queryCompletedCount" resultType="java.lang.Long">
  92. SELECT COUNT(log_id) FROM fs_course_watch_log
  93. <where>
  94. finish_time IS NOT NULL
  95. <if test="startTime != null and endTime != null">
  96. AND create_time BETWEEN #{startTime} AND #{endTime}
  97. </if>
  98. <if test="userType != null">
  99. and send_type=${userType}
  100. </if>
  101. <if test="companyId != null">
  102. and company_id = #{companyId}
  103. </if>
  104. <if test="companyUserId != null">
  105. and company_user_id = #{companyUserId}
  106. </if>
  107. </where>
  108. </select>
  109. <select id="queryAnswerMemberCount" resultType="java.lang.Long">
  110. SELECT COUNT(DISTINCT user_id) FROM fs_course_answer_logs
  111. <where>
  112. <if test="startTime != null and endTime != null">
  113. create_time BETWEEN #{startTime} AND #{endTime}
  114. </if>
  115. <if test="companyId != null">
  116. and company_id = #{companyId}
  117. </if>
  118. <if test="companyUserId != null">
  119. and company_user_id = #{companyUserId}
  120. </if>
  121. </where>
  122. </select>
  123. <select id="queryCorrectUserCount" resultType="java.lang.Long">
  124. SELECT COUNT(DISTINCT user_id) FROM fs_course_answer_logs
  125. <where>
  126. is_right = 1
  127. <if test="startTime != null and endTime != null">
  128. and create_time BETWEEN #{startTime} AND #{endTime}
  129. </if>
  130. <if test="companyId != null">
  131. and company_id = #{companyId}
  132. </if>
  133. <if test="companyUserId != null">
  134. and company_user_id = #{companyUserId}
  135. </if>
  136. </where>
  137. </select>
  138. <select id="queryRewardCount" resultType="java.lang.Long">
  139. select count(*) from fs_course_red_packet_log rpl
  140. left join fs_course_watch_log log
  141. on rpl.watch_log_id=log.log_id
  142. <where>
  143. <if test="startTime != null and endTime != null">
  144. and rpl.create_time BETWEEN #{startTime} AND #{endTime}
  145. </if>
  146. <if test="userType != null">
  147. and log.send_type = ${userType}
  148. </if>
  149. <if test="companyId != null">
  150. and log.company_id = #{companyId}
  151. </if>
  152. <if test="companyUserId != null">
  153. and log.company_user_id = #{companyUserId}
  154. </if>
  155. </where>
  156. </select>
  157. <select id="queryRewardMoney" resultType="java.math.BigDecimal">
  158. select sum(rpl.amount) from fs_course_red_packet_log rpl
  159. left join fs_course_watch_log log
  160. on rpl.watch_log_id=log.log_id
  161. <where>
  162. <if test="startTime != null and endTime != null">
  163. and rpl.create_time BETWEEN #{startTime} AND #{endTime}
  164. </if>
  165. <if test="userType != null">
  166. and log.send_type = ${userType}
  167. </if>
  168. <if test="companyId != null">
  169. and log.company_id = #{companyId}
  170. </if>
  171. <if test="companyUserId != null">
  172. and log.company_user_id = #{companyUserId}
  173. </if>
  174. </where>
  175. </select>
  176. <select id="smsBalance" resultType="java.lang.Long">
  177. select sum(remain_sms_count) from company_sms
  178. </select>
  179. <select id="smsBalanceCompany" resultType="java.lang.Long">
  180. select sum(remain_sms_count) from company_sms
  181. <where>
  182. <if test="companyId != null">
  183. company_id = #{companyId}
  184. </if>
  185. </where>
  186. </select>
  187. <select id="authorizationInfo" resultType="com.fs.statis.dto.AuthorizationInfoDTO">
  188. select version_limit,today_watch_user_count from fs_statistics_index limit 1
  189. </select>
  190. <select id="watchEndPlayTrend" resultType="com.fs.statis.dto.WatchEndPlayTrendDTO">
  191. SELECT
  192. -- 今日/昨日 小时
  193. <if test="type == 0 or type == 1">
  194. DATE_FORMAT(create_time, '%H') AS start_date,
  195. </if>
  196. -- 本周/本月/上月 天
  197. <if test="type == 2 or type == 3 or type == 4">
  198. DATE_FORMAT(create_time, '%Y-%m-%d') AS start_date,
  199. </if>
  200. COUNT(DISTINCT user_id) AS watch_user_count,
  201. COUNT(DISTINCT CASE WHEN log_type = 2 THEN user_id END) AS completed_user_count
  202. FROM
  203. fs_course_watch_log
  204. <where>
  205. <if test="startTime != null">
  206. create_time <![CDATA[>=]]> #{startTime}
  207. </if>
  208. <if test="endTime != null">
  209. AND create_time <![CDATA[<]]> #{endTime}
  210. </if>
  211. <if test="userType != null">
  212. AND send_type = ${userType}
  213. </if>
  214. <if test="companyId != null">
  215. AND company_id = #{companyId}
  216. </if>
  217. <if test="companyUserId != null">
  218. AND company_user_id = #{companyUserId}
  219. </if>
  220. </where>
  221. GROUP BY
  222. start_date
  223. ORDER BY
  224. start_date
  225. </select>
  226. <select id="deaMemberTopTen" resultType="com.fs.statis.dto.DeaMemberTopTenDTO">
  227. SELECT
  228. company_id,
  229. <if test="statisticalType == 0">
  230. count(DISTINCT user_id) AS watch_user_count
  231. </if>
  232. <if test="statisticalType == 1">
  233. COUNT(DISTINCT CASE WHEN log_type = 2 THEN user_id END) AS watch_user_count
  234. </if>
  235. FROM
  236. fs_course_watch_log
  237. <where>
  238. <if test="startTime != null">
  239. create_time <![CDATA[>=]]> #{startTime}
  240. </if>
  241. <if test="endTime != null">
  242. AND create_time <![CDATA[<]]> #{endTime}
  243. </if>
  244. <if test="userType != null">
  245. AND send_type = ${userType}
  246. </if>
  247. <if test="companyId != null">
  248. AND company_id = ${companyId}
  249. </if>
  250. </where>
  251. GROUP BY company_id
  252. limit 10
  253. </select>
  254. <select id="watchCourseTopTen" resultType="com.fs.statis.dto.CourseStatsDTO">
  255. SELECT
  256. w.course_id AS course_id,
  257. COUNT(DISTINCT w.user_id) AS watch_user_count,
  258. COUNT(DISTINCT CASE WHEN w.log_type = 2 THEN w.user_id END) AS completed_user_count,
  259. COUNT(DISTINCT a.user_id) AS answer_user_count,
  260. COUNT(DISTINCT CASE WHEN a.is_right = 1 THEN a.user_id END) AS correct_user_count
  261. FROM
  262. fs_course_watch_log w
  263. LEFT JOIN
  264. fs_course_answer_logs a ON w.video_id = a.video_id AND w.user_id = a.user_id
  265. <where>
  266. <if test="startTime != null">
  267. w.create_time <![CDATA[>=]]> #{startTime}
  268. </if>
  269. <if test="endTime != null">
  270. AND w.create_time <![CDATA[<]]> #{endTime}
  271. </if>
  272. <if test="userType != null">
  273. AND w.send_type = ${userType}
  274. </if>
  275. <if test="companyId != null">
  276. AND w.company_id = ${companyId}
  277. </if>
  278. <if test="companyUserId != null">
  279. AND w.company_user_id= #{companyUserId}
  280. </if>
  281. </where>
  282. GROUP BY
  283. w.course_id
  284. ORDER BY
  285. -- 观看人数
  286. <if test="statisticalType == 0">
  287. COUNT(DISTINCT w.user_id)
  288. </if>
  289. <if test="statisticalType == 1">
  290. COUNT(DISTINCT CASE WHEN w.log_type = 2 THEN w.user_id END)
  291. </if>
  292. <if test="statisticalType == 2">
  293. COUNT(DISTINCT a.user_id)
  294. </if>
  295. <if test="statisticalType == 3">
  296. COUNT(DISTINCT CASE WHEN a.is_right = 1 THEN a.user_id END)
  297. </if>
  298. ${sort}
  299. LIMIT 10
  300. </select>
  301. <select id="rewardMoneyTopTen" resultType="com.fs.statis.dto.RewardMoneyTopTenDTO">
  302. SELECT
  303. -- 按公司
  304. <if test="dataType == 0">
  305. rpl.company_id as company_id,
  306. </if>
  307. -- 按课程
  308. <if test="dataType == 1">
  309. rpl.course_id as course_id,
  310. </if>
  311. SUM(rpl.amount) as rewardMoney
  312. FROM
  313. fs_course_red_packet_log rpl
  314. left join fs_course_watch_log log
  315. on rpl.watch_log_id=log.log_id
  316. <where>
  317. <if test="startTime != null">
  318. AND rpl.create_time <![CDATA[>=]]> #{startTime}
  319. </if>
  320. <if test="endTime != null">
  321. AND rpl.create_time <![CDATA[<]]> #{endTime}
  322. </if>
  323. <if test="userType != null">
  324. and log.send_type = ${userType}
  325. </if>
  326. <if test="companyId != null">
  327. and log.company_id = ${companyId}
  328. </if>
  329. <if test="companyUserId != null">
  330. and log.company_user_id = #{companyUserId}
  331. </if>
  332. </where>
  333. GROUP BY
  334. <if test="dataType == 0">
  335. rpl.company_id
  336. </if>
  337. <if test="dataType == 1">
  338. rpl.course_id
  339. </if>
  340. ORDER BY
  341. rewardMoney DESC
  342. LIMIT 10
  343. </select>
  344. <select id="rewardMoneyTrendDTO" resultType="com.fs.statis.dto.RewardMoneyTrendDTO">
  345. select
  346. -- 今日/昨日 小时
  347. <if test="type == 0 or type == 1">
  348. DATE_FORMAT(rpl.create_time, '%H') AS start_date,
  349. </if>
  350. -- 本周/本月/上月 天
  351. <if test="type == 2 or type == 3 or type == 4">
  352. DATE_FORMAT(rpl.create_time, '%Y-%m-%d') AS start_date,
  353. </if>
  354. SUM(rpl.amount) as rewardMoney
  355. from fs_course_red_packet_log rpl
  356. left join fs_course_watch_log log
  357. on rpl.watch_log_id=log.log_id
  358. <where>
  359. <if test="startTime != null">
  360. rpl.create_time <![CDATA[>=]]> #{startTime}
  361. </if>
  362. <if test="endTime != null">
  363. AND rpl.create_time <![CDATA[<]]> #{endTime}
  364. </if>
  365. <if test="userType != null">
  366. and log.send_type = ${userType}
  367. </if>
  368. <if test="companyId != null">
  369. and log.company_id = ${companyId}
  370. </if>
  371. <if test="companyUserId != null">
  372. and log.company_user_id = #{companyUserId}
  373. </if>
  374. </where>
  375. group by start_date
  376. </select>
  377. <select id="getCurrentBalance" resultType="java.math.BigDecimal">
  378. select sum(money) from company where is_del=0
  379. </select>
  380. <select id="dealerAggregatedCompanyId" resultType="com.fs.statis.dto.DealerAggregatedDTO">
  381. SELECT
  382. 1 AS dealder_count,
  383. (SELECT COUNT(*) FROM COMPANY_USER
  384. <where>
  385. <if test="companyId != null">
  386. company_id = #{companyId}
  387. </if>
  388. <if test="companyUserId != null">
  389. AND user_id = #{companyUserId}
  390. </if>
  391. </where>
  392. ) AS group_mgr_count,
  393. (SELECT COUNT(*) FROM FS_USER
  394. <where>
  395. <if test="companyId != null">
  396. AND company_id = #{companyId}
  397. </if>
  398. <if test="companyUserId != null">
  399. AND company_user_id = #{companyUserId}
  400. </if>
  401. </where>
  402. ) AS member_count,
  403. (SELECT COUNT(*) FROM FS_USER
  404. <where>
  405. STATUS=1
  406. <if test="companyId != null">
  407. AND company_id = #{companyId}
  408. </if>
  409. <if test="companyUserId != null">
  410. AND company_user_id = #{companyUserId}
  411. </if>
  412. </where>
  413. ) AS normal_num,
  414. (SELECT COUNT(*) FROM FS_USER
  415. <where>
  416. STATUS=0
  417. <if test="companyId != null">
  418. AND company_id = #{companyId}
  419. </if>
  420. <if test="companyUserId != null">
  421. AND company_user_id = #{companyUserId}
  422. </if>
  423. </where>
  424. ) AS black_num,
  425. (select COUNT(*) FROM qw_user
  426. <where>
  427. <if test="companyId != null">
  428. AND company_id = ${companyId}
  429. </if>
  430. <if test="companyUserId != null">
  431. AND company_user_id = #{companyUserId}
  432. </if>
  433. </where>
  434. ) AS qw_member_num
  435. </select>
  436. <select id="getCurrentBalanceCompanyId" resultType="java.math.BigDecimal">
  437. select sum(money) from company
  438. <where>
  439. <if test="companyId != null">
  440. company_id = #{companyId}
  441. </if>
  442. AND is_del=0
  443. </where>
  444. </select>
  445. </mapper>