446 lines
18 KiB
XML
446 lines
18 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._3e.dao.RaceDao">
|
|
<resultMap id="BaseResultMap" type="com._3e.entity.Race">
|
|
<id column="raceid" property="raceid"/>
|
|
<result column="racename" property="racename"/>
|
|
<result column="holder" property="holder"/>
|
|
<result column="racetype" property="racetype"/>
|
|
<result column="description" property="description"/>
|
|
<result column="starttime" property="starttime"/>
|
|
<result column="endtime" property="endtime"/>
|
|
<result column="joinrace" property="joinrace"/>
|
|
<result column="credential" property="credential"/>
|
|
<result column="badge" property="badge"/>
|
|
<result column="reward" property="reward"/>
|
|
<result column="timelength" property="timelength"/>
|
|
<result column="content" property="content"/>
|
|
<result column="status" property="status"/>
|
|
<result column="created" property="created"/>
|
|
<result column="raceareaid" property="raceareaid"/>
|
|
<result column="origivoice" property="origivoice"/>
|
|
<result column="banner" property="banner"/>
|
|
<result column="title" property="title"/>
|
|
<result column="groupLevel" property="groupLevel"/>
|
|
<result column="way" property="way"/>
|
|
<result column="wayId" property="wayId"/>
|
|
<result column="maxCount" property="maxCount"/>
|
|
<result column="prePeople" property="prePeople"/>
|
|
<result column="grades" property="grades" jdbcType="ARRAY" typeHandler="com._3e.http.wrongbook.typehandler.SmallIntArrayTypeHandler"/>
|
|
<result column="jField" property="jField"/>
|
|
</resultMap>
|
|
<select id= "getNextSeq" resultType="int">
|
|
SELECT NEXTVAL('seq_racescoreid')
|
|
</select>
|
|
|
|
<insert id= "doSaveRaceScore" parameterType="com._3e.entity.Racescore" >
|
|
INSERT INTO racescore(racescoreid,uid,raceid,score,ismax,accuracy,fluent,integrity,content,created,areaid,uuid)
|
|
VALUES (
|
|
<if test="racescoreid == 0">
|
|
(SELECT NEXTVAL('seq_racescoreid')),
|
|
</if>
|
|
<if test="racescoreid != 0">
|
|
#{racescoreid},
|
|
</if>
|
|
#{uid},#{raceid},#{score},#{ismax},#{accuracy},#{fluent},#{integrity},#{content},#{created},#{areaid},#{uuid})
|
|
</insert>
|
|
|
|
<insert id= "doSaveMaxScore" parameterType="com._3e.entity.Racemaxscore" >
|
|
INSERT INTO racemaxscore(raceid,uid,maxscore,created,racescoreid)
|
|
VALUES (#{raceid},#{uid},#{maxscore},#{created},#{racescoreid})
|
|
</insert>
|
|
|
|
<update id= "doUpdateMaxScore" parameterType="com._3e.entity.Racemaxscore">
|
|
update Racemaxscore set maxscore = #{maxscore} ,created = #{created},racescoreid = #{racescoreid}
|
|
where raceid = #{raceid} and uid = #{uid}
|
|
</update>
|
|
|
|
<update id= "doRecordRaceVoice" parameterType="map" >
|
|
update racescore set uuid = #{uuid} where racescoreid = #{racescoreid} and areaid=#{areaid}
|
|
</update>
|
|
|
|
<select id= "findMyAllRacescore" parameterType="map" resultType="com._3e.entity.Racescore" >
|
|
SELECT * FROM racescore
|
|
WHERE uid = #{uid}
|
|
and areaid = #{areaid}
|
|
and to_char(created, 'yyyy-MM-dd') >= #{begintime}
|
|
and to_char(created, 'yyyy-MM-dd') <= #{endtime}
|
|
ORDER BY score desc,raceScoreId desc
|
|
<if test="page != null">
|
|
LIMIT #{page.limit} OFFSET #{page.offset}
|
|
</if>
|
|
</select>
|
|
|
|
<select id= "findMyAllRacescoreAndEssay" parameterType="map" resultType="com._3e.entity.Racescore" >
|
|
select * from (
|
|
SELECT racescoreid,raceid,score,created FROM racescore
|
|
WHERE uid = #{uid}
|
|
and areaid = #{areaid}
|
|
and to_char(created, 'yyyy-MM-dd') >= #{begintime}
|
|
and to_char(created, 'yyyy-MM-dd') <= #{endtime}
|
|
union all
|
|
select essayanswerid AS racescoreid,raceid,score,created from essayanswer where uid = #{uid} and areaid = #{areaid} and raceid != 0
|
|
and to_char(created, 'yyyy-MM-dd') >= #{begintime}
|
|
and to_char(created, 'yyyy-MM-dd') <= #{endtime}
|
|
) a
|
|
ORDER BY score desc,raceid desc
|
|
<if test="page != null">
|
|
LIMIT #{page.limit} OFFSET #{page.offset}
|
|
</if>
|
|
</select>
|
|
|
|
<select id= "findRaceByRaceid" parameterType="int" resultMap="BaseResultMap" >
|
|
SELECT * FROM Race
|
|
WHERE raceid = #{raceid}
|
|
</select>
|
|
|
|
<!--没有使用-->
|
|
<select id= "findStudentClassRaceGoodVoice" parameterType="long" resultType="com._3e.entity.Racescore" >
|
|
SELECT * FROM racescore
|
|
WHERE EXISTS (
|
|
SELECT * FROM (
|
|
SELECT b.* FROM studentownclass b
|
|
WHERE EXISTS (
|
|
SELECT C.* FROM studentownclass C
|
|
WHERE b.classesid = C.classesid AND C.studentid = #{uid}
|
|
)
|
|
) d
|
|
WHERE uid = d.studentid
|
|
)
|
|
and uuid <![CDATA[<>]]> ''
|
|
</select>
|
|
|
|
<!--没有使用-->
|
|
<select id= "findTeacherClassRaceGoodVoice" parameterType="long" resultType="com._3e.entity.Racescore" >
|
|
SELECT * FROM racescore
|
|
WHERE EXISTS (
|
|
SELECT * FROM (
|
|
SELECT b.* FROM teacher b
|
|
WHERE EXISTS (
|
|
SELECT C.* FROM classes C
|
|
WHERE C .teacherid = b.teacherid AND C.teacherid = #{uid}
|
|
)
|
|
) d
|
|
WHERE uid = d.teacherid
|
|
)
|
|
and uuid <![CDATA[<>]]> ''
|
|
</select>
|
|
|
|
<select id= "findMyRaceGoodVoice" parameterType="map" resultType="com._3e.entity.Racescore" >
|
|
SELECT * FROM Racescore
|
|
WHERE uid = #{uid}
|
|
and areaid = #{areaid}
|
|
and uuid <![CDATA[<>]]> ''
|
|
and created between '${begintime} 00:00:00' and '${endtime} 23:59:59'
|
|
ORDER BY score desc, racescoreid desc
|
|
<if test="page != null">
|
|
LIMIT #{page.limit} OFFSET #{page.offset}
|
|
</if>
|
|
</select>
|
|
|
|
<select id= "findRaceRank" parameterType="map" resultType="int" >
|
|
SELECT count(1) FROM racescore WHERE score >= #{score} AND raceid = #{raceid}
|
|
</select>
|
|
|
|
<select id= "findRaceSchool" parameterType="int" resultType="com._3e.entity.School" >
|
|
SELECT * FROM school
|
|
WHERE schoolid IN(
|
|
SELECT schoolid FROM schoolownrace WHERE raceid = #{raceid})
|
|
AND STATUS =1
|
|
</select>
|
|
|
|
<select id= "findMyOngoingRace" parameterType="long" resultType="com._3e.entity.Race" >
|
|
SELECT b.*
|
|
FROM ( SELECT distinct a.raceId
|
|
FROM RaceScore a
|
|
WHERE a.uid = #{uid}
|
|
)a
|
|
INNER JOIN Race b
|
|
ON a.raceId = b.raceId
|
|
and b.endTime > current_timestamp
|
|
ORDER BY raceId DESC
|
|
</select>
|
|
|
|
<select id= "findMyOngoingRaceAndEssay" parameterType="long" resultType="com._3e.entity.Race" >
|
|
SELECT b.*
|
|
FROM ( SELECT distinct a.raceId
|
|
FROM RaceScore a
|
|
WHERE a.uid = #{uid}
|
|
)a
|
|
INNER JOIN Race b
|
|
ON a.raceId = b.raceId
|
|
and b.endTime > current_timestamp
|
|
union all
|
|
SELECT b.*
|
|
FROM ( SELECT distinct a.raceId
|
|
FROM EssayAnswer a
|
|
WHERE a.uid = #{uid} and a.raceId != 0
|
|
)a
|
|
INNER JOIN Race b
|
|
ON a.raceId = b.raceId
|
|
and b.endTime > current_timestamp
|
|
ORDER BY raceId DESC
|
|
</select>
|
|
|
|
<select id= "findRaceIdList" parameterType="com.mobile.common.page.Page" resultType="com._3e.entity.Race" >
|
|
select raceId
|
|
from Race
|
|
where endTime > '2015-06-30 23:59:59' AND (status = 0 or current_timestamp > endTime)
|
|
and starttime > ( current_date + interval '-1 year')
|
|
order by endTime desc ,raceId desc
|
|
limit #{limit} offset #{offset}
|
|
</select>
|
|
|
|
<select id="findOverRace" parameterType="map" resultType="com._3e.http.race.dto._3EResRaceOver" >
|
|
WITH temp as (
|
|
select raceId , raceName , startTime , endTime ,way,wayId
|
|
from Race
|
|
where raceId in
|
|
<foreach collection="raceids" index="index" item="item" separator="," close=")" open="(">
|
|
#{item.raceid}
|
|
</foreach> ) ,
|
|
temp2 as (
|
|
select n.raceid , n.uid , n.maxscore as score ,
|
|
rank() over (partition by n.raceId order by n.maxscore desc ,m.avgscore desc, n.created desc ) as mm
|
|
from RacemaxScore n
|
|
inner join (
|
|
select raceid,uid,avg(score) avgscore from racescore
|
|
where raceid in
|
|
<foreach collection="raceids" index="index" item="item" separator="," close=")" open="(">
|
|
#{item.raceid}
|
|
</foreach>
|
|
group by raceid,uid) as m
|
|
on m.raceid = n.raceid and n.uid=m.uid
|
|
inner join student s on n.uid = s.studentid and s.status = 1
|
|
where n.raceid in
|
|
<foreach collection="raceids" index="index" item="item" separator="," close=")" open="(">
|
|
#{item.raceid}
|
|
</foreach> ) ,
|
|
temp3 as ( SELECT q.raceId , count(q.racescoreId) joinTotal
|
|
FROM raceScore q
|
|
where q.raceId in
|
|
<foreach collection="raceids" index="index" item="item" separator="," close=")" open="(">
|
|
#{item.raceid}
|
|
</foreach>
|
|
GROUP BY q.raceId )
|
|
SELECT a.raceId , a.raceName , a.startTime , a.endTime , a.way,a.wayId,
|
|
case when c.joinTotal is null then 0 else c.joinTotal end as joinTotal ,
|
|
case when b.uid is null then 0 else b.uid end as uid ,
|
|
case when b.score is null then 0 else b.score end as score ,
|
|
case when d.truename is null then '' else d.truename end as truename
|
|
FROM temp as a
|
|
left join temp2 as b
|
|
on a.raceId = b.raceId and b.mm = 1
|
|
left join temp3 as c
|
|
ON a.raceId = c.raceId
|
|
left JOIN V_Baseuser d
|
|
on b.uid = d.studentId and b.mm = 1
|
|
and status=1
|
|
ORDER BY a.endTime desc , raceId desc
|
|
</select>
|
|
|
|
<select id= "findOngoingRaceList" parameterType="int" resultType="com._3e.entity.Race" >
|
|
SELECT raceId , raceName , holder , raceType , '' as description ,
|
|
startTime , endTime , joinRace , credential , badge , '' as reward ,
|
|
timeLength , '' as content , status , created , raceAreaId , banner
|
|
FROM Race
|
|
WHERE status = 1
|
|
<if test="_parameter != 0">
|
|
and raceType = #{racetype}
|
|
</if>
|
|
and current_timestamp < endTime
|
|
ORDER BY endTime, raceId
|
|
</select>
|
|
|
|
<select id= "getOnGoingNetRace" parameterType="int" resultType="com._3e.entity.Race" >
|
|
SELECT raceId , raceName , holder , raceType , '' as description ,
|
|
startTime , endTime , joinRace , credential , badge , '' as reward ,
|
|
timeLength , '' as content , status , created , raceAreaId , banner ,title,way,wayId
|
|
FROM Race
|
|
WHERE status = 1
|
|
and raceType = #{raceType}
|
|
and groupLevel = #{groupLevel}
|
|
and current_timestamp < endTime
|
|
ORDER BY endTime desc, raceId desc limit 1
|
|
</select>
|
|
<!--区分中小学组-->
|
|
<select id= "findOngoingRaceList_1" parameterType="int" resultType="com._3e.entity.Race" >
|
|
SELECT raceId ,title,raceName , holder , raceType , '' as description ,
|
|
startTime , endTime , joinRace , credential , badge , '' as reward ,
|
|
timeLength , '' as content , status , created , raceAreaId , banner,grouplevel,way,wayId
|
|
FROM Race
|
|
WHERE status = 1
|
|
<if test="_parameter!= 0">
|
|
and racetype = #{racetype}
|
|
</if>
|
|
and current_timestamp < endTime
|
|
ORDER BY raceType,endTime, raceId
|
|
</select>
|
|
|
|
<select id= "findOngoingRaceList_2" parameterType="int" resultType="com._3e.entity.Race" >
|
|
(SELECT raceId ,title,raceName , holder , raceType , '' as description ,
|
|
startTime , endTime , joinRace , credential , badge , '' as reward ,
|
|
timeLength , '' as content , status , created , raceAreaId , banner,grouplevel,way,wayId,jField
|
|
FROM Race
|
|
WHERE status = 1 and (racetype = 1 or racetype = 4)
|
|
and current_timestamp < endTime
|
|
ORDER BY endTime, raceId)
|
|
union all
|
|
(SELECT raceId ,title,raceName , holder , raceType , '' as description ,
|
|
startTime , endTime , joinRace , credential , badge , '' as reward ,
|
|
timeLength , '' as content , status , created , raceAreaId , banner,grouplevel,way,wayId,jField
|
|
FROM Race
|
|
WHERE status = 1 and (racetype = 2 or racetype = 3)
|
|
and current_timestamp < endTime
|
|
ORDER BY raceType,endTime, raceId)
|
|
</select>
|
|
|
|
<select id="findJoinRacePhbByRaceID" parameterType="map" resultType="com._3e.http.race.dto._3EResRacePhb" >
|
|
SELECT m.raceid , m.uid , m.maxscore , m.created , m.racescoreid , r.uuid, m.avgscore
|
|
FROM racemaxscore m
|
|
INNER JOIN racescore r
|
|
ON m.raceid = #{raceId}
|
|
AND m.racescoreid = r.racescoreid
|
|
inner join student s on m.uid=s.studentid
|
|
and s.status=1
|
|
ORDER BY m.maxscore desc ,m.avgscore DESC, m.created DESC
|
|
<if test="page != null">
|
|
LIMIT 20 OFFSET #{page.offset}
|
|
</if>
|
|
</select>
|
|
|
|
<select id="findMyFrontJoinRacePhbByRaceID" parameterType="map" resultType="int" >
|
|
select count(*) as rankid from RaceMaxscore m inner join student s on
|
|
m.uid=s.studentid
|
|
and s.status=1 and raceid =#{raceId} and maxScore >#{score}
|
|
</select>
|
|
<select id="findMyFrontJoinRacePhbByRaceID_1" parameterType="map" resultType="com._3e.http.race.dto._3EResRacePhb" >
|
|
select avgscore from RaceMaxscore m inner join student s on
|
|
m.uid=s.studentid
|
|
and s.status=1 and raceid =#{raceId} and maxScore =#{score}
|
|
</select>
|
|
|
|
<select id= "findMyJoinRacePhbByRaceID" parameterType="map" resultType="com._3e.http.race.dto._3EResRacePhb" >
|
|
SELECT ROW_NUMBER() OVER(ORDER BY m.maxscore DESC,m.avgscore DESC,m.created DESC) AS rowindex,
|
|
m.raceid,m.uid,m.maxscore,m.created,m.racescoreid,m.avgscore,r.uuid
|
|
FROM racemaxscore m
|
|
INNER JOIN racescore r
|
|
ON m.racescoreid = r.racescoreid
|
|
AND m.raceid = #{raceId} AND m.uid = #{uid}
|
|
ORDER BY m.maxscore DESC,m.avgscore DESC,m.created DESC
|
|
</select>
|
|
|
|
<select id= "getJoinRaceCountByRaceID" parameterType="int" resultType="int" >
|
|
select count(*) from RaceMaxScore m
|
|
inner join racescore r
|
|
on r.racescoreid = m.racescoreid
|
|
where m.raceId = #{raceid}
|
|
</select>
|
|
|
|
<select id="getUserJoinRaceCountByRaceID" resultType="java.lang.Integer">
|
|
select count(*) from RaceScore
|
|
where raceId = #{raceId} and uid = #{studentId}
|
|
</select>
|
|
<select id= "getJoinRaceCountByRaceID_1" parameterType="int" resultType="int" >
|
|
<!--select * from RaceMaxScore m
|
|
inner join racescore r
|
|
on r.racescoreid = m.racescoreid
|
|
where m.raceId = #{raceid}
|
|
ORDER BY m.maxscore-->
|
|
select count(*) from RaceMaxScore r
|
|
inner join student s on r.uid=s.studentid
|
|
where raceid = #{raceId}
|
|
</select>
|
|
|
|
<select id="findRaceMaxScore" parameterType="map" resultType="com._3e.entity.Racemaxscore" >
|
|
SELECT * FROM Racemaxscore
|
|
WHERE uid = #{uid} and raceid = #{raceId}
|
|
</select>
|
|
|
|
<select id="findMyRaceAvgScore" parameterType="map" resultType="double">
|
|
SELECT round(AVG(score),2) AS avgScore
|
|
FROM racescore
|
|
WHERE raceId =#{raceId}
|
|
and areaid = #{areaid}
|
|
and uid=#{uid}
|
|
and score > 0
|
|
GROUP BY uid
|
|
</select>
|
|
|
|
<update id="doSaveAvgScore" parameterType="map">
|
|
update racemaxscore
|
|
<set>
|
|
<if test="myAvgSoce != null">avgscore = #{myAvgSoce}</if>
|
|
</set>
|
|
WHERE raceid = #{raceId} and uid = #{uid}
|
|
</update>
|
|
|
|
<select id="findStudentCountbyClasses" parameterType="map" resultType="int">
|
|
WITH temp as ( select soc.studentId
|
|
from StudentOwnClass soc inner join student s on soc.studentid=s.studentid and soc.classesId = #{classesid}
|
|
and soc.areaid = #{areaid} and s.areaid = #{areaid}
|
|
and s.status=1
|
|
),
|
|
temp1 as (SELECT b.uid from temp as a INNER JOIN racescore b ON a.studentid = b.uid and b.areaid = #{areaid}
|
|
and b.created between '${starttime} 00:00:00' and '${endtime} 23:59:59')
|
|
SELECT count(uid) from temp1
|
|
</select>
|
|
<select id="findMyJoinMaxScore" parameterType="map" resultType="com._3e.http.race.dto._3EResIsPromotion">
|
|
select maxscore,avgscore from racemaxscore where uid = #{uid} and raceid = #{raceid}
|
|
|
|
</select>
|
|
|
|
<select id="findMyJoinJoinNum" parameterType="map" resultType="com._3e.http.race.dto._3EResIsPromotion">
|
|
select count(1) as joinNum from racescore where uid = #{uid} and raceid = #{raceid} and areaid = #{areaid}
|
|
</select>
|
|
|
|
<select id="findSchoolJoinNum" parameterType="map" resultType="com._3e.http.race.dto._3EResIsPromotion">
|
|
select * from (
|
|
select uid,round(sum(allscore)/sum(count),2) avgscore,sum(count) joinnum from (
|
|
select rms.uid,rms.avgscore*rs.count allscore,rs.count from racemaxscore rms INNER JOIN (select uid,count(1) from racescore
|
|
where raceid = #{primaryRaceId} and areaid = #{areaid} and created between #{primaryStartTime} and #{primaryEndTime} group by uid) rs
|
|
on rms.uid = rs.uid and rms.raceid = #{primaryRaceId}
|
|
INNER JOIN student s on rms.uid = s.studentid and s.areaid = #{areaid}
|
|
INNER JOIN studentownclass st on s.studentid = st.studentid and st.status=1 and s.status = 1 and st.areaid = #{areaid}
|
|
INNER JOIN classes c on st.classesid = c.classesid
|
|
INNER JOIN school sl on c.schoolid = sl.schoolid and sl.schoolid = #{schoolid}
|
|
UNION all
|
|
select rms.uid,rms.avgscore*rs.count allscore,rs.count from racemaxscore rms INNER JOIN (select uid,count(1) from racescore
|
|
where raceid = #{midleRaceId} and areaid = #{areaid} and created between #{midleStartTime} and #{midleEndTime} group by uid) rs
|
|
on rms.uid = rs.uid and rms.raceid = #{midleRaceId}
|
|
INNER JOIN student s on rms.uid = s.studentid and s.areaid = #{areaid}
|
|
INNER JOIN studentownclass st on s.studentid = st.studentid and st.status=1 and s.status = 1 and st.areaid = #{areaid}
|
|
INNER JOIN classes c on st.classesid = c.classesid
|
|
INNER JOIN school sl on c.schoolid = sl.schoolid and sl.schoolid = #{schoolid}
|
|
|
|
) su where uid not in
|
|
<foreach collection="studentids" open="(" close=")" index="index" item="studentid" separator=",">
|
|
#{studentid}
|
|
</foreach>
|
|
GROUP BY uid ) mo where mo.avgscore>60 ORDER BY joinnum desc,avgscore desc limit 5
|
|
|
|
</select>
|
|
|
|
|
|
<select id="findTwoRaceScore" parameterType="map" resultType="com._3e.http.race.dto._3EResIsPromotion">
|
|
select rms.uid,rms.avgscore,rms.maxscore,rs.count joinnum from racemaxscore rms INNER JOIN (select uid,count(1) from racescore
|
|
where raceid = #{primaryRaceId} and areaid = #{areaid} and created between #{primaryStartTime} and #{primaryEndTime} group by uid) rs
|
|
on rms.uid = rs.uid and rms.raceid = #{primaryRaceId}
|
|
INNER JOIN student s on rms.uid = s.studentid and s.areaid = #{areaid}
|
|
INNER JOIN studentownclass st on s.studentid = st.studentid and st.status=1 and s.status = 1 and st.areaid = #{areaid}
|
|
INNER JOIN classes c on st.classesid = c.classesid
|
|
INNER JOIN school sl on c.schoolid = sl.schoolid and sl.schoolid = #{schoolid} and rms.uid = #{uid}
|
|
UNION all
|
|
select rms.uid,rms.avgscore,rms.maxscore,rs.count joinnum from racemaxscore rms INNER JOIN (select uid,count(1) from racescore
|
|
where raceid = #{midleRaceId} and areaid = #{areaid} and created between #{midleStartTime} and #{midleEndTime} group by uid) rs
|
|
on rms.uid = rs.uid and rms.raceid = #{midleRaceId}
|
|
INNER JOIN student s on rms.uid = s.studentid and s.areaid = #{areaid}
|
|
INNER JOIN studentownclass st on s.studentid = st.studentid and st.status=1 and s.status = 1 and st.areaid = #{areaid}
|
|
INNER JOIN classes c on st.classesid = c.classesid
|
|
INNER JOIN school sl on c.schoolid = sl.schoolid and sl.schoolid = #{schoolid} and rms.uid = #{uid}
|
|
</select>
|
|
|
|
</mapper>
|