You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
dianshang-houduan/src/main/resources/mappers/TeachingClassStudentMapper.xml

127 lines
5.7 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.sztzjy.linkCommerce.mapper.TeachingClassStudentMapper">
<resultMap id="BaseResultMap" type="com.sztzjy.linkCommerce.entity.TeachingClassStudent">
<id column="id" jdbcType="VARCHAR" property="id" />
<result column="teaching_class_id" jdbcType="VARCHAR" property="teachingClassId" />
<result column="student_user_id" jdbcType="VARCHAR" property="studentUserId" />
<result column="admin_class_id" jdbcType="VARCHAR" property="adminClassId" />
<result column="status" jdbcType="VARCHAR" property="status" />
<result column="join_reason" jdbcType="VARCHAR" property="joinReason" />
<result column="join_time" jdbcType="TIMESTAMP" property="joinTime" />
<result column="exit_time" jdbcType="TIMESTAMP" property="exitTime" />
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
</resultMap>
<sql id="Base_Column_List">
id, teaching_class_id, student_user_id, admin_class_id, status, join_reason, join_time, exit_time, create_time
</sql>
<select id="countByTeachingClassId" parameterType="java.lang.String" resultType="java.lang.Long">
select count(*) from teaching_class_student
where teaching_class_id = #{teachingClassId,jdbcType=VARCHAR}
and status = 'IN_PROGRESS'
</select>
<select id="countByStudentUserIdAndTeachingClassId" resultType="java.lang.Long">
select count(*) from teaching_class_student
where student_user_id = #{studentUserId,jdbcType=VARCHAR}
and teaching_class_id = #{teachingClassId,jdbcType=VARCHAR}
and status = 'IN_PROGRESS'
</select>
<select id="countByStudentUserIdExcludingTeachingClass" resultType="java.lang.Long">
select count(*) from teaching_class_student
where student_user_id = #{studentUserId,jdbcType=VARCHAR}
and status = 'IN_PROGRESS'
<if test="teachingClassId != null and teachingClassId != ''">
and teaching_class_id != #{teachingClassId,jdbcType=VARCHAR}
</if>
</select>
<select id="selectByTeachingClassId" parameterType="java.lang.String" resultMap="BaseResultMap">
select <include refid="Base_Column_List" />
from teaching_class_student
where teaching_class_id = #{teachingClassId,jdbcType=VARCHAR}
and status = 'IN_PROGRESS'
</select>
<select id="selectActiveByStudentUserId" parameterType="java.lang.String" resultMap="BaseResultMap">
select <include refid="Base_Column_List" />
from teaching_class_student
where student_user_id = #{studentUserId,jdbcType=VARCHAR}
and status = 'IN_PROGRESS'
order by join_time desc, create_time desc
limit 1
</select>
<select id="selectByStudentUserIdAndTeachingClassId" resultMap="BaseResultMap">
select <include refid="Base_Column_List" />
from teaching_class_student
where student_user_id = #{studentUserId,jdbcType=VARCHAR}
and teaching_class_id = #{teachingClassId,jdbcType=VARCHAR}
order by create_time desc
limit 1
</select>
<insert id="insertSelective" parameterType="com.sztzjy.linkCommerce.entity.TeachingClassStudent">
insert into teaching_class_student
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">id,</if>
<if test="teachingClassId != null">teaching_class_id,</if>
<if test="studentUserId != null">student_user_id,</if>
<if test="adminClassId != null">admin_class_id,</if>
<if test="status != null">status,</if>
<if test="joinReason != null">join_reason,</if>
<if test="joinTime != null">join_time,</if>
<if test="exitTime != null">exit_time,</if>
<if test="createTime != null">create_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">#{id,jdbcType=VARCHAR},</if>
<if test="teachingClassId != null">#{teachingClassId,jdbcType=VARCHAR},</if>
<if test="studentUserId != null">#{studentUserId,jdbcType=VARCHAR},</if>
<if test="adminClassId != null">#{adminClassId,jdbcType=VARCHAR},</if>
<if test="status != null">#{status,jdbcType=VARCHAR},</if>
<if test="joinReason != null">#{joinReason,jdbcType=VARCHAR},</if>
<if test="joinTime != null">#{joinTime,jdbcType=TIMESTAMP},</if>
<if test="exitTime != null">#{exitTime,jdbcType=TIMESTAMP},</if>
<if test="createTime != null">#{createTime,jdbcType=TIMESTAMP},</if>
</trim>
</insert>
<update id="exitActiveByStudentUserIdExceptClass">
update teaching_class_student
set status = 'EXITED',
exit_time = CURRENT_TIMESTAMP
where student_user_id = #{studentUserId,jdbcType=VARCHAR}
and status = 'IN_PROGRESS'
and teaching_class_id != #{teachingClassId,jdbcType=VARCHAR}
</update>
<update id="updateMembershipToActive">
update teaching_class_student
set status = 'IN_PROGRESS',
admin_class_id = #{adminClassId,jdbcType=VARCHAR},
join_reason = #{joinReason,jdbcType=VARCHAR},
join_time = CURRENT_TIMESTAMP,
exit_time = null
where student_user_id = #{studentUserId,jdbcType=VARCHAR}
and teaching_class_id = #{teachingClassId,jdbcType=VARCHAR}
</update>
<delete id="deleteByTeachingClassId" parameterType="java.lang.String">
delete from teaching_class_student
where teaching_class_id = #{teachingClassId,jdbcType=VARCHAR}
</delete>
<update id="deleteByStudentUserIdAndTeachingClassId">
update teaching_class_student
set status = 'EXITED',
exit_time = CURRENT_TIMESTAMP
where student_user_id = #{studentUserId,jdbcType=VARCHAR}
and teaching_class_id = #{teachingClassId,jdbcType=VARCHAR}
and status = 'IN_PROGRESS'
</update>
</mapper>