2026-03-10 16:40:19 +08:00

222 lines
9.4 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="com.univ3e.dao.UnivUserHonorDao">
<insert id="doSave" parameterType="com.univ3e.entity.UnivUserHonor" >
INSERT INTO univuserhonor(uid,totalpoint,userlevel,levelname,totalmoney,
goldmedalcount,silvermedalcount,bronzemedalcount,cupcount,flowercount,
totalscore,howmuch,studyduration,studynum,befollowcount,areaid)
VALUES (#{uid},#{totalpoint},#{userlevel},#{levelname},#{totalmoney},
#{goldmedalcount},#{silvermedalcount},#{bronzemedalcount},#{cupcount},#{flowercount},
#{totalscore},#{howmuch},#{studyduration},#{studynum},#{befollowcount},#{areaid})
</insert>
<update id="doUpdateHonor" parameterType="map">
update univuserhonor
set totalmoney = totalmoney + #{totalmoney},totalscore = totalscore + #{totalscore},
howmuch = howmuch + #{howmuch},totalpoint=totalpoint + #{totalpoint},
goldmedalcount=goldmedalcount+#{goldmedalcount},silvermedalcount=silvermedalcount+#{silvermedalcount},
bronzemedalcount=bronzemedalcount+#{bronzemedalcount},userlevel=#{userlevel},levelname=#{levelname}
where uid=#{uid}
</update>
<update id="doMinusBefollowcount" parameterType="long">
update univuserhonor set befollowcount = befollowcount -1 where uid=#{uid}
</update>
<update id="doPlusBefollowcount" parameterType="long">
update univuserhonor set befollowcount = befollowcount + 1 where uid= #{uid}
</update>
<select id="getUserHonorByUid" parameterType="long" resultType="com.univ3e.entity.UnivUserHonor">
SELECT * FROM UnivUserHonor
WHERE uid = #{uid}
</select>
<!-- 班级榜单 -->
<select id="findClassBD" parameterType="map" resultType="com._3e.http.myspace.dto._3EResClassRand" >
<!-- A 学霸榜 -->
<if test="bdType == 'A'.toString()">
SELECT A.*,X.rankvalue,X.userLevel,X.levelName,s.truename FROM univstudentownclass A
INNER JOIN
(select q.uid , Round( q.totalScore / q.howmuch ) as rankvalue , userLevel , levelName from UnivStudentOwnClass p
inner join UnivUserHonor q
on p.classesId in
<foreach item="item" index="index" collection="classids"
open="(" separator="," close=")">
#{item}
</foreach>
and p.studentId = q.uid
where q.howmuch &gt; 1 and p.status =1
order by rankvalue desc , q.howmuch desc ) X
ON A.STUDENTID = X.UID
INNER JOIN univstudent s ON a.studentid = s.studentid
WHERE A.STUDENTID = X.UID and X.rankvalue &gt; 0 and A.classesid in
<foreach item="item" index="index" collection="classids"
open="(" separator="," close=")">
#{item}
</foreach>
ORDER BY X.rankvalue desc,A.studentid
</if>
<!-- B 金牌榜 -->
<if test="bdType == 'B'.toString()">
SELECT A.*,X.goldmedalcount as rankvalue
FROM v_univstudentclass A,univuserhonor X
where A.STUDENTID = X.UID and A.classesid in
<foreach item="item" index="index" collection="classids"
open="(" separator="," close=")">
#{item}
</foreach>
and X.goldmedalcount &gt; 0
ORDER BY X.goldmedalcount desc,A.studentid
</if>
<!-- C 人气榜 -->
<if test="bdType == 'C'.toString()">
select a.uid , b.truename , b.avatar,b.studentid, m.avgScore as rankvalue,
a.userLevel , a.levelName
From ( select p.studentId , count(*) as avgScore
from UnivStudentOwnClass p inner join UnivFollowShip q
on p.classesId in
<foreach item="item" index="index" collection="classids"
open="(" separator="," close=")">
#{item}
</foreach>
and p.studentId = q.beFollower
where p.status =1 group by p.studentId order by avgScore desc , p.studentId asc) m
inner join univUserHonor a on m.studentId = a.uid
inner join univStudent b on a.uid = b.studentId
ORDER BY m.avgScore desc, b.studentid
</if>
<if test="page != null">
LIMIT #{page.limit} OFFSET #{page.offset}
</if>
</select>
<!-- 班级榜单 -->
<select id= "findClassBD_1" parameterType="map" resultType="com._3e.http.myspace.dto._3EResClassRand" >
<!-- A 学霸榜 -->
<if test="bdType == 'A'.toString()">
<if test="time==null">
SELECT A.*,x.uid,X.rankvalue,X.rankvalue as score,X.userLevel,X.levelName FROM v_univstudentclass A,
(select q.uid , q.totalScore / q.howmuch ::numeric as rankvalue , userLevel , levelName from univStudentOwnClass p
inner join univUserHonor q
on p.classesId =#{classids}
where q.howmuch &gt; 1 and p.status =1
and p.studentId = q.uid
order by rankvalue desc , q.howmuch desc ) X
WHERE A.STUDENTID = X.UID and X.rankvalue &gt; 0
and A.classesid =#{classids}
ORDER BY X.rankvalue desc,A.studentid
</if>
<if test="time!=null">
SELECT a.uid,
avg(a.score) AS score,st.truename
FROM univachivement a
inner join univstudentownclass s on a.uid=s.studentId and s.status=1 and s.classesId=#{classids}
and (a.pointcasetype = ANY (ARRAY[3, 5, 6, 7, 8]))
<if test='time=="week"'>
AND a.created&gt; ( current_date + interval '-1 week') and a.created&lt;current_date
</if>
<if test='time=="month"'>
AND a.created&gt; ( current_date + interval '-1 month') and a.created&lt;current_date
</if>
inner join univstudent st on a.uid=st.studentid
GROUP BY a.uid ,st.truename
order by score desc ,a.uid
limit 10
</if>
</if>
<!-- B 金牌榜 -->
<if test="bdType == 'B'.toString()">
WITH temp AS (
SELECT b.userid AS uid,
count(*) AS howmuch
FROM univbadgelog b inner join univstudentownclass s on b.userid=s.studentid and s.classesid=#{classids}
and s.status=1
and b.badgetype = 1 AND b.badgecaseid = 4
<if test="time=='week'">
AND b.created&gt; ( current_date + interval '-1 week') and b.created&lt;current_date
</if>
<if test="time=='month'">
AND b.created&gt; ( current_date + interval '-1 month') and b.created&lt;current_date
</if>
GROUP BY b.userid
order by howmuch desc limit 10
)
select t.howmuch rankvalue,t.uid,s.truename from
temp t inner join univstudent s on t.uid=s.studentid
order by t.howmuch desc,uid desc
</if>
<!-- C 人气榜 -->
<if test="bdType == 'C'.toString()">
select a.uid , b.truename , b.avatar,b.studentid, m.avgScore as rankvalue,
a.userLevel , a.levelName
From ( select p.studentId , count(*) as avgScore
from univStudentOwnClass p inner join univFollowShip q
on p.classesId =#{#{classids}}
and p.studentId = q.beFollower
where p.status =1 group by p.studentId order by avgScore desc , p.studentId asc) m
inner join univUserHonor a on m.studentId = a.uid
inner join univStudent b on a.uid = b.studentId
ORDER BY m.avgScore desc, b.studentid
</if>
<!-- D 勤学榜 -->
<if test="bdType == 'D'.toString()">
<if test="time=='month'">
SELECT a.uid,
count(a.objectid) AS numCount,st.truename
FROM univachivement a
inner join univstudentownclass s on a.uid=s.studentId and s.status=1 and s.classesId=#{classids}
and (a.pointcasetype = ANY (ARRAY[3, 5, 6, 7, 8]))
AND a.created&gt; ( current_date + interval '-1 month') and a.created&lt;current_date
inner join univstudent st on a.uid=st.studentid
GROUP BY a.uid ,st.truename
order by numCount desc ,a.uid
limit 10
</if>
<if test="time=='week'">
with temp0 as ( select s.studentid
from univstudentownclass s
where s.classesId =#{classids}) ,
temp1 as ( select a.uid , count(a.objectid) AS numCount
from temp0 s
inner join univachivement a
on s.studentId = a.uid
and (a.pointcasetype = ANY (ARRAY[3, 5, 6, 7, 8])) AND a.created&gt; ( current_date + interval '-1 week')
and a.created&lt;current_date
GROUP BY a.uid
order by numCount desc ,a.uid asc )
select a.uid , a.numCount , st.truename
from temp1 a
inner join univstudent st
on a.uid=st.studentid
order by a.numCount desc ,a.uid asc
limit 10
</if>
</if>
</select>
<select id= "getLastMonthUserHonorByUid" parameterType="map" resultType="map" >
SELECT SUM(a.gold) AS gold, SUM(a.cup) AS cup, SUM(a.emoney) AS emoney
FROM (
SELECT COUNT(CASE WHEN badgecaseid=4 AND badgetype=1 THEN 1 END )AS gold,
COUNT(CASE WHEN badgecaseid=8 AND badgetype=2 THEN 1 END )AS cup,
0 AS emoney
FROM univbadgelog
WHERE userid = #{uid} AND badgecaseid IN (4,8)
AND created &gt;= #{startTime} AND created &lt;= #{endTime}
UNION
SELECT 0 AS gold, 0 AS cup, SUM(howmuch) AS emoney
FROM univemoneylog
WHERE uid = #{uid}
AND created &gt;= #{startTime} AND created &lt;= #{endTime}
) a
</select>
</mapper>