226 lines
9.1 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="FinishLessonStat">
<insert id="insertFinishLessonStat" parameterType="FinishLessonStat">
INSERT INTO FinishLessonStat ( uid, unitId, content, lessonCount,
completeCount, created, howmuch, maxScore, avgScore , areaid )
Values ( #{uid}, #{unitId}, #{content}, #{lessonCount},
#{completeCount},current_timestamp, #{howmuch}, #{maxScore},
#{avgScore} , #{areaid} )
</insert>
<update id="updateFinishLessonStat" parameterType="FinishLessonStat">
UPDATE FinishLessonStat
SET uid = #{uid}, unitId = #{unitId}, content = #{content},
lessonCount = #{lessonCount}, completeCount = #{completeCount},
created = #{created}, howmuch = #{howmuch},
maxScore = #{maxScore}, avgScore = #{avgScore} , areaid = #{areaid}
WHERE uid=#{uid} and areaid = #{areaid}
</update>
<select id="getFinishLessonStatByKey" parameterType="java.util.Map" resultType="FinishLessonStat">
SELECT uid , unitId , content , lessonCount , completeCount ,
created , howmuch , maxScore , avgScore , areaid
FROM FinishLessonStat
WHERE uid=#{uid} and unitId = #{unitId} and areaid = #{areaid}
</select>
<select id="getFinishLessonStatsCountByUid" parameterType="java.util.Map" resultType="Integer">
SELECT count(*) as howmuch
FROM FinishLessonStat
WHERE uid=#{uid} and areaid = #{areaid}
</select>
<select id="getFinishLessonStatsByUid" parameterType="java.util.Map" resultType="FinishLessonStat">
SELECT uid , unitId , content , lessonCount , completeCount ,
created , howmuch , maxScore , avgScore , areaid
FROM FinishLessonStat
WHERE uid=#{uid} and areaid = #{areaid}
<if test="pageSize!=null">
limit #{pageSize}
</if>
<if test="offset!=null">
offset #{offset}
</if>
</select>
<select id="getFinishLessonStatsCountByUnitId" parameterType="java.lang.Integer" resultType="Integer">
SELECT count(*) as howmuch
FROM FinishLessonStat
WHERE unitId=#{unitId}
</select>
<select id="getFinishLessonStatsByUnitId" parameterType="java.util.Map" resultType="FinishLessonStat">
SELECT uid , unitId , content , lessonCount , completeCount ,
created , howmuch , maxScore , avgScore , areaid
FROM FinishLessonStat
WHERE unitId=#{unitId}
ORDER BY finishLessonStatId desc
<if test="pageSize!=null">
limit #{pageSize}
</if>
<if test="offset!=null">
offset #{offset}
</if>
</select>
<delete id="deleteOldFinishLessons" parameterType="java.util.List">
<!-- delete from FinishLessonStat where 1=0
<iterate >
<![CDATA[
or (uid = #{item.uid} and unitid = #{item.unitId})
]]>
</iterate> -->
with temp as ( select distinct a.uid , b.parentId as unitId , a.areaId
from ( select uid , objectId , areaId
from Achivement
where achivetype = 'L'
and pointcasetype in ( 5, 6 , 7 , 8 )
and created &gt; current_date - interval '1 day'
and created &lt; current_date
) as a
inner join Lesson b
on a.objectId = b.lessonId )
DELETE FROM FinishLessonStat m
USING temp
WHERE m.uid = temp.uid and m.unitId = temp.UnitId
</delete>
<insert id="insertNewFinishLessons" parameterType="java.util.List">
<!-- Insert into FinishLessonStat ( uid , unitId , content , lessonCount ,
completeCount , created , howmuch , maxScore , avgScore , areaid )
select l.uid , l.unitId , m.lessonName , n.lessonCount , l.finishCount ,
current_timestamp , l.howmuch , l.maxScore , l.avgScore , l.areaid
from
( select a.uid , c.parentId as unitId , count( distinct c.lessonId ) as finishCount ,
count(*) as howmuch , max( score ) as maxScore , avg( score ) as avgScore , a.areaid
from Achivement a
inner join Lesson c
on a.achiveType = 'L' and a.pointCaseType in ( 5, 6 ,7 , 8 )
and a.objectId = c.lessonId
group by a.uid , c.parentId , a.areaid) l
inner join Lesson m
on l.unitId = m.lessonId
inner join ( select parentId , count(*) as lessonCount
from Lesson
group by parentId ) n
on l.unitId = n.parentId
where 1=0
<iterate >
<![CDATA[
or (uid = #{item.uid} and unitid = #{item.unitId})
]]>
</iterate> -->
with temp as ( select distinct a.uid , b.parentId as unitId , a.areaId
from ( select uid , objectId , areaId
from Achivement
where achivetype = 'L'
and pointcasetype in ( 5, 6 , 7 , 8 )
and created &gt; current_date - interval '1 day'
and created &lt; current_date
) as a
inner join Lesson b
on a.objectId = b.lessonId )
insert into FinishLessonStat ( uid , unitid , content , lessoncount , completecount ,
created , howmuch , maxscore , avgscore , areaId )
select p.uid , p.unitid , s.lessonname as content ,r.lessoncount , p.completecount ,
current_timestamp , p.howmuch , p.maxscore , p.avgscore ,p.areaId
from ( select temp.uid , temp.unitId , temp.areaid ,
count( distinct a.objectId ) as completecount,
count(a.*) as howmuch , max(a.score ) as maxscore , round(avg(a.score)) as avgscore
from temp
inner join Lesson b
on temp.unitId = b.parentId
inner join Achivement a
on temp.uid = a.uid and b.lessonId = a.objectId
and a.achivetype = 'L'
and a.pointCaseType in ( 5,6 ,7 ,8)
group by temp.uid , temp.unitId , temp.areaId ) as p
inner join ( select parentId as unitId , count(*) as lessonCount
from lesson
where LessonType = 'L' and status = 1
group by parentId ) as r
on p.unitId = r.unitid
inner join Lesson s
on p.unitId = s.lessonId
</insert>
<select id="lessonQueryStatForUser" parameterType="java.util.Map" resultType="FinishLessonStat">
Select b.uid , a.lessonId as unitId , a.lessonName as content ,
b.lessonCount , b.completeCount ,b.created ,b.howmuch ,b.maxScore ,
b.avgScore , b.areaid
from Lesson a
left join FinishLessonStat 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="getFinishLessonsByYes" resultType="FinishLessonStat">
select l.uid , l.unitId , m.lessonName , n.lessonCount , l.finishCount ,
current_timestamp , l.howmuch , l.maxScore , l.avgScore , l.areaid
from
( select a.uid , c.parentId as unitId , count( distinct c.lessonId ) as finishCount ,
count(*) as howmuch , max( score ) as maxScore , avg( score ) as avgScore , a.areaid
from Achivement a
inner join Lesson c
on a.achiveType = 'L' and a.pointCaseType in ( 5, 6 ,7 , 8 )
and a.objectId = c.lessonId
where a.created &lt; current_date and a.created &gt; current_date - interval '1 day'
group by a.uid , c.parentId , a.areaid) l
inner join Lesson m
on l.unitId = m.lessonId
inner join ( select parentId , count(*) as lessonCount
from Lesson
group by parentId ) n
on l.unitId = n.parentId
</select>
<select id="getFinishLessonByYesterday" resultType="FinishLessonStat">
with stat as ( select distinct a.uid , c.parentId as unitId , a.areaid
from Achivement a
inner join Lesson c
on a.achiveType = 'L' and a.pointCaseType in ( 5, 6 ,7 , 8 )
and a.objectId = c.lessonId
where a.created &lt; current_date
and a.created &gt; current_date - interval '1 day' )
select st.uid , st.unitId , l.lessonname as content ,
m.lessonCount , av.completeCount , current_timestamp ,
av.howmuch , av.maxScore , av.avgScore , st.areaid
from Stat as st
inner join ( select parentId as unitId , count(*) as lessonCount
from Lesson
where lessonType = 'L' and status = 1
group by parentId ) as m
on st.unitId = m.unitId
inner join Lesson l
on st.unitId = l.lessonId
inner join ( select a.uid , c.parentId as unitId ,
count( distinct a.objectId ) as completeCount ,
count( a.objectId ) as howmuch ,
max( a.score ) as maxScore ,
avg( a.score ) as avgScore
from Achivement a
inner join Lesson c
on a.uid in ( select uid from stat )
and a.achiveType = 'L' and a.pointCaseType in ( 5, 6 ,7 , 8 )
and a.objectId = c.lessonId
where a.created &lt; current_date
group by a.uid , c.parentId ) av
on st.uid = av.uid and st.unitId = av.unitId
</select>
</mapper>