1374 lines
61 KiB
XML
Raw Permalink Normal View History

2026-03-10 16:40:19 +08:00
<?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._3e.dao.ExamDao">
<select id= "getNextSeq" resultType="int">
SELECT NEXTVAL('seq_examid')
</select>
<select id= "getSeqExamAnser" resultType="int">
SELECT NEXTVAL('seq_examAnswerid')
</select>
<!-- 全网非听力考试列表 -->
<select id="findMockIsNetExam" parameterType="map" resultType="com._3e.entity.Exam" >
SELECT examid, examtype, isrecommend, title, description, exampapercount,
exampapers, created, starttime, endtime, teacherid, isoral
FROM exam
WHERE isNetExam=1 AND examType = #{_3EReqExamInfo.examType} AND isoral = #{_3EReqExamInfo.isoral}
AND startTime &lt; now() AND endTime &gt; now()
ORDER BY created DESC,title DESC,examid DESC
<if test="page != null">
LIMIT #{page.limit} OFFSET #{page.offset}
</if>
</select>
<!-- 全网听力考试列表 -->
<select id="findHearIsNetExam" parameterType="map" resultType="com._3e.entity.Exam" >
SELECT examid, examtype, isrecommend, title, description, exampapercount,
exampapers, created, starttime, endtime, teacherid, isoral
FROM v_hearexam
WHERE isNetExam=1 AND examType = #{_3EReqExamInfo.examType}
AND startTime &lt; now() AND endTime &gt; now()
ORDER BY created DESC,title DESC, isoral
<if test="page != null">
LIMIT #{page.limit} OFFSET #{page.offset}
</if>
</select>
<!-- 区域非听力考试列表 -->
<select id="findMockExam" parameterType="map" resultType="com._3e.entity.Exam" >
SELECT e.examid, e.examtype, e.isrecommend, e.title, e.description, e.exampapercount,
e.exampapers, e.created, e.starttime, e.endtime, e.teacherid, e.isoral
FROM Exam e
RIGHT JOIN ClassOwnExam c ON c.examid = e.examid AND e.isoral = #{_3EReqExamInfo.isoral}
WHERE e.examType = #{_3EReqExamInfo.examType}
AND e.startTime &lt; now() AND e.endTime &gt; now()
AND c.areaid = #{areaId} AND objectType = #{_3EReqExamInfo.objType}
ORDER BY created DESC,title DESC
</select>
<!-- 区域听力考试列表 -->
<select id="findHearExam" parameterType="map" resultType="com._3e.entity.Exam" >
SELECT e.examid, e.examtype, e.isrecommend, e.title, e.description, e.exampapercount,
e.exampapers, e.created, e.starttime, e.endtime, e.teacherid, e.isoral
FROM v_hearexam e
RIGHT JOIN ClassOwnExam c ON c.examid = e.examid AND e.isoral = 2
WHERE e.examType = #{_3EReqExamInfo.examType}
AND e.startTime &lt; now() AND e.endTime &gt; now()
AND c.areaid = #{areaId} AND objectType = #{_3EReqExamInfo.objType}
UNION
SELECT e.examid, e.examtype, e.isrecommend, e.title, e.description, e.exampapercount,
e.exampapers, e.created, e.starttime, e.endtime, e.teacherid, e.isoral
FROM v_hearexam e
RIGHT JOIN ClassOwnHear c ON c.examid = e.examid AND e.isoral = -1
WHERE e.examType = #{_3EReqExamInfo.examType}
AND e.startTime &lt; now() AND e.endTime &gt; now()
AND c.areaid = #{areaId} AND objectType = #{_3EReqExamInfo.objType}
ORDER BY created DESC,title DESC, isoral
</select>
<!-- 校园非听力考试列表 -->
<select id= "findMockSchoolExam" parameterType="map" resultType="com._3e.entity.Exam" >
<bind name="objecteType" value="_3EReqExamInfo.objType" />
SELECT e.examid, e.examtype, e.isrecommend, e.title, e.description, e.exampapercount,
e.exampapers, e.created, e.starttime, e.endtime, e.teacherid, e.isoral
FROM exam e
INNER JOIN ClassOwnExam c ON c.examid = e.examid AND c.objecttype = #{objecteType} AND e.isoral = #{_3EReqExamInfo.isoral}
WHERE e.examType = #{_3EReqExamInfo.examType}
AND e.startTime &lt; now() AND e.endTime &gt; now()
AND c.classesid = #{objid}
ORDER BY created DESC,title DESC
<if test="page != null">
LIMIT #{page.limit} OFFSET #{page.offset}
</if>
</select>
<!-- 校园听力考试列表 -->
<select id= "findSchoolHearExam" parameterType="map" resultType="com._3e.entity.Exam" >
<bind name="objecteType" value="_3EReqExamInfo.objType" />
SELECT e.examid, e.examtype, e.isrecommend, e.title, e.description, e.exampapercount,
e.exampapers, e.created, e.starttime, e.endtime, e.teacherid, e.isoral
FROM v_hearexam e
INNER JOIN ClassOwnExam c ON c.examid = e.examid AND c.objecttype = #{objecteType} AND e.isoral = 2
WHERE e.examType = #{_3EReqExamInfo.examType}
AND e.startTime &lt; now() AND e.endTime &gt; now()
AND c.classesid = #{objid}
UNION
SELECT e.examid, e.examtype, e.isrecommend, e.title, e.description, e.exampapercount,
e.exampapers, e.created, e.starttime, e.endtime, e.teacherid, e.isoral
FROM v_hearexam e
RIGHT JOIN ClassOwnHear c ON c.examid = e.examid AND c.objecttype = #{objecteType} AND e.isoral = -1
WHERE e.examType = #{_3EReqExamInfo.examType}
AND e.startTime &lt; now() AND e.endTime &gt; now()
AND c.classesid = #{objid}
ORDER BY created DESC,title DESC, isoral
<if test="page != null">
LIMIT #{page.limit} OFFSET #{page.offset}
</if>
</select>
<!-- 班级非听力考试列表 -->
<select id= "findMockUserExam" parameterType="map" resultType="com._3e.entity.Exam" >
<bind name="objecteType" value="_3EReqExamInfo.objType" />
<bind name="examType" value="_3EReqExamInfo.examType" />
<bind name="isoral" value="_3EReqExamInfo.isoral" />
SELECT examId , examType , isRecommend , title , description ,
examPaperCount , examPapers , created , startTime , endTime, isoral,type
FROM V_UserOwnExam
WHERE studentId= #{objid} AND isoral = #{isoral}
AND examType = #{examType} and type = #{type} and startTime &lt; now() and endTime &gt; now()
ORDER BY created DESC,examid DESC,title DESC
<if test="page != null">
LIMIT #{page.limit} OFFSET #{page.offset}
</if>
</select>
<!-- 班级听力考试列表 -->
<select id= "findMockUserHearExam" parameterType="map" resultType="com._3e.entity.Exam" >
<bind name="objecteType" value="_3EReqExamInfo.objType" />
<bind name="examType" value="_3EReqExamInfo.examType" />
<bind name="isoral" value="_3EReqExamInfo.isoral" />
SELECT h.examId , h.examType , h.isRecommend , h.title , h.description ,
h.examPaperCount , h.examPapers , h.created , h.startTime , h.endTime, h.isoral,h.type
FROM v_hearexam h inner join classownhear c on c.examid = h.examid and h.isoral=-1
inner join studentownclass s on s.classesid = c.classesid
and s.areaid=#{areaid}
and s.status = 1
WHERE s.studentId=#{objid} and c.objectType = #{objecteType}
AND h.examType = #{examType} and h.type = #{type} and h.startTime &lt; now() and h.endTime &gt; now()
union
SELECT h.examId , h.examType , h.isRecommend , h.title , h.description ,
h.examPaperCount , h.examPapers , h.created , h.startTime , h.endTime, h.isoral,h.type
FROM v_hearexam h
WHERE h.teacherId=#{objid} and h.examType = #{examType} and h.type = #{type} and
h.startTime &lt; now() and h.endTime &gt; now()
union
select h.examId , h.examType , h.isRecommend , h.title , h.description ,
h.examPaperCount , h.examPapers , h.created , h.startTime , h.endTime, h.isoral,h.type
FROM v_hearexam h inner join classownexam c on c.examid = h.examid and isoral=2
inner join studentownclass s on s.classesid = c.classesid
and s.areaid=#{areaid}
and s.status = 1
WHERE s.studentId=#{objid} and c.objectType = #{objecteType}
and h.examType = #{examType} and h.type = #{type} and h.startTime &lt; now() and h.endTime &gt; now()
order by created DESC,title DESC ,isoral
<if test="page != null">
LIMIT #{page.limit} OFFSET #{page.offset}
</if>
</select>
<select id= "findExamPaper" parameterType="int" resultType="com._3e.entity.ExamPaper" >
SELECT exampaperid, authortype, teacherid, examlevel, title, totalscore, status,
machinescore, humanscore, paperfile, md5code, content, isoral
FROM ExamPaper WHERE exampaperid = #{exampaperid}
</select>
<insert id= "doSaveExamAnswer" parameterType="com._3e.entity.ExamAnswer" >
INSERT INTO examanswer(
examanswerid, userid, examid, examtype, exampaperid, part1origiscore,
part1score, part1truescore, accuracy, fluent, integrity, part1content,
part2origiscore, part2score, part2truescore, part2content, origiscore,
score, truescore, created, areaid, machinescore, humanscore,
paperfile, md5code, content)
VALUES (
<!--<if test="examanswerid == 0">
(SELECT NEXTVAL('seq_examanswerid')),
</if>-->
<if test="examanswerid != 0">
#{examanswerid},
</if>
#{userid}, #{examid}, #{examtype}, #{exampaperid}, #{part1origiscore},
#{part1score}, #{part1truescore}, #{ accuracy}, #{ fluent}, #{ integrity}, #{ part1content},
#{part2origiscore}, #{ part2score}, #{ part2truescore}, #{ part2content}, #{ origiscore},
#{score}, #{ truescore}, #{ created}, #{ areaid}, #{ machinescore}, #{ humanscore},
#{paperfile}, #{ md5code}, #{ content})
</insert>
<update id= "doUpdateById" parameterType="com._3e.entity.ExamAnswer">
UPDATE examanswer
<set>
<if test="userid != null">userid=#{userid},</if>
<if test="examid != null"> examid=#{examid},</if>
<if test="examtype != null"> examtype=#{examtype},</if>
<if test="exampaperid != null"> exampaperid=#{exampaperid},</if>
<if test="part1origiscore != null"> part1origiscore=#{part1origiscore},</if>
<if test="part1score != null"> part1score=#{part1score},</if>
<if test="part1truescore != null"> part1truescore=#{part1truescore},</if>
<if test="accuracy != null"> accuracy=#{accuracy},</if>
<if test="fluent != null"> fluent=#{fluent},</if>
<if test="integrity != null"> integrity=#{integrity},</if>
<if test="part1content != null"> part1content=#{part1content},</if>
<if test="part2origiscore != null"> part2origiscore=#{part2origiscore},</if>
<if test="part2score != null"> part2score=#{part2score},</if>
<if test="part2truescore != null"> part2truescore=#{part2truescore},</if>
<if test="part2content != null"> part2content=#{part2content},</if>
<if test="origiscore != null"> origiscore=#{origiscore},</if>
<if test="score != null"> score=#{score},</if>
<if test="truescore != null"> truescore=#{truescore},</if>
<if test="created != null"> created=#{created},</if>
<if test="areaid != null"> areaid=#{areaId},</if>
<if test="machinescore != null"> machinescore=#{machinescore},</if>
<if test="humanscore != null"> humanscore=#{humanscore},</if>
<if test="paperfile != null"> paperfile=#{paperfile},</if>
<if test="md5code != null"> md5code=#{md5code},</if>
<if test="content != null"> content=#{content}</if>
</set>
WHERE examanswerid = #{examanswerid} and areaid=#{areaid}
</update>
<select id="findExamAnswerByExaminfo" parameterType="map" resultType="com._3e.entity.ExamAnswer" >
SELECT examanswerid FROM examAnswer WHERE userid = #{uid} AND examtype = #{examType} AND examid = #{examId}
and areaid=#{areaid}
</select>
<select id= "findMyExamAnswerHistor" parameterType="map" resultType="com._3e.http.exam.dto._3EResMyExamHistory" >
SELECT a.title, a.examtype, e.score, e.created, a.isoral as isoral,
CASE WHEN a.isoral = 1 THEN 'E'
WHEN a.isoral = 0 THEN 'R'
END AS fenlei, a.starttime
FROM examanswer e
INNER JOIN exam a ON e.examId = a.examId
WHERE e.created &gt; '${begintime} 00:00:00' AND e.created &lt; '${endTime} 23:59:59'
and e.areaid = #{areaid}
AND e.userid = #{userId}
UNION
SELECT a.title, a.examtype, e.score, e.created, 0 as isoral, 'H' AS fenlei,a.starttime
FROM hearanswer e
INNER JOIN hearexam a ON e.examId = a.examId
WHERE e.created &gt; '${begintime} 00:00:00' AND e.created &lt; '${endTime} 23:59:59'
and e.areaid = #{areaid}
AND e.userid = #{userId}
ORDER BY score DESC, created DESC
<if test="page != null">
LIMIT #{page.limit} OFFSET #{page.offset}
</if>
</select>
<select id= "findMyExamAnswerHistorV2" parameterType="map" resultType="com._3e.http.exam.dto._3EResMyExamHistory" >
SELECT e.examanswerid,a.title, a.examtype, e.score, e.created, a.isoral, a.starttime,a.type
FROM examanswer e
INNER JOIN exam a ON e.examId = a.examId
WHERE e.created &gt; '${begintime} 00:00:00' AND e.created &lt; '${endTime} 23:59:59'
and e.areaid = #{areaid}
AND e.userid = #{userId}
<if test="type != null">
and type = #{type}
</if>
UNION
SELECT e.examanswerid,a.title, a.examtype, e.score, e.created, -1 AS isoral,a.starttime,1 as type
FROM hearanswer e
INNER JOIN hearexam a ON e.examId = a.examId
WHERE e.created &gt; '${begintime} 00:00:00' AND e.created &lt; '${endTime} 23:59:59'
and e.areaid = #{areaid}
AND e.userid = #{userId}
ORDER BY score DESC, created DESC
<if test="page != null">
LIMIT #{page.limit} OFFSET #{page.offset}
</if>
</select>
<select id= "findMyMAXExamAnswerHistor" parameterType="map" resultType="com._3e.http.exam.dto._3EResMyExamHistory" >
SELECT a.title, a.examtype, e.score, e.created, a.isoral as isoral,
CASE WHEN a.isoral = 1 THEN 'E'
WHEN a.isoral = 0 THEN 'R'
END AS fenlei, a.starttime
FROM (
SELECT examId,score , created , rank() over (partition by examId order by score desc , created desc ) as mm
FROM examanswer
WHERE created &gt; '${begintime} 00:00:00' AND created &lt; '${endTime} 23:59:59'
and areaid = #{areaid}
AND userid = #{userId}
) e
INNER JOIN exam a ON e.examId = a.examId
WHERE e.mm = 1
UNION
SELECT a.title, a.examtype, e.score, e.created, 0 as isoral, 'H' AS fenlei,a.starttime
FROM (
SELECT examId, score , created , rank() over (partition by examId order by score desc , created desc ) as mm
FROM hearanswer
WHERE created &gt; '${begintime} 00:00:00' AND created &lt; '${endTime} 23:59:59'
and areaid = #{areaid}
AND userid = #{userId}
) e
INNER JOIN hearexam a ON e.examId = a.examId
WHERE e.mm = 1
ORDER BY score DESC, created DESC
<if test="page != null">
LIMIT #{page.limit} OFFSET #{page.offset}
</if>
</select>
<select id= "findMyMAXExamAnswerHistorV2" parameterType="map" resultType="com._3e.http.exam.dto._3EResMyExamHistory" >
SELECT e.examanswerid,a.title, a.examtype, e.score, e.created, a.isoral, a.starttime,a.type
FROM (
SELECT examanswerid,examId,score , created , rank() over (partition by examId order by score desc , created desc ) as mm
FROM examanswer
WHERE created &gt; '${begintime} 00:00:00' AND created &lt; '${endTime} 23:59:59'
and areaid = #{areaid}
AND userid = #{userId}
) e
INNER JOIN exam a ON e.examId = a.examId
WHERE e.mm = 1
<if test="type != null">
and type = #{type}
</if>
UNION
SELECT e.examanswerid,a.title, a.examtype, e.score, e.created, -1 AS isoral,a.starttime,1 as type
FROM (
SELECT examanswerid,examId, score , created , rank() over (partition by examId order by score desc , created desc ) as mm
FROM hearanswer
WHERE created &gt; '${begintime} 00:00:00' AND created &lt; '${endTime} 23:59:59'
and areaid = #{areaid}
AND userid = #{userId}
) e
INNER JOIN hearexam a ON e.examId = a.examId
WHERE e.mm = 1
ORDER BY score DESC, created DESC
<if test="page != null">
LIMIT #{page.limit} OFFSET #{page.offset}
</if>
</select>
<select id= "findExamAnswerHistorClassify" parameterType="map" resultType="com._3e.http.exam.dto._3EResExamHistory" >
<!-- <bind name="objecteType" value="_3EReqExamInfo.objType" /> -->
<!-- <bind name="userId" value="_3eReqUserInfo.studentid" /> -->
<!-- <bind name="schoolId" value="_3eReqUserInfo.schoolid" /> -->
WITH temp AS (
<choose>
<when test="objectType == 0"><!-- 全网 -->
SELECT examid,title,isOral from exam where isnetexam = 1
</when>
<when test="objectType==1 or objectType==2"><!--我的或学校 -->
SELECT e.examid, e.title, e.isOral
FROM Exam e
INNER JOIN ClassOwnExam c ON c.examid = e.examid
<if test="objectType==2"><!-- 学校 -->
INNER JOIN Classes s ON s.classesid = c.classesid
WHERE s.schoolid = #{schoolId}
AND c.objectType = #{objectType}
</if>
<if test="objectType == 1"><!-- 班级或学习小组 -->
INNER JOIN studentownclass s on s.classesid = c.classesid
and s.areaid = #{areaid}
and s.status = 1
WHERE s.studentid = #{userId}
AND c.objectType = #{objectType}
UNION
SELECT e.examid, e.title,e.isoral
FROM Exam e
RIGHT JOIN ClassOwnExam c ON c.examid = e.examid
INNER JOIN classes s ON s.classesid = c.classesid AND s.status = 1
WHERE s.teacherid = #{userId}
AND c.objectType = #{objectType}
</if>
</when>
<otherwise><!-- 行政级别分类 -->
SELECT e.examid,e.title, e.isOral
FROM Exam e
RIGHT JOIN ClassOwnExam c ON c.examid = e.examid
WHERE c.areaid = #{areaId}
AND c.objectType = #{objectType}
</otherwise>
</choose>
),
<!-- 以下是合并听力用,细节需测试 -->
temp1 AS (
<choose>
<when test="objectType == 0"><!-- 全网 -->
SELECT examid,title FROM hearexam where isnetexam = 1
</when>
<when test="objectType==1 or objectType==2"><!--我的或学校 -->
SELECT e.examid, e.title
FROM HearExam e
RIGHT JOIN ClassOwnHear c ON c.examid = e.examid
<if test="objectType==2"><!-- 学校 -->
INNER JOIN Classes s ON s.classesid = c.classesid
WHERE s.schoolid = #{schoolid}
AND c.objectType = #{objectType}
</if>
<if test="objectType == 1"><!-- 班级或学习小组 -->
INNER JOIN studentownclass s on s.classesid = c.classesid
and s.areaid = #{areaid}
and s.status = 1
WHERE s.studentid = #{userId}
AND c.objectType = #{objectType}
UNION
SELECT e.examid, e.title
FROM HearExam e
RIGHT JOIN ClassOwnHear c ON c.examid = e.examid
WHERE e.teacherid = #{userId}
AND c.objectType = #{objectType}
</if>
</when>
<otherwise><!-- 行政级别分类 -->
SELECT e.examid,e.title
FROM HearExam e
RIGHT JOIN ClassOwnHear c ON c.examid = e.examid
WHERE c.areaid = #{areaId}
AND c.objectType = #{objectType}
</otherwise>
</choose>
)
SELECT e.examid,e.title,e.isoral,avg(a.score) AS avgScore,max(a.created) AS lastTime,'E' AS fenlei
FROM temp e
INNER JOIN examanswer a ON e.examid = a.examid and a.areaid=#{areaid}
WHERE a.userid = #{userId}
GROUP BY e.examid,e.title,e.isoral
UNION
SELECT e.examid,e.title,0 AS isoral, avg(a.score) AS avgScore,max(a.created) AS lastTime,'H' AS fenlei
FROM temp1 e
INNER JOIN hearanswer a ON e.examid = a.examid and a.areaid=#{areaid}
WHERE a.userid = #{userId}
GROUP BY e.examid,e.title
ORDER BY lastTime DESC
<if test="page != null">
LIMIT #{page.limit} OFFSET #{page.offset}
</if>
</select>
<select id= "findExamPersons" parameterType="map" resultType="int" >
SELECT count(distinct userid)
<if test="fenlei == 'H'.toString()">
FROM hearanswer
</if>
<if test="fenlei != 'H'.toString()">
FROM examanswer
</if>
WHERE examid = #{examId}
and areaid = #{areaid}
AND score != 0
</select>
<select id= "findExamRankList" parameterType="map" resultType="com._3e.http.exam.dto._3EResExamRank" >
WITH temp AS(
SELECT examid,score AS maxScore,userid, created,
ROW_NUMBER() OVER(PARTITION BY userid ORDER BY score DESC,created DESC ) AS rank
<if test="fenlei == 'H'.toString()">
FROM hearanswer
</if>
<if test="fenlei != 'H'.toString()">
FROM examanswer
</if>
WHERE examid = #{examId}
and areaid = #{areaid}
AND score != 0
),
temp2 AS (SELECT examid,maxScore,userid, created FROM temp WHERE rank = 1 ),
temp3 AS (SELECT maxScore, userid, created,RANK() OVER(ORDER BY maxScore DESC,created DESC) AS rn FROM temp2 )
SELECT maxScore,userid,created,rn,
COALESCE((SELECT rn FROM temp3 WHERE userid = #{userId} LIMIT 1),0) AS myrn,
COALESCE((SELECT COALESCE(maxScore,0) FROM temp3 WHERE userid = #{userId} LIMIT 1),0) AS myMaxScore
FROM temp3
WHERE rn &lt;= 10
ORDER BY maxScore DESC,rn ASC
</select>
<select id="findAssignExam" parameterType="map" resultType="com._3e.entity.Exam" >
SELECT b.examid, b.examtype, b.title, b.description, b.exampapers,b.created,
b.starttime, b.endtime, b.isnetexam, b.teacherId, b.isoral,b.status,b.type,b.assignTime
FROM ClassOwnExam a
INNER join Exam b
ON a.classesId = #{classesId} and a.examId = b.examId
AND b.isoral = #{isOral}
<if test="examType != null">
AND b.examType = #{examType}
</if>
<if test="startTime != null">
and b.startTime &gt;= #{startTime}
</if>
<if test="endTime != null">
and b.endTime &lt;= #{endTime}
</if>
<if test="type != null">
and b.type = #{type}
</if>
ORDER BY b.examId DESC
<if test="page != null">
LIMIT #{page.limit} OFFSET #{page.offset}
</if>
</select>
<select id="findAssignHearExam" parameterType="map" resultType="com._3e.entity.Exam" >
SELECT b.examid, b.examtype, b.title, b.description, b.exampapers,b.created,
b.starttime, b.endtime, b.isnetexam, b.teacherId, b.isoral,b.status
FROM ClassOwnExam a
INNER join v_hearExam b
ON a.classesId = #{classesId} and a.examId = b.examId
AND b.isoral = #{isOral}
<if test="examType != null">
AND b.examType = #{examType}
</if>
<if test="startTime != null">
and b.startTime &gt;= #{startTime}
</if>
<if test="endTime != null">
and b.endTime &lt;= #{endTime}
</if>
UNION
SELECT b.examid, b.examtype, b.title, b.description, b.exampapers,b.created,
b.starttime, b.endtime, b.isnetexam, b.teacherId, b.isoral
FROM ClassOwnHear a
INNER join v_hearExam b
ON a.classesId = #{classesId} and a.examId = b.examId
AND b.isoral = -1
<if test="examType != null">
AND b.examType = #{examType}
</if>
<if test="startTime != null">
and b.startTime &gt;= #{startTime}
</if>
<if test="endTime != null">
and b.endTime &lt;= #{endTime}
</if>
ORDER BY created DESC
<if test="page != null">
LIMIT #{page.limit} OFFSET #{page.offset}
</if>
</select>
<select id= "findExam" parameterType="int" resultType="com._3e.entity.Exam" >
SELECT * FROM exam WHERE examid = #{examId}
</select>
<select id= "findClassExamMaxScore" parameterType="map" resultType="com._3e.dto.ExamScoreDto" >
WITH temp AS (
SELECT b.userId AS studentId , b.examAnswerId , b.examId , b.examType ,
b.examPaperId as examPaperId , b.score , b.created ,
case when b.score >= 85 then 'A'
when b.score >= 80 then 'B'
when b.score >= 70 then 'C'
when b.score >= 60 then 'D'
else 'E' end as level
, e.title ,b.truescore,
a.avgScore,a.avgTrueScore
FROM ( SELECT userId , examId ,
last_value( examAnswerId ) OVER (PARTITION BY userId order by score desc, created ASC) as tempId ,
row_number() OVER (PARTITION BY userId order by score desc, created ASC ) as rn,
AVG(score) OVER (PARTITION BY userId) AS avgScore,
AVG(truescore) OVER (PARTITION BY userId) AS avgTrueScore
FROM StudentOwnClass m
INNER JOIN ExamAnswer n
ON m.classesId = #{classesId}
and m.areaid = #{areaId} and n.areaid = #{areaId}
AND m.studentId = n.userId AND m.status = 1 AND examId = #{examId}
) a
INNER JOIN ExamAnswer b
ON a.tempId = b.examAnswerId and a.rn = 1 and b.areaid = #{areaId}
inner join Exam e on e.examId = b.examId
left join student s on b.userId = s.studentid and s.areaid=#{areaId}
)
SELECT t.studentId , COALESCE(t.examAnswerId,0) AS examAnswerId, COALESCE(t.examId,0) AS examId,
t.examType , COALESCE(t.examPaperId,0) AS examPaperId , COALESCE(t.score,0) AS score, t.created ,
t.level, t.title,s.truename, s.recognizecode, s.code,s.studentId AS userId,COALESCE(t.truescore,0) AS truescore,
COALESCE(t.avgScore,0) AS avgScore,COALESCE(t.avgTrueScore,0) AS avgTrueScore
FROM temp t
RIGHT JOIN StudentOwnClass o ON t.studentId = o.studentId and o.areaid=#{areaId}
INNER JOIN student s ON s.studentId = o.studentId and s.areaid=#{areaId}
WHERE o.classesId = #{classesId} AND o.status = 1 and s.status = 1
ORDER BY score DESC, t.created ASC nulls last, userId ASC
<if test="page != null">
LIMIT #{page.limit} OFFSET #{page.offset}
</if>
</select>
<insert id= "doSave" parameterType="com._3e.entity.Exam">
INSERT INTO exam(examid,examtype,title,description,exampapercount,exampapers,created,starttime,endtime,isnetexam,isrecommend,isoral,teacherid,type,assignTime)
VALUES (
<if test="examid == 0">
(SELECT NEXTVAL('seq_examid')),
</if>
<if test="examid != 0">
#{examid},
</if>
#{examtype},#{title},#{description},#{exampapercount},#{exampapers},#{created},#{starttime},#{endtime},#{isnetexam},#{isrecommend},#{isoral},#{teacherid},#{type},#{assignTime})
</insert>
<update id="doSaveUpdate" parameterType="com._3e.entity.Exam" >
UPDATE exam
<set>
<if test="examtype != null">
examtype = #{examtype},
</if>
<if test="isrecommend != null">
isrecommend = #{isrecommend},
</if>
<if test="title != null">
title = #{title},
</if>
<if test="description != null">
description = #{description},
</if>
<if test="exampapercount != null">
exampapercount = #{exampapercount},
</if>
<if test="exampapers != null">
exampapers = #{exampapers},
</if>
<if test="created != null">
created = #{created},
</if>
<if test="starttime != null">
starttime = #{starttime},
</if>
<if test="endtime != null">
endtime = #{endtime},
</if>
<if test="isnetexam != null">
isnetexam = #{isnetexam},
</if>
<if test="teacherid != null">
teacherid = #{teacherid},
</if>
<if test="isoral != null">
isoral = #{isoral},
</if>
<if test="status != null">
status = #{status},
</if>
<if test="type != null">
type = #{type}
</if>
</set>
WHERE examid = #{examid}
</update>
<insert id="doExamToClasses" parameterType="com._3e.entity.ClassOwnExam" >
INSERT INTO classownexam(classesid,examid,areaid,objecttype)
VALUES (#{classesid},#{examid},#{areaid},#{objecttype})
</insert>
<select id= "findExamPapers" parameterType="map" resultType="com._3e.entity.ExamPaper" >
SELECT distinct exampaperid, teacherid, examlevel, title,
status, areaid ,isOral
FROM V_ExamPaper WHERE teacherid = #{teacherId} and status = 1 AND isoral = #{isoral}
AND (exampaperid &gt; 112 or exampaperid &lt; 0)
<if test="title != null">
and title like '%'||#{title}||'%'
</if>
order by examPaperId desc
<if test="page != null">
LIMIT #{page.limit} OFFSET #{page.offset}
</if>
</select>
<select id= "findExamPapersByExamlevel" parameterType="map" resultType="com._3e.entity.ExamPaper" >
select distinct ep.exampaperid,ep.teacherid,ep.examlevel,ep.title,ep.status, ep.areaid ,ep.isOral from parameter p
INNER JOIN exampapertag e on p.paraid = e.tagid
INNER JOIN exampaper ep on e.exampaperid = ep.exampaperid
where p.paratype = #{paratype} and p.paraint = #{paraint}
and to_number(trim((p.memo::json->>'examlevel') :: text),'999999') in
<choose>
<when test="classlevelList != null">
<foreach collection="classlevelList" open="(" close=")" separator="," item="examlevel">
#{examlevel}
</foreach>
</when>
<otherwise>
(select classlevel from classes c where teacherid = #{teacherId} and classtype =1 and status =1 GROUP BY classlevel)
</otherwise>
</choose>
and e.status =1
and ep.status = 1 AND ep.isoral = #{isoral}
AND (ep.exampaperid &gt; 112 or ep.exampaperid &lt; 0)
<if test="title != null">
and ep.title like '%'||#{title}||'%'
</if>
order by ep.examPaperId desc
<if test="page != null">
LIMIT #{page.limit} OFFSET #{page.offset}
</if>
</select>
<select id= "findExamPapersByAllCondition" parameterType="map" resultType="com._3e.entity.ExamPaper" >
select * from (
select distinct ep.exampaperid,ep.teacherid,ep.examlevel,ep.title,ep.status, ep.areaid ,ep.isOral,ep.assignTime from parameter p
INNER JOIN exampapertag e on p.paraid = e.tagid
INNER JOIN exampaper ep on e.exampaperid = ep.exampaperid
where p.paratype = #{paratype} and p.paraint = #{paraint}
and p.paraid = #{tagid}
and e.status =1
and ep.status = 1 AND ep.isoral = #{isoral}
AND (ep.exampaperid &gt; 112 or ep.exampaperid &lt; 0)
<if test="title != null">
and ep.title like '%'||#{title}||'%'
</if>
INTERSECT
select distinct ep.exampaperid,ep.teacherid,ep.examlevel,ep.title,ep.status, ep.areaid ,ep.isOral,ep.assignTime from parameter p
INNER JOIN exampapertag e on p.paraid = e.tagid
INNER JOIN exampaper ep on e.exampaperid = ep.exampaperid
where p.paratype = #{paratype} and p.paraint = #{cityParaint}
and p.valueint = #{cityAreaid}
and e.status =1
and ep.status = 1 AND ep.isoral = #{isoral}
AND (ep.exampaperid &gt; 112 or ep.exampaperid &lt; 0)
<if test="title != null">
and ep.title like '%'||#{title}||'%'
</if>
INTERSECT
select distinct ep.exampaperid,ep.teacherid,ep.examlevel,ep.title,ep.status, ep.areaid ,ep.isOral,ep.assignTime from parameter p
INNER JOIN exampapertag e on p.paraid = e.tagid
INNER JOIN exampaper ep on e.exampaperid = ep.exampaperid
where p.paratype = #{paratype} and p.paraint = #{editionParaint}
and p.valueint = #{goodid}
and e.status =1
and ep.status = 1 AND ep.isoral = #{isoral}
AND (ep.exampaperid &gt; 112 or ep.exampaperid &lt; 0)
<if test="title != null">
and ep.title like '%'||#{title}||'%'
</if>
) a order by a.examPaperId desc
</select>
<select id= "findExamPapersByAllCondition_2" parameterType="map" resultType="com._3e.entity.ExamPaper" >
select * from (
select distinct ep.exampaperid,ep.teacherid,ep.examlevel,ep.title,ep.status, ep.areaid ,ep.isOral,ep.assignTime from parameter p
INNER JOIN exampapertag e on p.paraid = e.tagid
INNER JOIN exampaper ep on e.exampaperid = ep.exampaperid
where p.paratype = #{paratype} and p.paraint = #{paraint}
and p.paraid = #{tagid}
and e.status =1
and ep.status = 1 AND ep.isoral = #{isoral}
AND (ep.exampaperid &gt; 112 or ep.exampaperid &lt; 0)
<if test="title != null">
and ep.title like '%'||#{title}||'%'
</if>
INTERSECT
select distinct ep.exampaperid,ep.teacherid,ep.examlevel,ep.title,ep.status, ep.areaid ,ep.isOral,ep.assignTime from parameter p
INNER JOIN exampapertag e on p.paraid = e.tagid
INNER JOIN exampaper ep on e.exampaperid = ep.exampaperid
where p.paratype = #{paratype} and p.paraint = #{editionParaint}
and p.valueint = #{goodid}
and e.status =1
and ep.status = 1 AND ep.isoral = #{isoral}
AND (ep.exampaperid &gt; 112 or ep.exampaperid &lt; 0)
<if test="title != null">
and ep.title like '%'||#{title}||'%'
</if>
) a order by a.examPaperId desc
</select>
<select id= "findExamPapersByDefaultAllCondition" parameterType="map" resultType="com._3e.entity.ExamPaper" >
with temp as (select distinct ep.exampaperid from parameter p
INNER JOIN exampapertag e on p.paraid = e.tagid
INNER JOIN exampaper ep on e.exampaperid = ep.exampaperid
where p.paratype = #{paratype} and p.paraint = #{cityParaint}
and p.valueint = #{cityAreaid}
and e.status =1
and ep.status = 1 AND ep.isoral = #{isoral}
AND (ep.exampaperid &gt; 112 or ep.exampaperid &lt; 0)
<if test="title != null">
and ep.title like '%'||#{title}||'%'
</if>)
select * from (
select distinct ep.exampaperid,ep.teacherid,ep.examlevel,ep.title,ep.status, ep.areaid ,ep.isOral,ep.assignTime from parameter p
INNER JOIN exampapertag e on p.paraid = e.tagid
INNER JOIN exampaper ep on e.exampaperid = ep.exampaperid
where p.paratype = #{paratype} and p.paraint = #{paraint}
and p.paraid = #{tagid}
and e.status =1
and ep.status = 1 AND ep.isoral = #{isoral}
AND (ep.exampaperid &gt; 112 or ep.exampaperid &lt; 0)
<if test="title != null">
and ep.title like '%'||#{title}||'%'
</if>
INTERSECT
select distinct ep.exampaperid,ep.teacherid,ep.examlevel,ep.title,ep.status, ep.areaid ,ep.isOral,ep.assignTime from parameter p
INNER JOIN exampapertag e on p.paraid = e.tagid
INNER JOIN exampaper ep on e.exampaperid = ep.exampaperid
where p.paratype = #{paratype} and p.paraint = #{cityParaint}
and p.valueint = #{defaultCityAreaid} and ep.exampaperid not in(select exampaperid from temp)
and e.status =1
and ep.status = 1 AND ep.isoral = #{isoral}
AND (ep.exampaperid &gt; 112 or ep.exampaperid &lt; 0)
<if test="title != null">
and ep.title like '%'||#{title}||'%'
</if>
INTERSECT
select distinct ep.exampaperid,ep.teacherid,ep.examlevel,ep.title,ep.status, ep.areaid ,ep.isOral,ep.assignTime from parameter p
INNER JOIN exampapertag e on p.paraid = e.tagid
INNER JOIN exampaper ep on e.exampaperid = ep.exampaperid
where p.paratype = #{paratype} and p.paraint = #{editionParaint}
and p.valueint = #{goodid}
and e.status =1
and ep.status = 1 AND ep.isoral = #{isoral}
AND (ep.exampaperid &gt; 112 or ep.exampaperid &lt; 0)
<if test="title != null">
and ep.title like '%'||#{title}||'%'
</if>
) a order by a.examPaperId desc
</select>
<select id= "findExamPapersAdimissionBylevel" parameterType="map" resultType="com._3e.entity.ExamPaper" >
select distinct ep.exampaperid,ep.teacherid,ep.examlevel,ep.title,ep.status, ep.areaid ,ep.isOral from parameter p
INNER JOIN exampapertag e on p.paraid = e.tagid
INNER JOIN exampaper ep on e.exampaperid = ep.exampaperid
where p.paratype = #{paratype} and p.paraint = #{paraint}
and ep.exampaperid in
<foreach collection="paperIds" open="(" close=")" separator="," item="paperId">
#{paperId}
</foreach>
and to_number(trim((p.memo::json->>'examlevel') :: text),'999999') in
<choose>
<when test="classlevelList != null">
<foreach collection="classlevelList" open="(" close=")" separator="," item="examlevel">
#{examlevel}
</foreach>
</when>
<otherwise>
(select classlevel from classes c where teacherid = #{teacherId} and classtype =1 and status =1 GROUP BY classlevel)
</otherwise>
</choose>
and e.status =1
and ep.status = 1 AND ep.isoral = #{isoral}
AND (ep.exampaperid &gt; 112 or ep.exampaperid &lt; 0)
<if test="title != null">
and ep.title like '%'||#{title}||'%'
</if>
order by ep.examPaperId desc
<if test="page != null">
LIMIT #{page.limit} OFFSET #{page.offset}
</if>
</select>
<select id="findExamPapersAdimission" parameterType="map" resultType="com._3e.entity.ExamPaper">
SELECT distinct exampaperid, teacherid, examlevel, title,
status, areaid ,isOral,assignTime
FROM examPaper WHERE status = 1 AND isoral = #{isoral}
and exampaperid in
<foreach collection="paperIds" open="(" close=")" separator="," item="paperId">
#{paperId}
</foreach>
AND (exampaperid &gt; 112 or exampaperid &lt; 0)
<if test="title != null">
and title like '%'||#{title}||'%'
</if>
order by examPaperId desc
<if test="page != null">
LIMIT #{page.limit} OFFSET #{page.offset}
</if>
</select>
<select id= "findExam_v1" parameterType="map" resultType="com._3e.entity.Exam" >
select DISTINCT cl.teacherid,cl.classname,e.examid,e.examtype,e.examtype,e.title,e.description,e.exampapercount
,e.exampapers,e.created,e.starttime,e.endtime,e.isoral from classownexam ce inner join
exam e on ce.examid=e.examid inner join classes cl on ce.classesid=cl.classesid
where cl.teacherid=e.teacherid and cl.teacherid IN
<foreach item="teacherid" index="index" collection="teacherlist"
open="(" separator="," close=")">
#{teacherid}
</foreach>
<if test="status== '2'.toString()">
and e.endtime &lt; NOW()
</if>
<if test="status== '1'.toString()">
and e.endtime &gt; NOW()
</if>
and ce.classesid=#{classesid}
<if test="title != null">
and title like '%'||#{title}||'%'
</if>
and e.examtype='S'
order by e.created desc,e.title desc
<if test="page != null">
LIMIT #{page.limit} OFFSET #{page.offset}
</if>
</select>
<select id= "findExam_v2" parameterType="map" resultType="com._3e.entity.Exam" >
select cl.teacherid,cl.classname,e.examid,e.examtype,e.examtype,e.title,e.description,e.exampapercount
,e.exampapers,e.created,e.starttime,e.endtime,e.isoral from classownexam ce inner join
exam e on ce.examid=e.examid inner join classes cl on ce.classesid=cl.classesid
where cl.teacherid=e.teacherid and cl.classesid IN
<foreach item="item" index="index" collection="classids"
open="(" separator="," close=")">
#{item}
</foreach>
<if test="status== '2'.toString()">
and e.endtime &lt; NOW()
</if>
<if test="status== '1'.toString()">
and e.endtime &gt; NOW()
</if>
<if test="title != null">
and title like '%'||#{title}||'%'
</if>
and e.examtype='S'
order by e.created desc,e.title desc
<if test="page != null">
LIMIT #{page.limit} OFFSET #{page.offset}
</if>
</select>
<select id= "findExam_v3" parameterType="map" resultType="com._3e.entity.Exam" >
select DISTINCT cl.teacherid,cl.classname,e.examid,e.examtype,e.examtype,e.title,e.description,e.exampapercount
,e.exampapers,e.created,e.starttime,e.endtime,e.isoral,e.type,e.assignTime from classownexam ce inner join
exam e on ce.examid=e.examid inner join classes cl on ce.classesid=cl.classesid
where cl.teacherid=e.teacherid and cl.teacherid IN
<foreach item="teacherid" index="index" collection="teacherlist"
open="(" separator="," close=")">
#{teacherid}
</foreach>
<if test="status== '2'.toString()">
and e.endtime &lt; NOW()
</if>
<if test="status== '1'.toString()">
and e.endtime &gt; NOW()
</if>
and ce.classesid=#{classesid}
<if test="title != null">
and title like '%'||#{title}||'%'
</if>
<if test="type != null">
and e.type = #{type}
</if>
<!-- and e.examtype='S' -->
order by e.created desc,e.title desc
<if test="page != null">
LIMIT #{page.limit} OFFSET #{page.offset}
</if>
</select>
<select id= "findExam_v4" parameterType="map" resultType="com._3e.entity.Exam" >
select cl.teacherid,cl.classname,e.examid,e.examtype,e.examtype,e.title,e.description,e.exampapercount
,e.exampapers,e.created,e.starttime,e.endtime,e.isoral,e.type,e.assignTime from classownexam ce inner join
exam e on ce.examid=e.examid inner join classes cl on ce.classesid=cl.classesid
where cl.teacherid=e.teacherid and cl.classesid IN
<foreach item="item" index="index" collection="classids"
open="(" separator="," close=")">
#{item}
</foreach>
<if test="status== '2'.toString()">
and e.endtime &lt; NOW()
</if>
<if test="status== '1'.toString()">
and e.endtime &gt; NOW()
</if>
<if test="title != null">
and title like '%'||#{title}||'%'
</if>
<if test="type != null">
and e.type = #{type}
</if>
<!-- and e.examtype='S' -->
order by e.created desc,e.title desc
<if test="page != null">
LIMIT #{page.limit} OFFSET #{page.offset}
</if>
</select>
<select id= "findExam_v6" parameterType="map" resultType="com._3e.entity.Exam" >
select cl.teacherid,cl.classname,e.examid,e.examtype,e.examtype,e.title,e.description,e.exampapercount
,e.exampapers,e.created,e.starttime,e.endtime,e.isoral,e.type,e.assignTime from classownexam ce inner join
exam e on ce.examid=e.examid inner join classes cl on ce.classesid=cl.classesid
where cl.teacherid=e.teacherid and cl.classesid = #{classid}
and e.endtime &gt; NOW()
<if test="title != null">
and title like '%'||#{title}||'%'
</if>
<if test="type != null">
and e.type = #{type}
</if>
order by e.created desc,e.title desc
</select>
<insert id="doSaveHearAnswer" parameterType="com._3e.entity.HearAnswer" >
INSERT INTO HearAnswer(examanswerid,userid,examid,examtype,hearpaperid,score,answerdetail,created,areaid,origiscore)
VALUES (
<if test="examanswerid == 0">
(SELECT NEXTVAL('seq_hearanswerid')),
</if>
<if test="examanswerid != 0">
#{examanswerid},
</if>
#{userid},#{examid},#{examtype},#{hearpaperid},#{score},#{answerdetail},#{created},#{areaid},#{origiscore})
</insert>
<!--没有使用-->
<select id= "findMockhearexam" parameterType="map" resultType="com._3e.dto.HearexamDto" >
select * from (
SELECT h.* FROM hearexam h
inner join classownhear c
on c.examid = h.examid
inner join studentownclass s
on s.classesid = c.classesid and s.status = 1
WHERE s.studentId= #{uid}
AND h.examType = 'S'
and h.startTime &lt; now() and h.endTime &gt; now()
union
SELECT h.* FROM hearexam h
inner join classownhear c
on c.examid = h.examid
inner join classes co
on c.classesid = co.classesid and co.status = 1
WHERE co.teacherId = #{uid}
AND h.examType = 'S'
and h.startTime &lt; now() and h.endTime &gt; now()
UNION
SELECT h.* FROM hearexam h
WHERE isNetExam = 1 AND examType = 'S'
and startTime &lt; now() and endTime &gt; now()
) t
<if test="page != null">
LIMIT #{page.limit} OFFSET #{page.offset}
</if>
</select>
<select id="findHearexam" parameterType="int" resultType="com._3e.entity.Hearexam" >
SELECT * FROM hearexam WHERE examid = #{examId}
</select>
<select id="findHearexam_1" parameterType="map" resultType="com._3e.entity.Hearexam" >
select cl.teacherid,e.examid,e.examtype,e.examtype,e.title,e.description,e.exampapercount
,e.exampapers,e.created,e.starttime,e.endtime,e.isoral,cl.classname from classownhear ce
inner join v_hearexam e on ce.examid=e.examid inner join classes cl on ce.classesid=cl.classesid
where cl.teacherid=e.teacherid and cl.teacherid IN
<foreach item="teacherid" index="index" collection="teacherlist"
open="(" separator="," close=")">
#{teacherid}
</foreach>
and e.endtime &gt;NOW()
and ce.classesid=#{classesid}
and e.isoral=-1
and e.examtype='S'
order by created desc,title desc
</select>
<select id="findHearexam_2" parameterType="map" resultType="com._3e.entity.Hearexam" >
select cl.teacherid,e.examid,e.examtype,e.examtype,e.title,e.description,e.exampapercount
,e.exampapers,e.created,e.starttime,e.endtime,e.isoral,cl.classname from classownhear ce
inner join v_hearexam e on ce.examid=e.examid inner join classes cl on ce.classesid=cl.classesid
where cl.teacherid=e.teacherid and cl.classesid IN
<foreach item="item" index="index" collection="classids"
open="(" separator="," close=")">
#{item}
</foreach>
and e.endtime &gt;NOW()
and e.isoral=-1
and e.examtype='S'
order by created desc,title desc
</select>
<select id="findHearexam_3" parameterType="map" resultType="com._3e.entity.Hearexam" >
select cl.teacherid,e.examid,e.examtype,e.examtype,e.title,e.description,e.exampapercount
,e.exampapers,e.created,e.starttime,e.endtime,e.isoral,cl.classname from classownhear ce
inner join v_hearexam e on ce.examid=e.examid inner join classes cl on ce.classesid=cl.classesid
where cl.teacherid=e.teacherid and cl.teacherid IN
<foreach item="teacherid" index="index" collection="teacherlist"
open="(" separator="," close=")">
#{teacherid}
</foreach>
and e.endtime &gt;NOW()
and ce.classesid=#{classesid}
and e.isoral=-1
<!-- and e.examtype='S' -->
order by created desc,title desc
</select>
<select id="findHearexam_4" parameterType="map" resultType="com._3e.entity.Hearexam" >
select cl.teacherid,e.examid,e.examtype,e.examtype,e.title,e.description,e.exampapercount
,e.exampapers,e.created,e.starttime,e.endtime,e.isoral,cl.classname from classownhear ce
inner join v_hearexam e on ce.examid=e.examid inner join classes cl on ce.classesid=cl.classesid
where cl.teacherid=e.teacherid and cl.classesid IN
<foreach item="item" index="index" collection="classids"
open="(" separator="," close=")">
#{item}
</foreach>
and e.endtime &gt;NOW()
and e.isoral=-1
<!-- and e.examtype='S' -->
order by created desc,title desc
</select>
<select id="findHearexam_6" parameterType="map" resultType="com._3e.entity.Hearexam" >
select cl.teacherid,e.examid,e.examtype,e.examtype,e.title,e.description,e.exampapercount
,e.exampapers,e.created,e.starttime,e.endtime,e.isoral,cl.classname from classownhear ce
inner join v_hearexam e on ce.examid=e.examid inner join classes cl on ce.classesid=cl.classesid
where cl.teacherid=e.teacherid and cl.classesid = #{classid}
and e.endtime &gt;NOW()
and e.isoral=-1
<!-- and e.examtype='S' -->
order by created desc,title desc
</select>
<!--没有使用-->
<select id= "findFormalhearexam" parameterType="map" resultType="com._3e.dto.HearexamDto" >
SELECT h.* FROM hearexam h
inner join classownhear c
on c.examid = h.examid
inner join studentownclass s
on s.classesid = c.classesid and s.status = 1
WHERE s.studentId = #{uid}
AND h.examType = 'O'
and h.startTime &lt; now() and h.endTime &gt; now()
union
SELECT h.* FROM hearexam h
inner join classownhear c
on c.examid = h.examid
inner join classes co
on c.classesid = co.classesid and co.status = 1
WHERE co.teacherId = #{uid}
AND h.examType = 'O'
and h.startTime &lt; now() and h.endTime &gt; now()
<if test="page != null">
LIMIT #{page.limit} OFFSET #{page.offset}
</if>
</select>
<!--没有使用-->
<select id= "findHearAnswer" parameterType="map" resultType="com._3e.entity.HearAnswer" >
select * from hearanswer where userid = #{userId} and examid = #{examId}
<if test="examtype != null">
and examtype = #{examType}
</if>
<if test="page != null">
LIMIT #{page.limit} OFFSET #{page.offset}
</if>
</select>
<!-- <select id= "findAssignHearexam" parameterType="map" resultType="com._3e.entity.Hearexam" > -->
<!-- SELECT b.* -->
<!-- FROM ClassOwnHear a -->
<!-- INNER join HearExam b -->
<!-- ON a.classesId = #{classesId} and a.examId = b.examId -->
<!-- AND b.examType = #{examType} -->
<!-- <if test="startTime != null"> -->
<!-- and b.startTime &gt;= #{startTime} -->
<!-- </if> -->
<!-- <if test="endTime != null"> -->
<!-- and b.endtime &gt;= #{endTime} -->
<!-- </if> -->
<!-- ORDER BY b.examId DESC -->
<!-- <if test="page != null"> -->
<!-- LIMIT #{page.limit} OFFSET #{page.offset} -->
<!-- </if> -->
<!-- </select> -->
<!--没有使用-->
<select id= "findClassHearexamMaxScore" parameterType="map" resultType="com._3e.dto.ExamScoreDto" >
SELECT b.userId , b.examAnswerId , b.examId , b.examType ,
b.hearPaperId as examPaperId , b.score , b.created ,
case when b.score >= 85 then 'A'
when b.score >= 80 then 'B'
when b.score >= 70 then 'C'
when b.score >= 60 then 'D'
else 'E' end as level
, e.title
, s.truename, s.recognizecode, s.code
FROM ( SELECT userId , examId ,
last_value( examAnswerId ) OVER (PARTITION BY userId order by score desc ) as tempId ,
row_number() OVER (PARTITION BY userId order by score desc ) as rn
FROM StudentOwnClass m
INNER JOIN HearAnswer n
ON m.classesId = #{classesId} AND m.studentId = n.userId AND examId = #{examId}
) a
INNER JOIN HearAnswer b
ON a.tempId = b.examAnswerId and a.rn = 1 and b.areaid = #{areaId}
inner join HearExam e on e.examId = b.examId
left join student s on b.userId = s.studentid
ORDER BY b.score desc
<if test="page != null">
LIMIT #{page.limit} OFFSET #{page.offset}
</if>
</select>
<!--没有使用-->
<select id="findClassHearexamAllScore" parameterType="map" resultType="com._3e.dto.ExamScoreDto" >
SELECT b.userId , b.examAnswerId , b.examId , b.examType ,
b.hearPaperId as examPaperId , b.score , b.created ,
case when b.score >= 85 then 'A'
when b.score >= 80 then 'B'
when b.score >= 70 then 'C'
when b.score >= 60 then 'D'
else 'E' end as level
, e.title
FROM StudentOwnClass a
INNER JOIN hearAnswer b
ON a.classesId = #{classesId} AND a.studentId = b.userId AND b.examId = #{examId}
inner join hearExam e on e.examId = b.examId
ORDER BY b.examAnswerId desc
<if test="page != null">
LIMIT #{page.limit} OFFSET #{page.offset}
</if>
</select>
<select id= "findHearexamPaperByID" parameterType="int" resultType="com._3e.entity.Hearpaper" >
SELECT * FROM hearpaper WHERE hearpaperid = #{paperId}
</select>
<select id= "findIsExamToClass" parameterType="map" resultType="boolean" >
SELECT CASE WHEN (COUNT(*) &gt; 0) THEN true ELSE false END AS isFlag
FROM classOwnExam
WHERE examid = #{examId} and classesid =#{classesId}
</select>
<select id= "findHearPapersV2" parameterType="map" resultType="com._3e.entity.Hearpaper" >
SELECT hearpaperid, teacherid, examlevel, title,
status, areaid ,isOral
FROM V_HearPaper WHERE teacherid = #{teacherId} and status = 1
<if test="title != null">
and title like '%'||#{title}||'%'
</if>
order by hearpaperid desc
<if test="page != null">
LIMIT #{page.limit} OFFSET #{page.offset}
</if>
</select>
<select id="findExamPaperNamesByPaperIds" parameterType="java.util.List" resultType="com._3e.http.teachercenter.dto.manageexam._3EResPaper">
select exampaperid as paperId ,title from exampaper where exampaperid
in
<foreach collection="list" index="index" item="item" separator="," close=")" open="(">
#{item}
</foreach>
</select>
<select id="findHearPaperNamesByPaperIds" parameterType="java.util.List" resultType="com._3e.http.teachercenter.dto.manageexam._3EResPaper">
select hearpaperid as paperId ,title from hearpaper where hearpaperid
in
<foreach collection="list" index="index" item="item" separator="," close=")" open="(">
#{item}
</foreach>
</select>
<!--根据用户id查询用户所有的开始回答 测试的-->
<select id="findMyAllExamAnswer" parameterType="map" resultType="com._3e.entity.ExamAnswer">
select examanswerid,userid,exampaperid,origiscore,truescore,created,content
from examanswer where userid=#{userid} and created>'2019-10-17'
</select>
<!--模拟插入数据到错题本表-->
<!--insert INTO wrongbook (
uid,guid,parttype,exampaperid,examanswerid,origiscore,truescore,
multiques,iscorrect,created
) VALUES (
#{uid},#{guid},#{parttype},#{exampaperid},#{examanswerid},#{origiscore},#{truescore},
#{multiques, typeHandler=com._3e.http.wrongbook.typehandler.JSONTypeHandlerPg},
#{iscorrect}, #{created})
on conflict(uid,guid) do update set truescore=1-->
<!--<insert id="doSaveWrongBook" parameterType="com._3e.http.wrongbook.dto.WrongBook">
insert into wrongbook values(#{uid},#{guid},#{parttype},#{exampaperid},#{examanswerid},
#{origiscore},#{truescore},#{origiscore},#{multiques,typeHandler=com._3e.http.wrongbook.typehandler.JSONTypeHandlerPg},
#{iscorrect},#{created})
</insert>-->
<select id="findExamAnswerByUidAndExamid" parameterType="map" resultType="com._3e.http.exam.dto.ExamAnswerDto">
select created,score,truescore,origiscore from examanswer where userid=#{userid}
and areaid = #{areaid}
and examid=#{examid}
order by truescore desc limit 1
</select>
<!--没有使用-->
<select id="findContentOfAnswer" parameterType="map" resultType="com._3e.dto.ExamContentDto">
with temp as(
select * from (select userid,content,examid,truescore,created,areaid,
ROW_NUMBER() over(partition by userid order by truescore desc,created desc) new_index
from examanswer where examid=#{examid} and areaid=#{areaid}) a where a.new_index=1
)
select s.truename,s.studentid,t.content,t.examid,t.truescore,t.created
from student s INNER JOIN studentownclass sc
on sc.studentid=s.studentid
and sc.classesid=#{classesid} and sc.status=1 left JOIN temp t on t.userid=s.studentid
</select>
<!--查询老师布置的考试作业次数(当前班级)-->
<select id="findExamNumByteacherid" parameterType="map" resultType="int">
SELECT count(1) from exam e INNER JOIN
classownexam c on e.examid=c.examid and c.classesid=#{classesid}
and e.teacherid = #{teacherid} and e.created between '${starttime} 00:00:00' and '${endtime} 23:59:59'
</select>
<!--查询班级所有学生完成的考试的总次数,一个人做多次同一个考试只算一次-->
<select id="findClassStudentExamNum" parameterType="map" resultType="int">
WITH temp as(
select soc.studentId,e.examid from StudentOwnClass soc
inner join student s on soc.studentid=s.studentid
and soc.areaid = #{areaid} and s.areaid = #{areaid}
and soc.classesId = #{classesid} and s.status=1
INNER JOIN examanswer e on soc.studentid=e.userid
and e.areaid = #{areaid}
and e.created between '${starttime} 00:00:00' and '${endtime} 23:59:59'
INNER JOIN (select examid from classownexam where classesid =#{classesid}) c on e.examid = c.examid
GROUP BY soc.studentid,e.examid
)
SELECT count(*) from temp
</select>
<select id="findExamAnsweranalyAccordingToGuid" parameterType="map" resultType="com._3e.http.teachercenter.dto.manageexam._3EExamAnsweranaly">
select * from examansweranaly where classesid=#{classesid} and examid=#{examid} and exampaperid=#{exampaperid}
</select>
<select id="findAllExamPaperContent" resultType="com._3e.http.wcjtest.dto.ExamPaperContentDto">
select exampaperid,content from exampaper where exampaperid>130 or exampaperid &lt; 0 ORDER BY exampaperid
</select>
<select id="findClassOwnExamByExamid" resultType="com._3e.entity.ClassOwnExam" parameterType="int">
select * from classownexam where examid = #{examid}
</select>
<select id="findExamAnswerByUidAndAnswerId" resultType="com._3e.entity.ExamAnswer" parameterType="map">
select * from examAnswer where examanswerid = #{examAnswerId} and userid = #{uid}
</select>
<select id="findExampaperByteacherId" resultType="com._3e.http.teachercenter.dto.manageexam.ClassExamPaper" parameterType="map">
select c.classesid,c.classname,e.exampapers from classes c
INNER JOIN classownexam ce on c.classesid = ce.classesid and c.teacherid = #{teacherId} and c.status = 1
INNER JOIN exam e on ce.examid = e.examid and e.teacherid = #{teacherId} and e.type = #{type} and e.starttime > #{startTime} and e.endtime &lt; #{endTime}
and e.isOral = #{isoral} and (e.status = 1 or (e.status =0 and (e.starttime::timestamp + '15 min') &lt; e.endtime))
order by e.created desc
</select>
<select id="findExamPaperTag" resultType="com._3e.http.myspace.dto._3EResExamTag" parameterType="map">
select p.valueStr,e.tagId from exampapertag e
inner join parameter p on e.tagid = p.paraid
where e.exampaperid = #{exampaperId} and e.status =1
</select>
<select id="findExamanswerClassAssign" resultType="com._3e.entity.ExamAnswer">
WITH temp as (
select soc.studentId from StudentOwnClass soc
inner join student s on soc.studentid=s.studentid and s.areaid = #{areaId} and s.status = 1
where soc.classesId =#{classesId} and soc.areaid = #{areaId} and soc.status=1
)
SELECT * FROM (SELECT e.*, ROW_NUMBER() OVER (PARTITION BY e.userid ORDER BY e.score DESC) as rn
FROM examanswer e INNER JOIN temp t ON e.userid = t.studentId
WHERE e.examid = #{examId}
) ranked
WHERE rn = 1
</select>
</mapper>