ActivityEvaluationMapper.xml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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. <mapper namespace="com.yonge.cooleshow.biz.dal.dao.ActivityEvaluationDao">
  4. <resultMap id="BaseResultMap" type="com.yonge.cooleshow.biz.dal.entity.ActivityEvaluation">
  5. <result column="id_" property="id" />
  6. <result column="activity_id_" property="activityId" />
  7. <result column="music_sheet_id_" property="musicSheetId" />
  8. <result column="resource_type_" property="resourceType" />
  9. <result column="create_time_" property="createTime" />
  10. <result column="create_by_" property="createBy" />
  11. </resultMap>
  12. <!-- 表字段 -->
  13. <sql id="baseColumns">
  14. t.id_ as id
  15. , t.activity_id_ as activityId
  16. , t.music_sheet_id_ as musicSheetId
  17. , t.resource_type_ as resourceType
  18. , t.evaluation_difficulty_ as evaluationDifficulty
  19. , t.create_time_ as createTime
  20. , t.create_by_ as createBy
  21. </sql>
  22. <select id="detail" resultType="com.yonge.cooleshow.biz.dal.vo.ActivityEvaluationVo">
  23. SELECT
  24. <include refid="baseColumns"/>
  25. FROM activity_evaluation t
  26. left join music_sheet ms on t.music_sheet_id_ = ms.id_ and find_in_set('PLATFORM',ms.provider_type_)
  27. where t.id_ = #{id}
  28. </select>
  29. <sql id="selectSql">
  30. SELECT
  31. <include refid="baseColumns" />
  32. , ms.music_sheet_name_ as musicSheetName
  33. , ms.music_subject_ AS subjectId
  34. , ms.title_img_ AS musicImage
  35. , ms.composer_ AS composer
  36. , (select group_concat(mt.name_) from music_tag mt where find_in_set(mt.id_,ms.music_tag_) and mt.del_flag_ = 0 and mt.state_ = 1) as musicTagNames
  37. , (select group_concat(s.name_) from subject s where find_in_set(s.id_,ms.music_subject_) and s.del_flag_ = 0 ) as subjectNames
  38. , ms.source_type_ as sourceType
  39. , ms.music_price_ as musicPrice
  40. FROM activity_evaluation t
  41. left join music_sheet ms on t.music_sheet_id_ = ms.id_ and find_in_set('PLATFORM',ms.provider_type_)
  42. <where>
  43. <if test="param.activityId != null">
  44. and t.activity_id_ = #{param.activityId}
  45. </if>
  46. </where>
  47. </sql>
  48. <select id="selectPage" resultType="com.yonge.cooleshow.biz.dal.vo.ActivityEvaluationVo">
  49. <include refid="selectSql"/>
  50. </select>
  51. <select id="selectAll" resultType="com.yonge.cooleshow.biz.dal.vo.ActivityEvaluationVo">
  52. <include refid="selectSql"/>
  53. </select>
  54. <insert id="addBatch">
  55. insert into activity_evaluation (activity_id_,create_by_, music_sheet_id_, resource_type_) values
  56. <foreach collection="musicSheetIds" item="item" separator="," index="index">
  57. (#{activityId,jdbcType=BIGINT},#{userId,jdbcType=BIGINT},#{item,jdbcType=BIGINT}, #{resourceType,jdbcType=VARCHAR})
  58. </foreach>
  59. </insert>
  60. <select id="selectActivityMusic" resultType="com.yonge.cooleshow.biz.dal.vo.ActivityMusicVo">
  61. select ms.id_ as musicSheetId
  62. ,ms.music_sheet_name_ as musicSheetName
  63. , ms.music_subject_ AS subjectId
  64. , ms.title_img_ AS musicImage
  65. ,s.name_ as musicSubject
  66. , ms.composer_ AS composer
  67. ,ae.id_ as evaluationId
  68. , ae.evaluation_difficulty_ AS evaluationDifficulty
  69. ,(select if(count(1)>0,1,0) as `join` from activity_evaluation_record aer where aer.evaluation_id_ = ae.id_ and aer.user_id_ = #{userId}) as `join`
  70. from activity_evaluation ae
  71. left join music_sheet ms on ms.id_ = ae.music_sheet_id_ and find_in_set('PLATFORM',ms.provider_type_)
  72. left join subject s on s.id_ = ms.music_subject_
  73. <where>
  74. ms.del_flag_ = 0
  75. <if test="activityPlanId != null">
  76. and ae.activity_id_ = #{activityPlanId}
  77. </if>
  78. </where>
  79. </select>
  80. <select id="selectActivityUser" resultType="com.yonge.cooleshow.biz.dal.vo.ActivityMusicVo">
  81. select t2.score
  82. ,t2.username_ as username
  83. ,t2.avatar_ as userAvatar
  84. ,s.name_ as userSubject
  85. ,t2.evaluationId
  86. ,t2.userId
  87. from
  88. (select aem2.evaluation_id_ as evaluationId
  89. ,su.id_ as userId
  90. ,su.username_
  91. ,su.avatar_
  92. ,t.score
  93. from (select
  94. max(aem.score_) as score,
  95. aem.evaluation_id_
  96. from activity_evaluation_record aem
  97. where
  98. aem.score_ is not null and aem.activity_id_ = #{activityPlanId}
  99. group by aem.evaluation_id_
  100. ) t
  101. left join activity_evaluation_record aem2 on aem2.score_ = t.score and t.evaluation_id_ = aem2.evaluation_id_
  102. left join sys_user su on su.id_ = aem2.user_id_
  103. where aem2.activity_id_ = #{activityPlanId} and su.del_flag_ = 0 group by t.score,t.evaluation_id_
  104. ) t2
  105. left join student stu on stu.user_id_ = t2.userId
  106. left join subject s on s.id_ = stu.subject_id_
  107. </select>
  108. <select id="musicPage" resultType="com.yonge.cooleshow.biz.dal.vo.MusicSheetVo">
  109. select
  110. <include refid="com.yonge.cooleshow.biz.dal.dao.MusicSheetDao.Base_Column_List"/>,
  111. su.username_ as addName,
  112. su.avatar_ as addUserAvatar,
  113. (select group_concat(mt.name_) from music_tag mt
  114. where find_in_set(mt.id_,t.music_tag_) and mt.del_flag_ = 0 and mt.state_ = 1) as musicTagNames
  115. from music_sheet t
  116. left join sys_user su on t.create_by_ = su.id_
  117. <if test="param.auditStatus != null">
  118. left join music_sheet_auth_record msar ON msar.music_sheet_id_ = t.id_
  119. </if>
  120. <where>
  121. su.del_flag_ = 0 and find_in_set('PLATFORM',t.provider_type_)
  122. and not exists(
  123. select 1 from activity_evaluation ae where ae.activity_id_ = ${param.activityId} and ae.music_sheet_id_ = t.id_
  124. )
  125. <include refid="com.yonge.cooleshow.biz.dal.dao.MusicSheetDao.QueryInfo"/>
  126. </where>
  127. ORDER BY CONVERT(t.music_sheet_name_ USING gbk) COLLATE gbk_chinese_ci,
  128. t.music_sheet_name_ COLLATE utf8mb4_bin,
  129. t.music_sheet_name_ REGEXP '^[0-9]' DESC, t.create_time_ DESC
  130. </select>
  131. <!--活动老师信息-->
  132. <resultMap id="ActivityTeacherPageInfoResultMap" type="com.yonge.cooleshow.biz.dal.vo.activity.ActivityTeacherWrapper">
  133. <result column="id_" jdbcType="BIGINT" property="id" />
  134. <result column="real_name_" jdbcType="BIGINT" property="realName" />
  135. <result column="username_" jdbcType="VARCHAR" property="username" />
  136. <result column="phone_" jdbcType="VARCHAR" property="phone" />
  137. <result column="subject_id_" jdbcType="VARCHAR" property="subjectId" />
  138. <result column="teacher_id" jdbcType="BIGINT" property="teacherId" />
  139. </resultMap>
  140. <sql id="ActivityTeacherPageInfo_Column_List">
  141. t1.id_ AS teacher_id, t1.real_name_, t1.username_, t1.phone_, t2.subject_id_
  142. <if test="record.activityId != null and record.addType == 0">, t3.id_</if>
  143. </sql>
  144. <sql id="ActivityTeacherPageInfo_Condition_List">
  145. <if test="record.id != null">
  146. AND t1.id_ = #{record.id}
  147. </if>
  148. <if test="record.mobile != null">
  149. AND t1.phone_ = #{record.mobile}
  150. </if>
  151. <if test="record.name != null">
  152. AND (t1.real_name_ LIKE '%${record.name}%' OR t1.username_ LIKE '%${record.name}%')
  153. </if>
  154. <if test="record.lockFlag != null">
  155. AND t1.lock_flag_ = #{record.lockFlag}
  156. </if>
  157. <if test="record.deleteFlag != null">
  158. AND t1.del_flag_ = #{record.deleteFlag}
  159. </if>
  160. <if test="record.addType == 1">
  161. AND t4.user_id IS NULL
  162. </if>
  163. </sql>
  164. <sql id="ActivityTeacherNotIn_Condition_List">
  165. <if test="record.activityType != null">
  166. AND t1.activity_type_ = #{record.activityType}
  167. </if>
  168. <if test="record.resourceType != null">
  169. AND t2.resource_type_ = #{record.resourceType}
  170. </if>
  171. <choose>
  172. <when test="record.activityId != null">
  173. AND (t2.activity_id_ = #{record.activityId} <if test="record.startTime != null and record.endTime != null"> OR (<include refid="ActivityTeacherNotIn_ActivityTime_Condition_List" />) </if>)
  174. </when>
  175. <otherwise>
  176. AND <include refid="ActivityTeacherNotIn_ActivityTime_Condition_List" />
  177. </otherwise>
  178. </choose>
  179. </sql>
  180. <sql id="ActivityTeacherNotIn_ActivityTime_Condition_List">
  181. <if test="record.startTime != null and record.endTime != null">
  182. t1.activity_state_ = #{record.activityState} AND ((unix_timestamp(t1.activity_start_) &lt;= #{record.startTime} AND #{record.startTime} &lt;= unix_timestamp(t1.activity_end_)) OR (unix_timestamp(t1.activity_start_) &lt;= #{record.endTime} AND #{record.endTime} &lt;= unix_timestamp(t1.activity_end_)))
  183. </if>
  184. </sql>
  185. <select id="selectActivityTeacherPageInfo" resultMap="ActivityTeacherPageInfoResultMap">
  186. SELECT <include refid="ActivityTeacherPageInfo_Column_List" />
  187. FROM sys_user t1 JOIN teacher t2 ON (t1.id_ = t2.user_id_ <if test="record.lockFlag !=null"> AND t2.lock_flag_ = #{record.lockFlag} </if> )
  188. <choose>
  189. <when test="record.addType == 1">
  190. LEFT JOIN (SELECT t2.music_sheet_id_ AS user_id FROM activity_plan t1 JOIN activity_evaluation t2 ON (t1.id_ = t2.activity_id_ <include refid="ActivityTeacherNotIn_Condition_List"/> ) )t4 ON (t4.user_id = t1.id_)
  191. </when>
  192. <otherwise>
  193. <if test="record.activityId != null and record.addType == 0"> JOIN activity_evaluation t3 ON (t1.id_ = t3.music_sheet_id_ AND t3.activity_id_ = #{record.activityId}) </if>
  194. </otherwise>
  195. </choose>
  196. <where>
  197. <include refid="ActivityTeacherPageInfo_Condition_List" />
  198. <if test="record.subjectIdList != null">
  199. AND <foreach collection="record.subjectIdList" separator="or" item="item" open="(" close=")"> FIND_IN_SET(#{item}, t2.subject_id_) </foreach>
  200. </if>
  201. </where>
  202. </select>
  203. <!--活动老师信息-->
  204. <!--时间匹配活动老师信息-->
  205. <resultMap id="ActivityTeacherByTimePageInfoResultMap" type="com.yonge.cooleshow.biz.dal.vo.activity.ActivityTeacherWrapper">
  206. <result column="real_name_" jdbcType="BIGINT" property="realName" />
  207. <result column="username_" jdbcType="VARCHAR" property="username" />
  208. <result column="teacher_id" jdbcType="BIGINT" property="teacherId" />
  209. </resultMap>
  210. <sql id="ActivityTeacherByTimePageInfo_Column_List">
  211. t4.id_ AS teacher_id, t4.real_name_, t4.username_
  212. </sql>
  213. <select id="selectActivityTeacherByTimePageInfo" resultMap="ActivityTeacherByTimePageInfoResultMap">
  214. SELECT <include refid="ActivityTeacherByTimePageInfo_Column_List" />
  215. FROM activity_plan t1 JOIN activity_evaluation t2 ON t1.id_ = t2.activity_id_ LEFT JOIN activity_evaluation t3 ON (t3.music_sheet_id_ = t2.music_sheet_id_ AND t3.activity_id_ = #{record.activityId}) JOIN sys_user t4 ON (t2.music_sheet_id_ = t4.id_)
  216. <where>
  217. t3.id_ IS NOT NULL
  218. <if test="record.activityId != null">
  219. AND t2.activity_id_ != #{record.activityId}
  220. </if>
  221. <if test="record.lockFlag != null">
  222. AND t4.lock_flag_ = #{record.lockFlag}
  223. </if>
  224. <if test="record.deleteFlag != null">
  225. AND t4.del_flag_ = #{record.deleteFlag}
  226. </if>
  227. <if test="record.activityState != null">
  228. AND t1.activity_state_ = #{record.activityState}
  229. </if>
  230. <if test="record.startTime != null and record.endTime != null">
  231. AND ((unix_timestamp(t1.activity_start_) &lt;= #{record.startTime} AND #{record.startTime} &lt;= unix_timestamp(t1.activity_end_)) OR (unix_timestamp(t1.activity_start_) &lt;= #{record.endTime} AND #{record.endTime} &lt;= unix_timestamp(t1.activity_end_)))
  232. </if>
  233. </where>
  234. </select>
  235. <!--时间匹配活动老师信息-->
  236. <!--评测活动声部曲目最多分-->
  237. <select id="selectSubjectMusicHighestScoreStat"
  238. resultType="com.yonge.cooleshow.biz.dal.wrapper.StatGroupWrapper">
  239. SELECT t1.evaluation_id_ AS id, MAX(t1.score_) AS number FROM activity_evaluation_record t1
  240. <where>
  241. t1.score_ IS NOT NULL
  242. <if test="activityId != null">
  243. AND t1.activity_id_ = #{activityId}
  244. </if>
  245. <if test="userId != null">
  246. AND t1.user_id_ = #{userId}
  247. </if>
  248. </where>
  249. GROUP BY t1.evaluation_id_
  250. </select>
  251. <!--评测活动声部曲目最多分-->
  252. </mapper>