2026-03-10 14:30:24 +08:00

169 lines
6.5 KiB
XML

<?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="FinishwordsStat">
<insert id="insertFinishwordsStat" parameterType="FinishwordsStat">
INSERT INTO FinishwordsStat ( uid, unitId, content, wordsCount, completeCount, created, howmuch, maxScore, avgScore , areaid ) Values ( #{uid}, #{unitId}, #{content}, #{wordsCount}, #{completeCount},current_timestamp, #{howmuch}, #{maxScore}, #{avgScore} , #{areaid} )
</insert>
<update id="updateFinishwordsStat" parameterType="FinishwordsStat">
UPDATE FinishwordsStat SET
uid = #{uid}, unitId = #{unitId}, content = #{content}, wordsCount = #{wordsCount}, completeCount = #{completeCount}, created = #{created}, howmuch = #{howmuch}, maxScore = #{maxScore}, avgScore = #{avgScore} , areaid= #{areaid}
where uid=#{uid} and unitId=#{unitId} and areaid = #{areaid}
</update>
<select id="getFinishwordsStatByKey" parameterType="java.util.Map" resultType="FinishwordsStat">
SELECT uid , unitId , content , wordsCount , completeCount , created , howmuch , maxScore , avgScore , areaid
FROM FinishwordsStat WHERE uid=#{uid} and unitId=#{unitId} and areaid = #{areaid}
</select>
<select id="getSeqFinishwordsStat" resultType="Integer" useCache="false" flushCache="true">
SELECT nextval('seq_finishwordsStatId') ;
</select>
<select id="getFinishwordsStatsCountByUid" parameterType="java.util.Map" resultType="Integer">
SELECT count(*) as howmuch from FinishwordsStat
WHERE uid=#{uid} and areaid = #{areaid}
</select>
<select id="getFinishwordsStatsByUid" parameterType="java.util.Map" resultType="FinishwordsStat">
SELECT uid , unitId , content , wordsCount , completeCount , created , howmuch , maxScore , avgScore , areaid
FROM FinishwordsStat
WHERE uid=#{uid} and areaid = #{areaid}
<if test="pageSize!=null">
limit #{pageSize}
</if>
<if test="offset!=null">
offset #{offset}
</if>
</select>
<select id="getFinishwordsStatsCountByUnitId" parameterType="java.lang.Integer" resultType="Integer">
SELECT count(*) as howmuch from FinishwordsStat
WHERE unitId=#{unitId}
</select>
<select id="getFinishwordsStatsByUnitId" parameterType="java.util.Map" resultType="FinishwordsStat">
SELECT uid , unitId , content , wordsCount , completeCount , created , howmuch , maxScore , avgScore , areaid
FROM FinishwordsStat
WHERE unitId=#{unitId}
ORDER BY finishwordsStatId desc
<if test="pageSize!=null">
limit #{pageSize}
</if>
<if test="offset!=null">
offset #{offset}
</if>
</select>
<delete id="deleteOldFinishWordss" parameterType="java.util.List">
with temp as ( select distinct a.uid , b.lessonId as unitId , a.areaId
from ( select uid , wordsId , areaId
from WordAchive
where
created &gt; current_date - interval '1 day'
and created &lt; current_date
) as a
inner join words b
on a.wordsId = b.wordsId )
DELETE FROM FinishWordsStat m
USING temp
WHERE m.uid = temp.uid and m.unitId = temp.UnitId
</delete>
<insert id="insertNewFinishWordss" parameterType="java.util.List">
with temp as ( select distinct a.uid , b.lessonId as unitId , a.areaId
from ( select uid , wordsId , areaId
from WordAchive
where
created &gt; current_date - interval '1 day'
and created &lt; current_date
) as a
inner join words b
on a.wordsId = b.wordsId )
insert into FinishWordsStat ( uid , unitid , content , wordscount ,
completecount , created , howmuch , maxscore , avgscore , areaid )
select p.uid , p.unitId , s.lessonname as content , r.wordsCount ,
p.completeCount , current_timestamp , howmuch , maxScore , avgScore , areaid
from ( select temp.uid , temp.unitId , temp.areaid , count( distinct a.wordsId ) as completecount,
count(a.wordachiveid) as howmuch , max(a.score ) as maxscore ,
round(avg(a.score)) as avgscore
from temp
inner join words b
on temp.unitId = b.lessonId
inner join WordAchive a
on temp.uid = a.uid and b.wordsId = a.wordsId
group by temp.uid , temp.unitId , temp.areaId ) as p
inner join ( select lessonId as unitId , count(*) as wordsCount
from Words
group by lessonId ) as r
on p.unitId = r.unitid
inner join Lesson s
on p.unitId = s.lessonId
</insert>
<select id="wordsQueryStatForUser" parameterType="java.util.Map" resultType="FinishwordsStat">
Select b.uid , a.lessonId as unitId , a.lessonName as content , b.wordsCount ,
b.completeCount ,b.created ,b.howmuch ,b.maxScore , b.avgScore , b.areaid
from Lesson a
left join FinishWordsStat b
on b.uid = #{uid} and a.lessonId = b.unitId and b.areaid=#{areaid}
where a.parentId = #{bookId}
order by a.orderId
</select>
<select id="getFinishWordsByYes" parameterType="java.util.Map" resultType="FinishwordsStat">
select l.uid , l.unitId , m.lessonName , n.wordsCount ,
l.finishCount , current_timestamp , l.howmuch , l.maxScore , l.avgScore , l.areaid
from
( select a.uid , b.lessonId as unitId , count( distinct b.wordsId ) as finishCount ,
count(*) as howmuch , max( score ) as maxScore , avg( score ) as avgScore , a.areaid
from WordAchive a
inner join Words b
on a.wordsId = b.wordsId
where a.created &lt; current_date and a.created &gt; current_date - interval '1 day'
group by a.uid , b.lessonId , a.areaid) l
inner join Lesson m
on l.unitId = m.lessonId
inner join ( select lessonId as unitId , count(*) as wordsCount
from Words
group by lessonId ) n
on l.unitId = n.unitId
</select>
<select id="finishWordsStatByDbFunc" resultType="Integer">
select f_FinishWordsStat( current_date - interval '1 day' ,
current_date - interval '0 day' )
</select>
</mapper>