ConsumptionBalanceMapper.xml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  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="companyUseId != 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. </where>
  215. GROUP BY
  216. start_date
  217. ORDER BY
  218. start_date
  219. </select>
  220. <select id="deaMemberTopTen" resultType="com.fs.statis.dto.DeaMemberTopTenDTO">
  221. SELECT
  222. company_id,
  223. <if test="statisticalType == 0">
  224. count(DISTINCT user_id) AS watch_user_count
  225. </if>
  226. <if test="statisticalType == 1">
  227. COUNT(DISTINCT CASE WHEN log_type = 2 THEN user_id END) AS watch_user_count
  228. </if>
  229. FROM
  230. fs_course_watch_log
  231. <where>
  232. <if test="startTime != null">
  233. create_time <![CDATA[>=]]> #{startTime}
  234. </if>
  235. <if test="endTime != null">
  236. AND create_time <![CDATA[<]]> #{endTime}
  237. </if>
  238. <if test="userType != null">
  239. AND send_type = ${userType}
  240. </if>
  241. <if test="companyId != null">
  242. AND company_id = ${companyId}
  243. </if>
  244. </where>
  245. GROUP BY company_id
  246. limit 10
  247. </select>
  248. <select id="watchCourseTopTen" resultType="com.fs.statis.dto.CourseStatsDTO">
  249. SELECT
  250. w.course_id AS course_id,
  251. COUNT(DISTINCT w.user_id) AS watch_user_count,
  252. COUNT(DISTINCT CASE WHEN w.log_type = 2 THEN w.user_id END) AS completed_user_count,
  253. COUNT(DISTINCT a.user_id) AS answer_user_count,
  254. COUNT(DISTINCT CASE WHEN a.is_right = 1 THEN a.user_id END) AS correct_user_count
  255. FROM
  256. fs_course_watch_log w
  257. LEFT JOIN
  258. fs_course_answer_logs a ON w.video_id = a.video_id AND w.user_id = a.user_id
  259. <where>
  260. <if test="startTime != null">
  261. w.create_time <![CDATA[>=]]> #{startTime}
  262. </if>
  263. <if test="endTime != null">
  264. AND w.create_time <![CDATA[<]]> #{endTime}
  265. </if>
  266. <if test="userType != null">
  267. AND w.send_type = ${userType}
  268. </if>
  269. <if test="companyId != null">
  270. AND w.company_id = ${companyId}
  271. </if>
  272. <if test="companyUserId != null">
  273. AND w.company_user_id= #{companyUserId}
  274. </if>
  275. </where>
  276. GROUP BY
  277. w.course_id
  278. ORDER BY
  279. -- 观看人数
  280. <if test="statisticalType == 0">
  281. COUNT(DISTINCT w.user_id)
  282. </if>
  283. <if test="statisticalType == 1">
  284. COUNT(DISTINCT CASE WHEN w.log_type = 2 THEN w.user_id END)
  285. </if>
  286. <if test="statisticalType == 2">
  287. COUNT(DISTINCT a.user_id)
  288. </if>
  289. <if test="statisticalType == 3">
  290. COUNT(DISTINCT CASE WHEN a.is_right = 1 THEN a.user_id END)
  291. </if>
  292. ${sort}
  293. LIMIT 10
  294. </select>
  295. <select id="rewardMoneyTopTen" resultType="com.fs.statis.dto.RewardMoneyTopTenDTO">
  296. SELECT
  297. -- 按公司
  298. <if test="dataType == 0">
  299. rpl.company_id as company_id,
  300. </if>
  301. -- 按课程
  302. <if test="dataType == 1">
  303. rpl.course_id as course_id,
  304. </if>
  305. SUM(rpl.amount) as rewardMoney
  306. FROM
  307. fs_course_red_packet_log rpl
  308. left join fs_course_watch_log log
  309. on rpl.watch_log_id=log.log_id
  310. <where>
  311. <if test="startTime != null">
  312. AND rpl.create_time <![CDATA[>=]]> #{startTime}
  313. </if>
  314. <if test="endTime != null">
  315. AND rpl.create_time <![CDATA[<]]> #{endTime}
  316. </if>
  317. <if test="userType != null">
  318. and log.send_type = ${userType}
  319. </if>
  320. <if test="companyId != null">
  321. and log.company_id = ${companyId}
  322. </if>
  323. </where>
  324. GROUP BY
  325. <if test="dataType == 0">
  326. rpl.company_id
  327. </if>
  328. <if test="dataType == 1">
  329. rpl.course_id
  330. </if>
  331. ORDER BY
  332. rewardMoney DESC
  333. LIMIT 10
  334. </select>
  335. <select id="rewardMoneyTrendDTO" resultType="com.fs.statis.dto.RewardMoneyTrendDTO">
  336. select
  337. -- 今日/昨日 小时
  338. <if test="type == 0 or type == 1">
  339. DATE_FORMAT(rpl.create_time, '%H') AS start_date,
  340. </if>
  341. -- 本周/本月/上月 天
  342. <if test="type == 2 or type == 3 or type == 4">
  343. DATE_FORMAT(rpl.create_time, '%Y-%m-%d') AS start_date,
  344. </if>
  345. SUM(rpl.amount) as rewardMoney
  346. from fs_course_red_packet_log rpl
  347. left join fs_course_watch_log log
  348. on rpl.watch_log_id=log.log_id
  349. <where>
  350. <if test="startTime != null">
  351. rpl.create_time <![CDATA[>=]]> #{startTime}
  352. </if>
  353. <if test="endTime != null">
  354. AND rpl.create_time <![CDATA[<]]> #{endTime}
  355. </if>
  356. <if test="userType != null">
  357. and log.send_type = ${userType}
  358. </if>
  359. <if test="companyId != null">
  360. and log.company_id = ${companyId}
  361. </if>
  362. </where>
  363. group by start_date
  364. </select>
  365. <select id="getCurrentBalance" resultType="java.math.BigDecimal">
  366. select sum(money) from company where is_del=0
  367. </select>
  368. <select id="dealerAggregatedCompanyId" resultType="com.fs.statis.dto.DealerAggregatedDTO">
  369. SELECT
  370. 1 AS dealder_count,
  371. (SELECT COUNT(*) FROM COMPANY_USER
  372. <where>
  373. <if test="companyId != null">
  374. company_id = #{companyId}
  375. </if>
  376. <if test="companyUserId != null">
  377. AND user_id = #{companyUserId}
  378. </if>
  379. </where>
  380. ) AS group_mgr_count,
  381. (SELECT COUNT(*) FROM FS_USER
  382. <where>
  383. <if test="companyId != null">
  384. AND company_id = #{companyId}
  385. </if>
  386. <if test="companyUserId != null">
  387. AND company_user_id = #{companyUserId}
  388. </if>
  389. </where>
  390. ) AS member_count,
  391. (SELECT COUNT(*) FROM FS_USER
  392. <where>
  393. STATUS=1
  394. <if test="companyId != null">
  395. AND company_id = #{companyId}
  396. </if>
  397. <if test="companyUserId != null">
  398. AND company_user_id = #{companyUserId}
  399. </if>
  400. </where>
  401. ) AS normal_num,
  402. (SELECT COUNT(*) FROM FS_USER
  403. <where>
  404. STATUS=0
  405. <if test="companyId != null">
  406. AND company_id = #{companyId}
  407. </if>
  408. <if test="companyUserId != null">
  409. AND company_user_id = #{companyUserId}
  410. </if>
  411. </where>
  412. ) AS black_num,
  413. (select COUNT(*) FROM qw_user
  414. <where>
  415. <if test="companyId != null">
  416. AND company_id = ${companyId}
  417. </if>
  418. <if test="companyUserId != null">
  419. AND company_user_id = #{companyUserId}
  420. </if>
  421. </where>
  422. ) AS qw_member_num
  423. </select>
  424. <select id="getCurrentBalanceCompanyId" resultType="java.math.BigDecimal">
  425. select sum(money) from company
  426. <where>
  427. <if test="companyId != null">
  428. company_id = #{companyId}
  429. </if>
  430. AND is_del=0
  431. </where>
  432. </select>
  433. </mapper>