123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284 |
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
- <mapper namespace="com.gyee.exam.modules.course.mapper.CourseMapper">
- <!-- 通用查询映射结果 -->
- <resultMap id="BaseResultMap" type="com.gyee.exam.modules.course.entity.Course">
- <id column="id" property="id" />
- <result column="title" property="title" />
- <result column="content" property="content" />
- <result column="cover" property="cover" />
- <result column="open_type" property="openType" />
- <result column="cat_id" property="catId" />
- <result column="lecturer_id" property="lecturerId" />
- <result column="periods" property="periods" />
- <result column="is_must" property="isMust" />
- <result column="points" property="points" />
- <result column="is_pay" property="isPay" />
- <result column="price" property="price" />
- <result column="check_on" property="checkOn" />
- <result column="check_sec" property="checkSec" />
- <result column="video_drag" property="videoDrag" />
- <result column="dept_code" property="deptCode" />
- <result column="state" property="state" />
- <result column="time_limit" property="timeLimit" />
- <result column="start_time" property="startTime" />
- <result column="end_time" property="endTime" />
- <result column="day_limit" property="dayLimit" />
- <result column="day_rule" property="dayRule" />
- <result column="face_start" property="faceStart" />
- <result column="face_interval" property="faceInterval" />
- <result column="face_check" property="faceCheck" />
- <result column="face_cam" property="faceCam" />
- <result column="face_chance" property="faceChance" />
- <result column="step_lock" property="stepLock" />
- <result column="create_time" property="createTime" />
- <result column="update_time" property="updateTime" />
- <result column="create_by" property="createBy" />
- <result column="update_by" property="updateBy" />
- <result column="data_flag" property="dataFlag" />
- </resultMap>
- <!-- 通用查询结果列 -->
- <sql id="Base_Column_List">
- `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`
- </sql>
- <resultMap id="UserCourseResultMap"
- type="com.gyee.exam.modules.course.dto.response.UserCourseRespDTO"
- extends="BaseResultMap">
- <result column="learn_file" property="learnFile" />
- <result column="total_file" property="totalFile" />
- <result column="state" property="state" />
- <result column="liveCount" property="liveCount" />
- </resultMap>
- <resultMap id="DetailResultMap"
- type="com.gyee.exam.modules.course.dto.ext.CourseDetailExtDTO"
- extends="BaseResultMap">
- <collection property="dirList" column="{id=id,stepLock=step_lock}" select="selectDir"></collection>
- <collection property="deptCodes" column="id" select="selectDept"></collection>
- <collection property="liveList" column="id" select="selectLive"></collection>
- </resultMap>
- <resultMap id="DirResultMap"
- type="com.gyee.exam.modules.course.dto.ext.CourseRefDirExtDTO"
- extends="com.gyee.exam.modules.course.mapper.CourseRefDirMapper.BaseResultMap">
- <collection property="fileList" column="{id=id,stepLock=step_lock}" select="selectFile"></collection>
- </resultMap>
- <resultMap id="FileResultMap"
- type="com.gyee.exam.modules.course.dto.ext.CourseRefFileExtDTO"
- extends="com.gyee.exam.modules.course.mapper.CourseRefFileMapper.BaseResultMap">
- <result column="title" property="title" />
- <result column="file_type" property="fileType" />
- <result column="file_url" property="fileUrl" />
- <result column="view_url" property="viewUrl" />
- <result column="learn_min" property="learnMin" />
- <result column="unlocked" property="unlocked" />
- </resultMap>
- <resultMap id="LiveResultMap"
- type="com.gyee.exam.modules.course.dto.response.CourseLiveRespDTO"
- extends="com.gyee.exam.modules.course.mapper.CourseLiveMapper.BaseResultMap">
- </resultMap>
- <select id="userPaging" resultMap="UserCourseResultMap">
- SELECT
- cs.id,cs.title,cs.cover,cs.cat_id,cs.periods,cs.is_must,cs.is_pay,cs.price,
- (SELECT COUNT(0) FROM el_course_live WHERE course_id=cs.id) AS liveCount,
- cl.update_time,cl.learn_file,cl.total_file,cl.state
- FROM el_course cs
- LEFT JOIN el_course_depart dept ON cs.id=dept.course_id AND cs.open_type=2
- LEFT JOIN el_course_learn cl ON cs.id=cl.course_id AND cl.user_id='{{userId}}'
- WHERE cs.state!=1 AND (
- cs.open_type=1
- OR (cs.open_type=2 AND dept.dept_code IN(SELECT dept_code FROM sys_user WHERE id='{{userId}}'))
- OR (cs.open_type=3 AND cs.id IN(SELECT course_id FROM el_course_person WHERE user_id='{{userId}}'))
- )
- <if test="query!=null">
- <if test="query.onlyLearn!=null and query.onlyLearn">
- AND cl.user_id IS NOT NULL
- </if>
- <if test="query.isMust!=null">
- AND cs.is_must=#{query.isMust}
- </if>
- <if test="query.catId!=null and query.catId!=''">
- AND cs.cat_id=#{query.catId}
- </if>
- <if test="query.title!=null and query.title!=''">
- AND cs.title LIKE '%${query.title}%'
- </if>
- <if test="query.learnState!=null">
- <if test="query.learnState == 1">AND cl.user_id IS NULL</if>
- <if test="query.learnState == 2">AND cl.user_id IS NOT NULL AND cl.state=0</if>
- <if test="query.learnState == 3">AND cl.user_id IS NOT NULL AND cl.state=1</if>
- </if>
- </if>
- ORDER BY cs.`update_time` DESC
- </select>
- <select id="userPagingToal" resultType="com.gyee.exam.modules.course.dto.response.UserCourseProcessDTO">
- SELECT
- cs.id,
- cs.title,
- SUM(rf.need_learn) needLearn,
- SUM(CASE WHEN fl.learn_min > rf.need_learn THEN rf.need_learn ELSE fl.learn_min END) learnMin,
- SUM(CASE WHEN fl.learn_min > rf.need_learn THEN rf.need_learn ELSE fl.learn_min END)/SUM(rf.need_learn) AS proportion
- FROM el_course cs
- LEFT JOIN el_course_ref_dir rd on cs.id = rd.course_id
- LEFT JOIN el_course_ref_file rf on rf.dir_id = rd.id
- LEFT JOIN el_course_file_unlock lk ON rf.file_id = lk.file_id AND lk.course_id = rf.course_id
- 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}}'
- GROUP BY cs.id
- </select>
- <select id="selectDir" resultMap="DirResultMap">
- SELECT dir.*,'${stepLock}' AS step_lock FROM el_course_ref_dir dir WHERE dir.course_id=#{id} ORDER BY dir.`sort` ASC
- </select>
- <select id="selectFile" resultMap="FileResultMap">
- SELECT rf.*,ff.title,ff.file_type,ff.file_url,ff.view_url,IFNULL(fl.learn_min,0) AS learn_min,
- (CASE WHEN (lk.id IS NULL AND rf.sort!='1' AND '${stepLock}'!='0') THEN 0 ELSE 1 END) AS unlocked
- FROM el_course_ref_file rf
- LEFT JOIN el_course_file ff ON rf.file_id=ff.id
- 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}}'
- 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}} '
- WHERE ff.id IS NOT NULL AND dir_id=#{id} ORDER BY `sort` ASC
- </select>
- <select id="selectDept" resultType="String">
- SELECT dept_code FROM el_course_depart WHERE course_id=#{id}
- </select>
- <select id="selectLive" resultMap="LiveResultMap">
- SELECT * FROM el_course_live
- WHERE course_id=#{id}
- ORDER BY start_time ASC
- </select>
- <select id="findDetail" resultMap="DetailResultMap">
- SELECT * FROM el_course WHERE id=#{id}
- </select>
- <select id="courseDepartRank" resultType="com.gyee.exam.modules.course.dto.response.CourseDepartRankDTO">
- select
- cd.dept_code deptCode,
- sd.dept_name deptName,
- count(cd .id) total
- from el_course_depart cd
- LEFT JOIN sys_depart sd on cd.dept_code = sd.dept_code
- LEFT JOIN el_course ec on ec.id = cd.course_id
- <where>
- <if test="query!=null">
- <if test="query.statDateL!=null ">
- AND ec.create_time >= #{query.statDateL}
- </if>
- <if test="query.statDateR!=null ">
- AND ec.create_time < #{query.statDateR}
- </if>
- <if test="query.q!=null and query.q!=''">
- AND cd.dept_code = #{query.q}
- </if>
- </if>
- </where>
- GROUP BY cd.dept_code order by count(cd .id) desc
- </select>
- <select id="courseDepartTotal" resultType="com.gyee.exam.modules.course.dto.response.CourseDepartTotalDTO">
- SELECT
- sd.dept_name deptName,
- dept.dept_code deptCode,
- COUNT( uc.id) AS ecTotalUser,-- 应培训人数
- COUNT(DISTINCT cl.user_id) AS ecActualUser,-- 学习人数
- COUNT(IF( cl.state = 1 ,1, NULL)) AS ecPassUser -- 学完人数
- FROM el_course ec
- LEFT JOIN el_course_depart dept on ec.id = dept.course_id
- LEFT JOIN sys_depart sd on sd.dept_code = dept.dept_code
- LEFT JOIN sys_user uc ON dept.dept_code=uc.dept_code
- LEFT JOIN el_course_learn cl ON cl.user_id=uc.id AND cl.course_id=dept.course_id
- <where>
- AND uc.id IS NOT NULL
- <if test="query!=null">
- <if test="query.statDateL!=null ">
- AND ec.create_time >= #{query.statDateL}
- </if>
- <if test="query.statDateR!=null ">
- AND ec.create_time < #{query.statDateR}
- </if>
- <if test="query.q!=null and query.q!=''">
- AND dept.dept_code = #{query.q}
- </if>
- </if>
- </where>
- GROUP BY dept.dept_code
- ORDER BY ecActualUser desc ,ecPassUser desc
- </select>
- <select id="courseDepartIdTotal"
- resultType="com.gyee.exam.modules.course.dto.response.courseDepartIdTotalDTO">
- SELECT
- ec.id,
- ec.title,
- ec.periods,
- ec.create_time,
- SUM(IF( cl.state = 1 ,1, 0)) passUser,
- count(uc.id) actualUser,
- (CASE WHEN SUM(IF( cl.state = 1 ,1, 0))>=count(uc.id) THEN 1 ELSE 0 END) AS passed
- FROM el_course ec
- LEFT JOIN el_course_depart dept on ec.id = dept.course_id
- LEFT JOIN sys_user uc ON dept.dept_code=uc.dept_code
- LEFT JOIN el_course_learn cl ON cl.user_id=uc.id AND cl.course_id=dept.course_id
- <where>
- <if test="query!=null">
- <if test="query.statDateL!=null ">
- AND ec.create_time >= #{query.statDateL}
- </if>
- <if test="query.statDateR!=null ">
- AND ec.create_time < #{query.statDateR}
- </if>
- <if test="query.q!=null and query.q!=''">
- AND dept.dept_code = #{query.q}
- </if>
- </if>
- </where>
- GROUP BY ec.id
- </select>
- </mapper>
|