572 lines
21 KiB
XML
Raw Permalink Normal View History

2026-03-10 14:30:24 +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="ExamAnswer">
<insert id="insertExamAnswer" parameterType="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 (
#{examAnswerId}, #{userId}, #{examId}, #{examType}, #{examPaperId},
#{part1OrigiScore}, #{part1Score}, #{part1TrueScore}, #{accuracy}, #{fluent}, #{integrity}, #{part1Content},
#{part2OrigiScore}, #{part2Score}, #{part2TrueScore}, #{part2Content}, #{origiScore}, #{score},
#{trueScore},current_timestamp , #{areaid} ,
#{machineScore} , #{humanScore} , #{paperFile} , #{md5Code} , #{content} )
</insert>
<update id="updateExamAnswer" parameterType="ExamAnswer">
UPDATE ExamAnswer
SET examAnswerId = #{examAnswerId}, userId = #{userId}, examId = #{examId}, examType = #{examType},
examPaperId = #{examPaperId}, part1OrigiScore = #{part1OrigiScore}, part1Score = #{part1Score},
part1TrueScore = #{part1TrueScore}, accuracy = #{accuracy}, fluent = #{fluent},
integrity = #{integrity}, part1Content = #{part1Content},
part2OrigiScore = #{part2OrigiScore}, part2Score = #{part2Score}, part2TrueScore = #{part2TrueScore},
part2Content = #{part2Content}, origiScore = #{origiScore}, score = #{score}, trueScore = #{trueScore},
created = #{created} , areaid = #{areaid} ,
machineScore = #{machineScore} , humanScore = #{humanScore} ,
paperFile = #{paperFile} , md5Code = #{md5Code} , content = #{content}
where examAnswerId=#{examAnswerId}
</update>
<select id="getExamAnswerByKey" parameterType="java.lang.Long" resultType="ExamAnswer">
SELECT 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
FROM ExamAnswer
WHERE examAnswerId=#{examAnswerId}
</select>
<select id="getSeqExamAnswer" resultType="Long" useCache="false" flushCache="true">
SELECT nextval('seq_examAnswerId') ;
</select>
<select id="getExamAnswersCountByUserId" parameterType="java.util.Map" resultType="Integer">
SELECT count(*) as howmuch from ExamAnswer
WHERE userId=#{userId} and areaid = #{areaid}
AND created &gt; #{startTime} and created &lt;= #{endTime}
</select>
<select id="getExamAnswersByUserId" parameterType="java.util.Map" resultType="ExamAnswer">
SELECT 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
FROM ExamAnswer
WHERE userId=#{userId} and areaid = #{areaid}
AND created &gt; #{startTime} and created &lt;= #{endTime}
ORDER BY examAnswerId desc
LIMIT #{pageSize} OFFSET #{offset}
</select>
<select id="getMaxExamAnswersCountByClassesId" parameterType="java.util.Map" resultType="Integer">
<!-- SELECT count(*)
FROM StudentOwnClass
where classesId = #{classesId} and status=1 -->
select count(soc.studentId ) from studentownclass soc inner join ExamAnswer as ea on ea.userId = soc.studentId
inner join exam as e on e.examid = ea.examId inner join student s on soc.studentid=s.studentid and s.status=1
where soc.classesId=#{classesId} and s.areaid=#{areaid} and soc.areaid=#{areaid} and soc.status=1
</select>
<select id="getMaxExamAnswersByClassesId" parameterType="java.util.Map" resultType="ExamAchive">
with stu as(select soc.studentId userId from studentownclass soc
inner join student s on soc.studentid=s.studentid and s.status=1
where soc.classesId=#{classesId} and s.areaid=#{areaid} and soc.areaid=#{areaid} and soc.status=1 )
SELECT stu.userId , b.examAnswerId , b.examId , b.examType ,
b.examPaperId , b.score , b.created ,
case when b.score &gt;= 85 then 'A'
when b.score &gt;= 80 then 'B'
when b.score &gt;= 70 then 'C'
when b.score &gt;= 60 then 'D'
else 'E' end as level
, e.title , b.trueScore , b.machineScore , b.humanScore,
b.origiScore
FROM ( SELECT n.userId , examId ,
last_value( examAnswerId ) OVER (PARTITION BY n.userId order by score desc , created asc ) as tempId ,
row_number() OVER (PARTITION BY n.userId order by score desc , created asc ) as rn
FROM stu m
INNER JOIN EXAMANSWER n
on m.userId = n.userId AND examId = #{examId} and n.areaId=#{areaid}
<if test="examPaperId!=null">
and n.examPaperId = #{examPaperId}
</if>
) 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
right join stu on stu.userId = b.userId
ORDER BY b.score desc nulls last, b.created asc nulls last,stu.userId
<if test="pageSize!=null">
limit #{pageSize}
</if>
<if test="offset!=null">
offset #{offset}
</if>
</select>
<select id="getMaxExamAnswersCountByClassesIdFilter" parameterType="java.util.Map" resultType="Integer">
with temp as(SELECT userId , score,
row_number() OVER (PARTITION BY userId order by score desc , created asc ) as rn
FROM StudentOwnClass m
INNER JOIN EXAMANSWER n
ON m.classesId = #{classesId}
AND m.studentId = n.userId AND n.examId = #{examId}
and m.areaId=#{areaid} and n.areaId=#{areaid}
)
select count(userId) from temp where rn=1
<if test="upperScore!=null">
and score&lt;#{upperScore}
</if>
<if test="lowerScore!=null">
and score&gt;#{lowerScore}
</if>
</select>
<select id="getMaxExamAnswersByClassesIdFilter" parameterType="java.util.Map" resultType="ExamAchive">
with stu as(select soc.studentId userId from studentownclass soc
inner join student s on soc.studentid=s.studentid and s.status=1
where soc.classesId=#{classesId} and s.areaid=#{areaid} and soc.areaid=#{areaid} and soc.status=1 ) ,
SELECT stu.userId , b.examAnswerId , b.examId , b.examType ,
b.examPaperId , b.score , b.created ,
case when b.score &gt;= 85 then 'A'
when b.score &gt;= 80 then 'B'
when b.score &gt;= 70 then 'C'
when b.score &gt;= 60 then 'D'
else 'E' end as level
, e.title , b.trueScore , b.machineScore , b.humanScore,
b.origiScore
FROM ( SELECT userId , examId ,
examAnswerId as tempId ,
row_number() OVER (PARTITION BY userId order by score desc , created asc ) as rn
FROM StudentOwnClass m
INNER JOIN EXAMANSWER n
ON m.classesId = #{classesId} AND m.studentId = n.userId AND examId = #{examId} and m.areaId=#{areaid} and n.areaId=#{areaid}
) a
INNER JOIN ExamAnswer b
ON a.tempId = b.examAnswerId and a.rn = 1 and b.areaid = #{areaid}
<if test="upperScore!=null">
and b.score&lt;#{upperScore}
</if>
<if test="lowerScore!=null">
and b.score&gt;#{lowerScore}
</if>
inner join stu on stu.userId = b.userId
ORDER BY b.score desc nulls last, b.created asc nulls last,stu.userId
<if test="pageSize!=null">
limit #{pageSize}
</if>
<if test="offset!=null">
offset #{offset}
</if>
</select>
<select id="getExamAnswersCountByClassesId" parameterType="java.util.Map" resultType="Integer">
SELECT count(*)
FROM StudentOwnClass a
INNER JOIN EXAMANSWER b
ON a.classesId = #{classesId} AND a.studentId = b.userId AND b.examId = #{examId} and b.areaid = #{areaid}
</select>
<select id="getExamAnswersByClassesId" parameterType="java.util.Map" resultType="ExamAchive">
SELECT b.userId , b.examAnswerId , b.examId , b.examType ,
b.examPaperId , b.score , b.created ,
case when b.score &gt;= 85 then 'A'
when b.score &gt;= 80 then 'B'
when b.score &gt;= 70 then 'C'
when b.score &gt;= 60 then 'D'
else 'E' end as level
, e.title , b.trueScore , b.machineScore , b.humanScore
FROM StudentOwnClass a
INNER JOIN EXAMANSWER b
ON a.classesId = #{classesId} AND a.studentId = b.userId AND b.examId = #{examId} and b.areaId=#{areaid}
inner join Exam e on e.examId = b.examId
ORDER BY b.examAnswerId desc
<if test="pageSize!=null">
limit #{pageSize}
</if>
<if test="offset!=null">
offset #{offset}
</if>
</select>
<select id="getMaxExamAchivesCountByUserId" parameterType="java.util.Map" resultType="Integer">
SELECT count( distinct e.examid )
FROM ExamAnswer e inner join exam em on e.examId=em.examId and em.isOral=#{isOral}
<if test="type == 1">
and (em.type = 1 or em.type = 2)
</if>
<if test="type != 1">
and em.type = #{type}
</if>
WHERE e.userId = #{userId}
AND e.created &gt; #{startTime} and e.created &lt;= #{endTime}
and e.areaid=#{areaid}
</select>
<select id="getMaxExamAchivesByUserId" parameterType="java.util.Map" resultType="ExamAchive">
SELECT b.userId , b.examAnswerId , b.examId , b.examType ,
b.examPaperId , b.score , b.created ,e.type,
case when b.score &gt;= 85 then 'A'
when b.score &gt;= 80 then 'B'
when b.score &gt;= 70 then 'C'
when b.score &gt;= 60 then 'D'
else 'E' end as level
, e.title , b.trueScore , b.machineScore , b.humanScore
FROM ( SELECT userId , examAnswerId , examId , examType ,
examPaperId , score , created ,
rank() over (partition by examId order by score desc , created desc ) as mm ,
trueScore , machineScore , humanScore
FROM EXAMANSWER
WHERE userId = #{userId}
and areaid=#{areaid}
AND created &gt; #{startTime} and created &lt;= #{endTime}
) b
INNER JOIN Exam e
on b.examId = e.examId and e.isOral=#{isOral}
<if test="type == 1">
and (e.type = 1 or e.type = 2)
</if>
<if test="type != 1">
and e.type = #{type}
</if>
WHERE b.mm = 1
ORDER BY b.created desc
<if test="pageSize!=null">
limit #{pageSize}
</if>
<if test="offset!=null">
offset #{offset}
</if>
</select>
<select id="getExamAchivesCountByUserId" parameterType="java.util.Map" resultType="Integer">
SELECT count(*)
FROM ExamAnswer b inner join exam e on b.examId = e.examid and e.isOral=#{isOral}
<if test="type == 1">
and (e.type = 1 or e.type = 2)
</if>
<if test="type != 1">
and e.type = #{type}
</if>
WHERE b.userId = #{userId} and b.areaid = #{areaid}
AND b.created &gt; #{startTime} and b.created &lt;= #{endTime}
</select>
<select id="getExamAchivesByUserId" parameterType="java.util.Map" resultType="ExamAchive">
SELECT b.userId , b.examAnswerId , b.examId , b.examType ,
b.examPaperId , b.score , b.created ,e.type,
case when b.score &gt;= 85 then 'A'
when b.score &gt;= 80 then 'B'
when b.score &gt;= 70 then 'C'
when b.score &gt;= 60 then 'D'
else 'E' end as level
, e.title , b.trueScore , b.machineScore , b.humanScore
FROM ExamAnswer b inner join Exam e on e.examId = b.examId and e.isOral=#{isOral}
<if test="type == 1">
and (e.type = 1 or e.type = 2)
</if>
<if test="type != 1">
and e.type = #{type}
</if>
WHERE b.userId = #{userId} and b.areaid = #{areaid}
AND b.created &gt; #{startTime} and b.created &lt;= #{endTime}
ORDER BY b.examAnswerId desc
<if test="pageSize!=null">
limit #{pageSize}
</if>
<if test="offset!=null">
offset #{offset}
</if>
</select>
<select id="getExamCountByExamIdByUserId" parameterType="java.util.Map" resultType="Integer">
select count(*)
from examanswer
where examid = #{examId} and userid = #{userId} and areaid=#{areaId}
</select>
<select id="getNewMaxHearAchivesCountByUserId" parameterType="java.util.Map" resultType="Integer">
with
temp as( SELECT count( distinct examid ) howmuch
FROM hearAnswer
WHERE userId = #{userId}
AND created &gt; #{startTime} and created &lt;= #{endTime}
and areaId=#{areaid}
) ,
temp1 as (
SELECT count( distinct e.examid ) howmuch
FROM ExamAnswer e inner join exam em on e.examId=em.examId and em.isOral=2
<if test="type == 1">
and (em.type = 1 or em.type = 2)
</if>
<if test="type != 1">
and em.type = #{type}
</if>
WHERE e.userId = #{userId}
AND e.created &gt; #{startTime} and e.created &lt;= #{endTime}
and e.areaId=#{areaid}
)
select t.howmuch+t1.howmuch from temp t,temp1 t1
</select>
<select id="getNewMaxHearAchivesByUserId" parameterType="java.util.Map" resultType="ExamAchive">
SELECT b.userId , b.examAnswerId , b.examId , b.examType ,
b.hearPaperId as examPaperId , b.score , b.created ,0 as type,
case when b.score &gt;= 85 then 'A'
when b.score &gt;= 80 then 'B'
when b.score &gt;= 70 then 'C'
when b.score &gt;= 60 then 'D'
else 'E' end as level
, e.title
FROM ( SELECT userId , examAnswerId , examId , examType ,
hearPaperId , score , created ,
rank() over (partition by examId order by score desc , created desc ) as mm
FROM hearANSWER
WHERE userId = #{userId} and areaid=#{areaid}
AND created &gt; #{startTime} and created &lt;= #{endTime}
) b
INNER JOIN HearExam e
on b.examId = e.examId
WHERE b.mm = 1
union
SELECT b.userId , b.examAnswerId , b.examId , b.examType ,
b.examPaperId , b.score , b.created ,e.type,
case when b.score &gt;= 85 then 'A'
when b.score &gt;= 80 then 'B'
when b.score &gt;= 70 then 'C'
when b.score &gt;= 60 then 'D'
else 'E' end as level
, e.title
FROM ( SELECT userId , examAnswerId , examId , examType ,
examPaperId , score , created ,
rank() over (partition by examId order by score desc , created desc ) as mm ,
trueScore , machineScore , humanScore
FROM EXAMANSWER
WHERE userId = #{userId} and areaid=#{areaid}
AND created &gt; #{startTime} and created &lt;= #{endTime}
) b
INNER JOIN Exam e
on b.examId = e.examId and e.isOral=2
<if test="type == 1">
and (e.type = 1 or e.type = 2)
</if>
<if test="type != 1">
and e.type = #{type}
</if>
WHERE b.mm = 1
ORDER BY created desc
<if test="pageSize!=null">
limit #{pageSize}
</if>
<if test="offset!=null">
offset #{offset}
</if>
</select>
<select id="getNewHearAchivesCountByUserId" parameterType="java.util.Map" resultType="Integer">
with temp as (
SELECT count(*) howmuch FROM hearAnswer b
WHERE b.userId = #{userId} and b.areaid = #{areaid}
AND b.created &gt; #{startTime} and b.created &lt;= #{endTime}
),
temp1 as(
SELECT count(*) howmuch
FROM ExamAnswer b inner join exam e on b.examId = e.examid and e.isOral=2
<if test="type == 1">
and (e.type = 1 or e.type = 2)
</if>
<if test="type != 1">
and e.type = #{type}
</if>
WHERE b.userId = #{userId} and b.areaid = #{areaid}
AND b.created &gt; #{startTime} and b.created &lt;= #{endTime})
select t.howmuch+t1.howmuch from temp t,temp1 t1
</select>
<select id="getNewHearAchivesByUserId" parameterType="java.util.Map" resultType="ExamAchive">
SELECT b.userId , b.examAnswerId , b.examId , b.examType ,
b.hearPaperId as examPaperId , b.score , b.created ,0 as type ,
case when b.score &gt;= 85 then 'A'
when b.score &gt;= 80 then 'B'
when b.score &gt;= 70 then 'C'
when b.score &gt;= 60 then 'D'
else 'E' end as level
, e.title
FROM hearAnswer b inner join hearExam e on e.examId = b.examId
WHERE b.userId = #{userId} and b.areaid = #{areaid}
AND b.created &gt; #{startTime} and b.created &lt;= #{endTime}
union
SELECT b.userId , b.examAnswerId , b.examId , b.examType ,
b.examPaperId , b.score , b.created ,e.type,
case when b.score &gt;= 85 then 'A'
when b.score &gt;= 80 then 'B'
when b.score &gt;= 70 then 'C'
when b.score &gt;= 60 then 'D'
else 'E' end as level
, e.title
FROM ExamAnswer b inner join Exam e on e.examId = b.examId and e.isOral=2
<if test="type == 1">
and (e.type = 1 or e.type = 2)
</if>
<if test="type != 1">
and e.type = #{type}
</if>
WHERE b.userId = #{userId} and b.areaid = #{areaid}
AND b.created &gt; #{startTime} and b.created &lt;= #{endTime}
ORDER BY created desc
<if test="pageSize!=null">
limit #{pageSize}
</if>
<if test="offset!=null">
offset #{offset}
</if>
</select>
<select id="getExamAnswerStatisticsByClassesId" parameterType="java.util.Map" resultType="java.util.Map">
with stu as(select soc.studentId userId from studentownclass soc
inner join student s on soc.studentid=s.studentid and s.status=1
where soc.classesId=#{classesId} and s.areaid=#{areaid} and soc.areaid=#{areaid} and soc.status=1 )
SELECT count(case when a.score &gt;= 85 then 1 else null end) "A",
count(case when a.score &gt;= 75 and a.score&lt;85 then 1 else null end) "B",
count(case when a.score &gt;= 65 and a.score&lt;75 then 1 else null end) "C",
count(case when a.score &gt;= 55 and a.score&lt;65 then 1 else null end) "D",
count(case when a.score &gt;= 0 and a.score&lt;55 then 1 else null end) "E",
count(case when a.score is null then 1 else null end) "N"
FROM ( SELECT userId , examId ,
score,
row_number() OVER (PARTITION BY userId order by score desc , created asc ) as rn
FROM StudentOwnClass m
INNER JOIN EXAMANSWER n
ON m.classesId = #{classesId} AND m.studentId = n.userId AND examId = #{examId} and m.areaId=#{areaid} and n.areaId=#{areaid}
) a
right join stu on stu.userId = a.userId and rn=1
</select>
<select id="getHearAnswerStatisticsByClassesId" parameterType="java.util.Map" resultType="java.util.Map">
with stu as(select soc.studentId userId from studentownclass soc
inner join student s on soc.studentid=s.studentid and s.status=1
where soc.classesId=#{classesId} and s.areaid=#{areaid} and soc.areaid=#{areaid} and soc.status=1 )
SELECT count(case when a.score &gt;= 85 then 1 else null end) "A",
count(case when a.score &gt;= 75 and a.score&lt;85 then 1 else null end) "B",
count(case when a.score &gt;= 65 and a.score&lt;75 then 1 else null end) "C",
count(case when a.score &gt;= 55 and a.score&lt;65 then 1 else null end) "D",
count(case when a.score &gt;= 0 and a.score&lt;55 then 1 else null end) "E",
count(case when a.score is null then 1 else null end) "N"
FROM ( SELECT userId , examId ,
score,
row_number() OVER (PARTITION BY userId order by score desc , created asc ) as rn
FROM StudentOwnClass m
INNER JOIN hearanswer n
ON m.classesId = #{classesId} AND m.studentId = n.userId AND examId = #{examId} and m.areaId=#{areaid} and n.areaId=#{areaid}
) a
right join stu on stu.userId = a.userId and rn=1
</select>
</mapper>