rt-sim-training-service/src/main/resources/mybatis/mapper/RaceQuestionDAO.xml

305 lines
11 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="club.joylink.rtss.dao.RaceQuestionDAO">
<resultMap id="BaseResultMap" type="club.joylink.rtss.entity.RaceQuestion">
<id column="id" jdbcType="BIGINT" property="id" />
<result column="topic" jdbcType="VARCHAR" property="topic" />
<result column="type" jdbcType="VARCHAR" property="type" />
<result column="create_user_id" jdbcType="BIGINT" property="createUserId" />
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
<result column="project_code" jdbcType="VARCHAR" property="projectCode" />
<result column="company_id" jdbcType="INTEGER" property="companyId" />
</resultMap>
<resultMap id="ResultMapRef" type="club.joylink.rtss.vo.client.question.QuestionVO">
<id column="id" jdbcType="BIGINT" property="id" />
<result column="topic" jdbcType="VARCHAR" property="topic" />
<result column="type" jdbcType="VARCHAR" property="type" />
<result column="project_code" jdbcType="VARCHAR" property="projectCode" />
<result column="company_id" jdbcType="VARCHAR" property="companyId" />
<collection property="optionList" ofType="club.joylink.rtss.vo.client.question.QuestionOptionVO">
<id column="oid" jdbcType="BIGINT" property="id" />
<result column="content" jdbcType="VARCHAR" property="content" />
<result column="correct" jdbcType="BIT" property="correct" />
<result column="order" jdbcType="TINYINT" property="order" />
</collection>
</resultMap>
<sql id="Example_Where_Clause">
<where>
<foreach collection="oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Update_By_Example_Where_Clause">
<where>
<foreach collection="example.oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Base_Column_List">
id, topic, `type`, create_user_id, create_time, project_code, company_id
</sql>
<select id="selectWithRef" resultMap="ResultMapRef">
SELECT q.id,q.topic,q.type,q.project_code,q.company_id, o.id oid,o.content,o.correct,o.order FROM race_question q JOIN race_question_option o ON q.id = o.question_id
<where>
<if test="topic != null">
q.topic LIKE concat('%',#{topic},'%')
</if>
<if test="type != null">
AND q.type = #{type}
</if>
<if test="projectCode != null">
AND q.project_code = #{projectCode}
</if>
<if test="projectCode == null">
AND q.project_code is null
<if test="companyId != null">
AND q.company_id = #{companyId}
</if>
<if test="companyId == null">
AND q.company_id is null
</if>
</if>
</where>
</select>
<select id="countNumByType" resultType="club.joylink.rtss.vo.client.competition.TheoryQuestionCountVO">
select count(*) as num,`type` from race_question
<where>
<if test="projectCode != null">
project_code = #{projectCode}
</if>
<if test="projectCode == null">
project_code is null
<if test="companyId != null">
AND company_id = #{companyId}
</if>
<if test="companyId == null">
AND company_id is null
</if>
</if>
</where>
group by `type`
</select>
<select id="selectByExample" parameterType="club.joylink.rtss.entity.RaceQuestionExample" resultMap="BaseResultMap">
select
<if test="distinct">
distinct
</if>
<include refid="Base_Column_List" />
from race_question
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
<if test="limit != null">
<if test="offset != null">
limit ${offset}, ${limit}
</if>
<if test="offset == null">
limit ${limit}
</if>
</if>
</select>
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from race_question
where id = #{id,jdbcType=BIGINT}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
delete from race_question
where id = #{id,jdbcType=BIGINT}
</delete>
<delete id="deleteByExample" parameterType="club.joylink.rtss.entity.RaceQuestionExample">
delete from race_question
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</delete>
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="club.joylink.rtss.entity.RaceQuestion" useGeneratedKeys="true">
insert into race_question (topic, `type`, create_user_id,
create_time, project_code, company_id
)
values (#{topic,jdbcType=VARCHAR}, #{type,jdbcType=VARCHAR}, #{createUserId,jdbcType=BIGINT},
#{createTime,jdbcType=TIMESTAMP}, #{projectCode,jdbcType=VARCHAR}, #{companyId,jdbcType=INTEGER}
)
</insert>
<insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="club.joylink.rtss.entity.RaceQuestion" useGeneratedKeys="true">
insert into race_question
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="topic != null">
topic,
</if>
<if test="type != null">
`type`,
</if>
<if test="createUserId != null">
create_user_id,
</if>
<if test="createTime != null">
create_time,
</if>
<if test="projectCode != null">
project_code,
</if>
<if test="companyId != null">
company_id,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="topic != null">
#{topic,jdbcType=VARCHAR},
</if>
<if test="type != null">
#{type,jdbcType=VARCHAR},
</if>
<if test="createUserId != null">
#{createUserId,jdbcType=BIGINT},
</if>
<if test="createTime != null">
#{createTime,jdbcType=TIMESTAMP},
</if>
<if test="projectCode != null">
#{projectCode,jdbcType=VARCHAR},
</if>
<if test="companyId != null">
#{companyId,jdbcType=INTEGER},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="club.joylink.rtss.entity.RaceQuestionExample" resultType="java.lang.Long">
select count(*) from race_question
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</select>
<update id="updateByExampleSelective" parameterType="map">
update race_question
<set>
<if test="record.id != null">
id = #{record.id,jdbcType=BIGINT},
</if>
<if test="record.topic != null">
topic = #{record.topic,jdbcType=VARCHAR},
</if>
<if test="record.type != null">
`type` = #{record.type,jdbcType=VARCHAR},
</if>
<if test="record.createUserId != null">
create_user_id = #{record.createUserId,jdbcType=BIGINT},
</if>
<if test="record.createTime != null">
create_time = #{record.createTime,jdbcType=TIMESTAMP},
</if>
<if test="record.projectCode != null">
project_code = #{record.projectCode,jdbcType=VARCHAR},
</if>
<if test="record.companyId != null">
company_id = #{record.companyId,jdbcType=INTEGER},
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByExample" parameterType="map">
update race_question
set id = #{record.id,jdbcType=BIGINT},
topic = #{record.topic,jdbcType=VARCHAR},
`type` = #{record.type,jdbcType=VARCHAR},
create_user_id = #{record.createUserId,jdbcType=BIGINT},
create_time = #{record.createTime,jdbcType=TIMESTAMP},
project_code = #{record.projectCode,jdbcType=VARCHAR},
company_id = #{record.companyId,jdbcType=INTEGER}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByPrimaryKeySelective" parameterType="club.joylink.rtss.entity.RaceQuestion">
update race_question
<set>
<if test="topic != null">
topic = #{topic,jdbcType=VARCHAR},
</if>
<if test="type != null">
`type` = #{type,jdbcType=VARCHAR},
</if>
<if test="createUserId != null">
create_user_id = #{createUserId,jdbcType=BIGINT},
</if>
<if test="createTime != null">
create_time = #{createTime,jdbcType=TIMESTAMP},
</if>
<if test="projectCode != null">
project_code = #{projectCode,jdbcType=VARCHAR},
</if>
<if test="companyId != null">
company_id = #{companyId,jdbcType=INTEGER},
</if>
</set>
where id = #{id,jdbcType=BIGINT}
</update>
<update id="updateByPrimaryKey" parameterType="club.joylink.rtss.entity.RaceQuestion">
update race_question
set topic = #{topic,jdbcType=VARCHAR},
`type` = #{type,jdbcType=VARCHAR},
create_user_id = #{createUserId,jdbcType=BIGINT},
create_time = #{createTime,jdbcType=TIMESTAMP},
project_code = #{projectCode,jdbcType=VARCHAR},
company_id = #{companyId,jdbcType=INTEGER}
where id = #{id,jdbcType=BIGINT}
</update>
</mapper>