156 lines
5.6 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="WrongBookDao" >
<insert id="insertWrongBook" parameterType="WrongBook">
INSERT INTO WrongBook
( uid, guid,partType,examPaperId,examAnswerId,origiScore,trueScore,multiQues,isCorrect,created,examId)
Values
( #{uid}, #{guid},#{partType},#{examPaperId},#{examAnswerId},#{origiScore},#{trueScore},#{multiQues,javaType=Object,jdbcType=OTHER,typeHandler=com.spoken.api.tools.JsonTypeHandler},#{isCorrect},#{created},#{examId} )
</insert>
<update id="updateWrongBook" parameterType="WrongBook">
UPDATE WrongBook SET
partType=#{partType},examPaperId=#{examPaperId},examAnswerId=#{examAnswerId},origiScore=#{origiScore},trueScore=#{trueScore},multiQues=#{multiQues,javaType=Object,jdbcType=OTHER,typeHandler=com.spoken.api.tools.JsonTypeHandler},isCorrect=#{isCorrect},created=#{created}
where guid=#{guid} and uid=#{uid} and examId=#{examId}
</update>
<select id="getWrongBook" parameterType="java.util.Map" resultType="WrongBook">
SELECT uid, guid,partType,examPaperId,examAnswerId,origiScore,trueScore,multiQues,isCorrect,created,examId
FROM WrongBook WHERE guid=#{guid} and uid=#{uid} and examId=#{examId}
</select>
<select id="getWrongBooks" parameterType="java.util.Map" resultType="WrongBookDto">
with temp as (
SELECT w.uid, w.guid,w.examId,parttype,w.exampaperid,examanswerid,
iscorrect,origiscore,created,truescore,quesType,
rank() over (partition by w.guid order by created desc , examanswerid desc ) as mm
FROM WrongBook w where uid=#{uid}
<if test="questionType=='read'">
and partType in (20001,20002)
</if>
<if test="questionType=='hear'">
and partType not in (20001,20002)
</if>
<if test="partTypes!=null">
and partType in
<foreach collection="partTypes" item="item" separator="," open="(" close=")">
#{item}
</foreach>
</if>
<if test="quesTypes!=null">
and quesType in
<foreach collection="quesTypes" item="item" separator="," open="(" close=")">
#{item}
</foreach>
</if>
)
select w.uid, w.guid,w.partType,w.examPaperId,w.examAnswerId,w.origiScore,
w.trueScore,w.isCorrect,w.created,w.examId,w.quesType
from temp w where mm=1
<if test="isCorrect!=null">
and w.isCorrect=#{isCorrect}
</if>
order by created desc ,guid
<if test="pageSize!=null">
LIMIT #{pageSize}
</if>
<if test="offset!=null">
OFFSET #{offset}
</if>
</select>
<select id="getWrongBooksCount" parameterType="java.util.Map" resultType="java.lang.Integer">
with temp as (
SELECT w.uid, w.guid,parttype,
iscorrect,
rank() over (partition by w.guid order by created desc , examanswerid desc ) as mm
FROM WrongBook w where uid=#{uid}
<if test="questionType=='read'">
and partType in (20001,20002)
</if>
<if test="questionType=='hear'">
and partType not in (20001,20002)
</if>
<if test="partTypes!=null">
and partType in
<foreach collection="partTypes" item="item" separator="," open="(" close=")">
#{item}
</foreach>
</if>
<if test="quesTypes!=null">
and quesType in
<foreach collection="quesTypes" item="item" separator="," open="(" close=")">
#{item}
</foreach>
</if>
)
SELECT count(distinct guid)
FROM temp w where w.mm=1
<if test="isCorrect!=null">
and w.isCorrect=#{isCorrect}
</if>
</select>
<update id="updateWrongBookIsCorrect" parameterType="java.util.Map">
UPDATE WrongBook SET
isCorrect=#{isCorrect},created=now(),trueScore=#{trueScore},multiQues=#{multiQues,javaType=Object,jdbcType=OTHER,typeHandler=com.spoken.api.tools.JsonTypeHandler}
where guid=#{guid} and uid=#{uid}
</update>
<select id="getWrongBookStatistics" parameterType="java.util.Map" resultType="java.util.Map">
with temp as (
SELECT w.uid, w.guid,parttype,
iscorrect,created,quesType,
rank() over (partition by w.guid order by created desc , examanswerid desc ) as mm
FROM WrongBook w where uid=#{uid}
<if test="questionType=='read'">
and partType in (20001,20002)
</if>
<if test="questionType=='hear'">
and partType not in (20001,20002)
</if> )
SELECT count(guid) as total,partType as "partType",quesType as "quesType",
count (case when isCorrect='0' then guid else null end ) as "notCorrectCount",
count (case when isCorrect='1' and created&gt;= current_date and created&lt;(current_date + interval '1 day') then guid else null end ) as "todayCorrectCount"
FROM temp w where w.mm=1
<if test="partType!=null">
and w.parttype=#{partType}
</if>
group by parttype,quesType
</select>
<select id="getWrongBookTitleByGuid" resultType="java.util.Map" parameterType="java.util.Map">
select e.title,w.examId as "examId" from wrongbook w inner join
exam e on e.examId=w.examId and guid=#{guid} and uid=#{uid} order by w.created desc
</select>
</mapper>