ExtracurricularExercisesMapper.xml 17 KB

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