CourseMapper.xml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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.gyee.exam.modules.course.mapper.CourseMapper">
  4. <!-- 通用查询映射结果 -->
  5. <resultMap id="BaseResultMap" type="com.gyee.exam.modules.course.entity.Course">
  6. <id column="id" property="id" />
  7. <result column="title" property="title" />
  8. <result column="content" property="content" />
  9. <result column="cover" property="cover" />
  10. <result column="open_type" property="openType" />
  11. <result column="cat_id" property="catId" />
  12. <result column="lecturer_id" property="lecturerId" />
  13. <result column="periods" property="periods" />
  14. <result column="is_must" property="isMust" />
  15. <result column="points" property="points" />
  16. <result column="is_pay" property="isPay" />
  17. <result column="price" property="price" />
  18. <result column="check_on" property="checkOn" />
  19. <result column="check_sec" property="checkSec" />
  20. <result column="video_drag" property="videoDrag" />
  21. <result column="dept_code" property="deptCode" />
  22. <result column="state" property="state" />
  23. <result column="time_limit" property="timeLimit" />
  24. <result column="start_time" property="startTime" />
  25. <result column="end_time" property="endTime" />
  26. <result column="day_limit" property="dayLimit" />
  27. <result column="day_rule" property="dayRule" />
  28. <result column="face_start" property="faceStart" />
  29. <result column="face_interval" property="faceInterval" />
  30. <result column="face_check" property="faceCheck" />
  31. <result column="face_cam" property="faceCam" />
  32. <result column="face_chance" property="faceChance" />
  33. <result column="step_lock" property="stepLock" />
  34. <result column="create_time" property="createTime" />
  35. <result column="update_time" property="updateTime" />
  36. <result column="create_by" property="createBy" />
  37. <result column="update_by" property="updateBy" />
  38. <result column="data_flag" property="dataFlag" />
  39. </resultMap>
  40. <!-- 通用查询结果列 -->
  41. <sql id="Base_Column_List">
  42. `id`,`title`,`content`,`cover`,`open_type`,`cat_id`,`lecturer_id`,`periods`,`is_must`,`points`,`is_pay`,`price`,`check_on`,`check_sec`,`video_drag`,`dept_code`,`state`,`time_limit`,`start_time`,`end_time`,`day_limit`,`day_rule`,`face_start`,`face_interval`,`face_check`,`face_cam`,`face_chance`,`step_lock`,`create_time`,`update_time`,`create_by`,`update_by`,`data_flag`
  43. </sql>
  44. <resultMap id="UserCourseResultMap"
  45. type="com.gyee.exam.modules.course.dto.response.UserCourseRespDTO"
  46. extends="BaseResultMap">
  47. <result column="learn_file" property="learnFile" />
  48. <result column="total_file" property="totalFile" />
  49. <result column="state" property="state" />
  50. <result column="liveCount" property="liveCount" />
  51. </resultMap>
  52. <resultMap id="DetailResultMap"
  53. type="com.gyee.exam.modules.course.dto.ext.CourseDetailExtDTO"
  54. extends="BaseResultMap">
  55. <collection property="dirList" column="{id=id,stepLock=step_lock}" select="selectDir"></collection>
  56. <collection property="deptCodes" column="id" select="selectDept"></collection>
  57. <collection property="liveList" column="id" select="selectLive"></collection>
  58. </resultMap>
  59. <resultMap id="DirResultMap"
  60. type="com.gyee.exam.modules.course.dto.ext.CourseRefDirExtDTO"
  61. extends="com.gyee.exam.modules.course.mapper.CourseRefDirMapper.BaseResultMap">
  62. <collection property="fileList" column="{id=id,stepLock=step_lock}" select="selectFile"></collection>
  63. </resultMap>
  64. <resultMap id="FileResultMap"
  65. type="com.gyee.exam.modules.course.dto.ext.CourseRefFileExtDTO"
  66. extends="com.gyee.exam.modules.course.mapper.CourseRefFileMapper.BaseResultMap">
  67. <result column="title" property="title" />
  68. <result column="file_type" property="fileType" />
  69. <result column="file_url" property="fileUrl" />
  70. <result column="view_url" property="viewUrl" />
  71. <result column="learn_min" property="learnMin" />
  72. <result column="unlocked" property="unlocked" />
  73. </resultMap>
  74. <resultMap id="LiveResultMap"
  75. type="com.gyee.exam.modules.course.dto.response.CourseLiveRespDTO"
  76. extends="com.gyee.exam.modules.course.mapper.CourseLiveMapper.BaseResultMap">
  77. </resultMap>
  78. <select id="userPaging" resultMap="UserCourseResultMap">
  79. SELECT
  80. cs.id,cs.title,cs.cover,cs.cat_id,cs.periods,cs.is_must,cs.is_pay,cs.price,
  81. (SELECT COUNT(0) FROM el_course_live WHERE course_id=cs.id) AS liveCount,
  82. cl.update_time,cl.learn_file,cl.total_file,cl.state
  83. FROM el_course cs
  84. LEFT JOIN el_course_depart dept ON cs.id=dept.course_id AND cs.open_type=2
  85. LEFT JOIN el_course_learn cl ON cs.id=cl.course_id AND cl.user_id='{{userId}}'
  86. WHERE cs.state!=1 AND (
  87. cs.open_type=1
  88. OR (cs.open_type=2 AND dept.dept_code IN(SELECT dept_code FROM sys_user WHERE id='{{userId}}'))
  89. OR (cs.open_type=3 AND cs.id IN(SELECT course_id FROM el_course_person WHERE user_id='{{userId}}'))
  90. )
  91. <if test="query!=null">
  92. <if test="query.onlyLearn!=null and query.onlyLearn">
  93. AND cl.user_id IS NOT NULL
  94. </if>
  95. <if test="query.isMust!=null">
  96. AND cs.is_must=#{query.isMust}
  97. </if>
  98. <if test="query.catId!=null and query.catId!=''">
  99. AND cs.cat_id=#{query.catId}
  100. </if>
  101. <if test="query.title!=null and query.title!=''">
  102. AND cs.title LIKE '%${query.title}%'
  103. </if>
  104. <if test="query.learnState!=null">
  105. <if test="query.learnState == 1">AND cl.user_id IS NULL</if>
  106. <if test="query.learnState == 2">AND cl.user_id IS NOT NULL AND cl.state=0</if>
  107. <if test="query.learnState == 3">AND cl.user_id IS NOT NULL AND cl.state=1</if>
  108. </if>
  109. </if>
  110. ORDER BY cs.`update_time` DESC
  111. </select>
  112. <select id="userPagingToal" resultType="com.gyee.exam.modules.course.dto.response.UserCourseProcessDTO">
  113. SELECT
  114. cs.id,
  115. cs.title,
  116. SUM(rf.need_learn) needLearn,
  117. SUM(CASE WHEN fl.learn_min > rf.need_learn THEN rf.need_learn ELSE fl.learn_min END) learnMin,
  118. SUM(CASE WHEN fl.learn_min > rf.need_learn THEN rf.need_learn ELSE fl.learn_min END)/SUM(rf.need_learn) AS proportion
  119. FROM el_course cs
  120. LEFT JOIN el_course_ref_dir rd on cs.id = rd.course_id
  121. LEFT JOIN el_course_ref_file rf on rf.dir_id = rd.id
  122. LEFT JOIN el_course_file_unlock lk ON rf.file_id = lk.file_id AND lk.course_id = rf.course_id
  123. left JOIN el_course_file_learn fl on fl.file_id = rf.file_id AND fl.course_id = rf.course_id AND fl.user_id ='{{userId}}'
  124. GROUP BY cs.id
  125. </select>
  126. <select id="selectDir" resultMap="DirResultMap">
  127. SELECT dir.*,'${stepLock}' AS step_lock FROM el_course_ref_dir dir WHERE dir.course_id=#{id} ORDER BY dir.`sort` ASC
  128. </select>
  129. <select id="selectFile" resultMap="FileResultMap">
  130. SELECT rf.*,ff.title,ff.file_type,ff.file_url,ff.view_url,IFNULL(fl.learn_min,0) AS learn_min,
  131. (CASE WHEN (lk.id IS NULL AND rf.sort!='1' AND '${stepLock}'!='0') THEN 0 ELSE 1 END) AS unlocked
  132. FROM el_course_ref_file rf
  133. LEFT JOIN el_course_file ff ON rf.file_id=ff.id
  134. LEFT JOIN el_course_file_unlock lk ON rf.file_id=lk.file_id AND lk.course_id=rf.course_id AND user_id='{{userId}}'
  135. LEFT JOIN el_course_file_learn fl ON fl.file_id=rf.file_id AND fl.course_id=rf.course_id AND fl.user_id='{{userId}} '
  136. WHERE ff.id IS NOT NULL AND dir_id=#{id} ORDER BY `sort` ASC
  137. </select>
  138. <select id="selectDept" resultType="String">
  139. SELECT dept_code FROM el_course_depart WHERE course_id=#{id}
  140. </select>
  141. <select id="selectLive" resultMap="LiveResultMap">
  142. SELECT * FROM el_course_live
  143. WHERE course_id=#{id}
  144. ORDER BY start_time ASC
  145. </select>
  146. <select id="findDetail" resultMap="DetailResultMap">
  147. SELECT * FROM el_course WHERE id=#{id}
  148. </select>
  149. <select id="courseDepartRank" resultType="com.gyee.exam.modules.course.dto.response.CourseDepartRankDTO">
  150. select
  151. cd.dept_code deptCode,
  152. sd.dept_name deptName,
  153. count(cd .id) total
  154. from el_course_depart cd
  155. LEFT JOIN sys_depart sd on cd.dept_code = sd.dept_code
  156. LEFT JOIN el_course ec on ec.id = cd.course_id
  157. <where>
  158. <if test="query!=null">
  159. <if test="query.statDateL!=null ">
  160. AND ec.create_time >= #{query.statDateL}
  161. </if>
  162. <if test="query.statDateR!=null ">
  163. AND ec.create_time &lt; #{query.statDateR}
  164. </if>
  165. <if test="query.q!=null and query.q!=''">
  166. AND cd.dept_code = #{query.q}
  167. </if>
  168. </if>
  169. </where>
  170. GROUP BY cd.dept_code order by count(cd .id) desc
  171. </select>
  172. <select id="courseDepartTotal" resultType="com.gyee.exam.modules.course.dto.response.CourseDepartTotalDTO">
  173. SELECT
  174. sd.dept_name deptName,
  175. dept.dept_code deptCode,
  176. COUNT( uc.id) AS ecTotalUser,-- 应培训人数
  177. COUNT(DISTINCT cl.user_id) AS ecActualUser,-- 学习人数
  178. COUNT(IF( cl.state = 1 ,1, NULL)) AS ecPassUser -- 学完人数
  179. FROM el_course ec
  180. LEFT JOIN el_course_depart dept on ec.id = dept.course_id
  181. LEFT JOIN sys_depart sd on sd.dept_code = dept.dept_code
  182. LEFT JOIN sys_user uc ON dept.dept_code=uc.dept_code
  183. LEFT JOIN el_course_learn cl ON cl.user_id=uc.id AND cl.course_id=dept.course_id
  184. <where>
  185. AND uc.id IS NOT NULL
  186. <if test="query!=null">
  187. <if test="query.statDateL!=null ">
  188. AND ec.create_time >= #{query.statDateL}
  189. </if>
  190. <if test="query.statDateR!=null ">
  191. AND ec.create_time &lt; #{query.statDateR}
  192. </if>
  193. <if test="query.q!=null and query.q!=''">
  194. AND dept.dept_code = #{query.q}
  195. </if>
  196. </if>
  197. </where>
  198. GROUP BY dept.dept_code
  199. ORDER BY ecActualUser desc ,ecPassUser desc
  200. </select>
  201. <select id="courseDepartIdTotal"
  202. resultType="com.gyee.exam.modules.course.dto.response.courseDepartIdTotalDTO">
  203. SELECT
  204. ec.id,
  205. ec.title,
  206. ec.periods,
  207. ec.create_time,
  208. SUM(IF( cl.state = 1 ,1, 0)) passUser,
  209. count(uc.id) actualUser,
  210. (CASE WHEN SUM(IF( cl.state = 1 ,1, 0))>=count(uc.id) THEN 1 ELSE 0 END) AS passed
  211. FROM el_course ec
  212. LEFT JOIN el_course_depart dept on ec.id = dept.course_id
  213. LEFT JOIN sys_user uc ON dept.dept_code=uc.dept_code
  214. LEFT JOIN el_course_learn cl ON cl.user_id=uc.id AND cl.course_id=dept.course_id
  215. <where>
  216. <if test="query!=null">
  217. <if test="query.statDateL!=null ">
  218. AND ec.create_time >= #{query.statDateL}
  219. </if>
  220. <if test="query.statDateR!=null ">
  221. AND ec.create_time &lt; #{query.statDateR}
  222. </if>
  223. <if test="query.q!=null and query.q!=''">
  224. AND dept.dept_code = #{query.q}
  225. </if>
  226. </if>
  227. </where>
  228. GROUP BY ec.id
  229. </select>
  230. </mapper>