ConsumptionBalanceMapper.xml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  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. </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 company_red_package_logs rpl
  122. left join fs_course_watch_log log
  123. on rpl.watch_log_id=log.log_id
  124. <where>
  125. rpl.operate_type=1
  126. <if test="startTime != null and endTime != null">
  127. and rpl.create_time BETWEEN #{startTime} AND #{endTime}
  128. </if>
  129. <if test="userType != null">
  130. and log.send_type = ${userType}
  131. </if>
  132. <if test="companyId != null">
  133. and log.company_id = #{companyId}
  134. </if>
  135. </where>
  136. </select>
  137. <select id="queryRewardMoney" resultType="java.math.BigDecimal">
  138. select sum(up_money) from company_red_package_logs rpl
  139. left join fs_course_watch_log log
  140. on rpl.watch_log_id=log.log_id
  141. <where>
  142. rpl.operate_type=1
  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. </where>
  153. </select>
  154. <select id="smsBalance" resultType="java.lang.Long">
  155. select sum(remain_sms_count) from company_sms
  156. </select>
  157. <select id="smsBalanceCompany" resultType="java.lang.Long">
  158. select sum(remain_sms_count) from company_sms
  159. <where>
  160. <if test="companyId != null">
  161. company_id = #{companyId}
  162. </if>
  163. </where>
  164. </select>
  165. <select id="authorizationInfo" resultType="com.fs.statis.dto.AuthorizationInfoDTO">
  166. select version_limit,today_watch_user_count from fs_statistics_index limit 1
  167. </select>
  168. <select id="watchEndPlayTrend" resultType="com.fs.statis.dto.WatchEndPlayTrendDTO">
  169. SELECT
  170. -- 今日/昨日 小时
  171. <if test="type == 0 or type == 1">
  172. DATE_FORMAT(create_time, '%H') AS start_date,
  173. </if>
  174. -- 本周/本月/上月 天
  175. <if test="type == 2 or type == 3 or type == 4">
  176. DATE_FORMAT(create_time, '%Y-%m-%d') AS start_date,
  177. </if>
  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. start_date
  195. ORDER BY
  196. start_date
  197. </select>
  198. <select id="deaMemberTopTen" resultType="com.fs.statis.dto.DeaMemberTopTenDTO">
  199. SELECT
  200. company_id,
  201. <if test="statisticalType == 0">
  202. count(DISTINCT user_id) AS watch_user_count
  203. </if>
  204. <if test="statisticalType == 1">
  205. COUNT(DISTINCT CASE WHEN log_type = 2 THEN user_id END) AS watch_user_count
  206. </if>
  207. FROM
  208. fs_course_watch_log
  209. <where>
  210. <if test="startTime != null">
  211. create_time <![CDATA[>=]]> #{startTime}
  212. </if>
  213. <if test="endTime != null">
  214. AND create_time <![CDATA[<]]> #{endTime}
  215. </if>
  216. <if test="userType != null">
  217. AND send_type = ${userType}
  218. </if>
  219. <if test="companyId != null">
  220. AND company_id = ${companyId}
  221. </if>
  222. </where>
  223. GROUP BY company_id
  224. limit 10
  225. </select>
  226. <select id="watchCourseTopTen" resultType="com.fs.statis.dto.CourseStatsDTO">
  227. SELECT
  228. w.course_id AS course_id,
  229. COUNT(DISTINCT w.user_id) AS watch_user_count,
  230. COUNT(DISTINCT CASE WHEN w.log_type = 2 THEN w.user_id END) AS completed_user_count,
  231. COUNT(DISTINCT a.user_id) AS answer_user_count,
  232. COUNT(DISTINCT CASE WHEN a.is_right = 1 THEN a.user_id END) AS correct_user_count
  233. FROM
  234. fs_course_watch_log w
  235. LEFT JOIN
  236. fs_course_answer_logs a ON w.video_id = a.video_id AND w.user_id = a.user_id
  237. <where>
  238. <if test="startTime != null">
  239. w.create_time <![CDATA[>=]]> #{startTime}
  240. </if>
  241. <if test="endTime != null">
  242. AND w.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 w.company_id = ${companyId}
  249. </if>
  250. </where>
  251. GROUP BY
  252. w.course_id
  253. ORDER BY
  254. -- 观看人数
  255. <if test="statisticalType == 0">
  256. COUNT(DISTINCT w.user_id)
  257. </if>
  258. <if test="statisticalType == 1">
  259. COUNT(DISTINCT CASE WHEN w.log_type = 2 THEN w.user_id END)
  260. </if>
  261. <if test="statisticalType == 2">
  262. COUNT(DISTINCT a.user_id)
  263. </if>
  264. <if test="statisticalType == 3">
  265. COUNT(DISTINCT CASE WHEN a.is_right = 1 THEN a.user_id END)
  266. </if>
  267. ${sort}
  268. LIMIT 10
  269. </select>
  270. <select id="rewardMoneyTopTen" resultType="com.fs.statis.dto.RewardMoneyTopTenDTO">
  271. SELECT
  272. -- 按公司
  273. <if test="dataType == 0">
  274. rpl.company_id as company_id,
  275. </if>
  276. -- 按课程
  277. <if test="dataType == 1">
  278. rpl.course_id as course_id,
  279. </if>
  280. SUM(rpl.money) as rewardMoney
  281. FROM
  282. company_red_package_logs rpl
  283. left join fs_course_watch_log log
  284. on rpl.watch_log_id=log.log_id
  285. <where>
  286. rpl.operate_type = 1
  287. AND rpl.status = 1
  288. <if test="startTime != null">
  289. AND rpl.create_time <![CDATA[>=]]> #{startTime}
  290. </if>
  291. <if test="endTime != null">
  292. AND rpl.create_time <![CDATA[<]]> #{endTime}
  293. </if>
  294. <if test="userType != null">
  295. and log.send_type = ${userType}
  296. </if>
  297. <if test="companyId != null">
  298. and log.company_id = ${companyId}
  299. </if>
  300. </where>
  301. GROUP BY
  302. <if test="dataType == 0">
  303. rpl.company_id
  304. </if>
  305. <if test="dataType == 1">
  306. rpl.course_id
  307. </if>
  308. ORDER BY
  309. rewardMoney DESC
  310. LIMIT 10
  311. </select>
  312. <select id="rewardMoneyTrendDTO" resultType="com.fs.statis.dto.RewardMoneyTrendDTO">
  313. select
  314. -- 今日/昨日 小时
  315. <if test="type == 0 or type == 1">
  316. DATE_FORMAT(rpl.create_time, '%H') AS start_date,
  317. </if>
  318. -- 本周/本月/上月 天
  319. <if test="type == 2 or type == 3 or type == 4">
  320. DATE_FORMAT(rpl.create_time, '%Y-%m-%d') AS start_date,
  321. </if>
  322. SUM(rpl.money) as rewardMoney
  323. from company_red_package_logs rpl
  324. left join fs_course_watch_log log
  325. on rpl.watch_log_id=log.log_id
  326. <where>
  327. <if test="startTime != null">
  328. rpl.create_time <![CDATA[>=]]> #{startTime}
  329. </if>
  330. <if test="endTime != null">
  331. AND rpl.create_time <![CDATA[<]]> #{endTime}
  332. </if>
  333. <if test="userType != null">
  334. and log.send_type = ${userType}
  335. </if>
  336. <if test="companyId != null">
  337. and log.company_id = ${companyId}
  338. </if>
  339. AND rpl.operate_type = 1
  340. AND rpl.status = 1
  341. </where>
  342. group by start_date
  343. </select>
  344. <select id="getCurrentBalance" resultType="java.math.BigDecimal">
  345. select sum(money) from company
  346. </select>
  347. <select id="dealerAggregatedCompanyId" resultType="com.fs.statis.dto.DealerAggregatedDTO">
  348. SELECT
  349. 1 AS dealder_count,
  350. (SELECT COUNT(*) FROM COMPANY_USER
  351. <where>
  352. <if test="companyId != null">
  353. company_id = #{companyId}
  354. </if>
  355. </where>
  356. ) AS group_mgr_count,
  357. (SELECT COUNT(*) FROM FS_USER
  358. <where>
  359. <if test="companyId != null">
  360. company_id = #{companyId}
  361. </if>
  362. </where>
  363. ) AS member_count,
  364. (SELECT COUNT(*) FROM FS_USER
  365. <where>
  366. STATUS=1
  367. <if test="companyId != null">
  368. AND company_id = #{companyId}
  369. </if>
  370. </where>
  371. ) AS normal_num,
  372. (SELECT COUNT(*) FROM FS_USER
  373. <where>
  374. STATUS=0
  375. <if test="companyId != null">
  376. AND company_id = #{companyId}
  377. </if>
  378. </where>
  379. ) AS black_num,
  380. (select COUNT(*) FROM qw_user) AS qw_member_num
  381. </select>
  382. <select id="getCurrentBalanceCompanyId" resultType="java.math.BigDecimal">
  383. select sum(money) from company
  384. <where>
  385. <if test="companyId != null">
  386. company_id = #{companyId}
  387. </if>
  388. </where>
  389. </select>
  390. </mapper>