ElCourseChapterMapper.xml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.zd.exam.mapper.ElCourseChapterMapper">
  6. <resultMap type="com.zd.exam.domain.ElCourseChapter" id="ElCourseChapterResult">
  7. <result property="id" column="id"/>
  8. <result property="userId" column="user_id"/>
  9. <result property="createBy" column="create_by"/>
  10. <result property="updateBy" column="update_by"/>
  11. <result property="deptId" column="dept_id"/>
  12. <result property="deptName" column="dept_name"/>
  13. <result property="createTime" column="create_time"/>
  14. <result property="updateTime" column="update_time"/>
  15. <result property="remark" column="remark"/>
  16. <result property="courseId" column="course_id"/>
  17. <result property="title" column="title"/>
  18. <result property="parentId" column="parent_id"/>
  19. <result property="position" column="position"/>
  20. <result property="resourcesId" column="resources_id"/>
  21. <result property="chapterData" column="chapter_data"/>
  22. <result property="description" column="description"/>
  23. <result property="free" column="free"/>
  24. <result property="type" column="type"/>
  25. <result property="allowdownload" column="allowdownload"/>
  26. <result property="duration" column="duration"/>
  27. <result property="isAssess" column="is_assess"/>
  28. <result property="assessName" column="assess_name"/>
  29. </resultMap>
  30. <sql id="selectElCourseChapterVo">
  31. select id,
  32. user_id,
  33. create_by,
  34. update_by,
  35. dept_id,
  36. dept_name,
  37. create_time,
  38. update_time,
  39. remark,
  40. course_id,
  41. title,
  42. parent_id,
  43. position,
  44. resources_id,
  45. chapter_data,
  46. description,
  47. free,
  48. type,
  49. allowdownload,
  50. duration,
  51. is_assess,
  52. assess_name
  53. from el_course_chapter
  54. </sql>
  55. <sql id="selectElCourseChapterListVo">
  56. select t.id,
  57. t.user_id,
  58. t.create_by,
  59. t.update_by,
  60. t.dept_id,
  61. t.dept_name,
  62. t.create_time,
  63. t.update_time,
  64. t.remark,
  65. t.course_id,
  66. t.title,
  67. t.parent_id,
  68. t.position,
  69. t.resources_id,
  70. t.chapter_data,
  71. t.description,
  72. t.free,
  73. ifnull(r.type, t.type) type,
  74. t.allowdownload,
  75. t.duration,
  76. r.postfix,
  77. t.is_assess,
  78. t.assess_name
  79. from el_course_chapter as t
  80. left join el_resources r on t.resources_id = r.id
  81. </sql>
  82. <select id="selectElCourseChapterList" parameterType="com.zd.exam.domain.ElCourseChapter"
  83. resultMap="ElCourseChapterResult">
  84. <include refid="selectElCourseChapterListVo"/>
  85. <where>
  86. <if test="userId != null ">and t.user_id = #{userId}</if>
  87. <if test="deptId != null ">and t.dept_id = #{deptId}</if>
  88. <if test="deptName != null and deptName != ''">and t.dept_name like concat('%', #{deptName}, '%')</if>
  89. <if test="courseId != null ">and t.course_id = #{courseId}</if>
  90. <if test="title != null and title != ''">and t.title = #{title}</if>
  91. <if test="parentId != null ">and t.parent_id = #{parentId}</if>
  92. <if test="position != null ">and t.position = #{position}</if>
  93. <if test="resourcesId != null ">and t.resources_id = #{resourcesId}</if>
  94. <if test="chapterData != null and chapterData != ''">and t.chapter_data = #{chapterData}</if>
  95. <if test="description != null and description != ''">and t.description = #{description}</if>
  96. <if test="free != null ">and t.free = #{free}</if>
  97. <if test="type != null ">and r.type = #{type}</if>
  98. <if test="allowdownload != null ">and t.allowdownload = #{allowdownload}</if>
  99. <if test="duration != null ">and t.duration = #{duration}</if>
  100. </where>
  101. </select>
  102. <select id="selectElCourseChapterById" resultMap="ElCourseChapterResult">
  103. <include refid="selectElCourseChapterVo"/>
  104. where id = #{id}
  105. </select>
  106. <select id="selectChapterLearnByCourseId" resultType="com.zd.exam.domain.vo.ChapterLearnVo">
  107. select
  108. c.id as courseId,
  109. c.title as courseTitle,
  110. cc.id as chapterId,
  111. cc.title as chapterTitle,
  112. cc.type as chapterType,
  113. cl.join_user_id as joinUserId,
  114. ifnull(cl.status, 2) as learnStatus
  115. from el_course c left join el_course_chapter cc on c.id = cc.course_id
  116. left join el_chapter_learn_record cl on c.id = cl.course_id and cc.id = cl.chapter_id
  117. where
  118. c.id = #{courseId} and (cl.join_user_id = #{joinUserId} or cl.join_user_id is null)
  119. </select>
  120. <select id="selectUserCourseChapterList" resultType="com.zd.exam.domain.ElCourseChapter">
  121. select t.id,
  122. t.user_id,
  123. t.create_by,
  124. t.update_by,
  125. t.dept_id,
  126. t.dept_name,
  127. t.create_time,
  128. t.update_time,
  129. t.remark,
  130. t.course_id,
  131. t.title,
  132. t.parent_id,
  133. t.position,
  134. t.resources_id,
  135. t.chapter_data,
  136. t.description,
  137. t.free,
  138. ifnull(r.type, t.type) type,
  139. t.allowdownload,
  140. t.duration,
  141. t.is_assess,
  142. (select count(1) from el_paper p where p.course_chapter_id = t.id and p.join_user_id = cl.join_user_id) as hasAssess,
  143. t.assess_name,
  144. r.postfix,
  145. ifnull(cl.status, 2) as learnStatus,
  146. case when t.is_assess = 0 then 1
  147. when (select count(1) from el_paper p where p.course_chapter_id = t.id and p.join_user_id = cl.join_user_id and p.total_score = p.user_score) > 0
  148. then 1
  149. else 0 end as assessStatus
  150. from el_course_chapter as t
  151. left join el_resources r on t.resources_id = r.id
  152. left join el_chapter_learn_record cl on t.id = cl.chapter_id and cl.join_user_id = #{userId}
  153. where
  154. t.course_id = #{courseId}
  155. </select>
  156. <select id="selectLearnDurationsByUserId" resultType="java.lang.Long">
  157. select sum(ifnull(duration, 0)) from el_chapter_learn_record where course_id = #{courseId} and join_user_id = #{userId} and status = 1
  158. </select>
  159. <select id="selectCourseTitleByChapterId" resultType="java.lang.String">
  160. select
  161. c.title as title
  162. from el_chapter_learn_record cl left join el_course c on cl.course_id = c.id
  163. where cl.id = #{recordId}
  164. </select>
  165. <select id="selectChapterDurationsByUserId" resultType="java.lang.Long">
  166. select ifnull(sum(duration), 0) from el_chapter_learn_record where chapter_id = #{chapterId} and join_user_id = #{userId} and status = 1
  167. </select>
  168. <insert id="insertElCourseChapter" parameterType="com.zd.exam.domain.ElCourseChapter" useGeneratedKeys="true"
  169. keyProperty="id">
  170. insert into el_course_chapter
  171. <trim prefix="(" suffix=")" suffixOverrides=",">
  172. <if test="userId != null">user_id,</if>
  173. <if test="createBy != null">create_by,</if>
  174. <if test="updateBy != null">update_by,</if>
  175. <if test="deptId != null">dept_id,</if>
  176. <if test="deptName != null">dept_name,</if>
  177. <if test="createTime != null">create_time,</if>
  178. <if test="updateTime != null">update_time,</if>
  179. <if test="remark != null">remark,</if>
  180. <if test="courseId != null">course_id,</if>
  181. <if test="title != null and title != ''">title,</if>
  182. <if test="parentId != null">parent_id,</if>
  183. <if test="position != null">position,</if>
  184. <if test="resourcesId != null">resources_id,</if>
  185. <if test="chapterData != null">chapter_data,</if>
  186. <if test="description != null and description != ''">description,</if>
  187. <if test="free != null">free,</if>
  188. <if test="type != null">type,</if>
  189. <if test="allowdownload != null">allowdownload,</if>
  190. <if test="duration != null">duration,</if>
  191. <if test="isAssess != null">is_assess,</if>
  192. <if test="assessName != null">assess_name,</if>
  193. </trim>
  194. <trim prefix="values (" suffix=")" suffixOverrides=",">
  195. <if test="userId != null">#{userId},</if>
  196. <if test="createBy != null">#{createBy},</if>
  197. <if test="updateBy != null">#{updateBy},</if>
  198. <if test="deptId != null">#{deptId},</if>
  199. <if test="deptName != null">#{deptName},</if>
  200. <if test="createTime != null">#{createTime},</if>
  201. <if test="updateTime != null">#{updateTime},</if>
  202. <if test="remark != null">#{remark},</if>
  203. <if test="courseId != null">#{courseId},</if>
  204. <if test="title != null and title != ''">#{title},</if>
  205. <if test="parentId != null">#{parentId},</if>
  206. <if test="position != null">#{position},</if>
  207. <if test="resourcesId != null">#{resourcesId},</if>
  208. <if test="chapterData != null">#{chapterData},</if>
  209. <if test="description != null and description != ''">#{description},</if>
  210. <if test="free != null">#{free},</if>
  211. <if test="type != null">#{type},</if>
  212. <if test="allowdownload != null">#{allowdownload},</if>
  213. <if test="duration != null">#{duration},</if>
  214. <if test="isAssess != null">#{isAssess},</if>
  215. <if test="assessName != null">#{assessName},</if>
  216. </trim>
  217. </insert>
  218. <update id="updateElCourseChapter" parameterType="com.zd.exam.domain.ElCourseChapter">
  219. update el_course_chapter
  220. <trim prefix="SET" suffixOverrides=",">
  221. <if test="userId != null">user_id = #{userId},</if>
  222. <if test="createBy != null">create_by = #{createBy},</if>
  223. <if test="updateBy != null">update_by = #{updateBy},</if>
  224. <if test="deptId != null">dept_id = #{deptId},</if>
  225. <if test="deptName != null">dept_name = #{deptName},</if>
  226. <if test="createTime != null">create_time = #{createTime},</if>
  227. <if test="updateTime != null">update_time = #{updateTime},</if>
  228. <if test="remark != null">remark = #{remark},</if>
  229. <if test="courseId != null">course_id = #{courseId},</if>
  230. <if test="title != null and title != ''">title = #{title},</if>
  231. <if test="parentId != null">parent_id = #{parentId},</if>
  232. <if test="position != null">position = #{position},</if>
  233. <if test="resourcesId != null">resources_id = #{resourcesId},</if>
  234. <if test="chapterData != null">chapter_data = #{chapterData},</if>
  235. <if test="description != null and description != ''">description = #{description},</if>
  236. <if test="free != null">free = #{free},</if>
  237. <if test="type != null">type = #{type},</if>
  238. <if test="allowdownload != null">allowdownload = #{allowdownload},</if>
  239. <if test="duration != null">duration = #{duration},</if>
  240. <if test="isAssess != null">is_assess = #{isAssess},</if>
  241. <if test="assessName != null">assess_name = #{assessName},</if>
  242. </trim>
  243. where id = #{id}
  244. </update>
  245. <delete id="deleteElCourseChapterById" >
  246. delete
  247. from el_course_chapter
  248. where id = #{id}
  249. </delete>
  250. <delete id="deleteElCourseChapterByIds">
  251. delete from el_course_chapter where id in
  252. <foreach item="id" collection="array" open="(" separator="," close=")">
  253. #{id}
  254. </foreach>
  255. </delete>
  256. </mapper>