ExtracurricularExercisesMapper.xml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  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.ExtracurricularExercisesDao">
  8. <resultMap type="com.ym.mec.biz.dal.entity.ExtracurricularExercises" id="ExtracurricularExercises">
  9. <result column="id_" property="id" />
  10. <result column="music_group_id_" property="musicGroupId" />
  11. <result column="teacher_id_" property="teacherId" />
  12. <result column="username_" property="teacher.username" />
  13. <result column="classGroupId" property="classGroupId" />
  14. <result column="student_id_list_" property="studentIdList" />
  15. <result column="batch_no_" property="batchNo" />
  16. <result column="title_" property="title" />
  17. <result column="attachments_" property="attachments" />
  18. <result column="content_" property="content" />
  19. <result column="expire_date_" property="expireDate" />
  20. <result column="completed_num_" property="completedNum" />
  21. <result column="expect_num_" property="expectNum" />
  22. <result column="create_time_" property="createTime" />
  23. <result column="update_time_" property="updateTime" />
  24. <result column="organ_name_" property="organName" />
  25. <result column="tenant_id_" property="tenantId" />
  26. <result column="music_score_id_" property="musicScoreId" />
  27. <result column="assignTime" property="assignTime" />
  28. <result column="musicGroupName" property="musicGroupName" />
  29. <result column="versionTag" property="versionTag" />
  30. </resultMap>
  31. <sql id="queryPageCondition">
  32. <where>
  33. ee.tenant_id_ = #{tenantId}
  34. <if test="teacherId != null">
  35. and teacher_id_ = #{teacherId}
  36. </if>
  37. <if test="musicGroupId != null">
  38. and music_group_id_ = #{musicGroupId}
  39. </if>
  40. <if test="title != null">
  41. and title_ like '%' #{title} '%'
  42. </if>
  43. <if test="batchNo != null">
  44. and batch_no_ = #{batchNo}
  45. </if>
  46. <if test="organIdList != null">
  47. AND FIND_IN_SET(o.id_, #{organIdList})
  48. </if>
  49. <if test="assignStartTime != null">
  50. AND date(ee.create_time_) &gt;= #{assignStartTime}
  51. </if>
  52. <if test="assignEndTime != null">
  53. AND date(ee.create_time_) &lt;= #{assignEndTime}
  54. </if>
  55. <if test="cloudHomeworkFlag != null and cloudHomeworkFlag == true">
  56. AND eer.music_score_id_ IS NOT NULL AND eer.music_score_id_ != ''
  57. </if>
  58. <if test="cloudHomeworkFlag != null and cloudHomeworkFlag == false">
  59. AND (eer.music_score_id_ IS NULL OR eer.music_score_id_ = '')
  60. </if>
  61. <if test="type != null">
  62. and ee.group_type_ = #{type}
  63. </if>
  64. <if test="search != null ">
  65. and (su.username_ like '%' #{search} '%' or mg.name_ like '%' #{search} '%')
  66. </if>
  67. <if test="type != null">
  68. and ee.group_type_ = #{type}
  69. </if>
  70. <if test="studentExerciseId != null">
  71. and ee.id_ = #{studentExerciseId}
  72. </if>
  73. <if test="studentAssignFlag != null">
  74. <if test="studentAssignFlag == true">
  75. and ee.music_group_id_ is null
  76. </if>
  77. <if test="studentAssignFlag == false">
  78. and ee.student_id_list_ is not null
  79. </if>
  80. </if>
  81. </where>
  82. </sql>
  83. <!-- 根据主键查询一条记录 -->
  84. <select id="get" resultMap="ExtracurricularExercises" >
  85. SELECT * FROM extracurricular_exercises WHERE id_ = #{id}
  86. </select>
  87. <!-- 全查询 -->
  88. <select id="findAll" resultMap="ExtracurricularExercises">
  89. SELECT * FROM extracurricular_exercises where tenant_id_ = #{tenantId} ORDER BY id_
  90. </select>
  91. <!-- 向数据库增加一条记录 -->
  92. <insert id="insert" parameterType="com.ym.mec.biz.dal.entity.ExtracurricularExercises" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
  93. INSERT INTO extracurricular_exercises (music_group_id_,teacher_id_,student_id_list_,batch_no_,
  94. title_,attachments_,content_,expire_date_,completed_num_,expect_num_,create_time_,update_time_,tenant_id_)
  95. VALUES(#{musicGroupId},#{teacherId},#{studentIdList},#{batchNo},#{title},#{attachments},
  96. #{content},#{expireDate},#{completedNum},#{expectNum},NOW(), NOW(),#{tenantId})
  97. </insert>
  98. <!-- 根据主键查询一条记录 -->
  99. <update id="update" parameterType="com.ym.mec.biz.dal.entity.ExtracurricularExercises">
  100. UPDATE extracurricular_exercises
  101. <set>
  102. <if test="studentIdList != null">
  103. student_id_list_ = #{studentIdList},
  104. </if>
  105. <if test="expireDate != null">
  106. expire_date_ = #{expireDate},
  107. </if>
  108. <if test="batchNo != null">
  109. batch_no_ = #{batchNo},
  110. </if>
  111. <if test="musicGroupId != null">
  112. music_group_id_ = #{musicGroupId},
  113. </if>
  114. <if test="teacherId != null">
  115. teacher_id_ = #{teacherId},
  116. </if>
  117. <if test="title != null">
  118. title_ = #{title},
  119. </if>
  120. <if test="expectNum != null">
  121. expect_num_ = #{expectNum},
  122. </if>
  123. <if test="content != null">
  124. content_ = #{content},
  125. </if>
  126. <if test="attachments != null">
  127. attachments_ = #{attachments},
  128. </if>
  129. <if test="completedNum != null">
  130. completed_num_ = #{completedNum},
  131. </if>
  132. update_time_ = NOW()
  133. </set> WHERE id_ = #{id} and tenant_id_ = #{tenantId}
  134. </update>
  135. <!-- 根据主键删除一条记录 -->
  136. <delete id="delete" >
  137. DELETE FROM extracurricular_exercises WHERE id_ = #{id}
  138. </delete>
  139. <!-- 分页查询 -->
  140. <select id="queryPage" resultMap="ExtracurricularExercises" parameterType="map">
  141. SELECT ee.id_,ee.teacher_id_,ee.student_id_list_,ee.batch_no_,ee.title_,ee.attachments_,ee.music_group_id_,
  142. ee.content_,ee.expire_date_,ee.completed_num_,ee.expect_num_,ee.create_time_,ee.update_time_,ee.tenant_id_
  143. ,u.real_name_ username_,o.name_ organ_name_,eer.music_score_id_,ee.create_time_ as assignTime,mg.name_ as musicGroupName,ee.class_group_id_ as classGroupId,ee.version_tag_ as versionTag
  144. FROM extracurricular_exercises ee LEFT JOIN sys_user u ON ee.teacher_id_ = u.id_
  145. LEFT JOIN teacher t ON t.id_ = ee.teacher_id_
  146. left join sys_user su on t.id_ = su.id_
  147. LEFT JOIN organization o ON o.id_ = t.organ_id_
  148. left join music_group mg on mg.id_ = ee.music_group_id_
  149. LEFT JOIN extracurricular_exercises_reply eer ON ee.id_ = eer.extracurricular_exercises_id_
  150. <include refid="queryPageCondition"/>
  151. GROUP BY ee.id_
  152. ORDER BY id_ <include refid="global.limit"/>
  153. </select>
  154. <!-- 查询当前表的总记录数 -->
  155. <select id="queryCount" resultType="int">
  156. SELECT COUNT(DISTINCT ee.id_) FROM extracurricular_exercises ee left join sys_user u on ee.teacher_id_ = u.id_
  157. left join teacher t on t.id_ = ee.teacher_id_
  158. left join sys_user su on t.id_ = su.id_
  159. left join organization o on o.id_ = t.organ_id_
  160. left join music_group mg on mg.id_ = ee.music_group_id_
  161. LEFT JOIN extracurricular_exercises_reply eer ON ee.id_ = eer.extracurricular_exercises_id_
  162. <include refid="queryPageCondition"/>
  163. </select>
  164. <sql id="queryExtraExercisesCondition">
  165. <where>
  166. tenant_id_ = #{tenantId}
  167. <if test="teacherId!=null">
  168. AND teacher_id_ = #{teacherId}
  169. </if>
  170. <if test="createTime!=null">
  171. AND DATE_FORMAT(create_time_, '%Y-%m') = DATE_FORMAT(#{createTime}, '%Y-%m')
  172. </if>
  173. </where>
  174. </sql>
  175. <select id="countExtraExercises" resultType="int">
  176. SELECT COUNT(id_) FROM extracurricular_exercises
  177. <include refid="queryExtraExercisesCondition"/>
  178. </select>
  179. <select id="findExtraExercises" resultMap="ExtracurricularExercises">
  180. SELECT * FROM extracurricular_exercises
  181. <include refid="queryExtraExercisesCondition"/>
  182. ORDER BY create_time_ DESC
  183. <include refid="global.limit"/>
  184. </select>
  185. <select id="findRepeatLastExercises" resultMap="ExtracurricularExercises">
  186. SELECT
  187. *
  188. FROM
  189. extracurricular_exercises
  190. WHERE
  191. teacher_id_ = #{teacherId}
  192. AND student_id_list_ = #{studentIdList}
  193. AND content_ = #{content}
  194. ORDER BY create_time_ DESC LIMIT 1
  195. </select>
  196. <select id="findNoExercisesStudentsInThisWeekWithTeacher"
  197. resultType="com.ym.mec.biz.dal.dto.BasicUserDto">
  198. SELECT
  199. su.id_ userId,
  200. su.username_ name,
  201. su.avatar_ headUrl,
  202. GROUP_CONCAT(sub.name_) subjectName,
  203. stu.member_rank_setting_id_ memberRankSettingId,
  204. stu.subject_id_list_ subjectIdList,
  205. sees.music_group_id_ musicGroupId
  206. FROM
  207. student_extracurricular_exercises_situation_ sees
  208. <if test="classGroupId!=null">
  209. LEFT JOIN class_group_student_mapper cgsm ON sees.student_id_ = cgsm.user_id_
  210. </if>
  211. LEFT JOIN student stu ON stu.user_id_ = sees.student_id_
  212. LEFT JOIN sys_user su ON su.id_ = sees.student_id_
  213. LEFT JOIN `subject` sub ON FIND_IN_SET( sub.id_, stu.subject_id_list_ )
  214. WHERE
  215. sees.monday_ = #{startDate}
  216. AND sees.teacher_id_ = #{teacherId}
  217. AND sees.actual_exercises_num_ &lt; sees.expect_exercises_num_
  218. AND sees.serve_type_ = 'EXERCISE'
  219. <if test="hasMember != null">
  220. <if test="hasMember == 1">
  221. AND stu.member_rank_setting_id_ IS NOT NULL
  222. </if>
  223. <if test="hasMember == 0">
  224. AND stu.member_rank_setting_id_ IS NULL
  225. </if>
  226. </if>
  227. <if test="studentIds!=null and studentIds!=''">
  228. AND FIND_IN_SET(sees.student_id_,#{studentIds})
  229. </if>
  230. <if test="musicGroupId!=null and musicGroupId!=''">
  231. AND sees.music_group_id_=#{musicGroupId}
  232. </if>
  233. <if test="classGroupId!=null">
  234. AND cgsm.class_group_id_ = #{classGroupId}
  235. </if>
  236. <if test="subjectId!=null">
  237. AND FIND_IN_SET(#{subjectId}, stu.subject_id_list_)
  238. </if>
  239. <if test="search!=null">
  240. AND (su.username_ LIKE CONCAT('%', #{search}, '%') OR su.phone_ LIKE CONCAT(#{search}, '%'))
  241. </if>
  242. GROUP BY su.id_
  243. ORDER BY
  244. su.id_;
  245. </select>
  246. <resultMap id="ExtracurricularExercisesHomeworkListDto" type="com.ym.mec.biz.dal.dto.ExtracurricularExercisesHomeworkListDto">
  247. <result property="type" column="type_"/>
  248. <result property="homeworkId" column="id_"/>
  249. </resultMap>
  250. <select id="countExtraExercilsesHomeworks" resultType="int">
  251. SELECT COUNT(id_) FROM (
  252. SELECT id_, create_time_,'EXERCISES' type_
  253. FROM extracurricular_exercises
  254. <where>
  255. tenant_id_ = #{tenantId}
  256. <if test="teacherId!=null">
  257. AND teacher_id_ = #{teacherId}
  258. </if>
  259. <if test="createTime!=null">
  260. AND DATE_FORMAT(create_time_, '%Y-%m') = DATE_FORMAT(#{createTime}, '%Y-%m')
  261. </if>
  262. <if test="startTime != null and startTime != ''">
  263. AND DATE_FORMAT(#{createTime}, '%Y-%m-%d') BETWEEN #{startTime} AND #{endTime}
  264. </if>
  265. </where>
  266. UNION ALL
  267. SELECT ch.id_,ch.create_time_,'HOMEWORK' type_ FROM course_homework ch
  268. LEFT JOIN course_schedule_teacher_salary csts ON ch.course_schedule_id_ = csts.course_schedule_id_ AND csts.teacher_role_ = 'BISHOP'
  269. <where>
  270. csts.tenant_id_ = #{tenantId}
  271. <if test="teacherId!=null">
  272. AND csts.user_id_ = #{teacherId}
  273. </if>
  274. <if test="classGroupId!=null">
  275. AND ch.class_group_id_=#{classGroupId}
  276. </if>
  277. <if test="createTime!=null">
  278. AND DATE_FORMAT(ch.create_time_,'%Y-%m')=DATE_FORMAT(#{createTime}, '%Y-%m')
  279. </if>
  280. </where>
  281. ) h
  282. </select>
  283. <select id="findExtraExercilsesHomeworks" resultMap="ExtracurricularExercisesHomeworkListDto">
  284. SELECT * FROM (
  285. SELECT id_, create_time_,'EXERCISES' type_
  286. FROM extracurricular_exercises
  287. <where>
  288. tenant_id_ = #{tenantId}
  289. <if test="teacherId!=null">
  290. AND teacher_id_ = #{teacherId}
  291. </if>
  292. <if test="createTime!=null">
  293. AND DATE_FORMAT(create_time_, '%Y-%m') = DATE_FORMAT(#{createTime}, '%Y-%m')
  294. </if>
  295. <if test="startTime != null and startTime != ''">
  296. AND DATE_FORMAT(#{createTime}, '%Y-%m-%d') BETWEEN #{startTime} AND #{endTime}
  297. </if>
  298. </where>
  299. UNION ALL
  300. SELECT ch.id_,ch.create_time_,'HOMEWORK' type_ FROM course_homework ch
  301. LEFT JOIN course_schedule_teacher_salary csts ON ch.course_schedule_id_ = csts.course_schedule_id_ AND csts.teacher_role_ = 'BISHOP'
  302. <where>
  303. csts.tenant_id_ = #{tenantId}
  304. <if test="teacherId!=null">
  305. AND csts.user_id_ = #{teacherId}
  306. </if>
  307. <if test="classGroupId!=null">
  308. AND ch.class_group_id_=#{classGroupId}
  309. </if>
  310. <if test="createTime!=null">
  311. AND DATE_FORMAT(ch.create_time_,'%Y-%m')=DATE_FORMAT(#{createTime}, '%Y-%m')
  312. </if>
  313. </where>) h
  314. </select>
  315. <select id="findByIdList" resultMap="com.ym.mec.biz.dal.dao.CourseHomeworkDao.teacherHomeworkListDto">
  316. SELECT id_ homework_id_,title_,content_,completed_num_,expect_num_,music_score_id_,
  317. expire_date_ expiry_date_,DATE_FORMAT(create_time_,'%Y-%m-%d') 'day_'
  318. FROM extracurricular_exercises WHERE id_ IN
  319. <foreach collection="exercisesIdList" separator="," item="item" open="(" close=")">
  320. #{item}
  321. </foreach>
  322. </select>
  323. <sql id="extraHomeworkDetailV2">
  324. <if test="startTime != null and endTime != null">
  325. create_time_ BETWEEN #{startTime} AND #{endTime}
  326. </if>
  327. <if test="homeWorkStatus != null">
  328. <if test="homeWorkStatus.code == 'UNASSIGNED'">
  329. AND id_ = -1
  330. </if>
  331. <if test="homeWorkStatus.code == 'ASSIGNED'">
  332. AND expire_date_ &gt;= NOW()
  333. </if>
  334. <if test="homeWorkStatus.code == 'DEADLINE'">
  335. AND expire_date_ &lt; NOW()
  336. </if>
  337. <if test="courseScheduleId != null">
  338. AND id_ = #{courseScheduleId}
  339. </if>
  340. </if>
  341. <if test="type != null">
  342. and group_type_ = #{type}
  343. </if>
  344. <if test="versionTag != null">
  345. and version_tag_ = #{versionTag}
  346. </if>
  347. </sql>
  348. <select id="countTeacherExtraHomeworkDetailV2" resultType="int">
  349. select count(1) from (
  350. select 1 from extracurricular_exercises
  351. <where>
  352. <include refid="extraHomeworkDetailV2"/>
  353. </where>
  354. <if test="subjectIds != null and subjectIds.size() != 0">
  355. union all
  356. select 1 from music_group
  357. where id_ in
  358. <foreach collection="subjectIds" item="item" separator="," open="(" close=")">
  359. #{item}
  360. </foreach>
  361. </if>) t
  362. </select>
  363. <select id="queryTeacherExtraHomeworkDetailV2"
  364. resultType="com.ym.mec.biz.dal.dto.CourseHomeworkWrapper$CourseHomeworkList">
  365. <if test="subjectIds != null and subjectIds.size() != 0">
  366. (select
  367. id_ as musicGroupId,
  368. 'UNASSIGNED' as homeWorkStatus,
  369. 'EXTRACURRICULAR' as `type`,
  370. null as courseScheduleId,
  371. null as courseHomeworkId,
  372. null as classGroupId,
  373. null as studentNum,
  374. null as finishNum,
  375. null as assignTime,
  376. null as expiryDate,
  377. null as studentIdList
  378. from music_group
  379. where id_ in
  380. <foreach collection="subjectIds" item="item" separator="," open="(" close=")">
  381. #{item}
  382. </foreach>
  383. )
  384. union all
  385. </if>
  386. (select
  387. music_group_id_ as musicGroupId,
  388. if(expire_date_ &gt; NOW(), 'ASSIGNED', 'DEADLINE') as homeWorkStatus,
  389. group_type_ as `type`,
  390. id_ as courseScheduleId,
  391. id_ as courseHomeworkId,
  392. class_group_id_ as classGroupId,
  393. expect_num_ as studentNum,
  394. completed_num_ as finishNum,
  395. create_time_ as assignTime,
  396. expire_date_ as expiryDate,
  397. student_id_list_ as studentIdList
  398. from extracurricular_exercises
  399. <where>
  400. <include refid="extraHomeworkDetailV2"/>
  401. </where>
  402. )
  403. <include refid="global.limit"/>
  404. </select>
  405. <update id="updateFinishNum">
  406. UPDATE extracurricular_exercises SET completed_num_ = ifnull(completed_num_,0) + 1 WHERE id_ = #{courseHomeworkId}
  407. </update>
  408. </mapper>