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

685 lines
23 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="SuperHero">
<select id="netSuperHeros" parameterType="java.util.Map" resultType="SuperHero">
<!-- with temp1 as ( select uid , avg(score) as avgScore ,
sum(score) as totalscore , count(objectId) as numCount
from achivement
where pointcasetype in (3,5,6,7,8)
<![CDATA[
and created > ( current_date + interval '-1 month')
and created < ( current_date +interval '-0 day')
]]>
group by uid ) ,
temp2 as ( select a.uid , a.avgScore , a.totalscore , a.numCount
from temp1 a
inner join Student b
on a.uid = b.studentId and b.status =1
<![CDATA[
where numCount > 1 and avgScore > 0
]]>
order by a.numCount desc, a.avgScore desc , a.totalScore desc ,a.uid desc
<dynamic>
<isNotEmpty prepend=" LIMIT " property="pageSize">
#{pageSize}
</isNotEmpty>
<isNotEmpty prepend=" OFFSET " property="offset">
#{offset}
</isNotEmpty>
</dynamic> )
select s.uid , m.truename , d.schoolId , d.schoolName , s.avgScore ,
'' as userLevel , '' as levelName , 0 as isFollowed , s.numCount
from temp2 s
inner join Student m
on s.uid = m.studentId and m.status =1
inner join StudentOwnClass n
on s.uid = n.studentId
inner join Classes c
on n.classesId = c.classesId and c.classType = 1
inner join School d
on c.schoolId = d.schoolId
order by s.numCount desc, s.avgScore desc , s.totalScore desc ,s.uid desc -->
select s.uid , s.truename , s.schoolId , s.schoolName , s.avgScore ,
'' as userLevel , '' as levelName , 0 as isFollowed , s.numCount
from mv_superhero s
order by s.numCount desc, s.avgScore desc , s.totalScore desc ,s.uid desc
<if test="pageSize!=null">
LIMIT #{pageSize}
</if>
<if test="offset!=null">
OFFSET #{offset}
</if>
</select>
<select id="netSuperHerosCount" resultType="Integer">
<!-- select count(*)
From ( select s.uid , s.avgScore , m.truename , c.schoolId , m.lastsignIn , totalScore
from ( select uid , avg(score) as avgScore ,sum(score) as totalscore , count(distinct(objectId)) from achivement
where pointcasetype in (3,5,6,7,8)
<![CDATA[
and created > (now() + interval '-1 month')
and created < ( current_date +interval '-0 day')
group by uid ) s
inner join Student m
on s.uid = m.studentId
inner join StudentOwnClass n
on s.uid = n.studentId
inner join Classes c
on n.classesId = c.classesId and c.classType = 1
where s.count > 1 and avgScore > 0
]]>
) a
inner join Student m
on a.uid = m.studentId
inner join StudentOwnClass b
on a.uid = b.studentId
inner join Classes c
on b.classesId = c.classesId and c.classType = 1
inner join School d
on c.schoolId = d.schoolId -->
select count(*)
from mv_superhero
</select>
<select id="classSuperHeros" parameterType="java.util.Map" resultType="SuperHero">
select a.uid , b.truename , 0 as schoolId , '' as schoolName , a.avgScore ,
a.userLevel , a.levelName , 0 as isFollowed
From ( select q.uid , q.totalScore / q.howmuch ::numeric as avgScore ,
userLevel , levelName
from StudentOwnClass p
inner join UserHonor q
on p.classesId = #{classesId} and p.studentId = q.uid
and p.areaId=#{areaId} and q.areaId=#{areaId}
where q.howmuch &gt; 1 and p.status =1
order by avgScore desc , q.howmuch desc
<if test="pageSize!=null">
LIMIT #{pageSize}
</if>
<if test="offset!=null">
OFFSET #{offset}
</if>
) a
inner join Student b
on a.uid = b.studentId and a.avgScore &gt; 0 and b.areaId=#{areaId}
order by a.avgScore desc ,a.uid
</select>
<select id="classSuperGoldens" parameterType="java.util.Map" resultType="SuperHero">
select a.uid , b.truename , 0 as schoolId , '' as schoolName , a.avgScore ,
a.userLevel , a.levelName , 0 as isFollowed
From ( select q.uid , q.goldmedalcount as avgScore ,
userLevel , levelName
from StudentOwnClass p
inner join UserHonor q
on p.classesId = #{classesId} and p.studentId = q.uid
where q.goldmedalcount &gt; 0 and p.status =1
order by q.goldmedalcount desc
<if test="pageSize!=null">
LIMIT #{pageSize}
</if>
<if test="offset!=null">
OFFSET #{offset}
</if>
) a
inner join Student b
on a.uid = b.studentId
order by a.avgScore desc,a.uid
</select>
<select id="classSuperFollows" parameterType="java.util.Map" resultType="SuperHero">
select a.uid , b.truename , 0 as schoolId , '' as schoolName , m.avgScore ,
a.userLevel , a.levelName , 0 as isFollowed
From ( select p.studentId , count(*) as avgScore
from StudentOwnClass p
inner join FollowShip q
on p.classesId = #{classesId} and p.studentId = q.beFollower
where p.status =1
group by p.studentId
order by avgScore desc , p.studentId asc
<if test="pageSize!=null">
LIMIT #{pageSize}
</if>
<if test="offset!=null">
OFFSET #{offset}
</if>
) m
inner join UserHonor a
on m.studentId = a.uid
inner join Student b
on a.uid = b.studentId
order by m.avgScore desc,a.uid
</select>
<select id="netSuperVoices" parameterType="java.util.Map" resultType="SuperVoice">
select a.uid , a.truename , a.schoolId , a.schoolName , a.voice , a.created ,
0 as isFollowed ,a.score , 0 as bookId , '' as bookName , 0 as unitId ,
'' as unitName , 0 as lessonId , '' as lessonName
from mv_supervoice a
order by a.score desc , a.created desc
<if test="pageSize!=null">
LIMIT #{pageSize}
</if>
<if test="offset!=null">
OFFSET #{offset}
</if>
</select>
<select id="netSuperVoicesCount" resultType="Integer">
select count(*)
from mv_supervoice
<!-- select count(distinct(a.uid))
from ( select p.uid , p.score , p.uuid , r.classesId , r.schoolId , p.created
from Achivement p
inner join StudentOwnClass q
<![CDATA[
on p.pointcasetype = 5 and length( p.uuid ) > 0
and p.achiveType = 'L' and p.uid = q.studentId
inner join Classes r
on q.classesId = r.classesId and r.classType = 1
inner join (select max(achivementid) as achivementid, uid , max(score) from Achivement a where pointcasetype = 5 and length( uuid ) > 0
and achiveType = 'L' and created > (now() + interval '-1 month')
and created < ( current_date +interval '-0 day') group by uid) m on p.achivementid = m.achivementid
where p.created > (now() + interval '-1 month')
and p.created < ( current_date +interval '-0 day')
]]>
) a
inner join School b
on a.schoolId = b.schoolId
inner join Student c
on a.uid = c.studentId -->
</select>
<select id="classSuperVoices" parameterType="java.util.Map" resultType="SuperVoice">
<!-- select a.uid , 0 as schoolId , '' as schoolName , a.uuid as voice , a.created ,
0 as isFollowed , a.score ,
d.lessonId as bookId , d.lessonName as bookName ,
c.lessonId as unitId , c.lessonName as unitName ,
b.lessonId , b.lessonName
from ( select p.uid , p.score , p.uuid , p.objectId , p.created
from StudentOwnClass q
inner join Achivement p
on q.classesId = #{classesId} and q.studentId = p.uid
<![CDATA[
and length( p.uuid ) > 0 and p.achiveType = 'L'
and p.score >= 75
and p.pointCaseType = 5 and p.uid = q.studentId
]]>
where q.status =1
<isEqual prepend="and" property="timeType" compareValue="month">
<![CDATA[
p.created > ( current_date + interval '-1 month')
and p.created < ( current_date +interval '-0 day')
]]>
</isEqual>
<isEqual prepend="and" property="timeType" compareValue="week">
<![CDATA[
p.created > ( current_date + interval '-1 week')
and p.created < ( current_date +interval '-0 day')
]]>
</isEqual>
) a
inner join Lesson b
on a.objectId = b.lessonId
inner join Lesson c
on b.parentId = c.lessonId
inner join Lesson d
on c.parentId = d.lessonId
order by a.score desc , a.created desc
<dynamic>
<isNotEmpty prepend=" LIMIT " property="pageSize">
#{pageSize}
</isNotEmpty>
<isNotEmpty prepend=" OFFSET " property="offset">
#{offset}
</isNotEmpty>
</dynamic> -->
<!-- with temp as ( select p.uid , p.score , p.uuid , p.objectId , p.created
from StudentOwnClass q
inner join mv_ClassVoice p
on q.classesId = #{classesId} and q.studentId = p.uid
where q.status =1
<if test='timeType == "week"'>and
p.created &gt; ( current_date + interval '-1 week')
</if>
order by p.score desc , p.created desc
<if test="pageSize!=null">
LIMIT #{pageSize}
</if>
<if test="offset!=null">
OFFSET #{offset}
</if>
)
select a.uid , 0 as schoolId , '' as schoolName , a.uuid as voice , a.created ,
0 as isFollowed , a.score , d.lessonId as bookId , d.lessonName as bookName ,
c.lessonId as unitId , c.lessonName as unitName , b.lessonId , b.lessonName
from temp a
inner join Lesson b
on a.objectId = b.lessonId
inner join Lesson c
on b.parentId = c.lessonId
inner join Lesson d
on c.parentId = d.lessonId
order by a.score desc , a.created desc -->
with temp as ( select p.uid , p.score , p.uuid , p.objectId , p.created
from mv_ClassVoice p
where p.classesId = #{classesId}
<if test='timeType == "week"'>and
p.created &gt; ( current_date + interval '-1 week')
</if>
order by p.created desc ,p.score desc
<if test="pageSize!=null">
LIMIT #{pageSize}
</if>
<if test="offset!=null">
OFFSET #{offset}
</if>
)
select a.uid , 0 as schoolId , '' as schoolName , a.uuid as voice , a.created ,
0 as isFollowed , a.score , d.lessonId as bookId , d.lessonName as bookName ,
c.lessonId as unitId , c.lessonName as unitName , b.lessonId , b.lessonName
from temp a
inner join Lesson b
on a.objectId = b.lessonId
inner join Lesson c
on b.parentId = c.lessonId
inner join Lesson d
on c.parentId = d.lessonId
order by a.created desc ,a.score desc
</select>
<select id="classSuperVoicesCount" parameterType="java.util.Map" resultType="Integer">
<!-- select count(*)
from StudentOwnClass q
inner join mv_ClassVoice p
on q.classesId = #{classesId} and q.studentId = p.uid
where q.status =1
<if test='timeType == "week"'>and
p.created &gt; ( current_date + interval '-1 week')
</if> -->
select count(*)
from mv_ClassVoice p
where p.classesId = #{classesId}
<if test='timeType == "week"'>and
p.created &gt; ( current_date + interval '-1 week')
</if>
</select>
<select id="privateVoicesCount" parameterType="java.util.Map" resultType="Integer">
select count(*)
from Achivement p
where length( p.uuid ) &gt; 0 and p.achiveType in ('L','S')
and p.pointCaseType = 5 and p.uid = #{uid} and p.areaId=#{areaId}
AND p.created &gt; #{startTime} and p.created &lt;= #{endTime};
</select>
<select id="privateVoices" parameterType="java.util.Map" resultType="PrivateSuperVoice">
with temp as(
select p.uid , p.score , p.uuid , p.objectId , p.created, p.achivementId,p.achiveType,p.pointCaseType
from Achivement p
where length( p.uuid ) &gt; 0 and p.achiveType in ('L','S')
AND p.created &gt; #{startTime} and p.created &lt;= #{endTime}
and p.pointCaseType in (5,7) and p.uid = #{uid} and p.areaId=#{areaId}
order by p.score desc , p.achivementId desc
<if test="pageSize!=null">
LIMIT #{pageSize}
</if>
<if test="offset!=null">
OFFSET #{offset}
</if>
)
select a.uid ,'' as truename , 0 as schoolId , '' as schoolName ,
a.uuid as voice , 0 as isFollowed , a.score , a.created ,
d.lessonId as bookId , d.lessonName as bookName ,
c.lessonId as unitId , c.lessonName as unitName ,
b.lessonId , b.lessonName , 0 as isNetMate,a.achiveType,a.pointCaseType as pointCaseType
from temp a
inner join Lesson b
on a.objectId = b.lessonId and a.achiveType='L'
inner join Lesson c
on b.parentId = c.lessonId
inner join Lesson d
on c.parentId = d.lessonId
union all
select a.uid ,'' as truename , 0 as schoolId , '' as schoolName ,
a.uuid as voice , 0 as isFollowed , a.score , a.created ,
b.materialId as bookId , b.title as bookName ,
b.materialId as unitId , '' as unitName ,
b.materialId , '' as title ,b.isNetMate,a.achiveType,a.pointCaseType as pointCaseType
from temp a
inner join Material b
on a.objectId = b.materialId and a.achiveType='S'
order by score desc,created desc
</select>
<select id="privateRaceVoices" parameterType="java.util.Map" resultType="SuperVoice">
select a.uid ,'' as truename , 0 as schoolId , '' as schoolName ,
a.uuid as voice , 0 as isFollowed , a.score , a.created ,
a.raceId as bookId, r.raceName as bookName ,
0 as unitId , '' as unitName ,
0 as lessonId , '' as lessonName,r.way,r.wayId
from ( select p.uid , p.score , p.uuid , p.raceId , p.created,p.raceScoreId
from RaceScore p
where length( p.uuid ) &gt; 0
and p.created &gt; #{startTime} and p.created &lt;= #{endTime}
and p.uid = #{uid} and p.areaId=#{areaId}
order by p.score desc , p.raceScoreId desc
<if test="pageSize!=null">
LIMIT #{pageSize}
</if>
<if test="offset!=null">
OFFSET #{offset}
</if>
) a
inner join race r on r.raceId = a.raceId
order by a.score desc , a.raceScoreId desc
</select>
<select id="privateRaceVoicesCount" parameterType="java.util.Map" resultType="Integer">
select count(*)
from RaceScore p
where length( p.uuid ) &gt; 0
and p.uid = #{uid} and p.areaId=#{areaId}
and p.created &gt; #{startTime} and p.created &lt;= #{endTime};
</select>
<select id="privateRaceRank" parameterType="long" resultType="java.util.HashMap">
select r.raceid , #{uid} as uid , sum( case when ( r.maxScore &gt; m.selfMaxScore )
and ( r.uid &lt;&gt; m.uid ) then 1 else 0 end ) + 1 as rank
from raceMaxScore r
inner join ( select raceId , uid , maxScore as selfMaxScore
from raceMaxScore
where uid =#{uid} ) m
on r.raceId = m.raceId
inner join student s on
r.uid=s.studentId and s.status = 1
group by r.raceId ;
</select>
<select id="classSuperHerosCount" parameterType="long" resultType="Integer">
select count(*)
from StudentOwnClass p
inner join UserHonor q
on p.classesId = #{classesId} and p.studentId = q.uid
where q.howmuch &gt; 1 and p.status =1
</select>
<select id="getLastYearGrowthRecordByUid" parameterType="java.util.Map" resultType="java.util.HashMap">
with
study as(
select uid,count(objectId) as studyCount ,max(score) as studyMaxScore from achivement
where pointcasetype in (3,5,6,7,8)
and created &gt; #{startTime} and created &lt;= #{endTime}
and uid = #{uid}
group by uid ),
assign as (
with temp as ( select objectId , created ,score from Achivement
where uid = #{uid} and pointcasetype in ( 3 , 5 , 6 , 7, 8)
and created &lt;= #{endTime} and created &gt; #{startTime}
)
SELECT so.studentid as uid, count(ac.objectId) as assignCount ,max(ac.score) assignMaxScore
FROM AssignDetail a
inner join Assignment s
on a.assignmentId = s.assignmentId and s.assignType='L' and s.status= 1
inner join AssignToClass t
on t.assignmentid = s.assignmentid
inner join Classes c
on c.classesid = t.classesid and c.status = 1
inner join StudentOwnClass so
on so.classesid = c.classesid and so.status = 1
and so.studentid = #{uid}
inner join temp ac
on ac.objectid = a.lessonId
and ac.created &lt;= s.endTime and ac.created &gt; s.startTime
group by so.studentid ),
exam as(
SELECT ea.userId uid, max(ea.score ) examMaxScore, count (ea.examId) examCount
FROM examanswer ea
inner join exam e
on ea.userId = #{uid} and ea.examid=e.examid
and ea.created&gt;e.starttime and ea.created &lt;=e.endtime
and ea.created&gt;#{startTime} and ea.created&lt;=#{endTime}
group BY ea.userId ),
hear as (
SELECT ea.userId uid, max(ea.score ) hearMaxScore, count (ea.examId) hearCount
FROM HearAnswer ea
inner join hearExam e
on ea.userId = #{uid} and ea.examid=e.examid
and ea.created&gt;e.starttime and ea.created &lt;=e.endtime
and ea.created&gt;#{startTime} and ea.created&lt;=#{endTime}
group BY ea.userId ),
race as (
select uid ,count(rs.raceId) raceCount,max(score) raceMaxScore from racescore rs inner join race r
on rs.raceid = r.raceid and
rs.created &gt; r.starttime and rs.created &lt;=r.endtime
and rs.created&gt;#{startTime} and rs.created&lt;=#{endTime}
where uid=#{uid}
group by uid),
voice as (
select uid,count(voiceid) voiceCount from dubuservoice where uid =#{uid}
and isdelete=0 and
created &gt; #{startTime} and created&lt;=#{endTime}
group by uid),
badge as (
select userid uid ,
count(case when badgecaseid =2 then 1 else null end ) as copperMedal,
count(case when badgecaseid =3 then 1 else null end ) as silverMedal ,
count(case when badgecaseid =4 then 1 else null end ) as goldMedal,
count(case when badgecaseid =6 then 1 else null end ) as copperCup,
count(case when badgecaseid =7 then 1 else null end ) as silverCup ,
count(case when badgecaseid =8 then 1 else null end ) as goldCup
from badgelog
where userid = #{uid}
and created &gt; #{startTime} and created &lt;= #{endTime}
group by userid ),
honor as (
select uid,levelname from userhonor where uid = #{uid})
select studyCount,studyMaxScore,assignCount,assignMaxScore,examCount,examMaxScore,hearCount,hearMaxScore,
raceCount,raceMaxScore,voiceCount,copperMedal,silverMedal,goldMedal,copperCup,silverCup,goldCup,levelname
from study s
full join assign a
on s.uid=a.uid
full join exam e
on s.uid =e.uid
full join hear h
on s.uid =h.uid
full join race r
on s.uid = r.uid
full join voice v
on s.uid = v.uid
full join badge b
on s.uid = b.uid
full join honor u
on s.uid = u.uid
</select>
<select id="netSuperGoldens" parameterType="java.util.Map" resultType="SuperHero">
with temp as(
select uid,howmuch,classesid from mv_monthgoldmedal order by howmuch desc,uid desc
<if test="pageSize!=null">
LIMIT #{pageSize}
</if>
<if test="offset!=null">
OFFSET #{offset}
</if>
)
select t.howmuch numCount,t.uid,s.truename,sl.schoolName from
temp t inner join student s on t.uid=s.studentid
inner join classes c on t.classesid = c.classesid
inner join school sl on c.schoolid=sl.schoolid
order by numCount desc,uid desc
<!-- select count(m.uid) numCount,m.uid,s.truename,sl.schoolName
from mv_goldmedal m inner join student s on m.uid=s.studentid
inner join classes c on m.classesid=c.classesid inner join school sl
on sl.schoolid=c.schoolid group by m.uid,s.truename,sl.schoolname
order by numCount desc,m.uid desc
<if test="pageSize!=null">
LIMIT #{pageSize}
</if>
<if test="offset!=null">
OFFSET #{offset}
</if> -->
</select>
<select id="classSuperGoldensByTime" parameterType="java.util.Map" resultType="SuperHero" >
with temp as(
select uid,howmuch,classesid from
<if test ='timeType == "week"'>
mv_weekgoldmedal
</if>
<if test ='timeType == "month"'>
mv_monthgoldmedal
</if>
where classesid = #{classesId}
order by howmuch desc,uid desc
<if test="pageSize!=null">
LIMIT #{pageSize}
</if>
<if test="offset!=null">
OFFSET #{offset}
</if>
)
select t.howmuch numCount,t.uid,s.truename from
temp t inner join student s on t.uid=s.studentid
order by numCount desc,uid desc
limit 10
<!-- select count(m.uid) numCount,m.uid,s.truename
from mv_goldmedal m inner join student s on m.uid=s.studentid
and m.classesId = #{classesId}
<if test='timeType == "week"'>and
m.created &gt; ( current_date + interval '-1 week')
</if>
group by m.uid,s.truename
order by numCount desc,m.uid desc
limit 10 -->
</select>
<select id="classSuperHerosByTime" parameterType="java.util.Map" resultType="SuperHero" >
<!-- SELECT a.uid,
count(a.objectid) AS numCount,st.truename
FROM achivement a
inner join studentownclass s on a.uid=s.studentId and s.status=1 and s.classesId=#{classesId}
and (a.pointcasetype = ANY (ARRAY[3, 5, 6, 7, 8]))
<if test='timeType=="week"'>
AND a.created&gt; ( current_date + interval '-1 week') and a.created&lt;current_date
</if>
<if test='timeType=="month"'>
AND a.created&gt; ( current_date + interval '-1 month') and a.created&lt;current_date
</if>
inner join student st on a.uid=st.studentid
GROUP BY a.uid ,st.truename
order by numCount desc ,a.uid
limit 10 -->
select a.uid,a.numCount,st.truename from
<if test='timeType=="month"'>
mv_month_studycount a
</if>
<if test='timeType=="week"'>
mv_week_studycount a
</if>
inner join studentownclass s on a.uid=s.studentId and s.status=1 and s.classesId=#{classesId}
inner join student st on a.uid=st.studentid
order by a.numCount desc ,a.uid
limit 10
</select>
</mapper>