ConsumptionBalanceMapper.xml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  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 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. -- 今日/昨日 小时
  169. <if test="type == 0 or type == 1">
  170. DATE_FORMAT(create_time, '%H') AS start_date,
  171. </if>
  172. -- 本周/本月/上月 天
  173. <if test="type == 2 or type == 3 or type == 4">
  174. DATE_FORMAT(create_time, '%Y-%m-%d') AS start_date,
  175. </if>
  176. COUNT(DISTINCT user_id) AS watch_user_count,
  177. COUNT(DISTINCT CASE WHEN log_type = 2 THEN user_id END) AS completed_user_count
  178. FROM
  179. fs_course_watch_log
  180. <where>
  181. <if test="startTime != null">
  182. create_time <![CDATA[>=]]> #{startTime}
  183. </if>
  184. <if test="endTime != null">
  185. AND create_time <![CDATA[<]]> #{endTime}
  186. </if>
  187. <if test="userType != null">
  188. AND send_type = ${userType}
  189. </if>
  190. </where>
  191. GROUP BY
  192. start_date
  193. ORDER BY
  194. start_date
  195. </select>
  196. <select id="deaMemberTopTen" resultType="com.fs.statis.dto.DeaMemberTopTenDTO">
  197. SELECT
  198. company_id,
  199. <if test="statisticalType == 0">
  200. count(DISTINCT user_id) AS watch_user_count
  201. </if>
  202. <if test="statisticalType == 1">
  203. COUNT(DISTINCT CASE WHEN log_type = 2 THEN user_id END) AS watch_user_count
  204. </if>
  205. FROM
  206. fs_course_watch_log
  207. <where>
  208. <if test="startTime != null">
  209. create_time <![CDATA[>=]]> #{startTime}
  210. </if>
  211. <if test="endTime != null">
  212. AND create_time <![CDATA[<]]> #{endTime}
  213. </if>
  214. <if test="userType != null">
  215. AND send_type = ${userType}
  216. </if>
  217. <if test="companyId != null">
  218. AND company_id = ${companyId}
  219. </if>
  220. </where>
  221. GROUP BY company_id
  222. limit 10
  223. </select>
  224. <select id="watchCourseTopTen" resultType="com.fs.statis.dto.CourseStatsDTO">
  225. SELECT
  226. w.course_id AS course_id,
  227. COUNT(DISTINCT w.user_id) AS watch_user_count,
  228. COUNT(DISTINCT CASE WHEN w.log_type = 2 THEN w.user_id END) AS completed_user_count,
  229. COUNT(DISTINCT a.user_id) AS answer_user_count,
  230. COUNT(DISTINCT CASE WHEN a.is_right = 1 THEN a.user_id END) AS correct_user_count
  231. FROM
  232. fs_course_watch_log w
  233. LEFT JOIN
  234. fs_course_answer_logs a ON w.video_id = a.video_id AND w.user_id = a.user_id
  235. <where>
  236. <if test="startTime != null">
  237. w.create_time <![CDATA[>=]]> #{startTime}
  238. </if>
  239. <if test="endTime != null">
  240. AND w.create_time <![CDATA[<]]> #{endTime}
  241. </if>
  242. <if test="userType != null">
  243. AND send_type = ${userType}
  244. </if>
  245. <if test="companyId != null">
  246. AND w.company_id = ${companyId}
  247. </if>
  248. </where>
  249. GROUP BY
  250. w.course_id
  251. ORDER BY
  252. -- 观看人数
  253. <if test="statisticalType == 0">
  254. COUNT(DISTINCT w.user_id)
  255. </if>
  256. <if test="statisticalType == 1">
  257. COUNT(DISTINCT CASE WHEN w.log_type = 2 THEN w.user_id END)
  258. </if>
  259. <if test="statisticalType == 2">
  260. COUNT(DISTINCT a.user_id)
  261. </if>
  262. <if test="statisticalType == 3">
  263. COUNT(DISTINCT CASE WHEN a.is_right = 1 THEN a.user_id END)
  264. </if>
  265. ${sort}
  266. LIMIT 10
  267. </select>
  268. <select id="rewardMoneyTopTen" resultType="com.fs.statis.dto.RewardMoneyTopTenDTO">
  269. SELECT
  270. -- 按公司
  271. <if test="dataType == 0">
  272. rpl.company_id as company_id,
  273. </if>
  274. -- 按课程
  275. <if test="dataType == 1">
  276. rpl.course_id as course_id,
  277. </if>
  278. SUM(rpl.amount) as rewardMoney
  279. FROM
  280. fs_course_red_packet_log rpl
  281. left join fs_course_watch_log log
  282. on rpl.watch_log_id=log.log_id
  283. <where>
  284. <if test="startTime != null">
  285. AND rpl.create_time <![CDATA[>=]]> #{startTime}
  286. </if>
  287. <if test="endTime != null">
  288. AND rpl.create_time <![CDATA[<]]> #{endTime}
  289. </if>
  290. <if test="userType != null">
  291. and log.send_type = ${userType}
  292. </if>
  293. <if test="companyId != null">
  294. and log.company_id = ${companyId}
  295. </if>
  296. </where>
  297. GROUP BY
  298. <if test="dataType == 0">
  299. rpl.company_id
  300. </if>
  301. <if test="dataType == 1">
  302. rpl.course_id
  303. </if>
  304. ORDER BY
  305. rewardMoney DESC
  306. LIMIT 10
  307. </select>
  308. <select id="rewardMoneyTrendDTO" resultType="com.fs.statis.dto.RewardMoneyTrendDTO">
  309. select
  310. -- 今日/昨日 小时
  311. <if test="type == 0 or type == 1">
  312. DATE_FORMAT(rpl.create_time, '%H') AS start_date,
  313. </if>
  314. -- 本周/本月/上月 天
  315. <if test="type == 2 or type == 3 or type == 4">
  316. DATE_FORMAT(rpl.create_time, '%Y-%m-%d') AS start_date,
  317. </if>
  318. SUM(rpl.amount) as rewardMoney
  319. from fs_course_red_packet_log rpl
  320. left join fs_course_watch_log log
  321. on rpl.watch_log_id=log.log_id
  322. <where>
  323. <if test="startTime != null">
  324. rpl.create_time <![CDATA[>=]]> #{startTime}
  325. </if>
  326. <if test="endTime != null">
  327. AND rpl.create_time <![CDATA[<]]> #{endTime}
  328. </if>
  329. <if test="userType != null">
  330. and log.send_type = ${userType}
  331. </if>
  332. <if test="companyId != null">
  333. and log.company_id = ${companyId}
  334. </if>
  335. </where>
  336. group by start_date
  337. </select>
  338. <select id="getCurrentBalance" resultType="java.math.BigDecimal">
  339. select sum(money) from company where is_del=0
  340. </select>
  341. <select id="dealerAggregatedCompanyId" resultType="com.fs.statis.dto.DealerAggregatedDTO">
  342. SELECT
  343. 1 AS dealder_count,
  344. (SELECT COUNT(*) FROM COMPANY_USER
  345. <where>
  346. <if test="companyId != null">
  347. company_id = #{companyId}
  348. </if>
  349. </where>
  350. ) AS group_mgr_count,
  351. (SELECT COUNT(*) FROM FS_USER
  352. <where>
  353. <if test="companyId != null">
  354. company_id = #{companyId}
  355. </if>
  356. </where>
  357. ) AS member_count,
  358. (SELECT COUNT(*) FROM FS_USER
  359. <where>
  360. STATUS=1
  361. <if test="companyId != null">
  362. AND company_id = #{companyId}
  363. </if>
  364. </where>
  365. ) AS normal_num,
  366. (SELECT COUNT(*) FROM FS_USER
  367. <where>
  368. STATUS=0
  369. <if test="companyId != null">
  370. AND company_id = #{companyId}
  371. </if>
  372. </where>
  373. ) AS black_num,
  374. (select COUNT(*) FROM qw_user
  375. <where>
  376. <if test="companyId != null">
  377. AND company_id = ${companyId}
  378. </if>
  379. </where>
  380. ) 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. AND is_del=0
  389. </where>
  390. </select>
  391. </mapper>