ActivityEvaluationMapper.xml 12 KB

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