245 lines
8.4 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="Race">
<resultMap id="BaseResultMap" type="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="endTime" property="endTime"/>
<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="prePeople" property="prePeople"/>
<result column="maxCount" property="maxCount"/>
<result property="jField" column="jField" typeHandler = "com.spoken.api.handlers.JSONTypeHandlerPg1" />
<result property="grades" column="grades" jdbcType="ARRAY"
typeHandler="com.spoken.api.handlers.ArrayTypeHandlerPg"/>
</resultMap>
<insert id="insertRace" parameterType="Race">
INSERT INTO Race ( raceId, raceName, holder, raceType, description,
startTime, endTime, joinRace, credential, badge, reward,
timeLength, content, status, created , raceAreaId ,origiVoice , banner , title,groupLevel
<if test="way != null">
,way
</if>
<if test="wayId != null">
,wayId
</if>
<if test="maxCount != null">
,maxCount
</if>
<if test="prePeople != null">
,prePeople
</if>
<if test="grades != null">
,grades
</if>
<if test="jField != null">
,jField
</if>
)
Values ( #{raceId}, #{raceName}, #{holder}, #{raceType}, #{description},
#{startTime}, #{endTime}, #{joinRace}, #{credential}, #{badge}, #{reward},
#{timeLength}, #{content}, #{status},current_timestamp , #{raceAreaId} , #{origiVoice} , #{banner} , #{title},#{groupLevel}
<if test="way != null">
,#{way}
</if>
<if test="wayId != null">
,#{wayId}
</if>
<if test="maxCount != null">
,#{maxCount}
</if>
<if test="prePeople != null">
,#{prePeople}
</if>
<if test="grades != null">
,#{grades,jdbcType=ARRAY, typeHandler=com.spoken.api.handlers.ArrayTypeHandlerPg}
</if>
<if test="jField != null">
,#{jField,typeHandler=com.spoken.api.handlers.JSONTypeHandlerPg1}
</if>
)
</insert>
<update id="updateRace" parameterType="Race">
UPDATE Race
SET raceId = #{raceId}, raceName = #{raceName}, holder = #{holder},
raceType = #{raceType}, description = #{description}, startTime = #{startTime},
endTime = #{endTime}, joinRace = #{joinRace}, credential = #{credential},
badge = #{badge}, reward = #{reward}, timeLength = #{timeLength},
content = #{content}, status = #{status}, raceAreaId = #{raceAreaId} , origiVoice= #{origiVoice} ,
banner = #{banner} , title = #{title},groupLevel=#{groupLevel}
<if test="way != null">
,way =#{way}
</if>
<if test="wayId != null">
,wayId =#{wayId}
</if>
<if test="maxCount != null">
,maxCount = #{maxCount}
</if>
<if test="prePeople != null">
,prePeople = #{prePeople}
</if>
<if test="grades != null">
,grades = #{grades,jdbcType=ARRAY, typeHandler=com.spoken.api.handlers.ArrayTypeHandlerPg}
</if>
<if test="jField != null">
,jfield = #{jField,typeHandler=com.spoken.api.handlers.JSONTypeHandlerPg1}
</if>
WHERE raceId=#{raceId}
</update>
<select id="getRaceByKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
SELECT raceId , raceName , holder , raceType , description , startTime ,
endTime , joinRace , credential , badge , reward , timeLength ,
content , status , created , raceAreaId , origiVoice , banner , title,groupLevel,way,wayId,prePeople,maxCount, grades,jField
FROM Race
WHERE raceId=#{raceId}
</select>
<select id="getSeqRace" resultType="Integer" useCache="false" flushCache="true">
SELECT nextval('seq_raceId') ;
</select>
<select id="getRacesCount" parameterType="java.util.Map" resultType="Integer">
SELECT COUNT(*)
FROM Race
WHERE status = 1
<if test="status==null">
<![CDATA[
and current_timestamp < endTime
]]>
</if>
<if test="title!=null">
and raceName like '%${title}%'
</if>
<if test="way == null or way == ''">
and way &lt; 3
</if>
</select>
<select id="getRaces" parameterType="java.util.Map" resultType="Race">
SELECT raceId , raceName , holder , raceType , description , startTime , endTime , joinRace , credential , badge ,
reward , timeLength , content , status , created , raceAreaId , origiVoice , banner , title,groupLevel ,way,wayId,prePeople,maxCount,jField
FROM Race
WHERE
status = 1
<if test="status==null">
<![CDATA[
and current_timestamp < endTime
]]>
</if>
<if test="title!=null">
and raceName like '%${title}%'
</if>
<if test="way == null or way == ''">
and way &lt; 3
</if>
ORDER BY raceId DESC
<if test="pageSize!=null">
LIMIT #{pageSize}
</if>
<if test="offset!=null">
OFFSET #{offset}
</if>
</select>
<select id="joinedRacesCount" parameterType="java.util.Map" resultType="Integer">
SELECT count(distinct(b.raceId))
FROM ( SELECT distinct a.raceId
FROM RaceScore a
WHERE a.uid = #{uid} )a
INNER JOIN Race b
ON a.raceId = b.raceId
<if test="groupLevel!=null">
and b.groupLevel=#{groupLevel}
</if>
and b.endTime &gt; current_timestamp
</select>
<select id="joinedRaces" parameterType="java.util.Map" resultType="Race">
SELECT b.raceId , b.raceName , b.holder , b.raceType , b.description ,
b.startTime , b.endTime , b.joinRace , b.credential , b.badge ,
b.reward , b.timeLength , b.content , b.status , b.created ,
b.raceAreaId , b.origiVoice , b.banner , b.title , groupLevel,way,wayId,prePeople,maxCount
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 &gt; current_timestamp
ORDER BY raceId DESC
<if test="pageSize!=null">
LIMIT #{pageSize}
</if>
<if test="offset!=null">
OFFSET #{offset}
</if>
</select>
<select id="checkSchoolRaceValidByStudentId" parameterType="java.util.Map" resultType="Integer">
select count(*) from schoolownrace c inner join race d
on c.raceid=d.raceid where d.raceid= #{raceId} and c.schoolid in
(select distinct(schoolid) from studentownclass a
inner join classes b on a.classesid = b.classesid
where a.studentid = #{studentid} )
</select>
<select id="checkSchoolRaceValidByTeacherId" parameterType="java.util.Map" resultType="Integer">
select count(*) from schoolownrace c inner join race d
on c.raceid=d.raceid where d.raceid= #{raceId} and c.schoolid =
(select schoolid from teacher where teacherid = #{teacherid})
</select>
<select id="getFinishRace" resultType="Integer">
select raceId from Race where endTime &lt; current_timestamp and endTime &gt; current_timestamp - interval '1 day'
</select>
<select id="getClassLevelByStudentId" parameterType="java.lang.Long" resultType="Integer">
select classlevel from classes c inner join studentownclass s on
c.classesid=s.classesid and s.studentid=#{studentid}
and c.classtype=1 and s.status=1 and c.status=1
</select>
</mapper>