ExtracurricularExercisesMapper.xml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  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_,group_type_)
  95. VALUES(#{musicGroupId},#{teacherId},#{studentIdList},#{batchNo},#{title},#{attachments},
  96. #{content},#{expireDate},#{completedNum},#{expectNum},NOW(), NOW(),#{tenantId},#{groupType})
  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. <if test="versionTag != null and versionTag != ''">
  133. version_tag_ = #{versionTag},
  134. </if>
  135. update_time_ = NOW()
  136. </set> WHERE id_ = #{id} and tenant_id_ = #{tenantId}
  137. </update>
  138. <!-- 根据主键删除一条记录 -->
  139. <delete id="delete" >
  140. DELETE FROM extracurricular_exercises WHERE id_ = #{id}
  141. </delete>
  142. <!-- 分页查询 -->
  143. <select id="queryPage" resultMap="ExtracurricularExercises" parameterType="map">
  144. SELECT ee.id_,ee.teacher_id_,ee.student_id_list_,ee.batch_no_,ee.title_,ee.attachments_,ee.music_group_id_,
  145. ee.content_,ee.expire_date_,ee.completed_num_,ee.expect_num_,ee.create_time_,ee.update_time_,ee.tenant_id_
  146. ,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
  147. FROM extracurricular_exercises ee LEFT JOIN sys_user u ON ee.teacher_id_ = u.id_
  148. LEFT JOIN teacher t ON t.id_ = ee.teacher_id_
  149. left join sys_user su on t.id_ = su.id_
  150. LEFT JOIN organization o ON o.id_ = t.organ_id_
  151. left join music_group mg on mg.id_ = ee.music_group_id_
  152. LEFT JOIN extracurricular_exercises_reply eer ON ee.id_ = eer.extracurricular_exercises_id_
  153. <include refid="queryPageCondition"/>
  154. GROUP BY ee.id_
  155. ORDER BY id_ desc <include refid="global.limit"/>
  156. </select>
  157. <!-- 查询当前表的总记录数 -->
  158. <select id="queryCount" resultType="int">
  159. SELECT COUNT(DISTINCT ee.id_) FROM extracurricular_exercises ee left join sys_user u on ee.teacher_id_ = u.id_
  160. left join teacher t on t.id_ = ee.teacher_id_
  161. left join sys_user su on t.id_ = su.id_
  162. left join organization o on o.id_ = t.organ_id_
  163. left join music_group mg on mg.id_ = ee.music_group_id_
  164. LEFT JOIN extracurricular_exercises_reply eer ON ee.id_ = eer.extracurricular_exercises_id_
  165. <include refid="queryPageCondition"/>
  166. </select>
  167. <sql id="queryExtraExercisesCondition">
  168. <where>
  169. tenant_id_ = #{tenantId}
  170. <if test="teacherId!=null">
  171. AND teacher_id_ = #{teacherId}
  172. </if>
  173. <if test="createTime!=null">
  174. AND DATE_FORMAT(create_time_, '%Y-%m') = DATE_FORMAT(#{createTime}, '%Y-%m')
  175. </if>
  176. </where>
  177. </sql>
  178. <select id="countExtraExercises" resultType="int">
  179. SELECT COUNT(id_) FROM extracurricular_exercises
  180. <include refid="queryExtraExercisesCondition"/>
  181. </select>
  182. <select id="findExtraExercises" resultMap="ExtracurricularExercises">
  183. SELECT * FROM extracurricular_exercises
  184. <include refid="queryExtraExercisesCondition"/>
  185. ORDER BY create_time_ DESC
  186. <include refid="global.limit"/>
  187. </select>
  188. <select id="findRepeatLastExercises" resultMap="ExtracurricularExercises">
  189. SELECT
  190. *
  191. FROM
  192. extracurricular_exercises
  193. WHERE
  194. teacher_id_ = #{teacherId}
  195. AND student_id_list_ = #{studentIdList}
  196. AND content_ = #{content}
  197. ORDER BY create_time_ DESC LIMIT 1
  198. </select>
  199. <select id="findNoExercisesStudentsInThisWeekWithTeacher"
  200. resultType="com.ym.mec.biz.dal.dto.BasicUserDto">
  201. SELECT
  202. su.id_ userId,
  203. su.username_ name,
  204. su.avatar_ headUrl,
  205. GROUP_CONCAT(sub.name_) subjectName,
  206. stu.member_rank_setting_id_ memberRankSettingId,
  207. stu.subject_id_list_ subjectIdList,
  208. sees.music_group_id_ musicGroupId
  209. FROM
  210. student_extracurricular_exercises_situation_ sees
  211. <if test="classGroupId!=null">
  212. LEFT JOIN class_group_student_mapper cgsm ON sees.student_id_ = cgsm.user_id_
  213. </if>
  214. LEFT JOIN student stu ON stu.user_id_ = sees.student_id_
  215. LEFT JOIN sys_user su ON su.id_ = sees.student_id_
  216. LEFT JOIN `subject` sub ON FIND_IN_SET( sub.id_, stu.subject_id_list_ )
  217. WHERE
  218. sees.monday_ = #{startDate}
  219. AND sees.teacher_id_ = #{teacherId}
  220. AND sees.actual_exercises_num_ &lt; sees.expect_exercises_num_
  221. AND sees.serve_type_ = 'EXERCISE'
  222. <if test="hasMember != null">
  223. <if test="hasMember == 1">
  224. AND stu.member_rank_setting_id_ IS NOT NULL
  225. </if>
  226. <if test="hasMember == 0">
  227. AND stu.member_rank_setting_id_ IS NULL
  228. </if>
  229. </if>
  230. <if test="studentIds!=null and studentIds!=''">
  231. AND FIND_IN_SET(sees.student_id_,#{studentIds})
  232. </if>
  233. <if test="musicGroupId!=null and musicGroupId!=''">
  234. AND sees.music_group_id_=#{musicGroupId}
  235. </if>
  236. <if test="classGroupId!=null">
  237. AND cgsm.class_group_id_ = #{classGroupId}
  238. </if>
  239. <if test="subjectId!=null">
  240. AND FIND_IN_SET(#{subjectId}, stu.subject_id_list_)
  241. </if>
  242. <if test="search!=null">
  243. AND (su.username_ LIKE CONCAT('%', #{search}, '%') OR su.phone_ LIKE CONCAT(#{search}, '%'))
  244. </if>
  245. GROUP BY su.id_
  246. ORDER BY
  247. su.id_;
  248. </select>
  249. <resultMap id="ExtracurricularExercisesHomeworkListDto" type="com.ym.mec.biz.dal.dto.ExtracurricularExercisesHomeworkListDto">
  250. <result property="type" column="type_"/>
  251. <result property="homeworkId" column="id_"/>
  252. </resultMap>
  253. <select id="countExtraExercilsesHomeworks" resultType="int">
  254. SELECT COUNT(id_) FROM (
  255. SELECT id_, create_time_,'EXERCISES' type_
  256. FROM extracurricular_exercises
  257. <where>
  258. tenant_id_ = #{tenantId}
  259. <if test="teacherId!=null">
  260. AND teacher_id_ = #{teacherId}
  261. </if>
  262. <if test="createTime!=null">
  263. AND DATE_FORMAT(create_time_, '%Y-%m') = DATE_FORMAT(#{createTime}, '%Y-%m')
  264. </if>
  265. <if test="startTime != null and startTime != ''">
  266. AND DATE_FORMAT(#{createTime}, '%Y-%m-%d') BETWEEN #{startTime} AND #{endTime}
  267. </if>
  268. </where>
  269. UNION ALL
  270. SELECT ch.id_,ch.create_time_,'HOMEWORK' type_ FROM course_homework ch
  271. LEFT JOIN course_schedule_teacher_salary csts ON ch.course_schedule_id_ = csts.course_schedule_id_ AND csts.teacher_role_ = 'BISHOP'
  272. <where>
  273. csts.tenant_id_ = #{tenantId}
  274. <if test="teacherId!=null">
  275. AND csts.user_id_ = #{teacherId}
  276. </if>
  277. <if test="classGroupId!=null">
  278. AND ch.class_group_id_=#{classGroupId}
  279. </if>
  280. <if test="createTime!=null">
  281. AND DATE_FORMAT(ch.create_time_,'%Y-%m')=DATE_FORMAT(#{createTime}, '%Y-%m')
  282. </if>
  283. </where>
  284. ) h
  285. </select>
  286. <select id="findExtraExercilsesHomeworks" resultMap="ExtracurricularExercisesHomeworkListDto">
  287. SELECT * FROM (
  288. SELECT id_, create_time_,'EXERCISES' type_
  289. FROM extracurricular_exercises
  290. <where>
  291. tenant_id_ = #{tenantId}
  292. <if test="teacherId!=null">
  293. AND teacher_id_ = #{teacherId}
  294. </if>
  295. <if test="createTime!=null">
  296. AND DATE_FORMAT(create_time_, '%Y-%m') = DATE_FORMAT(#{createTime}, '%Y-%m')
  297. </if>
  298. <if test="startTime != null and startTime != ''">
  299. AND DATE_FORMAT(#{createTime}, '%Y-%m-%d') BETWEEN #{startTime} AND #{endTime}
  300. </if>
  301. </where>
  302. UNION ALL
  303. SELECT ch.id_,ch.create_time_,'HOMEWORK' type_ FROM course_homework ch
  304. LEFT JOIN course_schedule_teacher_salary csts ON ch.course_schedule_id_ = csts.course_schedule_id_ AND csts.teacher_role_ = 'BISHOP'
  305. <where>
  306. csts.tenant_id_ = #{tenantId}
  307. <if test="teacherId!=null">
  308. AND csts.user_id_ = #{teacherId}
  309. </if>
  310. <if test="classGroupId!=null">
  311. AND ch.class_group_id_=#{classGroupId}
  312. </if>
  313. <if test="createTime!=null">
  314. AND DATE_FORMAT(ch.create_time_,'%Y-%m')=DATE_FORMAT(#{createTime}, '%Y-%m')
  315. </if>
  316. </where>) h
  317. </select>
  318. <select id="findByIdList" resultMap="com.ym.mec.biz.dal.dao.CourseHomeworkDao.teacherHomeworkListDto">
  319. SELECT id_ homework_id_,title_,content_,completed_num_,expect_num_,music_score_id_,
  320. expire_date_ expiry_date_,DATE_FORMAT(create_time_,'%Y-%m-%d') 'day_'
  321. FROM extracurricular_exercises WHERE id_ IN
  322. <foreach collection="exercisesIdList" separator="," item="item" open="(" close=")">
  323. #{item}
  324. </foreach>
  325. </select>
  326. <sql id="extraHomeworkDetailV2">
  327. <if test="startTime != null and endTime != null">
  328. create_time_ BETWEEN #{startTime} AND #{endTime}
  329. </if>
  330. <if test="homeWorkStatus != null">
  331. <if test="homeWorkStatus.code == 'UNASSIGNED'">
  332. AND id_ = -1
  333. </if>
  334. <if test="homeWorkStatus.code == 'ASSIGNED'">
  335. AND expire_date_ &gt;= NOW()
  336. </if>
  337. <if test="homeWorkStatus.code == 'DEADLINE'">
  338. AND expire_date_ &lt; NOW()
  339. </if>
  340. </if>
  341. <if test="courseScheduleId != null">
  342. AND id_ = #{courseScheduleId}
  343. </if>
  344. <if test="teacherId != null">
  345. and teacher_id_ = #{teacherId}
  346. </if>
  347. <if test="type != null">
  348. and group_type_ = #{type}
  349. </if>
  350. <if test="versionTag != null">
  351. and version_tag_ = #{versionTag}
  352. </if>
  353. </sql>
  354. <select id="countTeacherExtraHomeworkDetailV2" resultType="int">
  355. select count(1) from (
  356. select 1 from extracurricular_exercises
  357. <where>
  358. <include refid="extraHomeworkDetailV2"/>
  359. </where>
  360. <if test="subjectIds != null and subjectIds.size() != 0">
  361. union all
  362. select 1 from music_group
  363. where id_ in
  364. <foreach collection="subjectIds" item="item" separator="," open="(" close=")">
  365. #{item}
  366. </foreach>
  367. </if>) t
  368. </select>
  369. <select id="queryTeacherExtraHomeworkDetailV2"
  370. resultType="com.ym.mec.biz.dal.dto.CourseHomeworkWrapper$CourseHomeworkList">
  371. <if test="subjectIds != null and subjectIds.size() != 0">
  372. (select
  373. id_ as musicGroupId,
  374. 'UNASSIGNED' as homeWorkStatus,
  375. 'EXTRACURRICULAR' as `type`,
  376. null as courseScheduleId,
  377. null as courseHomeworkId,
  378. null as classGroupId,
  379. null as studentNum,
  380. null as finishNum,
  381. null as assignTime,
  382. null as expiryDate,
  383. null as studentIdList,
  384. null as teacherId
  385. from music_group
  386. where id_ in
  387. <foreach collection="subjectIds" item="item" separator="," open="(" close=")">
  388. #{item}
  389. </foreach>
  390. )
  391. union all
  392. </if>
  393. (select
  394. music_group_id_ as musicGroupId,
  395. if(expire_date_ &gt; NOW(), 'ASSIGNED', 'DEADLINE') as homeWorkStatus,
  396. group_type_ as `type`,
  397. id_ as courseScheduleId,
  398. id_ as courseHomeworkId,
  399. class_group_id_ as classGroupId,
  400. expect_num_ as studentNum,
  401. completed_num_ as finishNum,
  402. create_time_ as assignTime,
  403. expire_date_ as expiryDate,
  404. student_id_list_ as studentIdList,
  405. teacher_id_ as teacherId
  406. from extracurricular_exercises
  407. <where>
  408. <include refid="extraHomeworkDetailV2"/>
  409. </where>
  410. )
  411. <include refid="global.limit"/>
  412. </select>
  413. <update id="updateFinishNum">
  414. UPDATE extracurricular_exercises SET completed_num_ = ifnull(completed_num_,0) + 1 WHERE id_ = #{courseHomeworkId}
  415. </update>
  416. </mapper>