nxdt-system/bonus-modules/bonus-exam/src/main/resources/mapper/exam/ExamTaskMapper.xml

304 lines
14 KiB
XML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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.bonus.exam.mapper.ExamTaskMapper">
<!--添加考试任务-->
<insert id="addExamTask" useGeneratedKeys="true" keyProperty="examTaskId">
INSERT INTO edu_exam_task
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="examName != null and examName!=''">exam_name,</if>
<if test="examLduration != null">exam_lduration,</if>
<if test="startTime != null">start_time,</if>
<if test="endTime != null">end_time,</if>
<if test="examTarget != null and examTarget!=''">exam_target,</if>
<if test="examStatement != null and examStatement!=''">exam_statement,</if>
create_id,
create_user,
exam_task_id
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="examName != null and examName!=''">#{examName},</if>
<if test="examLduration != null">#{examLduration},</if>
<if test="startTime != null">#{startTime},</if>
<if test="endTime != null">#{endTime},</if>
<if test="examTarget != null and examTarget!=''">#{examTarget},</if>
<if test="examStatement != null and examStatement!=''">#{examStatement},</if>
#{createId},
#{createUser},
null
</trim>
</insert>
<!--修改考试任务-->
<update id="editExamTask">
UPDATE edu_exam_task SET exam_name = #{examName},exam_lduration = #{examLduration},
start_time = #{startTime}, end_time = #{endTime},exam_target = #{examTarget},
exam_statement = #{examStatement} WHERE exam_task_id = #{examTaskId}
</update>
<!--删除考试任务-->
<delete id="delExamTask">
UPDATE edu_exam_task SET is_active = '0' WHERE exam_task_id = #{examTaskId}
</delete>
<!--考试任务列表-->
<select id="getExamTasks" resultType="com.bonus.common.exam.vo.ExamTaskFirstOrderVo">
SELECT DISTINCT eet.exam_task_id AS examTaskId,
estp.exam_paper_id AS examPaperId,
eet.exam_name AS examName,
eete.exam_template_name AS templateName,
eet.exam_target AS examTarget,
eet.start_time AS startTime,
eet.end_time AS endTime,
eet.create_trime AS createTime,
eet.create_user AS createUser,
eet.exam_lduration AS examLduration,
CASE
WHEN NOW() &lt; eet.start_time THEN '0'
WHEN NOW() &gt;= eet.start_time AND NOW() &lt;= eet.end_time THEN '1'
WHEN NOW() &gt; eet.end_time THEN '2'
END AS examStatus
FROM edu_exam_task eet
LEFT JOIN ek_study_task_paper estp ON eet.exam_task_id = estp.study_task_id AND estp.task_type = '3'
LEFT JOIN edu_exam_paper eep ON estp.exam_paper_id = eep.exam_paper_id AND eep.is_active = '1'
LEFT JOIN edu_exam_template eete ON eep.exam_template_id = eete.exam_template_id
<where>
<if test="keyWord!=null and keyWord!=''">
AND (
INSTR(eet.exam_name,#{keyWord}) > 0 OR
INSTR(eete.exam_template_name,#{keyWord}) > 0
)
</if>
<if test="createUserName!=null and createUserName!=''">
AND INSTR(eet.createUser,#{createUserName}) > 0
</if>
<if test="startDate != null and startDate != '' and endDate != null and endDate != ''">
AND DATE_FORMAT(eet.create_trime,'%Y-%m-%d') BETWEEN #{startDate} AND #{endDate}
</if>
<if test="examStatus!=null and examStatus!=''">
AND CASE
WHEN NOW() &lt; eet.start_time THEN '0'
WHEN NOW() &gt;= eet.start_time AND NOW() &lt;= eet.end_time THEN '1'
WHEN NOW() &gt; eet.end_time THEN '2'
END = #{examStatus}
</if>
<if test="examStartTime != null and examStartTime != '' and examEndTime != null and examEndTime != ''">
AND DATE_FORMAT(eet.start_time,'%Y-%m-%d') BETWEEN #{examStartTime} AND #{examEndTime}
</if>
AND eet.is_active = '1'
</where>
ORDER BY eet.create_trime DESC
</select>
<!--查询考试题目数量-->
<select id="getExamPaperQuestion" resultType="java.lang.Integer">
SELECT COUNT(*) AS num
FROM edu_exam_paper_question
WHERE exam_paper_id = #{examPaperId}
</select>
<!--查询考试参与人数-->
<select id="getExamUserNum" resultType="java.lang.Integer">
SELECT COUNT(*) AS num
FROM ek_task_user
WHERE task_id = #{examTaskId} AND task_type = '3'
</select>
<!--判断考试名称是否存在-->
<select id="examTaskIsExist" resultType="java.lang.Integer">
<if test="examTaskId == null">
SELECT COUNT(*) FROM edu_exam_task WHERE exam_name = #{examName} AND is_active = '1'
</if>
<if test="examTaskId != null">
SELECT COUNT(*) FROM edu_exam_task WHERE exam_task_id != #{examTaskId} AND exam_name = #{examName} AND is_active = '1'
</if>
</select>
<!--查询考试任务详情-->
<select id="getExamTaskById" resultType="com.bonus.common.exam.vo.ExamTaskVo">
SELECT DISTINCT
exam_task_id AS examTaskId,
exam_name AS examName,
exam_lduration AS examLduration,
start_time AS startTime,
end_time AS endTime,
exam_target AS examTarget,
exam_statement AS examStatement
FROM edu_exam_task
WHERE exam_task_id = #{examTaskId}
</select>
<!--获取试卷详情-->
<select id="getExamPaperByType" resultType="com.bonus.common.exam.vo.ExamPaperVo">
SELECT eep.exam_paper_id AS examPaperId,
eep.exam_paper_name AS examPaperName,
eep.exam_template_id AS examTemplateId,
eep.pass_score AS passScore,
eep.esam_time AS esamTime,
eep.statement AS statement,
estp.exam_template_type AS examTemplateType,
eep.pape_type AS papeType,
eet.exam_template_name AS examTemplateName,
eep.total_score AS totalScore,
eet.question_num AS questionNum
FROM ek_study_task_paper estp
LEFT JOIN edu_exam_paper eep ON estp.exam_paper_id = eep.exam_paper_id AND eep.is_active = '1'
LEFT JOIN edu_exam_template eet ON eep.exam_template_id = eet.exam_template_id
WHERE estp.study_task_id = #{params.examTaskId} AND estp.task_type = '3' AND estp.exam_template_type = '1'
</select>
<!--获取学习任务人员列表-->
<select id="getEkTaskUserList" resultType="com.bonus.common.exam.vo.EkTaskUserVo">
SELECT su.nick_name AS userName,
etu.user_id AS userId,
etu.sex AS sex,
etu.pro_id AS proId,
ppi.pro_name AS proName,
pci.cont_name AS subName,
su.phonenumber AS phone,
su.id_card AS idCard,
etu.post_name AS postName,
sp.post_name AS workTypeName
FROM ek_task_user etu
LEFT JOIN sys_user su ON etu.user_id = su.user_id
LEFT JOIN pt_project_info ppi ON etu.pro_id = ppi.pro_id
LEFT JOIN pt_cont_info pci ON etu.sub_id = pci.cont_id
LEFT JOIN sys_post sp ON etu.post_id = sp.post_id
WHERE etu.task_id = #{examTaskId} AND etu.task_type = #{taskType}
</select>
<!--学员数据列表-->
<select id="getTaskUsers" resultType="com.bonus.common.exam.vo.StudyTaskPersonVo">
SELECT su.nick_name AS name,
etu.user_id AS userId,
etu.sex AS sex,
if(etu.sex = '0', '男', '女') AS sexName,
ppi.pro_name AS proName,
pci.cont_name AS subName,
su.phonenumber AS phone,
su.id_card AS idCard,
etu.post_name AS postName,
sp.post_name AS typeOfWork,
etu.user_uuid AS userUuid,
estp.exam_paper_id AS examPaperId,
ifnull(eepr.score,0) AS score,
CASE
WHEN ifnull(eepr.score,0) &gt;= eep.pass_score THEN '1'
ELSE '0'
END AS isPass
FROM ek_task_user etu
LEFT JOIN ek_study_task_paper estp ON etu.task_id = estp.study_task_id AND estp.task_type = '3'
LEFT JOIN edu_exam_paper eep ON estp.exam_paper_id = eep.exam_paper_id
LEFT JOIN edu_exam_paper_record eepr ON eep.exam_paper_id = eepr.exam_paper_id AND etu.user_id = eepr.uuid
LEFT JOIN sys_user su ON etu.user_id = su.user_id
LEFT JOIN pt_project_info ppi ON etu.pro_id = ppi.pro_id
LEFT JOIN pt_cont_info pci ON etu.sub_id = pci.cont_id
LEFT JOIN sys_post sp ON etu.post_id = sp.post_id
WHERE etu.task_id = #{examTaskId} AND etu.task_type = #{taskType}
<if test="userName!=null and userName!=''">
AND INSTR(su.nick_name,#{userName}) > 0
</if>
<if test="isPass!=null and isPass!=''">
AND CASE WHEN eepr.score IS NULL THEN '0'
WHEN eepr.score &gt;= eep.total_score THEN '1'
ELSE '0' END = #{isPass}
</if>
ORDER BY su.create_time DESC
</select>
<!--试题数据列表-->
<select id="getExamPaperQuestions" resultType="com.bonus.common.exam.vo.ExamPaperQuestionVo">
SELECT eqe.content,
eqe.question_type AS questionType,
eqe.correct_answer AS correctAnswer,
eep.exam_paper_id AS examPaperId,
eepq.question_id AS questionId
FROM edu_exam_paper eep
LEFT JOIN edu_exam_paper_question eepq ON eep.exam_paper_id = eepq.exam_paper_id
LEFT JOIN edu_questions_exam eqe ON eepq.question_id = eqe.question_id
WHERE eep.exam_paper_id = #{examPaperId}
<if test="questionType!=null and questionType!=''">
AND eqe.question_type = #{questionType}
</if>
<if test="content!=null and content!=''">
AND INSTR(eqe.content,#{content}) > 0
</if>
</select>
<!--获取学习任务学习人员-->
<select id="getEkTaskUsers" resultType="java.lang.String">
SELECT CONCAT(IF(etu.pro_id IS NULL,'',CONCAT(etu.pro_id,'-')),etu.user_id)
FROM ek_task_user etu
WHERE etu.task_id = #{examTaskId} AND etu.task_type = #{taskType}
</select>
<!--查询考试状态-->
<select id="getExamStatus" resultType="java.lang.String">
SELECT CASE
WHEN NOW() &lt; eet.start_time THEN '0'
WHEN NOW() &gt;= eet.start_time AND NOW() &lt;= eet.end_time THEN '1'
WHEN NOW() &gt; eet.end_time THEN '2'
END AS examStatus
FROM edu_exam_task eet
WHERE eet.exam_task_id = #{examTaskId}
</select>
<!--查询试题ID-->
<select id="viewExaminationPaper" resultType="java.lang.Integer">
SELECT question_id
FROM edu_exam_paper_question
WHERE exam_paper_id = #{examPaperId}
</select>
<!--获取考试详情-->
<select id="getExamPaperRecord" resultType="com.bonus.common.exam.vo.ExamPaperDetailVo">
SELECT eep.total_score AS totalScore,
eep.pass_score AS passScore,
eep.statement AS statement,
eepr.score,
eepr.scoring_rete AS scoringRete,
eepr.hand_paper AS handPaper,
eepr.answer_time AS answerTime,
su.nick_name AS userName,
sd.dept_name AS deptName,
eepr.paper_record_id AS paperRecordId
FROM edu_exam_paper eep
LEFT JOIN ek_study_task_paper estp ON eep.exam_paper_id = estp.exam_paper_id
LEFT JOIN ek_task_user etu ON estp.study_task_id = etu.task_id AND etu.task_type = '3'
LEFT JOIN edu_exam_template eet ON eep.exam_template_id = eet.exam_template_id
LEFT JOIN edu_exam_paper_record eepr ON eep.exam_paper_id = eepr.exam_paper_id and eepr.uuid = #{userId}
LEFT JOIN sys_user su ON su.user_id = etu.user_id
LEFT JOIN sys_dept sd ON su.dept_id = sd.dept_id
WHERE eep.exam_paper_id = #{examPaperId} AND (etu.user_uuid = #{userUuid} or etu.user_Id = #{userId})
</select>
<!--查询正确数量、错题数量、未答题数量-->
<select id="getAnswerResult" resultType="java.lang.Integer">
<if test="type == 1">
SELECT question_id AS questionId
FROM edu_exam_paper_details
WHERE paper_record_id = #{paperRecordId} AND choose_answer = answer
</if>
<if test="type == 2">
SELECT question_id AS questionId
FROM edu_exam_paper_details
WHERE paper_record_id = #{paperRecordId} AND choose_answer != answer
</if>
<if test="type == 3">
SELECT eepq.question_id AS questionId
FROM edu_exam_paper_question eepq
LEFT JOIN edu_exam_paper_record eepr ON eepq.exam_paper_id = eepr.exam_paper_id AND eepr.paper_record_id = #{paperRecordId}
LEFT JOIN edu_exam_paper_details eepd ON eepr.paper_record_id = eepd.paper_record_id
WHERE eepq.exam_paper_id = #{params.examPaperId} AND eepd.paper_details_id IS NULL
</if>
</select>
<!--查询用户选择答案、得分-->
<select id="getExamPaperDetails" resultType="java.util.Map">
SELECT choose_answer AS chooseAnswer,
score
FROM edu_exam_paper_details
WHERE paper_record_id = #{paperRecordId} AND question_id = #{questionId}
</select>
<!--查询题目的正确人数1或错误人数2-->
<select id="getCorrectNum" resultType="java.lang.Integer">
<if test="type == 1">
SELECT COUNT(*)
FROM edu_exam_paper_record eepr
LEFT JOIN edu_exam_paper_details eepd ON eepr.paper_record_id = eepd.paper_record_id
WHERE eepr.exam_paper_id = #{examPaperId} AND eepd.question_id = #{questionId} AND eepd.choose_answer = eepd.answer
</if>
<if test="type == 2">
SELECT COUNT(*)
FROM edu_exam_paper_record eepr
LEFT JOIN edu_exam_paper_details eepd ON eepr.paper_record_id = eepd.paper_record_id
WHERE eepr.exam_paper_id = #{examPaperId} AND eepd.question_id = #{questionId} AND eepd.choose_answer != eepd.answer
</if>
</select>
</mapper>