SysMusicCompareRecordMapper.xml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <!--
  4. 这个文件是自动生成的。
  5. 不要修改此文件。所有改动将在下次重新自动生成时丢失。
  6. -->
  7. <mapper namespace="com.ym.mec.biz.dal.dao.SysMusicCompareRecordDao">
  8. <resultMap type="com.ym.mec.biz.dal.entity.SysMusicCompareRecord" id="SysMusicCompareRecord">
  9. <result column="id_" property="id" />
  10. <result column="user_id_" property="userId" />
  11. <result column="sys_music_score_id_" property="sysMusicScoreId" />
  12. <result column="heard_level_" property="heardLevel" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler" />
  13. <result column="sys_music_score_name_" property="sysMusicScoreName" />
  14. <result column="behavior_id_" property="behaviorId"/>
  15. <result column="score_data_" property="scoreData" />
  16. <result column="score_" property="score" />
  17. <result column="intonation_" property="intonation" />
  18. <result column="cadence_" property="cadence" />
  19. <result column="integrity_" property="integrity" />
  20. <result column="record_file_path_" property="recordFilePath" />
  21. <result column="device_type_" property="deviceType" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler" />
  22. <result column="client_id_" property="clientId" />
  23. <result column="play_time_" property="playTime"/>
  24. <result column="feature_" property="feature" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler" />
  25. <result column="monday_" property="monday"/>
  26. <result column="create_time_" property="createTime" />
  27. </resultMap>
  28. <!-- 根据主键查询一条记录 -->
  29. <select id="get" resultMap="SysMusicCompareRecord" >
  30. SELECT * FROM sys_music_compare_record WHERE id_ = #{id}
  31. </select>
  32. <!-- 全查询 -->
  33. <select id="findAll" resultMap="SysMusicCompareRecord">
  34. SELECT * FROM sys_music_compare_record ORDER BY id_
  35. </select>
  36. <!-- 向数据库增加一条记录 -->
  37. <insert id="insert" parameterType="com.ym.mec.biz.dal.entity.SysMusicCompareRecord" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
  38. <!--
  39. <selectKey resultClass="int" keyProperty="id" >
  40. SELECT SEQ_WSDEFINITION_ID.nextval AS ID FROM DUAL
  41. </selectKey>
  42. -->
  43. INSERT INTO sys_music_compare_record (id_,user_id_,sys_music_score_id_,heard_level_,behavior_id_,score_data_,score_,intonation_,cadence_,integrity_,
  44. record_file_path_,device_type_,client_id_,play_time_,monday_,
  45. feature_,create_time_)
  46. VALUES(#{id},#{userId},#{sysMusicScoreId},#{heardLevel,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{behaviorId},#{scoreData},
  47. #{score},#{intonation},#{cadence},#{integrity},
  48. #{recordFilePath},#{deviceType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{clientId},#{playTime},#{monday},
  49. #{feature,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}, NOW())
  50. </insert>
  51. <!-- 根据主键查询一条记录 -->
  52. <update id="update" parameterType="com.ym.mec.biz.dal.entity.SysMusicCompareRecord">
  53. UPDATE sys_music_compare_record <set>
  54. <if test="userId != null">
  55. user_id_ = #{userId},
  56. </if>
  57. <if test="id != null">
  58. id_ = #{id},
  59. </if>
  60. <if test="sysMusicScoreId != null">
  61. sys_music_score_id_ = #{sysMusicScoreId},
  62. </if>
  63. <if test="scoreData != null">
  64. score_data_ = #{scoreData},
  65. </if>
  66. <if test="score != null">
  67. score_ = #{score},
  68. </if>
  69. <if test="integrity != null">
  70. integrity_ = #{integrity},
  71. </if>
  72. <if test="cadence != null">
  73. cadence_ = #{cadence},
  74. </if>
  75. <if test="sysMusicScoreId != null">
  76. sys_music_score_id_ = #{sysMusicScoreId},
  77. </if>
  78. <if test="recordFilePath != null">
  79. record_file_path_ = #{recordFilePath},
  80. </if>
  81. <if test="clientId != null">
  82. client_id_ = #{clientId},
  83. </if>
  84. <if test="playTime != null">
  85. play_time_ = #{playTime},
  86. </if>
  87. <if test="monday != null">
  88. monday_ = #{monday},
  89. </if>
  90. </set> WHERE id_ = #{id}
  91. </update>
  92. <!-- 根据主键删除一条记录 -->
  93. <delete id="delete" >
  94. DELETE FROM sys_music_compare_record WHERE id_ = #{id}
  95. </delete>
  96. <sql id="queryCondition">
  97. <where>
  98. <if test="userId!=null">
  99. AND smcr.user_id_=#{userId}
  100. </if>
  101. <if test="featureType != null">
  102. AND smcr.feature_ = #{featureType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  103. </if>
  104. <if test="startTime != null and startTime != ''">
  105. AND DATE_FORMAT(smcr.create_time_, '%Y-%m-%d') >= #{startTime}
  106. </if>
  107. <if test="endTime != null and endTime != ''">
  108. AND DATE_FORMAT(smcr.create_time_, '%Y-%m-%d') &lt;= #{endTime}
  109. </if>
  110. </where>
  111. </sql>
  112. <!-- 分页查询 -->
  113. <select id="queryPage" resultMap="SysMusicCompareRecord" parameterType="map">
  114. SELECT
  115. smcr.id_, smcr.user_id_, smcr.sys_music_score_id_,smcr.heard_level_, smcr.score_, smcr.intonation_, smcr.cadence_,
  116. smcr.integrity_, smcr.record_file_path_, smcr.client_id_, smcr.device_type_, smcr.play_time_,
  117. smcr.monday_, smcr.create_time_,
  118. sms.name_ sys_music_score_name_
  119. FROM sys_music_compare_record smcr
  120. LEFT JOIN sys_music_score sms on smcr.sys_music_score_id_ = sms.id_
  121. <include refid="queryCondition"/>
  122. ORDER BY id_ DESC
  123. <include refid="global.limit"/>
  124. </select>
  125. <!-- 查询当前表的总记录数 -->
  126. <select id="queryCount" resultType="int">
  127. SELECT COUNT(*) FROM sys_music_compare_record smcr
  128. <include refid="queryCondition"/>
  129. </select>
  130. <select id="getUserTrainStat" resultType="com.ym.mec.biz.dal.dto.MusicCompareRankingDto">
  131. SELECT
  132. smcr.user_id_ userId,
  133. su.avatar_ avatar,
  134. su.username_ studentName,
  135. sms.name_ musicScoreName,
  136. COUNT(smcr.id_) trainNum,
  137. SUM(smcr.score_)/COUNT(smcr.id_) score,
  138. COUNT(DISTINCT DATE(smcr.create_time_)) trainDays,
  139. SUM(smcr.play_time_) trainTime
  140. FROM sys_music_compare_record smcr
  141. LEFT JOIN sys_user su ON smcr.user_id_=su.id_
  142. LEFT JOIN sys_music_score sms ON smcr.sys_music_score_id_ = sms.id_
  143. WHERE EXISTS (SELECT user_id_ FROM student WHERE user_id_=smcr.user_id_)
  144. AND DATE_FORMAT(smcr.create_time_, '%Y-%m-%d') BETWEEN #{startTime} AND #{endTime}
  145. <if test="heardLevel!=null">
  146. AND smcr.heard_level_ = #{heardLevel, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  147. </if>
  148. GROUP BY smcr.user_id_
  149. </select>
  150. <select id="getUserTrainOverView" resultType="com.ym.mec.biz.dal.dto.StudentTrainOverviewDto">
  151. SELECT
  152. COUNT(DISTINCT smcr.behavior_id_) trainNum,
  153. COUNT(DISTINCT DAY(smcr.create_time_)) trainDays,
  154. SUM(smcr.play_time_) trainTime
  155. FROM sys_music_compare_record smcr
  156. WHERE smcr.user_id_=#{userId}
  157. AND EXISTS (SELECT user_id_ FROM student WHERE user_id_=smcr.user_id_)
  158. </select>
  159. <select id="getUserTrainChartData" resultType="com.ym.mec.biz.dal.dto.StudentTrainChartDto">
  160. SELECT
  161. DATE_FORMAT(smcr.create_time_, '%Y-%m-%d') trainDate,
  162. COUNT(DISTINCT smcr.behavior_id_) trainNum,
  163. SUM(smcr.play_time_) trainTime
  164. FROM sys_music_compare_record smcr
  165. WHERE smcr.user_id_=#{userId}
  166. AND EXISTS (SELECT user_id_ FROM student WHERE user_id_=smcr.user_id_)
  167. AND DATE_FORMAT(smcr.create_time_, '%Y-%m-%d') BETWEEN #{startTime} AND #{endTime}
  168. GROUP BY DATE_FORMAT(smcr.create_time_, '%Y-%m-%d')
  169. ORDER BY trainDate;
  170. </select>
  171. <sql id="queryMusicGroupStudentTrainDataConditon">
  172. <where>
  173. sr.music_group_status_='NORMAL' AND stu.user_id_ IS NOT NULL
  174. <if test="startTime!=null and endTime!=null">
  175. AND DATE_FORMAT( smcr.create_time_, '%Y-%m-%d' ) BETWEEN #{startTime} AND #{endTime}
  176. </if>
  177. <if test="musicGroupId!=null">
  178. AND sr.music_group_id_ = #{musicGroupId}
  179. </if>
  180. <if test="search!=null">
  181. AND (su.username_ LIKE CONCAT('%', #{search}, '%'))
  182. </if>
  183. </where>
  184. </sql>
  185. <select id="queryMusicGroupStudentTrainData" resultType="com.ym.mec.biz.dal.dto.MusicCompareRankingDto">
  186. SELECT
  187. smcr.user_id_ userId,
  188. su.avatar_ avatar,
  189. su.username_ studentName,
  190. COUNT( smcr.id_ ) trainNum,
  191. COUNT( DISTINCT DAY ( smcr.create_time_ )) trainDays,
  192. SUM( smcr.play_time_ ) trainTime,
  193. CASE WHEN stu.member_rank_setting_id_ IS NULL THEN 0 ELSE 1 END vipUser
  194. FROM
  195. sys_music_compare_record smcr
  196. LEFT JOIN sys_user su ON smcr.user_id_ = su.id_
  197. LEFT JOIN student stu ON stu.user_id_ = smcr.user_id_
  198. LEFT JOIN student_registration sr ON sr.user_id_=smcr.user_id_
  199. <include refid="queryMusicGroupStudentTrainDataConditon"></include>
  200. GROUP BY smcr.user_id_
  201. <if test="sortField!=null and sortField!=''">
  202. <if test="sortField == 'TRAINDAYS'">
  203. ORDER BY trainDays
  204. </if>
  205. <if test="sortField == 'TRAINTIME'">
  206. ORDER BY trainTime
  207. </if>
  208. <if test="sortField == 'TRAINNUM'">
  209. ORDER BY trainNum
  210. </if>
  211. </if>
  212. <include refid="global.limit"></include>
  213. </select>
  214. <select id="countMusicGroupStudentTrainData" resultType="int">
  215. SELECT
  216. COUNT(DISTINCT smcr.user_id_)
  217. FROM
  218. sys_music_compare_record smcr
  219. LEFT JOIN sys_user su ON smcr.user_id_ = su.id_
  220. LEFT JOIN student stu ON stu.user_id_ = smcr.user_id_
  221. LEFT JOIN student_registration sr ON sr.user_id_=smcr.user_id_
  222. <include refid="queryMusicGroupStudentTrainDataConditon"/>
  223. </select>
  224. <select id="queryStudentTrainData" resultType="com.ym.mec.biz.dal.dto.EduOrganStudentListDto">
  225. SELECT
  226. user_id_ studentId,
  227. COUNT(DISTINCT behavior_id_) cloudStudyUseNum,
  228. SUM(play_time_) cloudStudyUseTime
  229. FROM
  230. sys_music_compare_record
  231. GROUP BY
  232. user_id_
  233. </select>
  234. <select id="countStudentTrain" resultType="java.lang.Integer">
  235. SELECT COUNT(DISTINCT s.user_id_)
  236. FROM teacher t
  237. LEFT JOIN student s ON t.id_ = s.teacher_id_
  238. LEFT JOIN sys_user su ON su.id_ = s.user_id_
  239. LEFT JOIN sys_music_compare_record mcr ON mcr.user_id_ = s.user_id_
  240. <if test="startTime != null and startTime != ''">
  241. AND (DATE_FORMAT(mcr.create_time_, '%Y-%m-%d') >= #{startTime} OR mcr.id_ IS NULL)
  242. </if>
  243. <if test="endTime != null and endTime != ''">
  244. AND (DATE_FORMAT(mcr.create_time_, '%Y-%m-%d') &lt;= #{endTime} OR mcr.id_ IS NULL)
  245. </if>
  246. WHERE s.teacher_id_ = #{teacherId}
  247. <if test="search != null and search != ''">
  248. AND (su.phone_ LIKE CONCAT('%',#{search},'%') OR su.username_ LIKE CONCAT('%',#{search},'%'))
  249. </if>
  250. </select>
  251. <resultMap id="CountStudentTrainDataDto" type="com.ym.mec.biz.dal.dto.CountStudentTrainDataDto">
  252. <result property="trainNum" column="train_num_"/>
  253. <result property="recordNum" column="record_num_"/>
  254. <result property="avatar" column="avatar_"/>
  255. <result property="userId" column="user_id_"/>
  256. <result property="username" column="username_"/>
  257. <result property="phone" column="phone_"/>
  258. <result property="totalPlayTime" column="total_play_time_"/>
  259. <result property="trainDay" column="train_day_"/>
  260. <result property="musicGroupName" column="music_group_name_"/>
  261. </resultMap>
  262. <select id="queryStudentTrain" resultMap="CountStudentTrainDataDto">
  263. SELECT s.user_id_,su.avatar_,su.phone_,su.username_,ROUND(SUM(mcr.play_time_) / 60) total_play_time_,
  264. COUNT(DISTINCT DATE_FORMAT(mcr.create_time_,"%Y-%m-%d")) train_day_,
  265. COUNT(DISTINCT mcr.behavior_id_) train_num_,
  266. COUNT(CASE WHEN mcr.feature_ = 'CLOUD_STUDY_EVALUATION' THEN mcr.behavior_id_ ELSE NULL END) record_num_,GROUP_CONCAT(DISTINCT mg.name_) music_group_name_
  267. FROM teacher t
  268. LEFT JOIN student s ON t.id_ = s.teacher_id_
  269. LEFT JOIN student_registration sr ON sr.user_id_ = s.user_id_ AND sr.music_group_status_ = 'NORMAL'
  270. LEFT JOIN music_group mg ON mg.id_ = sr.music_group_id_ AND mg.status_ = 'PROGRESS'
  271. LEFT JOIN sys_user su ON su.id_ = s.user_id_
  272. LEFT JOIN sys_music_compare_record mcr ON mcr.user_id_ = s.user_id_
  273. <if test="startTime != null and startTime != ''">
  274. AND (DATE_FORMAT(mcr.create_time_, '%Y-%m-%d') >= #{startTime} OR mcr.id_ IS NULL)
  275. </if>
  276. <if test="endTime != null and endTime != ''">
  277. AND (DATE_FORMAT(mcr.create_time_, '%Y-%m-%d') &lt;= #{endTime} OR mcr.id_ IS NULL)
  278. </if>
  279. WHERE s.teacher_id_ = #{teacherId}
  280. <if test="search != null and search != ''">
  281. AND (su.phone_ LIKE CONCAT('%',#{search},'%') OR su.username_ LIKE CONCAT('%',#{search},'%'))
  282. </if>
  283. GROUP BY s.user_id_
  284. ORDER BY total_play_time_ DESC
  285. <include refid="global.limit"/>
  286. </select>
  287. <select id="getOrganNewCloudStudyNum" resultType="int">
  288. SELECT
  289. COUNT( DISTINCT user_id_ )
  290. FROM
  291. (
  292. SELECT
  293. smcr.user_id_
  294. FROM
  295. sys_music_compare_record smcr
  296. LEFT JOIN sys_user su ON smcr.user_id_ = su.id_
  297. WHERE
  298. su.del_flag_ = 0
  299. AND su.organ_id_ = #{organId}
  300. GROUP BY
  301. user_id_
  302. HAVING
  303. COUNT(
  304. DISTINCT DATE( smcr.create_time_ ))= 1
  305. AND MAX(
  306. DATE( smcr.create_time_ ))= CURDATE()) t
  307. </select>
  308. <select id="getOrgansTotalNewCloudStudyNum" resultType="int">
  309. SELECT
  310. COUNT( DISTINCT user_id_ )
  311. FROM
  312. (
  313. SELECT
  314. smcr.user_id_
  315. FROM
  316. sys_music_compare_record smcr
  317. LEFT JOIN sys_user su ON smcr.user_id_ = su.id_
  318. WHERE
  319. su.del_flag_ = 0
  320. <if test="organIds!=null and organIds.size()>0">
  321. AND su.organ_id_ IN
  322. <foreach collection="organIds" item="organId" open="(" close=")" separator=",">
  323. #{organId}
  324. </foreach>
  325. </if>
  326. GROUP BY
  327. user_id_
  328. HAVING
  329. COUNT(DISTINCT DATE( smcr.create_time_ ))= 1
  330. AND MAX(DATE( smcr.create_time_ ))= CURDATE()) t
  331. </select>
  332. <select id="getOrgansNewCloudStudyNum" resultType="map">
  333. SELECT
  334. organ_id_ 'key',
  335. COUNT( DISTINCT user_id_ ) 'value'
  336. FROM
  337. (
  338. SELECT
  339. su.organ_id_,
  340. smcr.user_id_
  341. FROM
  342. sys_music_compare_record smcr
  343. LEFT JOIN sys_user su ON smcr.user_id_ = su.id_
  344. WHERE
  345. su.del_flag_ = 0
  346. <if test="organIds!=null and organIds.size()>0">
  347. AND su.organ_id_ IN
  348. <foreach collection="organIds" item="organId" open="(" close=")" separator=",">
  349. #{organId}
  350. </foreach>
  351. </if>
  352. GROUP BY
  353. user_id_
  354. HAVING
  355. COUNT(
  356. DISTINCT DATE( smcr.create_time_ ))= 1
  357. AND MAX(
  358. DATE( smcr.create_time_ ))= CURDATE()) t
  359. GROUP BY t.organ_id_
  360. </select>
  361. <select id="getUserLastEvaluationData" resultMap="SysMusicCompareRecord">
  362. SELECT * FROM sys_music_compare_record WHERE user_id_=#{userId} ORDER BY create_time_ DESC LIMIT 1
  363. </select>
  364. </mapper>