460 lines
16 KiB
XML
Raw 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="Exam">
<insert id="insertExam" parameterType="Exam">
INSERT INTO Exam ( examId, examType, isRecommend, title, description,
examPaperCount, examPapers, created, startTime, endTime , isNetExam ,isOral,teacherId,status
<if test="assigntime != null">
,assigntime
</if>
<if test="type != null">
,type
</if>
)
Values ( #{examId}, #{examType}, #{isRecommend}, #{title}, #{description},
#{examPaperCount}, #{examPapers},current_timestamp, #{startTime}, #{endTime} , #{isNetExam} ,#{isOral},#{teacherId},#{status}
<if test="assigntime != null">
,#{assigntime}
</if>
<if test="type != null">
,#{type}
</if>
)
</insert>
<update id="updateExam" parameterType="Exam">
UPDATE Exam
SET examId = #{examId}, examType = #{examType}, isRecommend = #{isRecommend},
title = #{title}, description = #{description}, examPaperCount = #{examPaperCount},
examPapers = #{examPapers}, created = #{created}, startTime = #{startTime},
endTime = #{endTime} , isNetExam = #{isNetExam} ,isOral=#{isOral},teacherId=#{teacherId},status=#{status}
<if test="assigntime != null">
,assigntime =#{assigntime}
</if>
where examId=#{examId}
</update>
<select id="getExamByKey" parameterType="java.lang.Integer" resultType="Exam">
SELECT examId , examType , isRecommend , title , description , examPaperCount ,
examPapers , created , startTime , endTime , isNetExam, isOral, teacherId,status,assigntime
FROM Exam
WHERE examId=#{examId}
</select>
<select id="getExamByTeacherId" parameterType="java.util.Map" resultType="Exam">
SELECT e.examId , e.examType , e.isRecommend , e.title , e.description , e.examPaperCount ,
e.examPapers , e.created , e.startTime , e.endTime , e.isNetExam, e.isOral, e.teacherId,e.status,e.assigntime
FROM Exam as e inner join Admin as a on a.adminId = e.teacherId
WHERE e.status =1
<if test="teacherId != null ">
and e.teacherId=#{teacherId}
</if>
</select>
<select id="getSeqExam" resultType="Integer" useCache="false" flushCache="true">
SELECT nextval('seq_examId') ;
</select>
<select id="getExamsCountByClassesId" parameterType="java.util.Map" resultType="Integer">
SELECT COUNT(*)
FROM ClassOwnExam a
INNER join Exam b
ON a.classesId = #{classesId} and a.examId = b.examId
and b.isOral = #{isOral}
<if test="type != null">
and b.type = #{type}
</if>
<if test="examType!=null">
and b.examType = #{examType}
</if>
<if test="endTime!=null">
<![CDATA[
and b.endTime <= #{endTime}
]]>
</if>
<if test="startTime!=null">
<![CDATA[
and b.startTime >= #{startTime}
]]>
</if>
</select>
<select id="getExamsByClassesId" parameterType="java.util.Map" resultType="Exam">
SELECT b.examId , b.examType , b.isRecommend , b.title , b.description ,
b.examPaperCount , b.examPapers , b.created , b.startTime , b.endTime , b.isNetExam ,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="type != null">
and b.type = #{type}
</if>
<if test="examType!=null">
and b.examType = #{examType}
</if>
<if test="endTime!=null">
<![CDATA[
and b.endTime <= #{endTime}
]]>
</if>
<if test="startTime!=null">
<![CDATA[
and b.startTime >= #{startTime}
]]>
</if>
ORDER BY b.examId DESC
<if test="pageSize!=null">
limit #{pageSize}
</if>
<if test="offset!=null">
offset #{offset}
</if>
</select>
<select id="getPreviousExamsByTeacherId" parameterType="java.util.Map" resultType="ExamDto">
with temp as (
select e.examId,e.title,e.description,e.created,e.startTime,e.endTime,isOral,coe.classesId from exam e inner join
teacherownexam eox on e.examid=eox.examid and eox.teacherid=#{teacherId} and e.endTime&lt;now()
inner join classownexam coe on coe.examid = eox.examid
union
select h.examId,h.title,h.description,h.created,h.startTime,h.endTime,2 as isOral , coh.classesId from hearexam h
inner join classownhear coh on coh.examId = h.examId and teacherid=#{teacherId} and h.endTime&lt;now()
order by created desc,classesId,isOral
<if test="pageSize!=null">
limit #{pageSize}
</if>
<if test="offset!=null">
offset #{offset}
</if>
),
temp2 as(
select t.examid,count( distinct ea.userid )as howmuch,round( avg(ea.score)::numeric ,1 ) as
avgScore,t.classesId,isOral from examanswer ea
inner join temp t on ea.examid = t.examid and t.isOral!=2 and ea.areaId=#{areaId}
and ea.score&gt;0
inner join studentownclass sc on sc.classesId = t.classesId and sc.studentId=ea.userId and sc.status=1
and ea.userId!=#{teacherId}
group by t.examid,t.classesId,isOral
union
select t.examid,count( distinct ea.userid )as howmuch,round( avg(ea.score)::numeric ,1 ) as
avgScore,t.classesId ,isOral from hearanswer ea
inner join temp t on ea.examid = t.examid and t.isOral=2 and ea.areaId=#{areaId}
and ea.score&gt;0
inner join studentownclass sc on sc.classesId=t.classesId and sc.studentId=ea.userId and sc.status=1
and ea.userId!=#{teacherId}
group by t.examid,t.classesId,isOral )
select t.examId,t.title,t.description,t.created,t.startTime,t.endTime,t.isOral,avgScore,case when t2.howmuch&gt;0
then t2.howmuch else 0 end as howmuch,t.classesId from temp t left join temp2 t2 on t.examid=t2.examid and t.isOral=t2.isOral and t.classesId=t2.classesId
order by created desc
</select>
<select id="getPreviousExamsCountByTeacherId" parameterType="java.lang.Long" resultType="java.lang.Integer">
with examcount as(
select count(toe.examid) howmuch from teacherownexam toe inner join classownexam coe on
teacherid=#{teacherId} and toe.examId = coe.examid
inner join exam e on e.examId=toe.examid and e.endTime&lt;now() ),
hearcount as(
select count(coh.examId) howmuch from hearexam he inner join classownhear coh on teacherid=#{teacherId}
and he.examid=coh.examid and he.endTime&lt;now())
select e.howmuch+h.howmuch from examcount e,hearcount h
</select>
<select id="getNewHearExamsCountByClassesId" parameterType="java.util.Map" resultType="Integer">
with temp as (SELECT COUNT(*) howmuch
FROM v_hearexam a
INNER join ClassOwnhear b
ON b.classesId = #{classesId} and a.examId = b.examId and a.isOral=-1
<if test="type != null">
and a.type = #{type}
</if>
),
temp1 as (SELECT COUNT(*) howmuch
FROM v_hearexam a
INNER join ClassOwnexam b
ON b.classesId = #{classesId} and a.examId = b.examId and isOral=2
<if test="type != null">
and a.type = #{type}
</if>
)
select t.howmuch+t1.howmuch from temp t,temp1 t1
</select>
<select id="getNewHearExamsByClassesId" parameterType="java.util.Map" resultType="Exam">
select h.examId , h.examType , h.isRecommend , h.title , h.description ,
h.examPaperCount , h.examPapers , h.created , h.startTime , h.endTime ,
h.isNetExam , h.isOral,1 as status,h.type
FROM v_hearexam h inner join classownhear c on c.examid = h.examid and c.classesId=#{classesId} and h.isOral=-1
<if test="type != null">
and h.type = #{type}
</if>
union
select
h.examId , h.examType , h.isRecommend , h.title , h.description ,
h.examPaperCount , h.examPapers , h.created , h.startTime , h.endTime ,
h.isNetExam , h.isOral,e.status,h.type
FROM v_hearexam h inner join classownexam c on c.examid = h.examid and c.classesId=#{classesId} and isOral=2
inner join exam e on h.examid=e.examid
<if test="type != null">
and h.type = #{type}
</if>
order by created desc ,examId desc,isOral
<if test="pageSize!=null">
limit #{pageSize}
</if>
<if test="offset!=null">
offset #{offset}
</if>
</select>
<select id="getNewPreviousExamsByTeacherId" parameterType="java.util.Map" resultType="ExamDto">
with temp as (
select e.examId,e.title,e.description,e.created,e.startTime,e.endTime,isOral,coe.classesId from exam e inner join
teacherownexam eox on e.examid=eox.examid and eox.teacherid=#{teacherId} and e.endTime&lt;now()
inner join classownexam coe on coe.examid = eox.examid
union
select h.examId,h.title,h.description,h.created,h.startTime,h.endTime,-1 as isOral , coh.classesId from hearexam h
inner join classownhear coh on coh.examId = h.examId and teacherid=#{teacherId} and h.endTime&lt;now()
order by created desc,classesId,isOral
<if test="pageSize!=null">
limit #{pageSize}
</if>
<if test="offset!=null">
offset #{offset}
</if>
),
temp2 as(
select t.examid,count( distinct ea.userid )as howmuch,round( avg(ea.score)::numeric ,1 ) as
avgScore,t.classesId,isOral from examanswer ea
inner join temp t on ea.examid = t.examid and t.isOral&gt;=0 and ea.areaId=#{areaId}
and ea.score&gt;0
inner join studentownclass sc on sc.classesId = t.classesId and sc.studentId=ea.userId and sc.status=1
and ea.userId!=#{teacherId}
group by t.examid,t.classesId,isOral
union
select t.examid,count( distinct ea.userid )as howmuch,round( avg(ea.score)::numeric ,1 ) as
avgScore,t.classesId ,isOral from hearanswer ea
inner join temp t on ea.examid = t.examid and t.isOral=-1 and ea.areaId=#{areaId}
and ea.score&gt;0
inner join studentownclass sc on sc.classesId=t.classesId and sc.studentId=ea.userId and sc.status=1
and ea.userId!=#{teacherId}
group by t.examid,t.classesId,isOral )
select t.examId,t.title,t.description,t.created,t.startTime,t.endTime,t.isOral,avgScore,case when t2.howmuch&gt;0
then t2.howmuch else 0 end as howmuch,t.classesId from temp t left join temp2 t2 on t.examid=t2.examid and t.isOral=t2.isOral and t.classesId=t2.classesId
order by created desc
</select>
<select id="getExamsByTeacherId" parameterType="java.util.Map" resultType="Exam">
select e.examId,e.title,e.description,e.created,e.startTime,e.endTime,isOral,e.examType from exam e
inner join
teacherownexam eox on e.examid=eox.examid and eox.teacherid=#{teacherId}
<if test="nowTime!=null">
and e.endTime&gt;now()
</if>
<if test="examType!=null">
and e.examType=#{examType}
</if>
union
select h.examId,h.title,h.description,h.created,h.startTime,h.endTime,-1 as isOral,h.examType from hearexam h
where teacherid=#{teacherId}
<if test="nowTime!=null">
and h.endTime&gt;now()
</if>
<if test="examType!=null">
and h.examType=#{examType}
</if>
order by created desc,isOral
<if test="pageSize!=null">
limit #{pageSize}
</if>
<if test="offset!=null">
offset #{offset}
</if>
</select>
<select id="getExamsByTeacherIdCount" parameterType="java.util.Map" resultType="Exam">
with temp1 as(
select count(e.examId) examCount from exam e
inner join
teacherownexam eox on e.examid=eox.examid and eox.teacherid=#{teacherId}
<if test="nowTime!=null">
and e.endTime&gt;now()
</if>
<if test="examType!=null">
and e.examType=#{examType}
</if>),
temp2 as(select count(h.examId) hearCount from hearexam h
where teacherid=#{teacherId}
<if test="nowTime!=null">
and h.endTime&gt;now()
</if>
<if test="examType!=null">
and h.examType=#{examType}
</if>)
select t1.examCount+t2.hearCount from temp1 t1,temp2 t2
</select>
<select id="getAllExamsByStudentId" parameterType="java.util.Map" resultType="Exam">
select e.examId,e.title,e.description,e.created,e.startTime,e.endTime,isOral,e.examType from exam e
inner join
classownexam c on e.examid = c.examid
inner join studentownclass s on c.classesid=s.classesid and s.status=1 and s.studentId=#{studentId}
inner join classes cs on cs.classesid=s.classesid and cs.status=1
<if test="nowTime!=null">
and e.endTime&gt;now()
</if>
<if test="examType!=null">
and e.examType=#{examType}
</if>
union
select h.examId,h.title,h.description,h.created,h.startTime,h.endTime,-1 as isOral,h.examType from hearexam h
inner join
classownhear c on h.examid = c.examid
inner join studentownclass s on c.classesid=s.classesid and s.status=1 and s.studentId=#{studentId}
inner join classes cs on cs.classesid=s.classesid and cs.status=1
<if test="nowTime!=null">
and h.endTime&gt;now()
</if>
<if test="examType!=null">
and h.examType=#{examType}
</if>
order by created desc,examid desc,isOral
<if test="pageSize!=null">
limit #{pageSize}
</if>
<if test="offset!=null">
offset #{offset}
</if>
</select>
<select id="getAllExamsByStudentIdCount" parameterType="java.util.Map" resultType="Exam">
with temp1 as(
select count(e.examId) examCount from exam e
inner join
classownexam c on e.examid = c.examid
inner join studentownclass s on c.classesid=s.classesid and s.status=1 and s.studentId=#{studentId}
inner join classes cs on cs.classesid=s.classesid and cs.status=1
<if test="nowTime!=null">
and e.endTime&gt;now()
</if>
<if test="examType!=null">
and e.examType=#{examType}
</if>),
temp2 as(select count(h.examId) hearCount from hearexam h
inner join
classownhear c on h.examid = c.examid
inner join studentownclass s on c.classesid=s.classesid and s.status=1 and s.studentId=#{studentId}
inner join classes cs on cs.classesid=s.classesid and cs.status=1
<if test="nowTime!=null">
and h.endTime&gt;now()
</if>
<if test="examType!=null">
and h.examType=#{examType}
</if>
)
select t1.examCount+t2.hearCount from temp1 t1,temp2 t2
</select>
<select id="getExamPaperNameByExamPaperIds" parameterType="java.util.List" resultType="java.util.Map">
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="getHearPaperNameByHearPaperIds" parameterType="java.util.List" resultType="java.util.Map">
select hearpaperid as "paperId" ,title from hearpaper where hearpaperid
in
<foreach collection="list" index="index" item="item" separator="," close=")" open="(">
#{item}
</foreach>
</select>
<select id="findExamNumByTeacherId" parameterType="java.util.Map" resultType="java.lang.Integer">
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} and #{endTime}
</select>
<select id="findClassStudentExamNum" parameterType="java.util.Map" resultType="java.lang.Integer">
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}and #{endTime}
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>
</mapper>