ConsumptionBalanceMapper.xml 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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>
  20. <select id="analysisPreview" resultType="com.fs.statis.dto.AnalysisPreviewDTO">
  21. -- 观看人数
  22. select (select count(*) from fs_course_watch_log where create_time between #{startTime} and #{endTime} group by user_id) as watch_count,
  23. -- 完播人数
  24. (select count(*) from fs_course_watch_log where finish_time is not null and create_time between #{startTime} and #{endTime} group by user_id)
  25. as completed_user_count,
  26. -- 观看次数
  27. (select count(*) from fs_course_watch_log where create_time between #{startTime} and #{endTime}) as watch_count,
  28. -- 完播次数
  29. (select count(*) from fs_course_watch_log where create_time between #{startTime} and #{endTime}) as completed_count,
  30. -- 答题人数
  31. (select count(*) from fs_course_answer_logs where create_time between #{startTime} and #{endTime}) as answer_member_count,
  32. -- 正确人数
  33. (select count(*) from fs_course_answer_logs where is_right=1 AND create_time between #{startTime} and #{endTime}) as correct_user_count,
  34. -- 答题红包个数
  35. (select 0) as reward_type,
  36. (select 0) as reward_money
  37. </select>
  38. <select id="queryWatchCount" resultType="java.lang.Long">
  39. select count(log_id) from fs_course_watch_log where create_time between #{startTime} and #{endTime}
  40. </select>
  41. <select id="queryCompletedUserCount" resultType="java.lang.Long">
  42. select count(DISTINCT user_id) from fs_course_watch_log where finish_time is not null and create_time between #{startTime} and #{endTime}
  43. </select>
  44. <select id="queryWatchUserCount" resultType="java.lang.Long">
  45. select count(distinct user_id) from fs_course_watch_log where create_time between #{startTime} and #{endTime}
  46. </select>
  47. <select id="queryCompletedCount" resultType="java.lang.Long">
  48. SELECT COUNT(log_id) FROM fs_course_watch_log
  49. WHERE finish_time IS NOT NULL AND create_time BETWEEN #{startTime} AND #{endTime}
  50. </select>
  51. <select id="queryAnswerMemberCount" resultType="java.lang.Long">
  52. SELECT COUNT(DISTINCT user_id) FROM fs_course_answer_logs
  53. WHERE create_time BETWEEN #{startTime} AND #{endTime}
  54. </select>
  55. <select id="queryCorrectUserCount" resultType="java.lang.Long">
  56. SELECT COUNT(DISTINCT user_id) FROM fs_course_answer_logs
  57. WHERE is_right = 1 AND create_time BETWEEN #{startTime} AND #{endTime}
  58. </select>
  59. <select id="queryRewardCount" resultType="java.lang.Long">
  60. select count(*) from company_red_package_logs where operate_type=1 AND create_time BETWEEN #{startTime} AND #{endTime}
  61. </select>
  62. <select id="queryRewardMoney" resultType="java.math.BigDecimal">
  63. select sum(up_money) from company_red_package_logs where operate_type=1 AND create_time BETWEEN #{startTime} AND #{endTime}
  64. </select>
  65. <select id="smsBalance" resultType="java.lang.Long">
  66. select sum(remain_sms_count) from company_sms
  67. </select>
  68. <select id="authorizationInfo" resultType="com.fs.statis.dto.AuthorizationInfoDTO">
  69. select version_limit,today_watch_user_count from fs_statistics_index limit 1
  70. </select>
  71. <select id="watchEndPlayTrend" resultType="com.fs.statis.dto.WatchEndPlayTrendDTO">
  72. SELECT
  73. -- 今日/昨日 小时
  74. <if test="type == 0 or type == 1">
  75. DATE_FORMAT(create_time, '%H') AS start_date,
  76. </if>
  77. -- 本周/本月/上月 天
  78. <if test="type == 2 or type == 3 or type == 4">
  79. DATE_FORMAT(create_time, '%Y-%m-%d') AS start_date,
  80. </if>
  81. COUNT(DISTINCT user_id) AS watch_user_count,
  82. COUNT(DISTINCT CASE WHEN log_type = 2 THEN user_id END) AS completed_user_count
  83. FROM
  84. fs_course_watch_log
  85. <where>
  86. <if test="startTime != null">
  87. create_time <![CDATA[>=]]> #{startTime}
  88. </if>
  89. <if test="endTime != null">
  90. AND create_time <![CDATA[<]]> #{endTime}
  91. </if>
  92. </where>
  93. GROUP BY
  94. start_date
  95. ORDER BY
  96. start_date
  97. </select>
  98. <select id="deaMemberTopTen" resultType="com.fs.statis.dto.DeaMemberTopTenDTO">
  99. SELECT
  100. company_id,
  101. <if test="statisticalType == 0">
  102. count(DISTINCT user_id) AS watch_user_count
  103. </if>
  104. <if test="statisticalType == 1">
  105. COUNT(DISTINCT CASE WHEN log_type = 2 THEN user_id END) AS watch_user_count
  106. </if>
  107. FROM
  108. fs_course_watch_log
  109. <where>
  110. <if test="startTime != null">
  111. create_time <![CDATA[>=]]> #{startTime}
  112. </if>
  113. <if test="endTime != null">
  114. AND create_time <![CDATA[<]]> #{endTime}
  115. </if>
  116. </where>
  117. GROUP BY company_id
  118. limit 10
  119. </select>
  120. <select id="watchCourseTopTen" resultType="com.fs.statis.dto.CourseStatsDTO">
  121. SELECT
  122. w.course_id AS course_id,
  123. COUNT(DISTINCT w.user_id) AS watch_user_count,
  124. COUNT(DISTINCT CASE WHEN w.log_type = 2 THEN w.user_id END) AS completed_user_count,
  125. COUNT(DISTINCT a.user_id) AS answer_user_count,
  126. COUNT(DISTINCT CASE WHEN a.is_right = 1 THEN a.user_id END) AS correct_user_count
  127. FROM
  128. fs_course_watch_log w
  129. LEFT JOIN
  130. fs_course_answer_logs a ON w.video_id = a.video_id AND w.user_id = a.user_id
  131. <where>
  132. <if test="startTime != null">
  133. w.create_time <![CDATA[>=]]> #{startTime}
  134. </if>
  135. <if test="endTime != null">
  136. AND w.create_time <![CDATA[<]]> #{endTime}
  137. </if>
  138. </where>
  139. GROUP BY
  140. w.course_id
  141. ORDER BY
  142. -- 观看人数
  143. <if test="statisticalType == 0">
  144. COUNT(DISTINCT w.user_id)
  145. </if>
  146. <if test="statisticalType == 1">
  147. COUNT(DISTINCT CASE WHEN w.log_type = 2 THEN w.user_id END)
  148. </if>
  149. <if test="statisticalType == 2">
  150. COUNT(DISTINCT a.user_id)
  151. </if>
  152. <if test="statisticalType == 3">
  153. COUNT(DISTINCT CASE WHEN a.is_right = 1 THEN a.user_id END)
  154. </if>
  155. ${sort}
  156. LIMIT 10
  157. </select>
  158. <select id="rewardMoneyTopTen" resultType="com.fs.statis.dto.RewardMoneyTopTenDTO">
  159. SELECT
  160. -- 按公司
  161. <if test="dataType == 0">
  162. company_id,
  163. </if>
  164. -- 按课程
  165. <if test="dataType == 1">
  166. course_id,
  167. </if>
  168. SUM(money) as rewardMoney
  169. FROM
  170. company_red_package_logs
  171. <where>
  172. operate_type = 1
  173. AND status = 1
  174. <if test="startTime != null">
  175. AND create_time <![CDATA[>=]]> #{startTime}
  176. </if>
  177. <if test="endTime != null">
  178. AND create_time <![CDATA[<]]> #{endTime}
  179. </if>
  180. </where>
  181. GROUP BY
  182. <if test="dataType == 0">
  183. company_id
  184. </if>
  185. <if test="dataType == 1">
  186. course_id
  187. </if>
  188. ORDER BY
  189. rewardMoney DESC
  190. LIMIT 10
  191. </select>
  192. <select id="rewardMoneyTrendDTO" resultType="com.fs.statis.dto.RewardMoneyTrendDTO">
  193. select
  194. -- 今日/昨日 小时
  195. <if test="type == 0 or type == 1">
  196. DATE_FORMAT(create_time, '%H') AS start_date,
  197. </if>
  198. -- 本周/本月/上月 天
  199. <if test="type == 2 or type == 3 or type == 4">
  200. DATE_FORMAT(create_time, '%Y-%m-%d') AS start_date,
  201. </if>
  202. SUM(money) as rewardMoney
  203. from company_red_package_logs
  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. AND operate_type = 1
  212. AND status = 1
  213. </where>
  214. group by start_date
  215. </select>
  216. </mapper>